From 4bad1969d623deeb901db683e45b071f35a57062 Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 11 Jul 2005 08:17:30 +0000 Subject: [PATCH] changed these widget utils to count arguments git-svn-id: svn://svn.open-ils.org/ILS/trunk@1118 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/evergreen/util/widgets.js | 212 +++++++++++++++++---- 1 file changed, 180 insertions(+), 32 deletions(-) diff --git a/Evergreen/staff_client/chrome/content/evergreen/util/widgets.js b/Evergreen/staff_client/chrome/content/evergreen/util/widgets.js index 0caefa1ba8..7e8356d34d 100644 --- a/Evergreen/staff_client/chrome/content/evergreen/util/widgets.js +++ b/Evergreen/staff_client/chrome/content/evergreen/util/widgets.js @@ -4,9 +4,16 @@ sdump('D_WIDGETS',"Loading widgets.js\n"); // The first argument is the treechildren element for the tree. // Subsequent arguments are treated as textual values for treecells in that treeitem. var treeitem_id = 0; -function append_treeitem(d,e) { +function append_treeitem() { sdump('D_WIDGETS',arg_dump(arguments)); - if (typeof(e) != 'object') { e = d.getElementById(e); } + var d; var e; + if (arguments.length == 1) { + e = arguments[0]; + } else { + d = arguments[0]; + e = arguments[1]; + if (typeof(e) != 'object') { e = d.getElementById(e); } + } if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); } var treechildren = e; @@ -29,10 +36,21 @@ function append_treeitem(d,e) { // The first argument is the element, the second argument is the pertinant attribute, // and the third argument is an array of values to cycle through for setting the // element's attribute. Ex: var toggle = cycle_attribute( target,'toggle',['1','2','3'] ); -function cycle_attribute(d,e,a,v) { +function cycle_attribute() { sdump('D_WIDGETS',arg_dump(arguments)); - try { + var d; var e; var a; var v; + if (arguments.length == 3) { + e = arguments[0]; + a = arguments[1]; + v = arguments[2]; + } else { + d = arguments[0]; + e = arguments[1]; + a = arguments[2]; + v = arguments[3]; if (typeof(e) != 'object') { e = d.getElementById(e); } + } + try { if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); } if (!a) { throw('!a : a = ' + a); } if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); } @@ -66,9 +84,13 @@ function cycle_attribute(d,e,a,v) { } // Treats each argument as an element to disable -function disable_widgets(d) { +function disable_widgets() { sdump('D_WIDGETS',arg_dump(arguments)); - for (var i = 1; i < arguments.length; i++) { + var d = document; var idx = 0; + if (arguments[0].nodeName == '#document') { + idx = 1; d = arguments[0]; + } + for (var i = idx; i < arguments.length; i++) { if (typeof(arguments[i]) == 'object') { sdump('D_WIDGETS',arguments[i] + '.disabled = true;\n'); arguments[i].disabled = true; @@ -83,9 +105,16 @@ function disable_widgets(d) { } // removes listitems from listboxes -function empty_listbox(d,e) { +function empty_listbox() { sdump('D_WIDGETS',arg_dump(arguments)); - if (typeof(e) != 'object') { e = d.getElementById(e); } + var d; var e; + if (arguments.length == 1) { + e = arguments[0]; + } else { + d = arguments[0]; + e = arguments[1]; + if (typeof(e) != 'object') { e = d.getElementById(e); } + } if (typeof(e) != 'object') { sdump('D_WIDGETS','Failed on empty_listbox\n'); return; } var nl = e.getElementsByTagName('listitem'); for (var i = 0; i < nl.length; i++) { @@ -94,18 +123,29 @@ function empty_listbox(d,e) { } // removes all of an element's children -function empty_widget(d,e) { +function empty_widget() { sdump('D_WIDGETS',arg_dump(arguments)); - if (typeof(e) != 'object') { e = d.getElementById(e); } + var d; var e; + if (arguments.length == 1) { + e = arguments[0]; + } else { + d = arguments[0]; + e = arguments[1]; + if (typeof(e) != 'object') { e = d.getElementById(e); } + } if (typeof(e) != 'object') { sdump('D_WIDGETS','Failed on empty_widget\n'); return; } while (e.lastChild) { e.removeChild(e.lastChild); } } // Treats each argument as an element to enable -function enable_widgets(d) { +function enable_widgets() { sdump('D_WIDGETS',arg_dump(arguments)); - for (var i = 1; i < arguments.length; i++) { + var d = document; var idx = 0; + if (arguments[0].nodeName == '#document') { + idx = 1; d = arguments[0]; + } + for (var i = idx; i < arguments.length; i++) { if (typeof(arguments[i]) == 'object') { sdump('D_WIDGETS',arguments[i] + '.disabled = false;\n'); arguments[i].disabled = false; @@ -123,12 +163,19 @@ function enable_widgets(d) { // The first argument is the element to search for textboxes, and the second // argument is the current textbox. This function finds the next textbox and // gives it focus. -function fake_tab_for_textboxes(d,w,current) { +function fake_tab_for_textboxes() { sdump('D_WIDGETS',arg_dump(arguments)); - var flag = false; var next_one; - if (typeof(w)!='object') { - w = d.getElementById(w); + var d; var w; var current; + if (arguments.length == 2) { + w = arguments[0]; + current = arguments[1]; + } else { + d = arguments[0]; + w = arguments[1]; + current = arguments[2]; + if (typeof(w)!='object') { w = d.getElementById(w); } } + var flag = false; var next_one; sdump('D_WIDGETS', 'fake_tab_for_textboxes: Current ' + current + '\n'); var nl = w.getElementsByTagName('textbox'); //var nl = d.getElementsByTagName('textbox'); @@ -159,9 +206,20 @@ function fake_tab_for_textboxes(d,w,current) { // Not actually used anywhere. I'm not sure what this is :D // Ah, looks like it could handle XUL trees and fieldmapper trees // Ex. find( org_tree, function(o){return o.children();}, function(o){return (o.id == 'the winner');}) -function find_tree_via_children(d,tree,children_func,find_func) { +function find_tree_via_children() { sdump('D_WIDGETS',arg_dump(arguments)); - if (typeof(tree)!='object') tree = d.getElementById(tree); + var d; var tree; var children_func; var find_func; + if (arguments.length == 3) { + tree = arguments[0]; + children_func = arguments[1]; + find_func = arguments[2]; + } else { + d = arguments[0]; + tree = arguments[1]; + children_func = arguments[2]; + find_func = arguments[3]; + if (typeof(tree)!='object') tree = d.getElementById(tree); + } var t = find_func(tree); if (t) return t; @@ -175,8 +233,15 @@ function find_tree_via_children(d,tree,children_func,find_func) { // Give this element focus -function focus_widget(d,e) { +function focus_widget() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var e; + if (arguments.length == 1) { + e = arguments[0]; + } else { + d = arguments[0]; + e = arguments[1]; + } if (typeof(e) == 'object') { e.focus(); } else { @@ -186,9 +251,15 @@ function focus_widget(d,e) { } // Returns a list of selected treeitems from the specified tree -function get_list_from_tree_selection(d,tree_w) { +function get_list_from_tree_selection() { sdump('D_WIDGETS',arg_dump(arguments)); - sdump('D_WIDGETS','entering get_list_from_tree...\n'); + var d = document; var tree_w; + if (arguments.length == 1) { + tree_w = arguments[0]; + } else { + d = arguments[0]; + tree_w = arguments[1]; + } var hitlist; if (typeof(tree_w) != 'object') { hitlist = d.getElementById(tree_w); @@ -207,13 +278,19 @@ function get_list_from_tree_selection(d,tree_w) { list.push( i ); } } - sdump('D_WIDGETS','leaving get_list_from_tree...\n'); return list; } // Make sure we a widget -function get_widget(d,e) { +function get_widget() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var e; + if (arguments.length == 1) { + e = arguments[0]; + } else { + d = arguments[0]; + e = arguments[1]; + } if (typeof(e) == 'object') { return e; } else { @@ -224,8 +301,17 @@ function get_widget(d,e) { } // Increment a XUL progressmeter -function incr_progressmeter(d,meter,increment) { +function incr_progressmeter() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var meter; var increment; + if (arguments.length == 2) { + meter = arguments[0]; + increment = arguments[1]; + } else { + d = arguments[0]; + meter = arguments[1]; + increment = arguments[2]; + } if (typeof(meter)!='object') meter = d.getElementById(meter); if (typeof(meter)!='object') @@ -260,8 +346,15 @@ function map_array_to_treecells_via_treeitem( cols, treeitem ) { // Simulates radio buttons with checkboxes. Include this in command event listeners // for the pertinent textboxes. For any set of checkboxes that have the same 'group' // attribute, only one can be checked at a time. -function radio_checkbox(d,ev) { +function radio_checkbox() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var ev; + if (arguments.length == 1) { + ev = arguments[0]; + } else { + d = arguments[0]; + ev = arguments[1]; + } var target = ev.target; var group = target.getAttribute('group'); if (group) { @@ -282,27 +375,67 @@ function radio_checkbox(d,ev) { } // simpler version of set_decks -function set_deck(d,deck,idx) { +function set_deck() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var deck; var idx; + if (arguments.length == 2) { + deck = arguments[0]; + idx = arguments[1]; + } else { + d = arguments[0]; + deck = arguments[1]; + idx = arguments[2]; + } set_decks(d,{ deck : idx }); } // Takes a hash with key:value => deck element id : page index // Sets each deck to the corresponding index -function set_decks(d,params) { +function set_decks() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var params; + if (arguments.length == 1) { + params = arguments[0]; + } else { + d = arguments[0]; + params = arguments[1]; + } for (var deck_id in params) { - var deck; + var deck = deck_id; if (typeof(deck) != 'object') deck = d.getElementById( deck_id ) if (deck) deck.setAttribute( 'selectedIndex', params[deck_id] ); } } +// For setting a widget's displayable text +function set_widget_value_for_display(e,v) { + sdump('D_WIDGETS',arg_dump(arguments,{1:true})); + if (v == null || v == undefined) v = '.....'; + sdump('D_WIDGETS','e.tagName = ' + e.tagName + '\n'); + sdump('D_WIDGETS','e.nodeName = ' + e.nodeName + '\n'); + switch (e.tagName) { + case 'textbox' : e.value = v; break; + case 'label' : e.setAttribute('value',v); break; + default: try {e.setAttribute('value',v); e.value = v;} catch(E) {} break; + } +} + // swaps the values of two attributes for an element -function swap_attributes(d,e,a1,a2) { +function swap_attributes() { sdump('D_WIDGETS',arg_dump(arguments)); - if (typeof(e) != 'object') { e = d.getElementById(e); } + var d = document; var e; var a1; var a2; + if (arguments.length == 3) { + e = arguments[0]; + a1 = arguments[1]; + a2 = arguments[2]; + } else { + d = arguments[0]; + e = arguments[1]; + a1 = arguments[2]; + a2 = arguments[3]; + if (typeof(e) != 'object') { e = d.getElementById(e); } + } if (typeof(e) != 'object') { sdump('D_WIDGETS','Failed on swap_attributes\n'); return; } var a1_v = e.getAttribute(a1); var a2_v = e.getAttribute(a2); @@ -313,8 +446,14 @@ function swap_attributes(d,e,a1,a2) { } // Flips the hidden value for each row in a grid -function toggle_hidden_grid_rows(d,grid) { +function toggle_hidden_grid_rows() { sdump('D_WIDGETS',arg_dump(arguments)); + if (arguments.length == 1) { + grid = arguments[0]; + } else { + d = arguments[0]; + grid = arguments[1]; + } if (typeof(grid) != 'object') { grid = d.getElementById(grid); } @@ -335,8 +474,17 @@ function toggle_hidden_grid_rows(d,grid) { } /* The first parameter is the id of the element to set, or an array of ids for elements to set in batch. The second parameter is an object containing the attribute/value pairs to assign to the element or elements */ -function xul_setAttributes(d,el,attrs) { +function xul_setAttributes() { sdump('D_WIDGETS',arg_dump(arguments)); + var d = document; var el; var attrs; + if (arguments.length == 2) { + el = arguments[0]; + attrs = arguments[1]; + } else { + d = arguments[0]; + el = arguments[1]; + attrs = arguments[2]; + } if (typeof(el) == 'object') { for (var e in el) { var w = d.getElementById(e); -- 2.11.0