more coming together of the admin editor code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Jan 2006 21:31:35 +0000 (21:31 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Jan 2006 21:31:35 +0000 (21:31 +0000)
adding first round of the non-cataloged items editor.. need to add ranged retrieval

git-svn-id: svn://svn.open-ils.org/ILS/trunk@2839 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/admin/admin.css [new file with mode: 0644]
Open-ILS/xul/staff_client/server/admin/adminlib.js
Open-ILS/xul/staff_client/server/admin/non_cat_types.js [new file with mode: 0644]
Open-ILS/xul/staff_client/server/admin/non_cat_types.xml [new file with mode: 0644]
Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js
Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xml

diff --git a/Open-ILS/xul/staff_client/server/admin/admin.css b/Open-ILS/xul/staff_client/server/admin/admin.css
new file mode 100644 (file)
index 0000000..2979b0e
--- /dev/null
@@ -0,0 +1,15 @@
+.welcome_box { position:absolute; top: 5px; right: 5px; }
+.title { font-weight: bold; font-size: 14pt; margin: 10px;}
+.hide_me { visibility: hidden; display: none }
+.has_color { background: #E0F0E0; color: #000000; }
+.data_grid { font-weight: 500; border-collapse: collapse;}
+.data_grid thead tr { background: #E0F0E0; color: #000000; }
+.data_grid thead td { border: 1px solid #808080; padding-right: 5px; padding-left: 5px;}
+.data_grid tbody td { border: 1px solid #E0E0E0; padding: 5px; }
+.data_grid_center { text-align: center; }
+.data_grid_padded tbody td { padding: 10px; }
+.insert_row { border: 2px solid #A0B0A0; padding: 50px;}
+.padded { padding-left: 7px; padding-right: 7px; }
+select { width: 12em; }
+.select_big { width: 15em; }
+
index e00ee30..ebe61a5 100644 (file)
@@ -30,5 +30,23 @@ function fetchHighestPermOrgs( session, userId, perms ) {
        var orgs = req.getResultObject();
        for( var i = 0; i != orgs.length; i++ ) 
                PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
-       return 
+       return orgs;
+}
+
+/* offset is the depth of the highest org 
+       in the tree we're building 
+  */
+function buildOrgSel(selector, org, offset) {
+       insertSelectorVal( selector, -1, 
+               org.name(), org.id(), null, findOrgDepth(org) - offset );
+       for( var c in org.children() )
+               buildOrgSel( selector, org.children()[c], offset);
+}
+
+/** removes all child nodes in 'tbody' that have the attribute 'key' defined */
+function cleanTbody(tbody, key) {
+       for( var c  = 0; c < tbody.childNodes.length; c++ ) {
+               var child = tbody.childNodes[c];
+               if(child && child.getAttribute(key)) tbody.removeChild(child); 
+       }
 }
diff --git a/Open-ILS/xul/staff_client/server/admin/non_cat_types.js b/Open-ILS/xul/staff_client/server/admin/non_cat_types.js
new file mode 100644 (file)
index 0000000..fb31c23
--- /dev/null
@@ -0,0 +1,136 @@
+var FETCH_NON_CAT_TYPES = "open-ils.circ:open-ils.circ.non_cat_types.retrieve.all";
+var CREATE_NON_CAT_TYPE = "open-ils.circ:open-ils.circ.non_cat_type.create";
+var UPDATE_NON_CAT_TYPE = "open-ils.circ:open-ils.circ.non_cat_type.update";
+var myPerms = [ 
+       'CREATE_NON_CAT_TYPE', 
+       'UPDATE_NON_CAT_TYPE',
+       'DELETE_NON_CAT_TYPE' ];
+
+function ncEditorInit() {
+       fetchUser();
+       $('nc_user').appendChild(text(USER.usrname()));
+       setTimeout( function() { 
+               fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
+               ncBuildNew();
+               ncFetchTypes(); }, 20 );
+}
+
+function ncBuildNew() {
+
+       var name = $('nc_new_name');
+       name.focus();
+       setEnterFunc(name, ncCreateNew );
+
+       var org = findOrgUnit(PERMS['CREATE_NON_CAT_TYPE']);
+       var mydepth = findOrgDepth(org);
+       if( mydepth == -1 ) return;
+
+       var selector = $('nc_new_owner');
+       buildOrgSel(selector, org, mydepth );
+       if(org.children() && org.children()[0]) 
+               selector.disabled = false;
+
+       $('nc_new_submit').disabled = false;
+       $('nc_new_submit').onclick = ncCreateNew;
+}
+
+
+function ncFetchTypes() {
+       var req = new Request( FETCH_NON_CAT_TYPES, USER.home_ou() );   
+       req.callback(ncDisplayTypes);
+       req.send();
+}
+
+function ncCreateNew() {
+       var name = $('nc_new_name').value;
+       if(!name) return;
+       var org = getSelectorVal($('nc_new_owner'));
+       var req = new Request(CREATE_NON_CAT_TYPE, SESSION, name, org );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       ncFetchTypes();
+}
+
+
+var rowTemplate;
+function ncDisplayTypes(r) {
+
+       var types = r.getResultObject();
+       var tbody = $('nc_tbody');
+       if(!rowTemplate) 
+               rowTemplate = tbody.removeChild($('nc_row_template'));
+
+       removeChildren(tbody);
+       types = types.sort( 
+               function(a,b) {
+                       if( a.name().toLowerCase() > b.name().toLowerCase() ) return 1; 
+                       if( a.name().toLowerCase() < b.name().toLowerCase() ) return -1;        
+                       return 0;
+               });
+
+
+       for( var idx = 0; idx != types.length; idx++ ) {
+               var type = types[idx];
+               var org = findOrgUnit( type.owning_lib() );
+               var row = rowTemplate.cloneNode(true);
+               row.id = 'nc_row_' + type.id();
+               $n(row, 'nc_name').appendChild(text(type.name()));
+               $n(row, 'nc_owner').appendChild( text( org.name() ));
+               ncSetRowCallbacks( type, org, tbody, row );
+               tbody.appendChild(row);
+       }
+}
+
+function ncSetRowCallbacks( type, owner, tbody, row ) {
+       var tdepth = findOrgDepth( owner );
+       var mydepth = findOrgDepth( PERMS['UPDATE_NON_CAT_TYPE'] );
+       if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_edit').disabled = false;
+
+       mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
+       if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;
+
+       $n(row, 'nc_edit').onclick = 
+               function() { ncEditType( tbody, row, type ); };
+
+       $n(row, 'nc_delete').onclick = 
+               function() { ncDeleteType( tbody, row, type ); };
+}
+
+function ncEditType( tbody, row, type ) {
+       cleanTbody(row.parentNode, 'edit');
+       var row = $('nc_edit_row_temaplate').cloneNode(true);
+
+       var name = $n(row, 'nc_edit_name');
+       name.value = type.name();
+       name.focus();
+       name.select();
+
+       $n(row, 'nc_edit_submit').onclick = function() { 
+               var name = $n(row, 'nc_edit_name').value;
+               ncEditSubmit( type, name );
+       };
+
+       $n(row, 'nc_edit_cancel').onclick = 
+               function(){cleanTbody(row.parentNode, 'edit'); }
+
+       var r = $('nc_row_' + type.id());
+       if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
+       else{ tbody.appendChild(row); }
+}
+
+function ncEditSubmit( type, name ) {
+       if(!name) return;
+       type.name(name);
+       var req = new Request( UPDATE_NON_CAT_TYPE, SESSION, type );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       ncFetchTypes();
+}
+
+function ncDeleteType( tbody, row, type ) {
+       alert("Deleting type " + type.id() );
+}
+
+
diff --git a/Open-ILS/xul/staff_client/server/admin/non_cat_types.xml b/Open-ILS/xul/staff_client/server/admin/non_cat_types.xml
new file mode 100644 (file)
index 0000000..f77f09f
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version='1.0'?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
+
+       <head>
+               <title>Evergreen: Non Cataloged Types Editor</title>
+               <script language='javascript' src='/opac/common/js/utils.js'> </script>
+               <script language='javascript' src='/opac/common/js//config.js'> </script>
+               <script language='javascript' src='/opac/common/js/CGI.js'> </script>
+               <script language='javascript' src='/opac/common/js/Cookie.js'> </script>
+       
+               <script language='javascript' src='/opac/common/js/slimtree.js'> </script>
+               <script language='javascript' src='/opac/common/js/JSON.js'> </script>
+               <script language='javascript' src='/opac/common/js/fmall.js'> </script>
+               <script language='javascript' src='/opac/common/js/fmgen.js'> </script>
+               <script language='javascript' src='/opac/common/js/opac_utils.js'> </script>
+               <script language='javascript' src='/opac/common/js/OrgTree.js'> </script>
+               <script language='javascript' src='/opac/common/js/org_utils.js'> </script>
+               <script language='javascript' src='/opac/common/js/init.js'> </script>
+               <script language='javascript' src='/opac/common/js/RemoteRequest.js'> </script>
+               <script language='javascript' src='adminlib.js'> </script>
+               <script language='javascript' src='non_cat_types.js'> </script>
+
+               <link type='text/css' rel='stylesheet' href='admin.css' name='meduim_fonts' csstype='font'/>
+       </head>
+
+       <body onload='try{ncEditorInit();}catch(e){alert(js2JSON(e));}'>
+
+               <div class='welcome_box'>
+                       <span>Welcome </span><b><span id='nc_user'/></b>
+               </div>
+
+               <center>
+                       <div class='title'> Non Cataloged Types Editor </div>
+
+                       <br/>
+
+                       <table class='data_grid data_grid_center' width='65%'>
+                               <thead>
+                                       <tr><td colspan='3'>Create a new non-cataloged type</td></tr>
+                               </thead>
+                               <tbody>
+                                       <tr>
+                                               <td><input id='nc_new_name'> </input></td>
+                                               <td><select class='select_big' id='nc_new_owner' disabled='disabled'> </select></td>
+                                               <td><input id='nc_new_submit' type='submit' value='Create' disabled='disabled'> </input></td>
+                                       </tr>
+                               </tbody>
+                       </table>
+
+                       <br/> <hr/> <br/>
+
+                       <table id='nc_table' class='data_grid' width='85%'>
+                               <thead>
+                                       <tr>
+                                               <td>Name</td>
+                                               <td>Owning Location</td>
+                                               <td>Edit</td>
+                                               <td>Delete</td>
+                                       </tr>
+                               </thead>
+                               <tbody id='nc_tbody'>
+                                       <tr id='nc_row_template'>
+                                               <td name='nc_name'/>
+                                               <td name='nc_owner'/>
+                                               <td><input name='nc_edit' type='submit' value='Edit' disabled='disabled'/></td>
+                                               <td><input name='nc_delete' type='submit' value='Delete' disabled='disabled'/></td>
+                                       </tr>
+                               </tbody>
+                       </table>
+               </center>
+
+               <table class='hide_me'> <!-- repository for template rows -->
+                       <tbody>
+                               <tr id='nc_edit_row_temaplate' edit='1'>
+                                       <td colspan='4' align='center'>
+                                               <span class='padded'>
+                                                       <input name='nc_edit_name' type='text'> </input>
+                                               </span>
+                                               <span class='padded'>
+                                                       <input name='nc_edit_submit' type='submit' value='Submit'> </input>
+                                               </span>
+                                               <span class='padded'>
+                                                       <input name='nc_edit_cancel' type='submit' value='Cancel'> </input>
+                                               </span>
+                                       </td>
+                               </tr>
+                       </tbody>
+               </table>
+       </body>
+</html>
+
+
+       
index dd60cb3..6815dc9 100644 (file)
@@ -80,14 +80,6 @@ function scFetchPerm(perm) {
 }
 
 
-function _cleanTbody(tbody) {
-       for( var c  = 0; c < tbody.childNodes.length; c++ ) {
-               var child = tbody.childNodes[c];
-               if(child && child.getAttribute('edit')) tbody.removeChild(child); 
-       }
-}
-
-
 function scFetchAll( session, type, orgid, callback, args ) {
        var req = new Request( 
                SC_FETCH_ALL.replace(/TYPE/, type) , session, orgid );
@@ -149,8 +141,8 @@ function scInsertCat( tbody, cat, type ) {
 
        cat.entries().sort(  /* sort the entries by value */
                function( a, b ) { 
-                       if( a.value() > b.value()) return 1;
-                       if( a.value() < b.value()) return -1;
+                       if( a.value().toLowerCase() > b.value().toLowerCase()) return 1;
+                       if( a.value().toLowerCase() < b.value().toLowerCase()) return -1;
                        return 0;
                }
        );
@@ -196,7 +188,7 @@ function scCreateEntry( type, id, row ) {
 }
 
 function scNewEntry( type, cat, tbody ) {
-       _cleanTbody(tbody);
+       cleanTbody(tbody, 'edit');
        var row = $('sc_new_entry_row').cloneNode(true);
        row.setAttribute('edit', '1');
 
@@ -227,7 +219,7 @@ function scNewEntry( type, cat, tbody ) {
                org = findOrgUnit(c_org);
        }
        
-       _scBuildOrgSelector( $n(row, 'sc_new_entry_lib'), org, depth );
+       buildOrgSel( $n(row, 'sc_new_entry_lib'), org, depth );
        $n(row, 'sc_new_entry_name').focus();
 }
 
@@ -257,15 +249,9 @@ function scBuildNew() {
        }
 
        org = findOrgUnit( org );
-       _scBuildOrgSelector( selector, org, depth );
+       buildOrgSel( selector, org, depth );
 }
 
-function _scBuildOrgSelector(selector, org, offset) {
-       insertSelectorVal( selector, -1, 
-               org.name(), org.id(), null, findOrgDepth(org) - offset );
-       for( var c in org.children() )
-               _scBuildOrgSelector( selector, org.children()[c], offset);
-}
 
 function scNew() {
 
@@ -295,7 +281,7 @@ function scNew() {
 
 function scEdit( tbody, type, cat ) {
 
-       _cleanTbody(tbody);
+       _cleanTbody(tbody, 'edit');
        var row = $('sc_edit_row').cloneNode(true);
        row.setAttribute('edit', '1');
 
@@ -317,7 +303,7 @@ function scEdit( tbody, type, cat ) {
        var selector = null;
        if( myorg.children() && myorg.children().length > 0 ) {
                selector = $n(row, 'sc_edit_owning_lib');
-               _scBuildOrgSelector( selector, myorg, findOrgDepth(myorg) );
+               buildOrgSel( selector, myorg, findOrgDepth(myorg) );
                setSelector( selector, cat.owner() );
                unHideMe(selector);
 
@@ -386,7 +372,7 @@ function scEditGo( type, cat, row, selector ) {
 }
 
 function scUpdateEntry( cat, entry, tbody, type ) {
-       _cleanTbody(tbody);
+       _cleanTbody(tbody, 'edit');
        var row = $('sc_edit_entry_row').cloneNode(true);
        row.setAttribute('edit', '1');
 
index 931d179..36408a6 100644 (file)
                <script language='javascript' src='/opac/common/js/RemoteRequest.js'> </script>
                <script language='javascript' src='adminlib.js'> </script>
                <script language='javascript' src='stat_cat_editor.js'> </script>
-
-               <style type='text/css'>
-                       .hide_me { visibility: hidden; display: none }
-                       .has_color { background: #E0F0E0; color: #000000; }
-                       .data_grid { font-weight: 500; border-collapse: collapse;}
-                       .data_grid thead tr { background: #E0F0E0; color: #000000; }
-                       .data_grid thead td { border: 1px solid #808080; padding-right: 5px; padding-left: 5px;}
-                       .data_grid tbody td { border: 1px solid #E0E0E0; padding: 5px; }
-                       .data_grid_center { text-align: center; }
-                       .data_grid_padded tbody td { padding: 10px; }
-                       /*.selector option { width: 10em; }*/
-                       .insert_row { border: 2px solid #A0B0A0; padding: 50px;}
-                       .padded { padding-left: 7px; padding-right: 7px; }
-                       select { width: 12em; }
-               </style>
-
+               <link type='text/css' rel='stylesheet' href='admin.css' name='meduim_fonts' csstype='font'/>
        </head>
 
        <body onload='try{scEditorInit();}catch(e){alert(js2JSON(e));}'>
@@ -67,7 +52,7 @@
                                                </td>
                                                <td>Owning Library: </td>
                                                <td>
-                                                       <select id='sc_owning_lib_selector'>
+                                                       <select class='select_big' id='sc_owning_lib_selector'>
                                                        </select>
                                                </td>
                                        </tr>
                                <td><input name='sc_edit_name'> </input></td>
                                <td>
                                        <span class='hide_me' name='sc_edit_show_owning_lib'> </span>
-                                       <select class='hide_me' name='sc_edit_owning_lib'> </select>
+                                       <select class='hide_me select_big' name='sc_edit_owning_lib'> </select>
                                </td>
 
                                <td>
                                                <input type='text' name='sc_new_entry_name'/>
                                        </span>
                                        <span class='padded'>
-                                               <select name='sc_new_entry_lib'> </select>
+                                               <select name='sc_new_entry_lib' class='select_big'> </select>
                                        </span>
                                        <span class='padded'>
                                                <input type='submit' name='sc_new_entry_create' value='Create new entry'/>