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' ];
10 function ncEditorInit() {
12 $('nc_user').appendChild(text(USER.usrname()));
13 setTimeout( function() {
14 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
16 ncFetchTypes(); }, 20 );
20 function ncBuildNew() {
22 var name = $('nc_new_name');
24 setEnterFunc(name, ncCreateNew );
26 var org = findOrgUnit(PERMS['CREATE_NON_CAT_TYPE']);
27 var mydepth = findOrgDepth(org);
28 if( mydepth == -1 ) return;
30 var selector = $('nc_new_owner');
31 buildOrgSel(selector, org, mydepth );
32 if(org.children() && org.children()[0])
33 selector.disabled = false;
35 $('nc_new_submit').disabled = false;
36 $('nc_new_submit').onclick = ncCreateNew;
40 function ncFetchTypes() {
41 var req = new Request( FETCH_NON_CAT_TYPES, USER.home_ou() );
42 req.callback(ncDisplayTypes);
46 function ncCreateNew() {
47 var name = $('nc_new_name').value;
49 var org = getSelectorVal($('nc_new_owner'));
50 var time = $('nc_new_interval_count').value;
51 var type = getSelectorVal($('nc_new_interval_type'));
52 var inh = $('nc_new_inhouse').checked ? 1 : null;
54 var req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org, time + ' ' + type, inh );
56 var res = req.result();
57 if(checkILSEvent(res)) throw res;
63 function ncDisplayTypes(r) {
65 var types = r.getResultObject();
66 var tbody = $('nc_tbody');
68 rowTemplate = tbody.removeChild($('nc_row_template'));
70 removeChildren(tbody);
74 if( a.name()+''.toLowerCase() > b.name()+''.toLowerCase() ) return 1;
75 if( a.name()+''.toLowerCase() < b.name()+''.toLowerCase() ) return -1;
80 for( var idx = 0; idx != types.length; idx++ ) {
82 var type = types[idx];
83 var org = findOrgUnit( type.owning_lib() );
84 var row = rowTemplate.cloneNode(true);
87 row.id = 'nc_row_' + type.id();
88 $n(row, 'nc_name').appendChild(text(type.name()));
89 $n(row, 'nc_owner').appendChild(text(org.name()));
90 $n(row, 'nc_inhouse').checked = isTrue(type.in_house());
92 var idata = _splitInterval(type.circ_duration());
93 $n(row, 'nc_interval_count').value = idata[0];
94 setSelector( $n(row, 'nc_interval_type'), idata[1]);
96 ncSetRowCallbacks( type, org, tbody, row );
97 tbody.appendChild(row);
101 /* this is a kind of brittle, but works with the data we create */
102 function _splitInterval( interval ) {
103 interval = interval.split(/ /);
104 var time = interval[0];
105 var type = interval[1];
107 if( time.match(/:/) ) {
108 var d = time.split(/:/);
109 if(d[0] == '00') return [ d[1], 'minutes' ];
110 if(d[0] != '00' && d[1] != '00')
111 return [ parseInt(d[1]) + (d[0]*60), 'minutes' ];
112 return [ d[0], 'hours' ]
115 if( type.match(/mi/i) ) return [ time, 'minutes' ];
116 if( type.match(/h/i) ) return [ time, 'hours' ];
117 if( type.match(/d/i) ) return [ time, 'days' ];
118 if( type.match(/w/i) ) return [ time, 'weeks' ];
119 if( type.match(/mo/i) ) return [ time, 'months' ];
122 function ncSetRowCallbacks( type, owner, tbody, row ) {
124 checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
126 checkDisabled( $n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE' );
128 $n(row, 'nc_edit').onclick =
129 function() { ncEditType( tbody, row, type ); };
131 $n(row, 'nc_delete').onclick =
132 function() { ncDeleteType( tbody, row, type ); };
135 function ncEditType( tbody, row, type ) {
136 cleanTbody(row.parentNode, 'edit');
137 var row = $('nc_edit_row_temaplate').cloneNode(true);
139 var name = $n(row, 'nc_edit_name');
140 name.value = type.name();
142 var idata = _splitInterval(type.circ_duration());
143 $n(row, 'nc_edit_interval_count').value = idata[0];
144 setSelector( $n(row, 'nc_edit_interval_type'), idata[1]);
146 $n(row, 'nc_edit_inhouse').checked = isTrue(type.in_house());
147 $n(row, 'nc_edit_owner').appendChild(text( findOrgUnit(type.owning_lib()).name() ));
149 $n(row, 'nc_edit_submit').onclick = function() {
150 var name = $n(row, 'nc_edit_name').value;
151 var time = $n(row, 'nc_edit_interval_count').value;
152 var tp = getSelectorVal($n(row, 'nc_edit_interval_type'));
153 var inh = $n(row, 'nc_edit_inhouse').checked ? 't' : 'f';
154 ncEditSubmit( type, name, time + ' ' + tp, inh );
157 $n(row, 'nc_edit_cancel').onclick =
158 function(){cleanTbody(row.parentNode, 'edit'); }
160 var r = $('nc_row_' + type.id());
161 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
162 else{ tbody.appendChild(row); }
168 function ncEditSubmit( type, name, interval, inhouse ) {
171 type.circ_duration(interval);
172 type.in_house(inhouse);
173 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
175 var res = req.result();
176 if(checkILSEvent(res)) throw res;
180 function ncDeleteType( tbody, row, type ) {
181 if( ! confirm($('nc_delete_confirm').innerHTML) ) return;
182 var req = new Request(DELETE_NON_CAT_TYPE, SESSION, type.id());
185 var res = r.getResultObject();
186 if(checkILSEvent(res)) alertILSEvent(res);