2013-01-29 18:52:30 +01:00
|
|
|
angular.module('webui.services.rpc.helpers', [
|
|
|
|
'webui.services.deps', 'webui.services.rpc'
|
|
|
|
])
|
|
|
|
.factory('$rpchelpers', ['$_', '$rpc', function(_, rpc) {
|
|
|
|
return {
|
|
|
|
addUris: function(uris) {
|
|
|
|
var cnt = 0;
|
2013-01-30 04:52:01 +01:00
|
|
|
var cb = function(ret) {
|
2013-01-29 18:52:30 +01:00
|
|
|
cnt--;
|
|
|
|
if (!cnt) {
|
|
|
|
// close modal
|
|
|
|
console.log('closing modal');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_.each(uris, function(uri) {
|
|
|
|
cnt++;
|
|
|
|
// passing true to batch all the addUri calls
|
2013-01-30 04:52:01 +01:00
|
|
|
rpc.once('addUri', [uri], cb, true);
|
2013-01-29 18:52:30 +01:00
|
|
|
});
|
|
|
|
|
2013-01-30 07:13:38 +01:00
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
},
|
|
|
|
addTorrents: function(txts) {
|
|
|
|
var cnt = 0;
|
|
|
|
var cb = function(ret) {
|
|
|
|
cnt--;
|
|
|
|
if (!cnt) {
|
|
|
|
// close modal
|
|
|
|
console.log('closing modal');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_.each(txts, function(txt) {
|
|
|
|
cnt++;
|
|
|
|
// passing true to batch all the addUri calls
|
|
|
|
rpc.once('addTorrent', [txt], cb, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
},
|
|
|
|
addMetalinks: function(txts) {
|
|
|
|
var cnt = 0;
|
|
|
|
var cb = function(ret) {
|
|
|
|
cnt--;
|
|
|
|
if (!cnt) {
|
|
|
|
// close modal
|
|
|
|
console.log('closing modal');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_.each(txts, function(txt) {
|
|
|
|
cnt++;
|
|
|
|
// passing true to batch all the addUri calls
|
|
|
|
rpc.once('addMetalink', [txt], cb, true);
|
|
|
|
});
|
|
|
|
|
2013-01-29 18:52:30 +01:00
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|