imce_rename.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //implementation of imce.hookOpSubmit
  2. imce.renameOpSubmit = function(dop) {
  3. if (imce.fopValidate('rename')) {
  4. imce.fopLoading('rename', true);
  5. jQuery.ajax(jQuery.extend(imce.fopSettings('rename'), {success: imce.renameResponse}));
  6. }
  7. };
  8. //add hook.load
  9. imce.hooks.load.push(function() {
  10. //set click function for rename tab to toggle crop UI
  11. imce.ops['rename'].func = imce.renamePrepare;
  12. });
  13. //populate the text box with the current file or dir name
  14. imce.renamePrepare = function(response) {
  15. var i = 0;
  16. for (var fid in imce.selected) {
  17. jQuery('#edit-new-name').val(unescape(imce.selected[fid].id));
  18. i++;
  19. }
  20. if (i == 0) {
  21. jQuery('#edit-new-name').val(unescape(imce.conf.dir));
  22. }
  23. if (i > 1) {
  24. imce.setMessage(Drupal.t('Only one file can be renamed at a time.'), 'error');
  25. setTimeout(function() {jQuery('#op-close-link').click();}, 5);
  26. }
  27. //hack to make renaming of directories possible
  28. if (imce.selcount == 0) {
  29. imce.selcount = 1;
  30. imce.selected['__IS_DIR__'] = '__IS_DIR__';
  31. }
  32. };
  33. //custom response. keep track of overwritten files.
  34. imce.renameResponse = function(response) {
  35. imce.processResponse(response);
  36. imce.vars.cache = false;
  37. imce.navigate('.'); //should be folder parent and only trigger when a dir is renamed.
  38. jQuery('#op-close-link').click(); //there is probably a better way to close the dialog than this.
  39. };