diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-03-29 15:27:58 +0100 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-05-06 16:22:21 +0200 |
commit | 1b90b3b65ea214a3a09922f6b9c1de304e5257da (patch) | |
tree | 65693ef7db16618eb76c86e4848dd88c4582c172 /install/ui/src | |
parent | 344e15452a64ef9dc43a66a7e0085aef0eb7c175 (diff) | |
download | freeipa-1b90b3b65ea214a3a09922f6b9c1de304e5257da.tar.gz freeipa-1b90b3b65ea214a3a09922f6b9c1de304e5257da.tar.xz freeipa-1b90b3b65ea214a3a09922f6b9c1de304e5257da.zip |
Add phase on exact position
https://fedorahosted.org/freeipa/ticket/3235
Diffstat (limited to 'install/ui/src')
-rw-r--r-- | install/ui/src/freeipa/_base/Phase_controller.js | 39 | ||||
-rw-r--r-- | install/ui/src/freeipa/phases.js | 31 | ||||
-rwxr-xr-x | install/ui/src/libs/jquery.ordered-map.js | 18 |
3 files changed, 79 insertions, 9 deletions
diff --git a/install/ui/src/freeipa/_base/Phase_controller.js b/install/ui/src/freeipa/_base/Phase_controller.js index 951aa51fe..471c36a0a 100644 --- a/install/ui/src/freeipa/_base/Phase_controller.js +++ b/install/ui/src/freeipa/_base/Phase_controller.js @@ -112,7 +112,7 @@ define([ }, /** - * Add task for a phase. + * Adds task for a phase. * * At phase execution, tasks are sorted by priority and executed in * that order. @@ -134,17 +134,48 @@ define([ }, /** - * Adds a phase. + * Adds a phase + * + * Possible options: + * before: 'name-of-phase' + * after: 'name-of-phase' + * position: 'position for new phase' + * * @param {String} phase name + * @param {Array} tasks + * @param {Object} options */ - add_phase: function(name, tasks) { + add_phase: function(name, tasks, options) { var phase = { name: name, tasks: tasks || [] }; - this.phases.put(name, phase); + var position; + if (options) { + if (options.before) { + position = this.phases.get_key_index(options.before); + } else if (options.after) { + position = this.phases.get_key_index(options.after); + if (position === -1) position = this.phases.length; + else position++; + } else if (options.position) { + position = options.position; + } + } + + this.phases.put(name, phase, position); + }, + + /** + * Checks if phases with given name exists + * + * @param {String} name + * @return {Boolean} + */ + exists: function(name) { + return !!this.phases.get(name); }, constructor: function(spec) { diff --git a/install/ui/src/freeipa/phases.js b/install/ui/src/freeipa/phases.js index 15b753a0c..e5a23d07f 100644 --- a/install/ui/src/freeipa/phases.js +++ b/install/ui/src/freeipa/phases.js @@ -54,10 +54,39 @@ define([ controller: new Phase_controller(spec), /** - * Registers phase task + * Registers a phase task + * + * @param {String} Phase name + * @param {Function} Task handler. Should return promise if async. + * @param {Number} Priority of task. Default 10. */ on: function(phase_name, handler, priority) { this.controller.add_task(phase_name, handler, priority); + }, + + /** + * Adds a phase + * + * Possible options: + * before: 'name-of-phase' + * after: 'name-of-phase' + * position: 'position for new phase' + * + * @param {String} Phase name + * @param {Object} Options + */ + add: function(phase_name, options) { + this.controller.add_phase(phase_name, null, options); + }, + + /** + * Checks if phases with given name exists + * + * @param {String} Name + * @return {Boolean} + */ + exists: function(name) { + return this.controller.exists(name); } }; diff --git a/install/ui/src/libs/jquery.ordered-map.js b/install/ui/src/libs/jquery.ordered-map.js index 33737b564..77d17c56a 100755 --- a/install/ui/src/libs/jquery.ordered-map.js +++ b/install/ui/src/libs/jquery.ordered-map.js @@ -35,15 +35,25 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) { return that.map[key]; }; - that.put = function(key, value) { + that.put = function(key, value, position) { + + var undefined; var i = that.get_key_index(key); if (i >= 0) { that.values[i] = value; } else { - that.keys.push(key); - that.values.push(value); - that.length = that.keys.length; + if (typeof position !== 'number') { + that.keys.push(key); + that.values.push(value); + that.length = that.keys.length; + } else { + if (position < 0) position = 0; + else if (position > that.length) position = that.length; + that.keys.splice(position, 0, key); + that.values.splice(position, 0, value); + that.length = that.keys.length; + } } that.map[key] = value; |