Get not loaded UIDs if select all is used.

This commit is contained in:
Hadi Nategh 2014-09-23 08:57:54 +00:00
parent d83d3db364
commit 22f8e05d5f
2 changed files with 91 additions and 52 deletions

View File

@ -568,6 +568,17 @@ app.classes.addressbook = AppJS.extend(
*/ */
addEmail: function(action, selected) addEmail: function(action, selected)
{ {
// Check for all selected.
var nm = this.et2.getWidgetById('nm');
if(fetchAll(selected, nm, jQuery.proxy(function(ids) {
// fetchAll() returns just the ID, no prefix, so map it to match normal selected
this.addEmail(action, ids.map(function(num) {return {id:'addressbook::'+num};}));
}, this)))
{
// Need more IDs, will use the above callback when they're ready.
return;
}
// Go through selected & pull email addresses from data // Go through selected & pull email addresses from data
var emails = []; var emails = [];
for(var i = 0; i < selected.length; i++) for(var i = 0; i < selected.length; i++)

View File

@ -117,7 +117,7 @@ function nm_action(_action, _senders, _target, _ids)
// Run a long task once for each ID with a nice dialog instead of // Run a long task once for each ID with a nice dialog instead of
// freezing for a while. If egw_open is set, and only 1 row selected, // freezing for a while. If egw_open is set, and only 1 row selected,
// egw_open will be used instead. // egw_open will be used instead.
if(doLongTask(idsArr, _action, mgr)) break; if(doLongTask(idsArr, ids.all,_action, mgr.data.nextmatch)) break;
// Fall through // Fall through
case 'egw_open': case 'egw_open':
@ -221,16 +221,23 @@ function nm_action(_action, _senders, _target, _ids)
} }
break; break;
} }
}
function doLongTask(idsArr, _action, mgr) /**
{ * Fetch all IDs to the client side, user wants to do something with them...
if(idsArr.length > 1 || typeof _action.data.egw_open == 'undefined') *
{ * @param {string[]} ids Array of selected IDs
if(_ids.all) * @param {et2_nextmatch} nextmatch
{ * @param {function} callback Callback function
* @returns {Boolean}
*/
function fetchAll(ids, nextmatch, callback)
{
if(!nextmatch || !nextmatch.controller) return false;
var selection = nextmatch.getSelection();
if(!selection.all) return false;
var nextmatch = mgr.data.nextmatch; if(nextmatch.controller._grid && nextmatch.controller._grid.getTotalCount() > ids.length)
if(nextmatch && nextmatch.controller && nextmatch.controller._grid && nextmatch.controller._grid.getTotalCount() > idsArr.length)
{ {
// Need to actually fetch all (TODO: just ids) to do this client side // Need to actually fetch all (TODO: just ids) to do this client side
var idsArr = []; var idsArr = [];
@ -264,20 +271,41 @@ function nm_action(_action, _senders, _target, _ids)
dialog.destroy(); dialog.destroy();
if(!cancel) if(!cancel)
{ {
et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr); callback.call(this, idsArr);
} }
} }
},_action); },this);
count += 200; count += 200;
} while (count < total) } while (count < total)
return true; return true;
} }
return false;
}
/**
* Fetch all IDs and run a long task.
*
* @param {String[]} idsArr Array of IDs
* @param {boolean} all True if all IDs are selected. They'll have to be fetched if missing.
* @param {type} _action
* @param {et2_nextmatch} nextmatch
* @returns {Boolean}
*/
function doLongTask(idsArr, all, _action, nextmatch)
{
if(all || idsArr.length > 1 || typeof _action.data.egw_open == 'undefined')
{
if(all)
{
var fetching = fetchAll(idsArr, nextmatch,function(idsArr){
et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr);
});
if(fetching) return true;
} }
et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr); et2_dialog.long_task(null,_action.data.message||_action.caption,_action.data.title,_action.data.menuaction,idsArr);
return true; return true;
} }
return false; return false;
}
} }
/** /**