The function imce.setSendTo allows to send only one file to the requesting application.
I would like to send more that one file.
In the README.txt file, it is written :

~~~~~~~ADVANCED INTEGRATION~~~~~~~~~
In case:
...
- Your application wants IMCE to send multiple files to it.(e.g., a gallery application)
...
Then you should consider applying advanced integration.

So it seems that it should be possible to send several images.
I tried this code (issued from imceImage) :

imceImage.open = function (url, field) {
 imceImage.pop = window.open(url, '', 'width=860,height=600,resizable=1');
   imceImage.pop['imceOnLoad'] = function (win) {
         win.imce.opAdd({name:'multiSendTo', title: Drupal.t('Add images to album'), func:imceImage.multiInsert( win)});
  
           }

              imceImage.pop.focus();  
}
imceImage.multiInsert = function ( win){
        console.debug(win.imce);
        var imce = win.imce;
        var op=$(imce.el('op-item-multiSendTo'));       
        var button=op.find('a');
        console.log(button);
        button.click(function (){
                console.debug(win.imce.selected);
                for (var fid in win.imce.selected){
                    var file = win.imce.fileGet(fid);
                   imceImage.insert (file,win);
                 }
                win.close();
        });
}

The problem is that in fact the button variable not corresponds to the list of tags of the imce window, but to the list of tags of the content form in which I called imce.
Is it the good way to make what I described before ?
How do I access to the button and add the click function ?

Comments

ufku’s picture

We open IMCE and set its onload function:

window.open('/?q=imce&app=myApp|imceload@initiateMyApp', '', 'width=760,height=560,resizable=1'); //initiateMyApp(win) will run when imce loads

Now we define our initiator function in which we do the necessary manipulations to IMCE interface:

initiateMyApp = function (win) {
  var imce = win.imce;
  ...use imce methods to add/remove/change things...
}

You should pass your onload function in the URL. Setting imceOnLoad property of popup object is deprecated because of limited support by browsers.

Inside onload function define your file operation

imce.opAdd({
  name: 'name',
  title: Drupal.t('title'),
  func: function() {
    // iterate over selected files
    for (var fid in imce.selected) {
      var file = imce.fileGet(fid);
      alert(file.toString());
    }
  }
});
lucuhb’s picture

Thanks for your response. I didn't know why ImceImage was noted as deprecated : is it for this problem of setting imceOnLoad of popup object ?

ufku’s picture

Status: Active » Fixed

I have no idea why imceimage deprecated. I'm not a maintainer of that module.

lucuhb’s picture

Status: Fixed » Closed (fixed)

As you says, I used the imceload on the url. Now all work. Thanks.

gregarios’s picture

Priority: Normal » Major
Status: Closed (fixed) » Active

Is there any way one of you with the "working" code could attach the whole "imceimage.js" file to this thread please?

lucuhb’s picture

You will find this on this imceimage thread : #1006108: IMCEImage for multi-elements field

ufku’s picture

Status: Active » Closed (won't fix)