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);
73 if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
74 if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
78 for( var idx = 0; idx != types.length; idx++ ) {
80 var type = types[idx];
81 var org = findOrgUnit( type.owning_lib() );
82 var row = rowTemplate.cloneNode(true);
85 row.id = 'nc_row_' + type.id();
86 $n(row, 'nc_name').appendChild(text(type.name()));
87 $n(row, 'nc_owner').appendChild(text(org.name()));
88 $n(row, 'nc_inhouse').checked = isTrue(type.in_house());
90 var idata = _splitInterval(type.circ_duration());
91 $n(row, 'nc_interval_count').value = idata[0];
92 setSelector( $n(row, 'nc_interval_type'), idata[1]);
94 ncSetRowCallbacks( type, org, tbody, row );
95 tbody.appendChild(row);
99 /* this is a kind of brittle, but works with the data we create */
100 function _splitInterval( interval ) {
101 interval = interval.split(/ /);
102 var time = interval[0];
103 var type = interval[1];
105 if( time.match(/:/) ) {
106 var d = time.split(/:/);
107 if(d[0] == '00') return [ d[1], 'minutes' ];
108 if(d[0] != '00' && d[1] != '00')
109 return [ parseInt(d[1]) + (d[0]*60), 'minutes' ];
110 return [ d[0], 'hours' ]
113 if( type.match(/mi/i) ) return [ time, 'minutes' ];
114 if( type.match(/h/i) ) return [ time, 'hours' ];
115 if( type.match(/d/i) ) return [ time, 'days' ];
116 if( type.match(/w/i) ) return [ time, 'weeks' ];
117 if( type.match(/mo/i) ) return [ time, 'months' ];
120 function ncSetRowCallbacks( type, owner, tbody, row ) {
122 checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
124 checkDisabled( $n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE' );
126 $n(row, 'nc_edit').onclick =
127 function() { ncEditType( tbody, row, type ); };
129 $n(row, 'nc_delete').onclick =
130 function() { ncDeleteType( tbody, row, type ); };
133 function ncEditType( tbody, row, type ) {
134 cleanTbody(row.parentNode, 'edit');
135 var row = $('nc_edit_row_temaplate').cloneNode(true);
137 var name = $n(row, 'nc_edit_name');
138 name.value = type.name();
140 var idata = _splitInterval(type.circ_duration());
141 $n(row, 'nc_edit_interval_count').value = idata[0];
142 setSelector( $n(row, 'nc_edit_interval_type'), idata[1]);
144 $n(row, 'nc_edit_inhouse').checked = isTrue(type.in_house());
145 $n(row, 'nc_edit_owner').appendChild(text( findOrgUnit(type.owning_lib()).name() ));
147 $n(row, 'nc_edit_submit').onclick = function() {
148 var name = $n(row, 'nc_edit_name').value;
149 var time = $n(row, 'nc_edit_interval_count').value;
150 var tp = getSelectorVal($n(row, 'nc_edit_interval_type'));
151 var inh = $n(row, 'nc_edit_inhouse').checked ? 't' : 'f';
152 ncEditSubmit( type, name, time + ' ' + tp, inh );
155 $n(row, 'nc_edit_cancel').onclick =
156 function(){cleanTbody(row.parentNode, 'edit'); }
158 var r = $('nc_row_' + type.id());
159 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
160 else{ tbody.appendChild(row); }
166 function ncEditSubmit( type, name, interval, inhouse ) {
169 type.circ_duration(interval);
170 type.in_house(inhouse);
171 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
173 var res = req.result();
174 if(checkILSEvent(res)) throw res;
178 function ncDeleteType( tbody, row, type ) {
179 if( ! confirm($('nc_delete_confirm').innerHTML) ) return;
180 var req = new Request(DELETE_NON_CAT_TYPE, SESSION, type.id());
183 var res = r.getResultObject();
184 if(checkILSEvent(res)) alertILSEvent(res);