summaryrefslogtreecommitdiffstats
path: root/install/ui
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2013-03-29 15:27:58 +0100
committerPetr Vobornik <pvoborni@redhat.com>2013-05-06 16:22:21 +0200
commit1b90b3b65ea214a3a09922f6b9c1de304e5257da (patch)
tree65693ef7db16618eb76c86e4848dd88c4582c172 /install/ui
parent344e15452a64ef9dc43a66a7e0085aef0eb7c175 (diff)
downloadfreeipa-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')
-rw-r--r--install/ui/src/freeipa/_base/Phase_controller.js39
-rw-r--r--install/ui/src/freeipa/phases.js31
-rwxr-xr-xinstall/ui/src/libs/jquery.ordered-map.js18
-rwxr-xr-xinstall/ui/test/ordered_map_tests.js37
4 files changed, 113 insertions, 12 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;
diff --git a/install/ui/test/ordered_map_tests.js b/install/ui/test/ordered_map_tests.js
index e8d8a7460..f3d2d5b36 100755
--- a/install/ui/test/ordered_map_tests.js
+++ b/install/ui/test/ordered_map_tests.js
@@ -43,16 +43,47 @@ test("Testing $.ordered_map.put().", function() {
var key2 = 'key2';
var value2 = 'value2';
+ var key3 = 'key3';
+ var value3 = 'value3';
+
+ var key4 = 'key4';
+ var value4 = 'value4';
+
+ var key5 = 'key5';
+ var value5 = 'value5';
+
+ var key6 = 'key6';
+ var value6 = 'value6';
+
+ var key7 = 'key7';
+ var value7 = 'value7';
+
+ var key8 = 'key8';
+ var value8 = 'value8';
+
var map = {};
map[key1] = value1;
map[key2] = value2;
+ map[key3] = value3;
+ map[key4] = value4;
+ map[key5] = value5;
+ map[key6] = value6;
+ map[key7] = value7;
+ map[key8] = value8;
test.put(key1, value1);
test.put(key2, value2);
- strictEqual(test.length, 2, 'Checking length.');
- deepEqual(test.keys, [key1, key2], 'Checking keys.');
- deepEqual(test.values, [value1, value2], 'Checking values.');
+ test.put(key3, value3, 1); //put before key2
+ test.put(key4, value4, 0); //put at beginning
+ test.put(key5, value5, -2); //put at beginning
+ test.put(key6, value6, 5); //put at end
+ test.put(key7, value7, 100); //put at end
+ test.put(key8, value8, 'foobar'); //put at end
+
+ strictEqual(test.length, 8, 'Checking length.');
+ deepEqual(test.keys, [key5, key4, key1, key3, key2, key6, key7, key8], 'Checking keys.');
+ deepEqual(test.values, [value5, value4, value1, value3, value2, value6, value7, value8], 'Checking values.');
deepEqual(test.map, map, 'Checking map.');
});