simple refinement for rpc helpers in angular

This commit is contained in:
hamza zia 2013-03-09 05:44:37 +00:00
parent 0060d884d3
commit 949534ccf2

View File

@ -4,54 +4,28 @@ angular.module('webui.services.rpc.helpers', [
.factory('$rpchelpers', ['$_', '$rpc', '$alerts', function(_, rpc, alerts) { .factory('$rpchelpers', ['$_', '$rpc', '$alerts', function(_, rpc, alerts) {
return { return {
addUris: function(uris) { addUris: function(uris) {
var cnt = 0;
var cb = function(data) {
cnt--;
if (!cnt) {
// close modal
console.log('closing modal');
}
};
_.each(uris, function(uri) { _.each(uris, function(uri) {
cnt++;
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addUri', [uri], cb, true); rpc.once('addUri', [uri], angular.noop, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls
rpc.forceUpdate(); rpc.forceUpdate();
}, },
addTorrents: function(txts) { addTorrents: function(txts) {
var cnt = 0;
var cb = function(data) {
cnt--;
if (!cnt) {
// close modal
console.log('closing modal');
}
};
_.each(txts, function(txt) { _.each(txts, function(txt) {
cnt++;
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addTorrent', [txt], cb, true); rpc.once('addTorrent', [txt], angular.noop, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls
rpc.forceUpdate(); rpc.forceUpdate();
}, },
addMetalinks: function(txts) { addMetalinks: function(txts) {
var cnt = 0;
var cb = function(data) {
cnt--;
if (!cnt) {
// close modal
console.log('closing modal');
}
};
_.each(txts, function(txt) { _.each(txts, function(txt) {
cnt++;
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addMetalink', [txt], cb, true); rpc.once('addMetalink', [txt], angular.noop, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls