]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/copy_locations.js
0516e008b5b15b784f47be032ffb1ecb9e4184f5
[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, USER.ws_ou());
41         req.callback(clDraw);
42         setTimeout( function(){req.send()}, 500 );
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         alertId('cl_update_success');
72         clGo();
73 }
74
75 var rowTemplate;
76 function clDraw(r) {
77
78         var cls = r.getResultObject();
79         if(checkILSEvent(cls)) throw cls;
80
81         var tbody = $('cl_tbody');
82         if(!rowTemplate)
83                 rowTemplate = tbody.removeChild($('cl_row'));
84         removeChildren(tbody);
85
86     for(var i = 0; i < cls.length; i++) /* force stringify */
87         cls[i].name(new String(cls[i].name()));
88
89         cls = cls.sort( function(a,b) {
90                         if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
91                         if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
92                         return 0;
93                 });
94
95         for( var c in cls ) {
96                 var cl = cls[c];
97                 var row = rowTemplate.cloneNode(true);
98                 clBuildRow( tbody, row, cl );
99                 tbody.appendChild(row);
100         }
101 }
102
103 function clBuildRow( tbody, row, cl ) {
104         $n( row, 'cl_name').appendChild(text(cl.name()));
105         $n( row, 'cl_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
106         $n( row, 'cl_holdable').appendChild(text( (cl.holdable()) ? YES : NO ) );
107         $n( row, 'cl_visible').appendChild(text( (cl.opac_visible()) ? YES : NO ) );
108         $n( row, 'cl_circulate').appendChild(text( (cl.circulate()) ? YES : NO ) );
109
110         var edit = $n( row, 'cl_edit');
111         edit.onclick = function() { clEdit( cl, tbody, row ); };
112         checkDisabled( edit, cl.owning_lib(), 'UPDATE_COPY_LOCATION');
113
114         var del = $n( row, 'cl_delete' );
115         del.onclick = function() { clDelete( cl, tbody, row ); };
116         checkDisabled( del, cl.owning_lib(), 'DELETE_COPY_LOCATION');
117 }
118
119 function clEdit( cl, tbody, row ) {
120
121         cleanTbody(tbody, 'edit');
122         var r = $('cl_edit').cloneNode(true);
123         r.setAttribute('edit','1');
124         
125         var name = $n(r, 'cl_edit_name');
126         name.setAttribute('size', cl.name().length + 3);
127         name.value = cl.name();
128
129         $n(r, 'cl_edit_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
130
131         var arr = _clOptions(r);
132         if(cl.holdable()) arr[0].checked = true;
133         else arr[1].checked = true;
134         if(cl.opac_visible()) arr[2].checked = true;
135         else arr[3].checked = true;
136         if(cl.circulate()) arr[4].checked = true;
137         else arr[5].checked = true;
138
139         $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');}
140         $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); }
141
142         insRow(tbody, row, r);
143         name.focus();
144         name.select();
145 }
146
147 function _clOptions(r) {
148         var arr = [];
149         arr[0] = $n( $n(r,'cl_edit_holdable_yes'), 'cl_edit_holdable');
150         arr[1] = $n( $n(r,'cl_edit_holdable_no'), 'cl_edit_holdable');
151         arr[2] = $n( $n(r,'cl_edit_visible_yes'), 'cl_edit_visible');
152         arr[3] = $n( $n(r,'cl_edit_visible_no'), 'cl_edit_visible');
153         arr[4] = $n( $n(r,'cl_edit_circulate_yes'), 'cl_edit_circulate');
154         arr[5] = $n( $n(r,'cl_edit_circulate_no'), 'cl_edit_circulate');
155         return arr;
156 }
157
158 function clEditCommit( tbody, r, cl ) {
159
160         var arr = _clOptions(r);
161         if(arr[0].checked) cl.holdable(1);
162         else cl.holdable(0);
163         if(arr[2].checked) cl.opac_visible(1);
164         else cl.opac_visible(0);
165         if(arr[4].checked) cl.circulate(1);
166         else cl.circulate(0);
167         cl.name($n(r, 'cl_edit_name').value);
168
169         var req = new Request( UPDATE_CL, SESSION, cl );
170         req.send(true);
171         var res = req.result();
172         if(checkILSEvent(res)) throw res;
173         alertId('cl_update_success');
174
175         clGo();
176 }
177
178
179 function clDelete( cl, tbody, row ) {
180         if(!confirm($('cl_delete_confirm').innerHTML)) return;
181         var req = new Request( DELETE_CL, SESSION, cl.id() );
182         req.send(true);
183         var res = req.result();
184         if(checkILSEvent(res)) throw res;
185         alertId('cl_update_success');
186         clGo();
187 }
188
189