1 var FETCH_NON_CAT_TYPES = "open-ils.circ:open-ils.circ.non_cat_types.retrieve.all";
2 var CREATE_NON_CAT_TYPE = "open-ils.circ:open-ils.circ.non_cat_type.create";
3 var UPDATE_NON_CAT_TYPE = "open-ils.circ:open-ils.circ.non_cat_type.update";
4 var DELETE_NON_CAT_TYPE = 'open-ils.circ:open-ils.circ.non_cataloged_type.delete';
8 'DELETE_NON_CAT_TYPE' ];
12 function ncEditorInit() {
14 $('nc_user').appendChild(text(USER.usrname()));
17 fetchHighestWorkPermOrgs(SESSION, USER.id(), myPerms,
27 function ncSetupFocus() {
28 var fselector = $('nc_org_filter');
29 var org_list = OILS_WORK_PERMS.UPDATE_NON_CAT_TYPE;
30 if(org_list.length == 0)
32 fselector.disabled = false;
33 buildMergedOrgSel(fselector, org_list, 0, 'shortname');
34 fselector.onchange = function() {
35 focusOrg = getSelectorVal(fselector);
40 focusOrg = USER.ws_ou();
41 if(!orgIsMineFromSet(org_list, USER.ws_ou()))
42 focusOrg = org_list[0];
43 setSelector(fselector, focusOrg);
46 function ncBuildNew() {
48 var name = $('nc_new_name');
51 var org_list = OILS_WORK_PERMS.CREATE_NON_CAT_TYPE;
52 if(org_list.length == 0) return;
54 var selector = $('nc_new_owner');
55 buildMergedOrgSel(selector, org_list, 0, 'shortname');
56 selector.disabled = false;
58 $('nc_new_submit').disabled = false;
59 $('nc_new_submit').onclick = ncCreateNew;
63 function ncFetchTypes() {
64 var req = new Request( FETCH_NON_CAT_TYPES, focusOrg );
65 req.callback(ncDisplayTypes);
66 setTimeout(function(){req.send();}, 500);
69 function ncCreateNew() {
70 var name = $('nc_new_name').value;
72 var org = getSelectorVal($('nc_new_owner'));
73 var time = $('nc_new_interval_count').value;
74 var type = getSelectorVal($('nc_new_interval_type'));
75 var inh = $('nc_new_inhouse').checked ? 1 : null;
77 var req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org, time + ' ' + type, inh );
78 req.request.alertEvent = false;
80 var res = req.result();
82 if(checkILSEvent(res)) {
83 if( res.textcode == 'NON_CAT_TYPE_EXISTS' )
84 return alertId('nc_type_exists');
88 alertId('nc_update_success');
94 function ncDisplayTypes(r) {
96 var types = r.getResultObject();
97 var tbody = $('nc_tbody');
99 rowTemplate = tbody.removeChild($('nc_row_template'));
101 removeChildren(tbody);
105 if( a.name()+''.toLowerCase() > b.name()+''.toLowerCase() ) return 1;
106 if( a.name()+''.toLowerCase() < b.name()+''.toLowerCase() ) return -1;
111 for( var idx = 0; idx != types.length; idx++ ) {
113 var type = types[idx];
114 var org = findOrgUnit( type.owning_lib() );
115 var row = rowTemplate.cloneNode(true);
118 row.id = 'nc_row_' + type.id();
119 $n(row, 'nc_name').appendChild(text(type.name()));
120 $n(row, 'nc_owner').appendChild(text(org.name()));
121 $n(row, 'nc_inhouse').checked = isTrue(type.in_house());
123 var idata = _splitInterval(type.circ_duration());
124 $n(row, 'nc_interval_count').value = idata[0];
125 setSelector( $n(row, 'nc_interval_type'), idata[1]);
127 ncSetRowCallbacks( type, org, tbody, row );
128 tbody.appendChild(row);
132 /* this is a kind of brittle, but works with the data we create */
133 function _splitInterval( interval ) {
134 interval = interval.split(/ /);
135 var time = interval[0];
136 var type = interval[1];
138 if( time.match(/:/) ) {
139 var d = time.split(/:/);
140 if(d[0] == '00') return [ d[1], 'minutes' ];
141 if(d[0] != '00' && d[1] != '00')
142 return [ parseInt(d[1]) + (d[0]*60), 'minutes' ];
143 return [ d[0], 'hours' ]
146 if( type.match(/mi/i) ) return [ time, 'minutes' ];
147 if( type.match(/h/i) ) return [ time, 'hours' ];
148 if( type.match(/d/i) ) return [ time, 'days' ];
149 if( type.match(/w/i) ) return [ time, 'weeks' ];
150 if( type.match(/mo/i) ) return [ time, 'months' ];
153 function ncSetRowCallbacks( type, owner, tbody, row ) {
155 checkPermOrgDisabled($n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
157 checkPermOrgDisabled($n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE');
159 $n(row, 'nc_edit').onclick =
160 function() { ncEditType( tbody, row, type ); };
162 $n(row, 'nc_delete').onclick =
163 function() { ncDeleteType( tbody, row, type ); };
166 function ncEditType( tbody, row, type ) {
167 cleanTbody(row.parentNode, 'edit');
168 var row = $('nc_edit_row_template').cloneNode(true);
170 var name = $n(row, 'nc_edit_name');
171 name.value = type.name();
173 var idata = _splitInterval(type.circ_duration());
174 $n(row, 'nc_edit_interval_count').value = idata[0];
175 setSelector( $n(row, 'nc_edit_interval_type'), idata[1]);
177 $n(row, 'nc_edit_inhouse').checked = isTrue(type.in_house());
178 $n(row, 'nc_edit_owner').appendChild(text( findOrgUnit(type.owning_lib()).name() ));
180 $n(row, 'nc_edit_submit').onclick = function() {
181 var name = $n(row, 'nc_edit_name').value;
182 var time = $n(row, 'nc_edit_interval_count').value;
183 var tp = getSelectorVal($n(row, 'nc_edit_interval_type'));
184 var inh = $n(row, 'nc_edit_inhouse').checked ? 't' : 'f';
185 ncEditSubmit( type, name, time + ' ' + tp, inh );
188 $n(row, 'nc_edit_cancel').onclick =
189 function(){cleanTbody(row.parentNode, 'edit'); }
191 var r = $('nc_row_' + type.id());
192 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
193 else{ tbody.appendChild(row); }
199 function ncEditSubmit( type, name, interval, inhouse ) {
202 type.circ_duration(interval);
203 type.in_house(inhouse);
204 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
206 var res = req.result();
207 if(checkILSEvent(res)) throw res;
208 alertId('nc_update_success');
212 function ncDeleteType( tbody, row, type ) {
213 if( ! confirm($('nc_delete_confirm').innerHTML) ) return;
214 var req = new Request(DELETE_NON_CAT_TYPE, SESSION, type.id());
217 var res = r.getResultObject();
218 if(checkILSEvent(res)) alertILSEvent(res);
219 alertId('nc_update_success');