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';
11 'CREATE_COPY_LOCATION',
12 'UPDATE_COPY_LOCATION',
13 'DELETE_COPY_LOCATION',
16 function clEditorInit() {
18 session = cgi.param('ses');
19 if(!session) throw "User session is not defined!";
21 $('user').appendChild(text(USER.usrname()));
22 YES = $('yes').innerHTML;
23 NO = $('no').innerHTML;
27 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
28 $('cl_new_name').focus();
35 function clHoldMsg() {
36 alert($('cl_hold_msg').innerHTML);
40 var req = new Request(RETRIEVE_CL, USER.ws_ou());
45 function clBuildNew() {
46 org = PERMS['CREATE_COPY_LOCATION'];
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;
54 var sub = $('sc_new_submit');
56 sub.onclick = clCreateNew;
59 function clCreateNew() {
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 );
67 var req = new Request(CREATE_CL, SESSION, cl);
69 var res = req.result();
70 if(checkILSEvent(res)) throw res;
77 var cls = r.getResultObject();
78 if(checkILSEvent(cls)) throw cls;
80 var tbody = $('cl_tbody');
82 rowTemplate = tbody.removeChild($('cl_row'));
83 removeChildren(tbody);
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;
93 var row = rowTemplate.cloneNode(true);
94 clBuildRow( tbody, row, cl );
95 tbody.appendChild(row);
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 ) );
106 var edit = $n( row, 'cl_edit');
107 edit.onclick = function() { clEdit( cl, tbody, row ); };
108 checkDisabled( edit, cl.owning_lib(), 'UPDATE_COPY_LOCATION');
110 var del = $n( row, 'cl_delete' );
111 del.onclick = function() { clDelete( cl, tbody, row ); };
112 checkDisabled( del, cl.owning_lib(), 'DELETE_COPY_LOCATION');
115 function clEdit( cl, tbody, row ) {
117 cleanTbody(tbody, 'edit');
118 var r = $('cl_edit').cloneNode(true);
119 r.setAttribute('edit','1');
121 var name = $n(r, 'cl_edit_name');
122 name.setAttribute('size', cl.name().length + 3);
123 name.value = cl.name();
125 $n(r, 'cl_edit_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
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;
135 $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');}
136 $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); }
138 insRow(tbody, row, r);
143 function _clOptions(r) {
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');
154 function clEditCommit( tbody, r, cl ) {
156 var arr = _clOptions(r);
157 if(arr[0].checked) cl.holdable(1);
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);
165 var req = new Request( UPDATE_CL, SESSION, cl );
167 var res = req.result();
168 if(checkILSEvent(res)) throw res;
174 function clDelete( cl, tbody, row ) {
175 if(!confirm($('cl_delete_confirm').innerHTML)) return;
176 var req = new Request( DELETE_CL, SESSION, cl.id() );
178 var res = req.result();
179 if(checkILSEvent(res)) throw res;