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 );
18 function ncBuildNew() {
20 var name = $('nc_new_name');
22 setEnterFunc(name, ncCreateNew );
24 var org = findOrgUnit(PERMS['CREATE_NON_CAT_TYPE']);
25 var mydepth = findOrgDepth(org);
26 if( mydepth == -1 ) return;
28 var selector = $('nc_new_owner');
29 buildOrgSel(selector, org, mydepth );
30 if(org.children() && org.children()[0])
31 selector.disabled = false;
33 $('nc_new_submit').disabled = false;
34 $('nc_new_submit').onclick = ncCreateNew;
38 function ncFetchTypes() {
39 var req = new Request( FETCH_NON_CAT_TYPES, USER.home_ou() );
40 req.callback(ncDisplayTypes);
44 function ncCreateNew() {
45 var name = $('nc_new_name').value;
47 var org = getSelectorVal($('nc_new_owner'));
48 var req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org );
50 var res = req.result();
51 if(checkILSEvent(res)) throw res;
57 function ncDisplayTypes(r) {
59 var types = r.getResultObject();
60 var tbody = $('nc_tbody');
62 rowTemplate = tbody.removeChild($('nc_row_template'));
64 removeChildren(tbody);
67 if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1;
68 if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;
73 for( var idx = 0; idx != types.length; idx++ ) {
74 var type = types[idx];
75 var org = findOrgUnit( type.owning_lib() );
76 var row = rowTemplate.cloneNode(true);
77 row.id = 'nc_row_' + type.id();
78 $n(row, 'nc_name').appendChild(text(type.name()));
79 $n(row, 'nc_owner').appendChild( text( org.name() ));
80 ncSetRowCallbacks( type, org, tbody, row );
81 tbody.appendChild(row);
85 function ncSetRowCallbacks( type, owner, tbody, row ) {
86 var tdepth = findOrgDepth( owner );
87 var mydepth = findOrgDepth( PERMS['UPDATE_NON_CAT_TYPE'] );
88 if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_edit').disabled = false;
90 mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
91 if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;
93 $n(row, 'nc_edit').onclick =
94 function() { ncEditType( tbody, row, type ); };
96 $n(row, 'nc_delete').onclick =
97 function() { ncDeleteType( tbody, row, type ); };
100 function ncEditType( tbody, row, type ) {
101 cleanTbody(row.parentNode, 'edit');
102 var row = $('nc_edit_row_temaplate').cloneNode(true);
104 var name = $n(row, 'nc_edit_name');
105 name.value = type.name();
109 $n(row, 'nc_edit_submit').onclick = function() {
110 var name = $n(row, 'nc_edit_name').value;
111 ncEditSubmit( type, name );
114 $n(row, 'nc_edit_cancel').onclick =
115 function(){cleanTbody(row.parentNode, 'edit'); }
117 var r = $('nc_row_' + type.id());
118 if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
119 else{ tbody.appendChild(row); }
122 function ncEditSubmit( type, name ) {
125 var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
127 var res = req.result();
128 if(checkILSEvent(res)) throw res;
132 function ncDeleteType( tbody, row, type ) {
133 alert("Deleting type " + type.id() );