added initial infrastructure for modals in angular
This commit is contained in:
parent
567d6f8179
commit
2a18278f43
12
angular.html
12
angular.html
|
@ -47,15 +47,17 @@
|
|||
<script src="js/services/deps.js"></script>
|
||||
<script src="js/services/base64.js"></script>
|
||||
<script src="js/services/utils.js"></script>
|
||||
<script src="js/services/modals.js"></script>
|
||||
|
||||
<script src="js/services/rpc/jsoncall.js"></script>
|
||||
<script src="js/services/rpc/sockcall.js"></script>
|
||||
<script src="js/services/rpc/syscall.js"></script>
|
||||
<script src="js/services/rpc/rpc.js"></script>
|
||||
<script src="js/services/rpc/helpers.js"></script>
|
||||
|
||||
|
||||
<script src="js/ctrls/nav.js"></script>
|
||||
<script src="js/ctrls/modal.js"></script>
|
||||
<script src="js/ctrls/nav.js"></script>
|
||||
<script src="js/ctrls/download.js"></script>
|
||||
|
||||
|
||||
|
@ -87,7 +89,7 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="#" data-toggle="modal" data-target=".modal-adduris">
|
||||
<a href="#" ng-click="addUris()">
|
||||
<i class="icon-download"></i> By URIs
|
||||
</a>
|
||||
</li>
|
||||
|
@ -292,7 +294,7 @@
|
|||
<div ng-controller="ModalCtrl">
|
||||
|
||||
<!--{{{ add new Download template -->
|
||||
<div class="modal hide modal-adduris">
|
||||
<div class="modal hide modal-adduris" modal="getUris.shown">
|
||||
<div class="modal-header">
|
||||
<button class="close" data-dismiss="modal">x</button>
|
||||
<h3>Add Downloads By URIs</h3>
|
||||
|
@ -300,7 +302,7 @@
|
|||
<form class="modal-body">
|
||||
<fieldset>
|
||||
<legend>Download URIs</legend>
|
||||
<textarea rows="6" ng-model="uris"></textarea>
|
||||
<textarea rows="6" ng-model="getUris.uris"></textarea>
|
||||
<p class="help-block">
|
||||
{{ uris }} <br>
|
||||
You can add multiple downloads (files)
|
||||
|
@ -328,7 +330,7 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
|
|||
</fieldset>
|
||||
</form>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" ng-click="addUris()">Add Downloads</button>
|
||||
<button class="btn" ng-click="getUris.finish()">Add Downloads</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- add new Download template end }}}-->
|
||||
|
|
|
@ -1,31 +1,42 @@
|
|||
angular
|
||||
.module('webui.ctrls.modal', [
|
||||
'webui.services.rpc', 'webui.services.deps'
|
||||
'webui.services.rpc', 'webui.services.deps', 'webui.services.modals'
|
||||
])
|
||||
.controller('ModalCtrl', ['$_', '$scope', '$rpc', function(_, scope, rpc) {
|
||||
scope.uris = '';
|
||||
scope.addUris = function() {
|
||||
console.log(scope.uris);
|
||||
var cnt = 0;
|
||||
var cb = function() {
|
||||
cnt--;
|
||||
if (!cnt) {
|
||||
// close modal
|
||||
console.log('closing modal');
|
||||
}
|
||||
};
|
||||
_.chain(scope.uris.trim().split(/\n\r?/g))
|
||||
.map(function(d) { return d.trim().split(/\s+/g) })
|
||||
.filter(function(d) { return d.length })
|
||||
.each(function(uris) {
|
||||
cnt++;
|
||||
// passing true to batch all the addUri calls
|
||||
rpc.once('addUri', [uris], cb, true);
|
||||
})
|
||||
.controller('ModalCtrl', [
|
||||
'$_', '$scope', '$rpc', '$modals',
|
||||
function(_, scope, rpc, modals) {
|
||||
|
||||
// now dispatch all addUri syscalls
|
||||
rpc.forceUpdate();
|
||||
scope.getUris = {
|
||||
cb: null,
|
||||
uris: '',
|
||||
shown: false,
|
||||
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 = '';
|
||||
|
||||
scope.uris = '';
|
||||
if (this.cb) this.cb(uris);
|
||||
|
||||
this.cb = null;
|
||||
this.shown = false;
|
||||
}
|
||||
};
|
||||
modals.register('getUris', function(cb) {
|
||||
if (scope.getUris.cb != null && scope.getUris.shown) {
|
||||
// modal already shown, user is busy
|
||||
// TODO: get a better method of passing this on
|
||||
cb([]);
|
||||
}
|
||||
else {
|
||||
scope.getUris.cb = cb;
|
||||
scope.getUris.shown = true;
|
||||
};
|
||||
});
|
||||
|
||||
}]);
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
angular
|
||||
.module('webui.ctrls.nav', ['webui.services.constants', 'webui.services.modals'])
|
||||
.controller('NavCtrl', ['$scope', '$name', '$modals', function(scope, name, modals) {
|
||||
.module('webui.ctrls.nav', [
|
||||
'webui.services.constants', 'webui.services.modals',
|
||||
'webui.services.rpc.helpers'
|
||||
])
|
||||
.controller('NavCtrl', [
|
||||
'$scope', '$name', '$modals', '$rpchelpers',
|
||||
function(scope, name, modals, rhelpers) {
|
||||
|
||||
scope.name = name;
|
||||
|
||||
// initially collapsed in mobile resolution
|
||||
scope.collapsed = true;
|
||||
|
||||
scope.addUris = function() {
|
||||
modals.invoke('getUris', rhelpers.addUris);
|
||||
};
|
||||
|
||||
}]);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('webui', [
|
||||
'webui.services.utils', 'webui.services.deps', 'webui.services.base64',
|
||||
'webui.services.constants', 'webui.services.rpc',
|
||||
'webui.services.constants', 'webui.services.rpc', 'webui.services.modals',
|
||||
'webui.filters.bytes', 'webui.filters.path',
|
||||
'webui.directives.chunkbar', 'webui.directives.dgraph',
|
||||
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal'
|
||||
|
@ -10,6 +10,7 @@ $(function() {
|
|||
angular.bootstrap(document, [
|
||||
// external deps
|
||||
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
||||
'ui.bootstrap.modal',
|
||||
'webui'
|
||||
])
|
||||
});
|
||||
|
|
18
js/services/modals.js
Normal file
18
js/services/modals.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
angular.module('webui.services.modals', [])
|
||||
.factory('$modals', function() {
|
||||
var modals = {};
|
||||
return {
|
||||
// register a new modal, cb is the function which
|
||||
// will further recieve the args when called through
|
||||
// invoke
|
||||
register: function(name, cb) {
|
||||
modals[name] = cb;
|
||||
},
|
||||
// invoke an already registered modal, false if not found
|
||||
invoke: function(name, cb) {
|
||||
if (!modals[name]) return false;
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
return modals[name].apply({}, args);
|
||||
}
|
||||
};
|
||||
});
|
25
js/services/rpc/helpers.js
Normal file
25
js/services/rpc/helpers.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
angular.module('webui.services.rpc.helpers', [
|
||||
'webui.services.deps', 'webui.services.rpc'
|
||||
])
|
||||
.factory('$rpchelpers', ['$_', '$rpc', function(_, rpc) {
|
||||
return {
|
||||
addUris: function(uris) {
|
||||
var cnt = 0;
|
||||
var cb = function() {
|
||||
cnt--;
|
||||
if (!cnt) {
|
||||
// close modal
|
||||
console.log('closing modal');
|
||||
}
|
||||
};
|
||||
_.each(uris, function(uri) {
|
||||
cnt++;
|
||||
// passing true to batch all the addUri calls
|
||||
rpc.once('addUri', [uris], cb, true);
|
||||
});
|
||||
|
||||
// now dispatch all addUri syscalls
|
||||
rpc.forceUpdate();
|
||||
}
|
||||
};
|
||||
}]);
|
Loading…
Reference in New Issue
Block a user