一个上传对话框 - 两个目标?

时间:2010-08-06 13:41:17

标签: file-upload ckeditor

使用CKeditor 3,我创建了图像处理功能:
上传接收器(filebrowserUploadUrl)和图像浏览器对话框(filebrowserBrowseUrl)
- 两者都很完美

但当然我的用户想要更多......我们有两个图像数据库:Common和Private
- 图像浏览器允许用户从中选择图像。

我的上传接收器(php)可以轻松地将新图像放入其中任何一个容器中 - 但是如何让用户选择哪一个?

三个想法 - 所有涉及修改上传对话框标签(type = file + upload-button)
通过以下方式添加目标选择器:

Using two different upload-buttons: (Upload to Common) and (Upload to Private)  
both pointing to the same filebrowserUploadUrl but adding a parameter:  
&target=C or &target=P

A couple of "radio switches": Common or Private  
- essentially doing the same: Adding &target=(P or C)  
with one of them selected by default, so the user can't break it by negligence...

Just a single checkbox: Private (or not) ~ adding &target=P (or not)

我真的尝试过(我的手指在流血,我已经愤怒地吐了两次!)但是作为一个非jQuery javascript开发者,我只是无法理解这一切。当我添加一个文本字段时,它显示正常:) - 但是实际的上传表单(在iframe中)还没有一个仍然只包含type = file字段?!?

所以我很欣赏如何修改upload-dialog-tab来完成它的例子?

我已准备好启动平台(我认为):

CKEDITOR.on( 'dialogDefinition',
 function( ev )
 {
 var dialogName = ev.data.name;
 var dialogDefinition = ev.data.definition;

 if ( dialogName == 'image' )
   {
   var infoTab = dialogDefinition.getContents( 'Upload' );
   infoTab.add({

     what ?

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题,但确实不得不对它嗤之以鼻:)

我认为这里的CKeditor可能存在错误(或者可能是设计上的..) 添加新字段(无论是在image.js中还是通过CKEDITOR.on('dialogDefinition'..),它们只是不会转换为iframe中实际上传表单上的新字段。(错误或功能?)

所以,我在/plugins/image/dialogs/image.js添加了一个复选框(私有?不是) 在文件字段和按钮之间的(id:'Upload')部分,使用onClick-event执行业务,这很难:

{
    type : 'checkbox',
    id : 'PrivateFlag',
    label: 'Private',
    checked : false,
    onClick: function()
       {
       var theFrame = document.getElementById("125_fileInput");
       var theDoc = theFrame.contentDocument || theFrame.contentWindow.document;
       var theForm = theDoc.forms[0];
       var action = theForm.getAttribute("action"); // alert("pre:"+theForm.getAttribute("action"));

       if (action.indexOf("&target=P") == -1)
          action += "&target=P";
       else
          action = action.replace("&target=P","");

       theForm.setAttribute("action",action); // alert("post: "+theForm.getAttribute("action"));
       }
},

它有效(至少只要iframe的id为“125_fileInput”)

IE修改(当然):

if (navigator.appName == 'Microsoft Internet Explorer') // aka BrokenTurd
    {
    var theFrame = document.frames[1]; // may be inaccurate in your case..
    var theDoc = theFrame.document;
    }
else
    {
    var theFrame = document.getElementById("125_fileInput");
    var theDoc = theFrame.contentDocument || theFrame.contentWindow.document;
    }
相关问题