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 req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org, time + ' ' + type );
54 var res = req.result();
55 if(checkILSEvent(res)) throw res;
61 function ncDisplayTypes(r) {
63 var types = r.getResultObject();
64 var tbody = $('nc_tbody');
66 rowTemplate = tbody.removeChild($('nc_row_template'));
68 removeChildren(tbody);
71 if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
72 if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
76 for( var idx = 0; idx != types.length; idx++ ) {
78 var type = types[idx];
79 var org = findOrgUnit( type.owning_lib() );
80 var row = rowTemplate.cloneNode(true);
82 row.id = 'nc_row_' + type.id();
83 $n(row, 'nc_name').appendChild(text(type.name()));
84 $n(row, 'nc_owner').appendChild(text(org.name()));
86 var idata = _splitInterval(type.circ_duration());
87 $n(row, 'nc_interval_count').value = idata[0];
88 setSelector( $n(row, 'nc_interval_type'), idata[1]);
90 ncSetRowCallbacks( type, org, tbody, row );
91 tbody.appendChild(row);
95 /* this is a kind of brittle, but works with the data we create */
96 function _splitInterval( interval ) {
97 interval = interval.split(/ /);
98 var time = interval[0];
99 var type = interval[1];
100 if( time.match(/:/) ) return [ time.replace(/(\d{2}):\d{2}:\d{2}/,'$1'), 'hours' ];
101 if( type.match(/h/) ) return [ time, 'hours' ];
102 if( type.match(/d/) ) return [ time, 'days' ];
103 if( type.match(/w/) ) return [ time, 'weeks' ];
104 if( type.match(/m/) ) return [ time, 'months' ];
107 function ncSetRowCallbacks( type, owner, tbody, row ) {
109 checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
112 mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
113 if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;
115 checkDisabled( $n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE' );
117 $n(row, 'nc_edit').onclick =
118 function() { ncEditType( tbody, row, type ); };
120 $n(row, 'nc_delete').onclick =
121 function() { ncDeleteType( tbody, row, type ); };
124 function ncEditType( tbody, row, type ) {
125 cleanTbody(row.parentNode, 'edit');
126 var row = $('nc_edit_row_temaplate').cloneNode(true);
128 var name = $n(row, 'nc_edit_name');
129 name.value = type.name();
131 var idata = _splitInterval(type.circ_duration());
132 $n(row, 'nc_edit_interval_count').value = idata[0];
133 setSelector( $n(row, 'nc_edit_interval_type'), idata[1]);
135 $n(row, 'nc_edit_submit').onclick = function() {
136 var name = $n(row, 'nc_edit_name').value;
137 var time = $n(row, 'nc_edit_interval_count').value;
138 var tp = getSelectorVal($n(row, 'nc_edit_interval_type'));
139 ncEditSubmit( type, name, time + ' ' + tp );
142 $n(row, 'nc_edit_cancel').onclick =
143 function(){cleanTbody(row.parentNode, 'edit'); }
145 var r = $('nc_row_' + type.id());
146 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
147 else{ tbody.appendChild(row); }
153 function ncEditSubmit( type, name, interval ) {
156 type.circ_duration(interval);
157 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
159 var res = req.result();
160 if(checkILSEvent(res)) throw res;
164 function ncDeleteType( tbody, row, type ) {
165 if( ! confirm($('nc_delete_confirm').innerHTML) ) return;
166 var req = new Request(DELETE_NON_CAT_TYPE, SESSION, type.id());
169 var res = r.getResultObject();
170 if(checkILSEvent(res)) alertILSEvent(res);