summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/RuleEngine/web/component-columns.js')
-rw-r--r--extensions/RuleEngine/web/component-columns.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/extensions/RuleEngine/web/component-columns.js b/extensions/RuleEngine/web/component-columns.js
new file mode 100644
index 000000000..714b29670
--- /dev/null
+++ b/extensions/RuleEngine/web/component-columns.js
@@ -0,0 +1,125 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/*
+ * REDHAT EXTENSION 1133884
+ *
+ * This file is a customised version of js/change-columns.js
+ * It is designed to work with the component_select template
+ * for changing components in the rules engine.
+ *
+ * If we needed to use this in mutiple places it might need
+ * to be made into templated code, or have the logic
+ * completly rewritten.
+ * */
+
+function initChangeColumns() {
+ window.onunload = unload;
+ var av_select = document.getElementById("available_columns");
+ var sel_select = document.getElementById("p2_component");
+ YAHOO.util.Dom.removeClass(
+ ['avail_header', av_select, 'select_button',
+ 'deselect_button'], 'bz_default_hidden');
+ switch_options(sel_select, av_select, false);
+ sel_select.selectedIndex = -1;
+ updateView();
+}
+
+function switch_options(from_box, to_box, selected) {
+ for (var i = 0; i<from_box.options.length; i++) {
+ var opt = from_box.options[i];
+ if (opt.selected == selected) {
+ var newopt = new Option(opt.text, opt.value, opt.defaultselected, opt.selected);
+ insert_sorted(to_box, newopt);
+ from_box.options[i] = null;
+ i = i - 1;
+ }
+ }
+}
+
+function insert_sorted(to_box, option) {
+ var options_dest = to_box.options;
+
+ var left = 0;
+ var right = options_dest.length - 1;
+ var ptr;
+
+ // Add to beginning if destination is empty.
+ if(options_dest.length == 0) {
+ options_dest.add(option);
+ return;
+ }
+
+ // Perform binary search to determine where to insert
+ while(left <= right) {
+ ptr = Math.floor((left + right) / 2);
+
+ if(option.text.localeCompare(options_dest[ptr].text) < 0) {
+ right = ptr - 1;
+ }
+ else if(option.text.localeCompare(options_dest[ptr].text) > 0) {
+ left = ptr + 1;
+ }
+ }
+
+ options_dest.add(option, left);
+}
+
+function move_select() {
+ var av_select = document.getElementById("available_columns");
+ var sel_select = document.getElementById("p2_component");
+ switch_options(av_select, sel_select, true);
+ updateView();
+}
+
+function move_deselect() {
+ var av_select = document.getElementById("available_columns");
+ var sel_select = document.getElementById("p2_component");
+ switch_options(sel_select, av_select, true);
+ updateView();
+}
+
+function updateView() {
+ var select_button = document.getElementById("select_button");
+ var deselect_button = document.getElementById("deselect_button");
+ select_button.disabled = true;
+ deselect_button.disabled = true;
+ var av_select = document.getElementById("available_columns");
+ var sel_select = document.getElementById("p2_component");
+ for (var i = 0; i < av_select.options.length; i++) {
+ if (av_select.options[i].selected) {
+ select_button.disabled = false;
+ break;
+ }
+ }
+ for (var i = 0; i < sel_select.options.length; i++) {
+ if (sel_select.options[i].selected) {
+ deselect_button.disabled = false;
+ break;
+ }
+ }
+}
+
+function change_submit() {
+ var sel_select = document.getElementById("p2_component");
+ for (var i = 0; i < sel_select.options.length; i++) {
+ sel_select.options[i].selected = true;
+ }
+ return false;
+}
+
+function unload() {
+ var sel_select = document.getElementById("p2_component");
+ for (var i = 0; i < sel_select.options.length; i++) {
+ sel_select.options[i].selected = true;
+ }
+}
+
+function clear_selected() {
+ unload()
+ move_deselect()
+ updateView()
+ var av_select = document.getElementById("available_columns");
+}