]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/HoldsWindow.js
object to model the holds window...
[Evergreen.git] / Open-ILS / src / javascript / opac / HoldsWindow.js
1 function HoldsWindow(record) {
2         this.record = record;
3 }
4
5 HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
6
7         var hwindow = this;
8         var func = function() {
9
10                 var wrapper = elem("div");
11                 var id = hwindow.record.doc_id();
12
13                 var org = UserSession.instance().userObject.home_ou();
14                 wrapper.appendChild(hwindow.buildPickuplibSelector(org));
15                 if(type == "M")
16                         wrapper.appendChild(hwindow.buildResourceSelector());
17                 wrapper.appendChild(hwindow.buildSubmit());
18
19                 hwindow.win = window.open(null,"PLACE_HOLD_" + id,
20                         "location=0,menubar=0,status=0,resizeable,resize," +
21                         "outerHeight=500,outerWidth=500,height=500," +
22                         "width=500,scrollbars=1," +
23                         /*"screenX=100,screenY=100,top=100,left=100," + */
24                         "alwaysraised, chrome" )
25         
26                 hwindow.win.document.write("<html>" + wrapper.innerHTML + "</html>");
27                 hwindow.win.document.close();
28                 hwindow.win.document.title = "View MARC";
29                 hwindow.win.focus();
30         }
31
32         return func;
33 }
34
35 HoldsWindow.prototype.buildSubmit = function() {
36         var div = elem("div");
37         var bdiv = elem("div")
38
39         bdiv.setAttribute("style", 
40                 "border-top: 1px solid lightgrey;" +
41                 "border-bottom: 1px solid lightgrey;" +
42                 "width:100%;text-align:center;");
43
44         var button = elem("input", 
45                 {type:"submit", value:"Place Hold"});
46
47         div.appendChild(elem("br"));
48         bdiv.appendChild(button);
49         div.appendChild(bdiv);
50
51         return div;
52 }
53
54 /* builds a selecor where the client can select the location to which
55         the item is sent */
56 HoldsWindow.prototype.buildPickuplibSelector = function(selected_id) {
57
58         var div = elem("div");
59         var tdiv = elem("div",null, null,
60                 "Select the location where the item(s) shall be delivered");
61
62         var sdiv = elem("div");
63         var selector = elem("select");
64
65         /* this is not copied over... XXX fix me */
66         selector.onchange = function() {
67                 alert("Change!");
68                 var idx = selector.selectedIndex;
69                 var option = selector.options[idx];
70                 var org = findOrgUnit(option.value);
71
72                 var d = getById("selector_error_div");
73                 if(d) div.removeChild(d);
74
75                 if(parseInt(findOrgType(org.ou_type()).depth()) < 2) {
76                         alert("A REGION was selected");
77                         var err = elem("div",
78                                 {id:"selector_error_div", style:"color:red"},null, 
79                                 org.name() + " is a library system, please select a single branch");
80                         div.appendChild(err);
81                 } else {
82                         alert("Depth is " + findOrgType(org.ou_type()).depth());
83                 }
84         }
85
86         sdiv.appendChild(selector);
87         _buildOrgList(selector, selected_id, null);
88
89         div.appendChild(elem("br"));
90         div.appendChild(tdiv);
91         div.appendChild(sdiv);
92         return div;
93 }
94
95 /* utility function for building a org list selector object */
96 function _buildOrgList(selector, selected_id, org) {
97
98         if(selected_id == null) selected_id = -1;
99
100         if(org == null) {
101                 org = globalOrgTree;
102
103         } else { /* add the org to the list */
104                 var index = selector.options.length;
105                 if(IE) {
106                         var node = elem("pre");
107                         for(var x=2; x <= findOrgType(org.ou_type()).depth(); x++) {
108                                 node.appendChild(mktext("    "));
109                         }
110                         node.appendChild(mktext(org.name()));
111                         var select = new Option("", org.id());
112                         selector.options[index] = select;
113                         select.appendChild(node);
114         
115                 } else {
116                         var pad = (findOrgType(org.ou_type()).depth() - 1) * 12;
117                         var select = new Option(org.name(), org.id());
118                         select.setAttribute("style", "padding-left: " + pad);
119                         selector.options[index] = select;
120                 }
121
122                 if(parseInt(org.id()) == parseInt(selected_id)) {
123                         selector.selectedIndex = index;
124                         selector.options[index].selected = true;
125                 }
126         }
127
128         for(var idx in org.children()) 
129                 _buildOrgList(selector, selected_id, org.children()[idx]);
130 }
131
132 HoldsWindow.prototype.buildResourceSelector = function() {
133
134         /* useful message */
135         var big_div = elem('div');
136
137         var desc_div = elem("div",null, null, 
138                 "Select all acceptible item formats");
139
140         var resources = [ 
141                 "text", 
142                 "moving image",
143                 "sound recording",
144                 "software, multimedia",
145                 "still images",
146                 "cartographic",
147                 "mixed material",
148                 "notated music",
149                 "three dimensional object" ];
150         
151         var table = elem("table");      
152
153         for( var idx in resources ) {
154                 var row = table.insertRow(table.rows.length)
155         
156                 var pic_cell = row.insertCell(0);
157                 var name_cell = row.insertCell(1);
158                 var box_cell = row.insertCell(2);
159                 var box = elem("input", 
160                         {type:"checkbox", id: resources[idx] + "_hold_checkbox"}, null);
161
162                 if(idx == 0) { /* select text by default */
163                         box.setAttribute("checked","checked");
164                         box.checked = true;
165                 }
166                 
167                 pic_cell.appendChild(mkResourceImage(resources[idx]));
168                 name_cell.appendChild(mktext(resources[idx]));
169                 box_cell.appendChild(mktext(" "));
170                 box_cell.appendChild(box);
171         }
172
173         big_div.appendChild(elem("br"));
174         big_div.appendChild(desc_div);
175         big_div.appendChild(table);
176         return big_div;
177
178 }
179
180 function mkResourceImage(resource) {
181         var pic = elem("img");
182         pic.setAttribute("src", "/images/" + resource + ".jpg");
183         pic.setAttribute("width", "20");
184         pic.setAttribute("height", "20");
185         pic.setAttribute("title", resource);
186         return pic;
187 }
188
189