]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/opac/simple.js
LP#1690468: fix Exclude Electronic Resources checkbox with advanced search limiters
[working/Evergreen.git] / Open-ILS / web / js / ui / default / opac / simple.js
1 /* Keep this dead simple. No dojo. */
2 function $(s) { return document.getElementById(s); }
3 function removeClass(node, cls) {
4     if (!node || !node.className) return;
5     node.className =
6         node.className.replace(new RegExp("\\b" + cls + "\\b", "g"), "");
7 }
8 function addClass(node, cls) {
9     if (!node) return;
10     removeClass(node, cls);
11     if (!node.className) node.className = cls;
12     else node.className += ' ' + cls;
13 }
14 function unHideMe(node) { removeClass(node, "hide_me"); }
15 function hideMe(node) { addClass(node, "hide_me"); }
16
17 var _search_row_template, _expert_row_template;
18 function addSearchRow() {
19     if (!_search_row_template) {
20         t = $("adv_global_row").cloneNode(true);
21         t.id = null;
22         _search_row_template = t;
23     }
24
25     $("adv_global_tbody").insertBefore(
26         _search_row_template.cloneNode(true),
27         $("adv_global_addrow")
28     );
29
30     $("adv_global_input_table").rows[$("adv_global_input_table").rows.length - 2].getElementsByTagName("input")[0].value = "";
31 }
32
33 (function($){
34 var _search_row_template, _expert_row_template, t;
35 var _el_adv_global_row = $("adv_global_row"), _el_adv_expert_row = $("adv_expert_row");
36 if (_el_adv_global_row) {
37     t = _el_adv_global_row.cloneNode(true);
38     t.id = null;
39     _search_row_template = t;
40 }
41
42 if (_el_adv_expert_row) {
43     t = _el_adv_expert_row.cloneNode(true);
44     t.id = null;
45     _expert_row_template = t;
46 }
47 function addExpertRow() {
48     $("adv_expert_rows_here").appendChild(
49         _expert_row_template.cloneNode(true)
50     );
51 }
52
53 window.addSearchRow = addSearchRow;
54 window.addExpertRow = addExpertRow;
55 })($);
56 function killRowIfAtLeast(min, link) {
57     var row = link.parentNode.parentNode;
58     if (row.parentNode.getElementsByTagName("tr").length > min)
59         row.parentNode.removeChild(row);
60     return false;
61 }
62 function print_node(node_id) {
63     var iframe = document.createElement("iframe");
64     var source_node = $(node_id);
65     source_node.parentNode.appendChild(iframe);
66
67     var iwin = iframe.contentWindow;
68
69     /* These next three statements are only needed by IE, but they don't
70      * hurt FF/Chrome. */
71     iwin.document.open();
72     iwin.document.write(    /* XXX make better/customizable? */
73         "<html><head><title>Receipt</title></head><body></body></html>"
74     );
75     iwin.document.close();
76
77     iwin.document.body.innerHTML = source_node.innerHTML;
78     iframe.focus();
79
80     try { iframe.print(); } catch (e) { iwin.print(); }
81     setTimeout(function() { iframe.style.display = "none"; }, 3500);
82 }
83 function select_all_checkboxes(name, checked) {
84     var all = document.getElementsByTagName("input");
85     for (var i = 0; i < all.length; i++) {
86         if (all[i].type == "checkbox" && all[i].name == name) {
87             all[i].checked = checked;
88         }
89     }
90 }
91
92 function search_modifier_onchange(type, checkbox, submitOnChange) {
93     if (checkbox.form._adv && !checkbox.checked) {
94         var search_box = $('search_box');
95         var reg = new RegExp('#' + type + ' ?', 'g');
96         search_box.value = search_box.value.replace(reg, "");
97     }
98
99     if (submitOnChange) {  
100         checkbox.form.submit(); 
101     }
102 }
103
104 function exclude_onchange(checkbox) {
105     if (checkbox.form._adv && !checkbox.checked) {
106         var search_box = $('search_box');
107         // Other functions' form submits may create duplicates of this, so /g
108         var reg = /-search_format\(electronic\)/g;
109         search_box.value = search_box.value.replace(reg, "");
110         // Remove from the search form itself
111         var search_format_inputs = document.getElementsByName("fi:-search_format");
112         for (var j = 0; j < search_format_inputs.length; j++) {
113             if (search_format_inputs[j].value == 'electronic') {
114                 search_format_inputs[j].parentNode.removeChild(search_format_inputs[j]);
115             }
116         }
117
118     }
119
120     checkbox.form.submit();
121 }