global settings partially working in angular

This commit is contained in:
hamza zia 2013-02-20 14:12:55 +01:00
parent 1a3ddf5089
commit 30ae20260f
4 changed files with 64 additions and 52 deletions

View File

@ -304,7 +304,7 @@
<!--{{{ add new Download template --> <!--{{{ add new Download template -->
<div class="modal hide modal-adduris" modal="getUris.shown"> <div class="modal hide modal-adduris" modal="getUris.shown">
<div class="modal-header"> <div class="modal-header">
<button class="close" ng-click="getUris.shown = false">x</button> <button class="close" ng-click="getUris.close()">x</button>
<h3>Add Downloads By URIs</h3> <h3>Add Downloads By URIs</h3>
</div> </div>
<form class="modal-body"> <form class="modal-body">
@ -337,8 +337,8 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</fieldset> </fieldset>
</form> </form>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" ng-click="getUris.shown = false">Cancel</button> <button class="btn" ng-click="getUris.close()">Cancel</button>
<button class="btn btn-primary" ng-click="getUris.finish()">Start</button> <button class="btn btn-primary" ng-click="getUris.success()">Start</button>
</div> </div>
</div> </div>
<!-- }}} --> <!-- }}} -->
@ -346,7 +346,7 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<!-- {{{ add new torrent --> <!-- {{{ add new torrent -->
<div class="modal hide" modal="getTorrents.shown"> <div class="modal hide" modal="getTorrents.shown">
<div class="modal-header"> <div class="modal-header">
<button class="close" ng-click="getTorrents.shown = false">x</button> <button class="close" ng-click="getTorrents.close()">x</button>
<h3>Add Downloads By Torrents</h3> <h3>Add Downloads By Torrents</h3>
</div> </div>
<form class="modal-body"> <form class="modal-body">
@ -363,8 +363,8 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</fieldset> </fieldset>
</form> </form>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" ng-click="getTorrents.shown = false">Cancel</button> <button class="btn" ng-click="getTorrents.close()">Cancel</button>
<button class="btn btn-primary" ng-click="getTorrents.finish()">Start</button> <button class="btn btn-primary" ng-click="getTorrents.success()">Start</button>
</div> </div>
</div </div
<!-- }}} --> <!-- }}} -->
@ -372,7 +372,7 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<!-- {{{ add new metalink --> <!-- {{{ add new metalink -->
<div class="modal hide" modal="getMetalinks.shown"> <div class="modal hide" modal="getMetalinks.shown">
<div class="modal-header"> <div class="modal-header">
<button class="close" ng-click="getMetalinks.shown = false">x</button> <button class="close" ng-click="getMetalinks.close()">x</button>
<h3>Add Downloads By Metalinks</h3> <h3>Add Downloads By Metalinks</h3>
</div> </div>
<form class="modal-body"> <form class="modal-body">
@ -387,8 +387,8 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</fieldset> </fieldset>
</form> </form>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" ng-click="getMetalinks.shown = false">Cancel</button> <button class="btn" ng-click="getMetalinks.close()">Cancel</button>
<button class="btn btn-primary" ng-click="getMetalinks.finish()">Start</button> <button class="btn btn-primary" ng-click="getMetalinks.success()">Start</button>
</div> </div>
</div </div
<!-- }}} --> <!-- }}} -->
@ -396,7 +396,7 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<!-- {{{ global settings --> <!-- {{{ global settings -->
<div class="modal hide" modal="globalSettings.shown"> <div class="modal hide" modal="globalSettings.shown">
<div class="modal-header"> <div class="modal-header">
<button class="close" ng-click="globalSettings.shown = false">x</button> <button class="close" ng-click="globalSettings.close()">x</button>
<h3>Global Settings</h3> <h3>Global Settings</h3>
</div> </div>
@ -404,16 +404,14 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<fieldset> <fieldset>
<legend>Global Settings</legend> <legend>Global Settings</legend>
<div class="control-group"> <div class="control-group">
<div ng-repeat="(name, val) in globalSettings.settings"> <div ng-repeat="(name, set) in globalSettings.settings">
<label class="control-label">{{name}}</label> <label class="control-label">{{name}}</label>
<div class="controls"> <div class="controls">
<select ng-show="val.options.length"> <select ng-show="set.options.length" ng-options="opt for opt in set.options" ng-model="set.val">
<option ng-repeat="opt in val.options" value="{{opt}}">{{opt}}</option>
</select> </select>
<input ng-show="!val.options.length" typ="text" class="input-xlarge" placeholder="{{val.val}}"/> <input ng-show="!set.options.length" typ="text" class="input-xlarge" ng-model="set.val"/>
<p class="help-block">{{set.desc}}</p>
<p class="help-block">{{val.desc}}</p>
</div> </div>
<br><br> <br><br>
</div> </div>
@ -422,8 +420,8 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</form> </form>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" ng-click="globalSettings.shown = false">Cancel</button> <button class="btn" ng-click="globalSettings.close()">Cancel</button>
<button class="btn btn-primary">Save</button> <button class="btn btn-success" ng-click="globalSettings.success()">Save</button>
</div> </div>
</div </div
<!-- }}} --> <!-- }}} -->

View File

@ -30,8 +30,8 @@ angular
'webui.services.settings' 'webui.services.settings'
]) ])
.controller('ModalCtrl', [ .controller('ModalCtrl', [
'$_', '$scope', '$rpc', '$modals', '$settings', '$_', '$scope', '$rpc', '$modals',
function(_, scope, rpc, modals, settings) { function(_, scope, rpc, modals) {
scope.getUris = { scope.getUris = {
shown: false, shown: false,
@ -45,14 +45,18 @@ angular
.filter(function(d) { return d.length }) .filter(function(d) { return d.length })
.value(); .value();
}, },
finish: function() { success: function() {
var uris = this.parse(); var uris = this.parse();
this.uris = ''; this.uris = '';
if (this.cb) this.cb(uris); if (this.cb) this.cb(uris);
this.close();
},
close: function() {
this.shown = this.open = false;
this.cb = null; this.cb = null;
this.shown = false;
} }
}; };
@ -62,16 +66,19 @@ angular
init: function(cb) { this.shown = true; this.cb = cb }, init: function(cb) { this.shown = true; this.cb = cb },
files: [], files: [],
finish: function() { success: function() {
var self = this; var self = this;
console.log('parsing files'); console.log('parsing files');
parseFiles(self.files, function(txts) { parseFiles(self.files, function(txts) {
console.log('calling cb', this.cb); console.log('calling cb', this.cb);
if (self.cb) self.cb(txts); if (self.cb) self.cb(txts);
self.cb = null; self.close();
self.shown = false;
}); });
},
close: function() {
this.cb = null;
this.shown = false;
} }
}; };
}); });
@ -79,26 +86,18 @@ angular
scope.globalSettings = { scope.globalSettings = {
shown: false, shown: false,
settings: [], settings: [],
init: function(cb) { init: function(settings, cb) {
var self = this; this.cb = cb;
self.cb = cb; this.settings = settings;
this.shown = true;
rpc.once('getGlobalOption', [], function(data) {
var vals = data[0];
for (var i in vals) {
if (!(i in data)) {
data.push({ name: i, val: vals[i], desc: '' });
}
else data[i].val = vals[i];
}
console.log(vals);
self.shown = true;
});
self.settings = settings;
}, },
finish: function() { success: function() {
if (this.cb) this.cb(this.settings);
this.close();
},
close: function() {
this.cb = null;
this.shown = this.open = false;
} }
}; };
@ -107,14 +106,13 @@ angular
'globalSettings' 'globalSettings'
], function(name) { ], function(name) {
modals.register(name, function(cb) { modals.register(name, function(cb) {
if (scope[name].open) { if (scope[name].open && scope[name].cb) {
// modal already shown, user is busy // modal already shown, user is busy
// TODO: get a better method of passing this info // TODO: get a better method of passing this info
cb([]); cb([]);
} }
else { else {
var args = Array.prototype.slice.call(arguments, 0); var args = Array.prototype.slice.call(arguments, 0);
console.log('setting cb for ', name, cb);
scope[name].open = true; scope[name].open = true;
scope[name].init.apply(scope[name], args); scope[name].init.apply(scope[name], args);
}; };

View File

@ -1,11 +1,12 @@
angular angular
.module('webui.ctrls.nav', [ .module('webui.ctrls.nav', [
'webui.services.constants', 'webui.services.modals', 'webui.services.constants', 'webui.services.modals',
'webui.services.rpc.helpers' 'webui.services.rpc', 'webui.services.rpc.helpers',
'webui.services.settings'
]) ])
.controller('NavCtrl', [ .controller('NavCtrl', [
'$scope', '$name', '$modals', '$rpchelpers', '$scope', '$name', '$modals', '$rpc', '$rpchelpers', '$settings',
function(scope, name, modals, rhelpers) { function(scope, name, modals, rpc, rhelpers, settings) {
scope.name = name; scope.name = name;
@ -37,8 +38,23 @@ angular
}; };
scope.changeGSettings = function() { scope.changeGSettings = function() {
modals.invoke('globalSettings', function() { rpc.once('getGlobalOption', [], function(data) {
alert('closing dialog'); var vals = data[0];
for (var i in vals) {
if (!(i in settings)) {
settings[i] = { name: i, val: vals[i], desc: '' };
}
else {
settings[i].val = vals[i];
}
}
modals.invoke('globalSettings', settings, function(settings) {
var sets = {};
for (var i in settings) { sets[i] = settings[i].val };
rpc.once('changeGlobalOption', [sets]);
});
}); });
}; };

View File

@ -84,7 +84,7 @@ angular.module('webui.services.settings', [])
}, },
"bt-prioritize-piece": { "bt-prioritize-piece": {
val: '1M', val: '',
desc: "Try to download first and last pieces of each file first. This is useful for previewing files. The argument can contain 2 keywords: head and tail. To include both keywords, they must be separated by comma. These keywords can take one parameter, SIZE. For example, if head=<SIZE> is specified, pieces in the range of first SIZE bytes of each file get higher priority. tail=<SIZE> means the range of last SIZE bytes of each file. SIZE can include K or M (1K = 1024, 1M = 1024K). If SIZE is omitted, SIZE=1M is used." desc: "Try to download first and last pieces of each file first. This is useful for previewing files. The argument can contain 2 keywords: head and tail. To include both keywords, they must be separated by comma. These keywords can take one parameter, SIZE. For example, if head=<SIZE> is specified, pieces in the range of first SIZE bytes of each file get higher priority. tail=<SIZE> means the range of last SIZE bytes of each file. SIZE can include K or M (1K = 1024, 1M = 1024K). If SIZE is omitted, SIZE=1M is used."
}, },