]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/copy_locations.js
added some more utility code and css
[Evergreen.git] / Open-ILS / xul / staff_client / server / admin / copy_locations.js
1 var RETRIEVE_CL = 'open-ils.circ:open-ils.circ.copy_location.retrieve.all';
2 var CREATE_CL = 'open-ils.circ:open-ils.circ.copy_location.create';
3 var UPDATE_CL = 'open-ils.circ:open-ils.circ.copy_location.update';
4 var DELETE_CL = 'open-ils.circ:open-ils.circ.copy_location.delete';
5
6
7 var YES;
8 var NO;
9
10 var myPerms = [
11         'CREATE_COPY_LOCATION',
12         'UPDATE_COPY_LOCATION', 
13         'DELETE_COPY_LOCATION',
14         ];
15
16 function clEditorInit() {
17         cgi = new CGI();
18         session = cgi.param('ses');
19         if(!session) throw "User session is not defined!";
20         fetchUser(session);
21         $('user').appendChild(text(USER.usrname()));
22         YES = $('yes').innerHTML;
23         NO = $('no').innerHTML;
24
25         setTimeout( 
26                 function() { 
27                         fetchHighestPermOrgs( SESSION, USER.id(), myPerms ); 
28                         $('cl_new_name').focus();
29                         clBuildNew();
30                         clGo(); 
31                 }, 20 );
32 }
33
34
35 function clHoldMsg() {
36         alert($('cl_hold_msg').innerHTML);
37 }
38
39 function clGo() {       
40         var req = new Request(RETRIEVE_CL, SESSION, USER.home_ou());
41         req.callback(clDraw);
42         req.send();
43 }
44
45 function clBuildNew() {
46         org = PERMS['CREATE_COPY_LOCATION'];
47         if(org == -1) return;
48         var selector = $('cl_new_owner');
49         org = findOrgUnit(org);
50         buildOrgSel(selector, org, findOrgDepth(org));
51         if(org.children() && org.children()[0]) 
52                 selector.disabled = false;
53
54         var sub = $('sc_new_submit');
55         sub.disabled = false;
56         sub.onclick = clCreateNew;
57 }
58
59 function clCreateNew() {
60         var cl = new acpl();
61         cl.name( $('cl_new_name').value );
62         cl.owning_lib( getSelectorVal( $('cl_new_owner')));
63         cl.holdable( ($('cl_new_hold_yes').checked) ? 1 : 0 );
64         cl.opac_visible( ($('cl_new_vis_yes').checked) ? 1 : 0 );
65         cl.circulate( ($('cl_new_circulate_yes').checked) ? 1 : 0 );
66
67         var req = new Request(CREATE_CL, SESSION, cl);
68         req.send(true);
69         var res = req.result();
70         if(checkILSEvent(res)) throw res;
71         clGo();
72 }
73
74 var rowTemplate;
75 function clDraw(r) {
76
77         var cls = r.getResultObject();
78         if(checkILSEvent(cls)) throw cls;
79
80         var tbody = $('cl_tbody');
81         if(!rowTemplate)
82                 rowTemplate = tbody.removeChild($('cl_row'));
83         removeChildren(tbody);
84
85         cls = cls.sort( function(a,b) {
86                         if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
87                         if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
88                         return 0;
89                 });
90
91         for( var c in cls ) {
92                 var cl = cls[c];
93                 var row = rowTemplate.cloneNode(true);
94                 clBuildRow( tbody, row, cl );
95                 tbody.appendChild(row);
96         }
97 }
98
99 function clBuildRow( tbody, row, cl ) {
100         $n( row, 'cl_name').appendChild(text(cl.name()));
101         $n( row, 'cl_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
102         $n( row, 'cl_holdable').appendChild(text( (cl.holdable()) ? YES : NO ) );
103         $n( row, 'cl_visible').appendChild(text( (cl.opac_visible()) ? YES : NO ) );
104         $n( row, 'cl_circulate').appendChild(text( (cl.circulate()) ? YES : NO ) );
105
106         var edit = $n( row, 'cl_edit');
107         edit.onclick = function() { clEdit( cl, tbody, row ); };
108         checkDisabled( edit, cl.owning_lib(), 'UPDATE_COPY_LOCATION');
109
110         var del = $n( row, 'cl_delete' );
111         del.onclick = function() { clDelete( cl, tbody, row ); };
112         checkDisabled( del, cl.owning_lib(), 'DELETE_COPY_LOCATION');
113 }
114
115 function clEdit( cl, tbody, row ) {
116
117         cleanTbody(tbody, 'edit');
118         var r = $('cl_edit').cloneNode(true);
119         r.setAttribute('edit','1');
120         
121         var name = $n(r, 'cl_edit_name');
122         name.setAttribute('size', cl.name().length + 3);
123         name.value = cl.name();
124
125         $n(r, 'cl_edit_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
126
127         var arr = _clOptions(r);
128         if(cl.holdable()) arr[0].checked = true;
129         else arr[1].checked = true;
130         if(cl.opac_visible()) arr[2].checked = true;
131         else arr[3].checked = true;
132         if(cl.circulate()) arr[4].checked = true;
133         else arr[5].checked = true;
134
135         $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');}
136         $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); }
137
138         insRow(tbody, row, r);
139         name.focus();
140         name.select();
141 }
142
143 function _clOptions(r) {
144         var arr = [];
145         arr[0] = $n( $n(r,'cl_edit_holdable_yes'), 'cl_edit_holdable');
146         arr[1] = $n( $n(r,'cl_edit_holdable_no'), 'cl_edit_holdable');
147         arr[2] = $n( $n(r,'cl_edit_visible_yes'), 'cl_edit_visible');
148         arr[3] = $n( $n(r,'cl_edit_visible_no'), 'cl_edit_visible');
149         arr[4] = $n( $n(r,'cl_edit_circulate_yes'), 'cl_edit_circulate');
150         arr[5] = $n( $n(r,'cl_edit_circulate_no'), 'cl_edit_circulate');
151         return arr;
152 }
153
154 function clEditCommit( tbody, r, cl ) {
155
156         var arr = _clOptions(r);
157         if(arr[0].checked) cl.holdable(1);
158         else cl.holdable(0);
159         if(arr[2].checked) cl.opac_visible(1);
160         else cl.opac_visible(0);
161         if(arr[4].checked) cl.circulate(1);
162         else cl.circulate(0);
163         cl.name($n(r, 'cl_edit_name').value);
164
165         var req = new Request( UPDATE_CL, SESSION, cl );
166         req.send(true);
167         var res = req.result();
168         if(checkILSEvent(res)) throw res;
169
170         clGo();
171 }
172
173
174 function clDelete( cl, tbody, row ) {
175         if(!confirm($('cl_delete_confirm').innerHTML)) return;
176         var req = new Request( DELETE_CL, SESSION, cl.id() );
177         req.send(true);
178         var res = req.result();
179         if(checkILSEvent(res)) throw res;
180
181         clGo();
182 }
183
184