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 req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org );
52 var res = req.result();
53 if(checkILSEvent(res)) throw res;
59 function ncDisplayTypes(r) {
61 var types = r.getResultObject();
62 var tbody = $('nc_tbody');
64 rowTemplate = tbody.removeChild($('nc_row_template'));
66 removeChildren(tbody);
69 if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
70 if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
75 for( var idx = 0; idx != types.length; idx++ ) {
76 var type = types[idx];
77 var org = findOrgUnit( type.owning_lib() );
78 var row = rowTemplate.cloneNode(true);
79 row.id = 'nc_row_' + type.id();
80 $n(row, 'nc_name').appendChild(text(type.name()));
81 $n(row, 'nc_owner').appendChild( text( org.name() ));
82 ncSetRowCallbacks( type, org, tbody, row );
83 tbody.appendChild(row);
87 function ncSetRowCallbacks( type, owner, tbody, row ) {
89 checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
92 mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
93 if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;
95 checkDisabled( $n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE' );
97 $n(row, 'nc_edit').onclick =
98 function() { ncEditType( tbody, row, type ); };
100 $n(row, 'nc_delete').onclick =
101 function() { ncDeleteType( tbody, row, type ); };
104 function ncEditType( tbody, row, type ) {
105 cleanTbody(row.parentNode, 'edit');
106 var row = $('nc_edit_row_temaplate').cloneNode(true);
108 var name = $n(row, 'nc_edit_name');
109 name.value = type.name();
111 $n(row, 'nc_edit_submit').onclick = function() {
112 var name = $n(row, 'nc_edit_name').value;
113 ncEditSubmit( type, name );
116 $n(row, 'nc_edit_cancel').onclick =
117 function(){cleanTbody(row.parentNode, 'edit'); }
119 var r = $('nc_row_' + type.id());
120 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
121 else{ tbody.appendChild(row); }
127 function ncEditSubmit( type, name ) {
130 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
132 var res = req.result();
133 if(checkILSEvent(res)) throw res;
137 function ncDeleteType( tbody, row, type ) {
138 if( ! confirm($('nc_delete_confirm').innerHTML) ) return;
139 var req = new Request(DELETE_NON_CAT_TYPE, SESSION, type.id());
142 var res = r.getResultObject();
143 if(checkILSEvent(res)) alertILSEvent(res);