2013-01-30 07:13:38 +01:00
|
|
|
var parseFiles = function(files, cb) {
|
|
|
|
var cnt = 0;
|
|
|
|
var txts = [];
|
|
|
|
var onload = function(res) {
|
|
|
|
var txt = res.target.result;
|
|
|
|
txts.push(txt.split(',')[1]);
|
|
|
|
cnt--;
|
|
|
|
if (!cnt) {
|
|
|
|
cb(txts);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_.each(files, function(file) {
|
|
|
|
cnt++;
|
|
|
|
console.log('starting file reader');
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = onload;
|
|
|
|
reader.onerror = function(err) {
|
|
|
|
// return error
|
|
|
|
// TODO: find a better way to propogate error upstream
|
|
|
|
console.log('got back error', err);
|
|
|
|
cb([]);
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-01-29 13:47:40 +01:00
|
|
|
angular
|
|
|
|
.module('webui.ctrls.modal', [
|
2013-01-29 18:52:30 +01:00
|
|
|
'webui.services.rpc', 'webui.services.deps', 'webui.services.modals'
|
2013-01-29 13:47:40 +01:00
|
|
|
])
|
2013-01-29 18:52:30 +01:00
|
|
|
.controller('ModalCtrl', [
|
|
|
|
'$_', '$scope', '$rpc', '$modals',
|
|
|
|
function(_, scope, rpc, modals) {
|
|
|
|
|
|
|
|
scope.getUris = {
|
|
|
|
cb: null,
|
|
|
|
shown: false,
|
2013-01-30 07:13:38 +01:00
|
|
|
|
|
|
|
uris: '',
|
2013-01-29 18:52:30 +01:00
|
|
|
parse: function() {
|
|
|
|
return _
|
|
|
|
.chain(this.uris.trim().split(/\n\r?/g))
|
|
|
|
.map(function(d) { return d.trim().split(/\s+/g) })
|
|
|
|
.filter(function(d) { return d.length })
|
|
|
|
.value();
|
|
|
|
},
|
|
|
|
finish: function() {
|
|
|
|
var uris = this.parse();
|
|
|
|
this.uris = '';
|
2013-01-15 09:24:09 +01:00
|
|
|
|
2013-01-29 18:52:30 +01:00
|
|
|
if (this.cb) this.cb(uris);
|
2013-01-28 15:18:21 +01:00
|
|
|
|
2013-01-29 18:52:30 +01:00
|
|
|
this.cb = null;
|
|
|
|
this.shown = false;
|
|
|
|
}
|
2013-01-28 15:18:21 +01:00
|
|
|
};
|
2013-01-30 07:13:38 +01:00
|
|
|
|
|
|
|
_.each(['getTorrents', 'getMetalinks'], function(name) {
|
|
|
|
scope[name] = {
|
|
|
|
cb: null,
|
|
|
|
shown: false,
|
|
|
|
|
|
|
|
files: [],
|
|
|
|
finish: function() {
|
|
|
|
var self = this;
|
|
|
|
console.log('parsing files');
|
|
|
|
parseFiles(self.files, function(txts) {
|
|
|
|
console.log('calling cb', this.cb);
|
|
|
|
if (self.cb) self.cb(txts);
|
|
|
|
|
|
|
|
self.cb = null;
|
|
|
|
self.shown = false;
|
|
|
|
});
|
|
|
|
}
|
2013-01-29 18:52:30 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-01-30 07:13:38 +01:00
|
|
|
_.each(['getUris', 'getTorrents', 'getMetalinks'], function(name) {
|
|
|
|
modals.register(name, function(cb) {
|
|
|
|
if (scope[name].cb != null && scope[name].shown) {
|
|
|
|
// modal already shown, user is busy
|
|
|
|
// TODO: get a better method of passing this on
|
|
|
|
cb([]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('setting cb for ', name, cb);
|
|
|
|
scope[name].cb = cb;
|
|
|
|
scope[name].shown = true;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-15 09:24:09 +01:00
|
|
|
}]);
|