Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kingdutch’s picture

The following patch will patch imce_filefield to allow for multiple files to be inserted at once.

This is related to #1591410: Insert multiple files

Kingdutch’s picture

Status: Active » Needs review
FileSize
3.84 KB

Patch didn't attach

kressin’s picture

Patch does not seem to work.

Kingdutch’s picture

Have you applied the patch in the referenced issue as well?

kressin’s picture

I applied the patch to imce.js and got the following result:

File to patch: imce.js
patching file imce.js
Hunk #1 FAILED at 38.
Hunk #2 FAILED at 72.

kressin’s picture

Seems like for some reason I got a different code in the patch file I downloaded from the patchfile @ #2. is this a two parted patch for imce and imce for filefield?

kressin’s picture

ok, sorry. did not see the patch was for imce.js and mice_set_app.js. patch worked but now the "insert" button in imce file browser no longer responds.

kressin’s picture

I get the error

Error: file is null

and it points to:

if ((',' + exts + ',').indexOf(',' + file.name.substr(file.name.lastIndexOf('.') + 1).toLowerCase() + ',') < 0) {

kressin’s picture

Hi Kingdutch,

been trying to figure out the problem for the last 24 hours. My best guess is that it might be a conflict with IMCE permitted extensions. I would be very grateful for your advice.

Thanks

kressin’s picture

Still trying to get this to work. Is it working for anyone?

Thanks

Rory’s picture

No luck. It doesn't work. The "insert" button does nothing now for me as well.

Rory’s picture

I think the problem lies with the other related patch that you have to apply to IMCE for this.

Because after *both* patches the files aren't even received at the point below, files[] is always empty. So it seems after both patches any selected files aren't being sent from the IMCE module to IMCE for FileField for this function there, if I'm not confused.

...
/**
 * Sendto callback for IMCE.
 */
imce_filefield.sendto = function(files, win) {
  $.each(files, function (index) {
...
Rory’s picture

Yep. It was an issue with the other patch. After applying it, look for the bunch of code that gets created in imce.js:

...
  if (max == 1) {
    imce.send = function (fid) { fid && func(imce.fileGet(fid), window);};
  }
  else {
    imce.send = function (fids) { 
      var fToSend = [];
      $.each(fids, function (index, value) {
        fToSend.push(imce.fileGet(value));
      });
      func(fToSend, window);
    }
  }
...

And the following line:
fToSend.push(imce.fileGet(value));
Change it to:
fToSend.push(imce.fileGet(index));

Then behold! It should work.

kressin’s picture

Unless I am missing something essential the code is not working for me. I replaced

fToSend.push(imce.fileGet(value));

with

fToSend.push(imce.fileGet(index));

at line 541 in imce.js

but when I try to insert multiple files I still get

"please choose one file" as an error.

What am I doing wrong? Any idea?

kressin’s picture

"insert" button went missing too.

kressin’s picture

It WORKS!!!!!!

Patching went wrong and now it works! Great job! thanks a lot for the superb code and help!!!

dimitriseng’s picture

Using the latest dev versions of both imce and imce_filefield. I have used the patches in this and the related imce issue and also made the change mentioned in #14. However, this does not work for me. When all of the patches are applied, I cannot even add a single file. I have tested with both an image and a file field, would this work for both?

Note that I had to apply the patches manually as they did not apply cleanly, they might need to be rolled out against the latest devs.

Any advice would be appreciated, thank you!

Rory’s picture

@dimitrisend - I've re-rolled and attached the patches for you. Apply these to the latest 7.x-1.x-dev versions of IMCE and IMCE FileField:

  • imce-7.x-1.x-dev.zip (commit ref: f1eca6e... November 29, 2012 - 01:01)
  • imce_filefield-7.x-1.x-dev.zip (commit ref: 2dade8b... September 25, 2012 - 00:39)

I've included the code change I found so all you have to do is apply the patches. I've also tested them successfully on a Drupal 7.18 installation.

Remember when configuring the file field (under 'Structure' > 'Content types' > 'manage fields') ensure you configure the maximum number of values users can enter for the field (under 'Field settings' > 'Number of values') consistent with the amount of files you wish to insert or you will encounter an error. For testing purposes I set this to 'Unlimited'. Secondly per the instructions in the IMCE FileField README don't forget to check 'Allow users to select files from IMCE File Browser for this field.'

@ufku - it would be good to hear your thoughts on these patches to IMCE and IMCE FileField. They demonstrate an impressive amount work to marry the two modules (thanks most in part to Kingdutch).

dimitriseng’s picture

@Rory - Thank you very much for all your great work on this issue!

I am using the latest dev versions of both imce and imce_filefield on D7.19, and using media 2.x. I can confirm that both patches apply ok. I have done some testing and it looks like this is working now and it is possible to upload multiple images, thank you!!

I only found one minor issue, which might be confusing the users, which is described below:

WITHOUT the 2 patches applied, I could insert a file in 2 ways:
1) Select a single file and press the "Insert" button.
2) Double click on a file to insert.
- Note: Only 1 file could be added at a time.

WITH the 2 patches applied, I would expect to be able to insert files in the following 3 ways:
1) Select a single file and press the "Insert" button. (default functionality)
2) Double click on a file. (default functionality)
3) Select multiple images and press the "Insert" button, which should insert all the selected imaged (functionality added by the 2 patches)

Option 1 still works ok. Option 3, which is the new functionality added by the patches, is also working, which is great. However, option 2 does not seem to be working for me any more. If I double click on a file then nothing happens. Moreover, if I double click on a file, then I am also not able to insert files using options 1 and 3 as well. I need to close the form and get back in in oder to be able to use 1 and 3 again, otherwise nothing happens.

Can you please check and confirm if you get the same bahaviour as well? If this is resolved then I would be more than happy to set it to RTBC, except if this is a problem with my setup. We would also need the maintainers to review as well.

Kingdutch’s picture

The error was in the operation that handled the dblclicking not sending a list of files but a single file.
I added a patch for both modules to this post, the only change in imce_filefield is on line 25 where I moved the return to the next line for clarity's sake.

The changes in the imce module are what fix the issue described in #19.

If this is to be put through to the main modules (both imce and imce for filefield will need to be willing to incorporate the patches) it might be a good idea to run through this with the coding standards broom as I must admit that it's not my strong point.

I tested this on drupal 7.18 with the dev versions of both modules. Please post back with more findings : )

dimitriseng’s picture

@Kingdutch - Thank you very much for your initial work on this and also for the updated patches in #20. I have tested and I can confirm that the issue I described in #19 is now resolved and I believe that this is now working as expected! It is now possible to instert multiple files.

Regarding coding standards, I am no expert in this but I believe that the coder module could help.

We now really need the maintainer(s) to review these 2 patches and hopefully commit to both. I think that ukfu is the maintenair for both. I will comment in the related issue as well, #1591410: Insert multiple files

@ukfu - these 2 patches are RTBC as far as I can see, can you please review and commit if these look good to you as well? Thank you.

ufku’s picture

Status: Needs review » Needs work

You don't need to patch IMCE if you use imceload parameter in URL which allows dynamically altering the IMCE methods and UI on load.

1- Replace sendto@imce_filefield.sendto with imceload@imce_filefield.imceload in the URL

2- Define imce_filefield.imceload that adds a custom file operation and overrides double click.

imce_filefield.imceload = function(win) {
  var imce = win.imce;

  // Add a custom sendto operation
  imce.opAdd({name: 'sendto', title: Drupal.t('Insert file'), func: function() {
    var fid, file;
    // Iterate over selected files. You may check imce.selcount before
    for (fid in imce.selected) {
      file = imce.fileGet(fid);
      // Now we have the selected file we can process it just like imce_filefield.sendto does.
    }
  }});

  // Override imce.send which is called on doubleclick
  imce.send = function(fid) {
    var file = imce.fileGet(fid);
    // Now we have the selected file we can process it just like imce_filefield.sendto does.
  };
};
dimitriseng’s picture

I have applied the patches in #20 to a production site for a few days and is working really well.

@ufku - thank you for the review of the patches and the suggestion in #22 that would allow this functionality to be available only by patching imce_filefield and not requiring a patch for imce.

@Kingdutch and Rory - thank you for all your good work on this so far! Would you be able to update the patch based on the suggestions from ufku in #22, which would remove the need to patch imce? I am happy to test this when it's done, thank you!

dimitriseng’s picture

@all - I have been using the patches in #20 on a production site for a couple of weeks now and this is working really well. Please see my comments in #23, if somebody is able to provide an updated patch I am happy to test and report back, thank you!

dimitriseng’s picture

Anybody able to check and provide a patch based on #22, #23 and #24? Happy to test if a patch is provided. If the right approach is as per #22 (only make changes to this module instead of requiring changes to imce as well) then it would be great to commit the required changes to this module as at the moment I have applied the patches to both. Thank you very much for all your great work!

Kingdutch’s picture

Status: Needs work » Postponed

This has not been forgotten so I don't think it needs all the bumps. I simply haven't had the time.

Hope to be able to look at this in April/May, marking this as postponed as the current solution works even though its a bit cumbersome and not as intended.

EDIT: Messing with the wrong issue queue, if you feel my status change was inappropriate feel free to revert.

dimitriseng’s picture

Status: Postponed » Needs work

@Kingdutch - thank you for all the work you have done on this issue. I fixed the status as this still needs work and it looks like you were referring to a different issue :) As this is currently assigned to yourself, can you please confirm whether or not you are planning to have a look at this and update the patch based on @ukfu's suggestions in #22? If you don't have time that's fine, we can unassign it from you and maybe somebody else will be able to complete this and I am happy to test. Please see my comments in #23, it would be great to get this in as it is a really useful feature. Thank you!

Kingdutch’s picture

Sorry I thought I had updated this issue already but it seems I have only done so in my head ;-)

I do plan on fixing this however I'm currently busy with paid work and school so it probably won't be before april before I get around to my list of drupal tasks. If someone wants to do it before I get to it feel free to assign it to yourself and throw in a patch, otherwise it'll get done mid april.

dimitriseng’s picture

@kingdutch - Thank you for the update and for allocating time to carry out this work, I will be happy to test a new patch once you or somebody else has time to put this together! :)

dimitriseng’s picture

@kingdutch - A gentle reminder to let us know when you will be able to work on this :) I am happy to test a patch when available, thank you.

eevensen’s picture

It would mean a lot for me if you could solve the multiple file inserts using the imce_filefield module :) Please let me know if you need any help!

dimitriseng’s picture

As per my comment in #21, the approach taken in #20 is to provide patches for both the imce and imce_filefield modules which I have tested and works great. However, the maintainer of these 2 modules, ukfu, as per the post in #22 suggests that the same can be achieved by just making changes to imce_filefield and not making any changes to imce, which is his preferred approach. We now need somebody with the technical skills to follow his suggestions in #22 and patch the imce_filefield module... Happy to test when this is done! :)

dimitriseng’s picture

Anybody? :)

ufku’s picture

Assigned: Kingdutch » Unassigned
Status: Needs work » Fixed

Just committed a patch. Wait for the nightly build or download the git snapshot for testing.
Please open a separate issue if you find bugs.

dimitriseng’s picture

@ukfu - I have tested with the latest dev version of imce for FileField and this functionality is now working correctly for all 3 use cases I described in #19, thank you very much! With this latest dev version, there is no need any more to patch imce, I have tested with imce v1.7.

pavel.karoukin’s picture

FileSize
7.29 KB

@ufku, your patch works pretty well in small cases, but I had to deal with hundreds of images. Two issues:
- using GET to send all filenames not working - exceeding limit for URL length
- waiting for each file to upload taking forever

Attached very dirty patch on fixing both of these issues. I've replaced GET with POST and sending all FIDs in one request making PHP code add files.

Now... I am using $GLOBALS and very likely it might cause race condition issues and overall looks ugly, but I spent 3 hours trying to figure out how to pass values using $form_state without any luck so far. It is 6am and I have to go to bed :)

So... check it out. Maybe it will help you to enhance module a bit more :) If no - nevermind. Just wanted to share my findings.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.