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