]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/copy_locations.js
adding first round
[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         setTimeout( function() { 
25                 fetchHighestPermOrgs( SESSION, USER.id(), myPerms ); clGo(); }, 20 );
26 }
27
28
29 function clHoldMsg() {
30         alert($('cl_hold_msg').innerHTML);
31 }
32
33 function clGo() {
34         var req = new Request(RETRIEVE_CL, SESSION, USER.home_ou());
35         req.callback(clDraw);
36         req.send();
37 }
38
39 var rowTemplate;
40 function clDraw(r) {
41
42         var cls = r.getResultObject();
43         if(checkILSEvent(cls)) throw cls;
44
45         var tbody = $('cl_tbody');
46         if(!rowTemplate)
47                 rowTemplate = tbody.removeChild($('cl_row'));
48         removeChildren(tbody);
49
50         cls = cls.sort( function(a,b) {
51                         if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
52                         if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
53                         return 0;
54                 });
55
56         for( var c in cls ) {
57                 var cl = cls[c];
58                 var row = rowTemplate.cloneNode(true);
59                 clBuildRow( tbody, row, cl );
60                 tbody.appendChild(row);
61         }
62 }
63
64 function clBuildRow( tbody, row, cl ) {
65         $n( row, 'cl_name').appendChild(text(cl.name()));
66         $n( row, 'cl_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
67         $n( row, 'cl_holdable').appendChild(text( (cl.holdable()) ? YES : NO ) );
68         $n( row, 'cl_visible').appendChild(text( (cl.opac_visible()) ? YES : NO ) );
69         $n( row, 'cl_circulate').appendChild(text( (cl.circulate()) ? YES : NO ) );
70         $n( row, 'cl_edit').onclick = function() { clEdit( cl, tbody, row ); };
71 }
72
73 function clEdit( cl, tbody, row ) {
74
75         cleanTbody(tbody, 'edit');
76         var r = $('cl_new').cloneNode(true);
77         r.setAttribute('edit','1');
78         
79         var name = $n(r, 'cl_new_name');
80         name.setAttribute('size', cl.name().length + 3);
81         name.value = cl.name();
82
83         $n(r, 'cl_new_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
84
85         var yhold = $n( $n(r,'cl_new_holdable_yes'), 'cl_new_holdable');
86         var nhold = $n( $n(r,'cl_new_holdable_no'), 'cl_new_holdable');
87         var yvis = $n( $n(r,'cl_new_visible_yes'), 'cl_new_visible');
88         var nvis = $n( $n(r,'cl_new_visible_no'), 'cl_new_visible');
89         var ycirc = $n( $n(r,'cl_new_circulate_yes'), 'cl_new_circulate');
90         var ncirc = $n( $n(r,'cl_new_circulate_no'), 'cl_new_circulate');
91
92         if(cl.holdable()) yhold.checked = true;
93         else nhold.checked = true;
94         if(cl.opac_visible()) yvis.checked = true;
95         else nvis.checked = true;
96         if(cl.circulate()) ycirc.checked = true;
97         else ncirc.checked = true;
98
99         $n(r, 'cl_new_cancel').onclick = function(){cleanTbody(tbody,'edit');}
100         $n(r, 'cl_new_commit').onclick = function(){clEditCommit( tbody, cl ); }
101
102         insRow(tbody, row, r);
103         name.focus();
104         name.select();
105 }
106
107 function clEditCommit( tbody, cl ) {
108         alert("committing: " + cl.id());        
109         cleanTbody(tbody,'edit');
110 }