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());
42 setTimeout( function(){req.send()}, 500 );
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;
71 alertId('cl_update_success');
78 var cls = r.getResultObject();
79 if(checkILSEvent(cls)) throw cls;
81 var tbody = $('cl_tbody');
83 rowTemplate = tbody.removeChild($('cl_row'));
84 removeChildren(tbody);
86 for(var i = 0; i < cls.length; i++) /* force stringify */
87 cls[i].name(new String(cls[i].name()));
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;
97 var row = rowTemplate.cloneNode(true);
98 clBuildRow( tbody, row, cl );
99 tbody.appendChild(row);
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 ) );
110 var edit = $n( row, 'cl_edit');
111 edit.onclick = function() { clEdit( cl, tbody, row ); };
112 checkDisabled( edit, cl.owning_lib(), 'UPDATE_COPY_LOCATION');
114 var del = $n( row, 'cl_delete' );
115 del.onclick = function() { clDelete( cl, tbody, row ); };
116 checkDisabled( del, cl.owning_lib(), 'DELETE_COPY_LOCATION');
119 function clEdit( cl, tbody, row ) {
121 cleanTbody(tbody, 'edit');
122 var r = $('cl_edit').cloneNode(true);
123 r.setAttribute('edit','1');
125 var name = $n(r, 'cl_edit_name');
126 name.setAttribute('size', cl.name().length + 3);
127 name.value = cl.name();
129 $n(r, 'cl_edit_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
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;
139 $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');}
140 $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); }
142 insRow(tbody, row, r);
147 function _clOptions(r) {
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');
158 function clEditCommit( tbody, r, cl ) {
160 var arr = _clOptions(r);
161 if(arr[0].checked) cl.holdable(1);
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);
169 var req = new Request( UPDATE_CL, SESSION, cl );
171 var res = req.result();
172 if(checkILSEvent(res)) throw res;
173 alertId('cl_update_success');
179 function clDelete( cl, tbody, row ) {
180 if(!confirm($('cl_delete_confirm').innerHTML)) return;
181 var req = new Request( DELETE_CL, SESSION, cl.id() );
183 var res = req.result();
184 if(checkILSEvent(res)) throw res;
185 alertId('cl_update_success');