From 88c7fa9d99a5221b9c01798446416545718f4239 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 23 May 2012 19:24:03 +0200 Subject: [PATCH] Issue #1591410: Implemented backwards compatible way to support multiple file insert. --- js/imce.js | 31 +++++++++++++++++++++++++++---- js/imce_set_app.js | 13 +++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/js/imce.js b/js/imce.js index f038087..abdc9f9 100644 --- a/js/imce.js +++ b/js/imce.js @@ -520,11 +520,34 @@ send: function (fid) { }, //add an operation for an external application to which the files are send. -setSendTo: function (title, func) { - imce.send = function (fid) { fid && func(imce.fileGet(fid), window);}; +setSendTo: function (title, func, min, max) { + // We always require a minimum of atleast 1. + if (min === undefined || min == null) { + min = 1; + } + // If no maximum is given we default to 1 which is expected behaviour from previous implementations. + // A null value is considered to be no maximum + if (max === undefined) { + max = 1; + } + + 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); + } + } + var opFunc = function () { - if (imce.selcount != 1) return imce.setMessage(Drupal.t('Please select a file.'), 'error'); - imce.send(imce.vars.prvfid); + if (imce.validateSelCount(min,max)) { + imce.send(imce.selected); + } }; imce.vars.prvtitle = title; return imce.opAdd({name: 'sendto', title: title, func: opFunc}); diff --git a/js/imce_set_app.js b/js/imce_set_app.js index 2390868..4245287 100644 --- a/js/imce_set_app.js +++ b/js/imce_set_app.js @@ -38,8 +38,17 @@ imce.hooks.load.push(function(win) { } // Set custom sendto function. appFinish is the default. var sendtoFunc = appFields.url ? appFinish : false; + + // Set min and max to undefined, passing these to setSendTo will result in default behaviour. + var min = undefined; + var max = undefined; + //check sendto@funcName syntax in URL - if (appFields.sendto && (func = isFunc(appFields.sendto))) { + if (appFields.sendto && ( + (appFields.sendto.indexOf('@') != -1 && (func = isFunc(appFields.sendto.split('@')[0])) && (min = appFields.sendto.split('@')[1]) && (max = appFields.sendto.split('@')[2])) || ( + func = isFunc(appFields.sendto) + ) + )) { sendtoFunc = func; delete appFields.sendto; } @@ -63,7 +72,7 @@ imce.hooks.load.push(function(win) { imce.highlight(filename.substr(filename.lastIndexOf('/')+1)); } // Set send to - sendtoFunc && imce.setSendTo(Drupal.t('Insert file'), sendtoFunc); + sendtoFunc && imce.setSendTo(Drupal.t('Insert file'), sendtoFunc, min, max); }); // Default sendTo function -- 1.7.10.2