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";
7 'DELETE_NON_CAT_TYPE' ];
9 function ncEditorInit() {
11 $('nc_user').appendChild(text(USER.usrname()));
12 setTimeout( function() {
13 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
15 ncFetchTypes(); }, 20 );
19 function ncBuildNew() {
21 var name = $('nc_new_name');
23 setEnterFunc(name, ncCreateNew );
25 var org = findOrgUnit(PERMS['CREATE_NON_CAT_TYPE']);
26 var mydepth = findOrgDepth(org);
27 if( mydepth == -1 ) return;
29 var selector = $('nc_new_owner');
30 buildOrgSel(selector, org, mydepth );
31 if(org.children() && org.children()[0])
32 selector.disabled = false;
34 $('nc_new_submit').disabled = false;
35 $('nc_new_submit').onclick = ncCreateNew;
39 function ncFetchTypes() {
40 var req = new Request( FETCH_NON_CAT_TYPES, USER.home_ou() );
41 req.callback(ncDisplayTypes);
45 function ncCreateNew() {
46 var name = $('nc_new_name').value;
48 var org = getSelectorVal($('nc_new_owner'));
49 var req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org );
51 var res = req.result();
52 if(checkILSEvent(res)) throw res;
58 function ncDisplayTypes(r) {
60 var types = r.getResultObject();
61 var tbody = $('nc_tbody');
63 rowTemplate = tbody.removeChild($('nc_row_template'));
65 removeChildren(tbody);
68 if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
69 if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
74 for( var idx = 0; idx != types.length; idx++ ) {
75 var type = types[idx];
76 var org = findOrgUnit( type.owning_lib() );
77 var row = rowTemplate.cloneNode(true);
78 row.id = 'nc_row_' + type.id();
79 $n(row, 'nc_name').appendChild(text(type.name()));
80 $n(row, 'nc_owner').appendChild( text( org.name() ));
81 ncSetRowCallbacks( type, org, tbody, row );
82 tbody.appendChild(row);
86 function ncSetRowCallbacks( type, owner, tbody, row ) {
88 checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
91 mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
92 if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;
94 checkDisabled( $n(row, 'nc_delete'), owner, 'DELETE_NON_CAT_TYPE' );
96 $n(row, 'nc_edit').onclick =
97 function() { ncEditType( tbody, row, type ); };
99 $n(row, 'nc_delete').onclick =
100 function() { ncDeleteType( tbody, row, type ); };
103 function ncEditType( tbody, row, type ) {
104 cleanTbody(row.parentNode, 'edit');
105 var row = $('nc_edit_row_temaplate').cloneNode(true);
107 var name = $n(row, 'nc_edit_name');
108 name.value = type.name();
110 $n(row, 'nc_edit_submit').onclick = function() {
111 var name = $n(row, 'nc_edit_name').value;
112 ncEditSubmit( type, name );
115 $n(row, 'nc_edit_cancel').onclick =
116 function(){cleanTbody(row.parentNode, 'edit'); }
118 var r = $('nc_row_' + type.id());
119 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
120 else{ tbody.appendChild(row); }
126 function ncEditSubmit( type, name ) {
129 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
131 var res = req.result();
132 if(checkILSEvent(res)) throw res;
136 function ncDeleteType( tbody, row, type ) {
137 alert("Deleting type " + type.id() );