adding v1 stat cat editor
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Jan 2006 21:51:27 +0000 (21:51 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Jan 2006 21:51:27 +0000 (21:51 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2706 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

diff --git a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js
new file mode 100644 (file)
index 0000000..5e76378
--- /dev/null
@@ -0,0 +1,372 @@
+var SC_FETCH_ALL               = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.retrieve.all';
+var SC_CREATE                  = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.create';
+var SC_UPDATE                  = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.update';
+var SC_DELETE                  = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.delete';
+var SC_ENTRY_CREATE    = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.entry.create';
+var SC_ENTRY_UPDATE    = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.entry.update';
+var SC_ENTRY_DELETE    = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.entry.delete';
+/*
+var SC_MAP_CREATE              = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.WHAT_map.create';
+var SC_MAP_UPDATE              = 'open-ils.circ:open-ils.circ.stat_cat.TYPE.WHAT_map.update';
+*/
+
+var ACTOR                              = 'actor';
+var ASSET                              = 'asset';
+var session                            = null;
+var user                                       = null;
+
+var scCache                            = {};
+var currentlyVisible;
+var opacVisible                = false;
+
+
+function scEditorInit() {
+       var cgi = new CGI();
+       session = cgi.param('ses');
+       var show = cgi.param('show');
+       user = fetchUser(session);
+       if(show == ACTOR) scShow(ACTOR);
+       else scShow(ASSET);
+       scBuildNew();
+       $('sc_user').appendChild(text(user.usrname()));
+}
+
+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 fetchUser(session) {
+       var request = new Request(FETCH_SESSION, session, 1 );
+       request.send(true);
+       var user = request.result();
+       if(checkILSEvent(user)) throw user;
+       return user;
+}
+
+
+function scFetchAll( session, type, orgid, callback, args ) {
+       var req = new Request( 
+               SC_FETCH_ALL.replace(/TYPE/, type) , session, orgid );
+       req.send(true);
+       return req.result();
+}
+
+function scShow(type) { 
+
+       currentlyVisible = type;
+
+       if( type == ASSET ) {
+               addCSSClass($('sc_show_copy'), 'has_color');
+               removeCSSClass($('sc_show_actor'), 'has_color');
+
+       } else if( type == ACTOR ) {
+               addCSSClass($('sc_show_actor'), 'has_color');
+               removeCSSClass($('sc_show_copy'), 'has_color');
+       }
+
+       scCache[type] = scFetchAll( session, type, user.home_ou() );  
+       scDraw( type, scCache[type] );
+}
+
+var scRow; var scCounter;
+function scDraw( type, cats ) {
+
+       if(!cats || cats.length == 0) return unHideMe($('sc_none'));
+       var tbody = $('sc_tbody');
+
+       if(!scRow) scRow = tbody.removeChild($('sc_tr'));
+       removeChildren(tbody);
+       unHideMe($('sc_table'));
+
+       scCounter = 0;
+       for( var c in cats ) scInsertCat( tbody, cats[c], type );
+}
+
+
+var scEntryCounter;
+function scInsertCat( tbody, cat, type ) {
+
+       var row = scRow.cloneNode(true);
+       row.id = 'sc_tr_' + cat.id();
+       var name_td = $n(row, 'sc_name');
+       name_td.appendChild( text(cat.name()) );
+       if(scCounter++ % 2) addCSSClass(row, 'has_color');
+
+       $n(row, 'sc_new_entry').onclick = function() { scNewEntry(type, cat, tbody); }
+       $n(row, 'sc_edit').onclick = function(){ scEdit(tbody, type, cat); };
+       /*$n(row, 'sc_delete').onclick = function(){ scDelete(type, cat.id()); };*/
+       $n(row, 'sc_owning_lib').appendChild( text( findOrgUnit(cat.owner()).name() ));
+
+       if( cat.opac_visible() ) unHideMe($n(row, 'sc_opac_visible'));
+       else unHideMe($n(row, 'sc_opac_invisible'));
+
+       tbody.appendChild(row);
+       scEntryCounter = 0;
+
+       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;
+                       return 0;
+               }
+       );
+
+       for( var e in cat.entries() ) 
+               scInsertEntry( cat, cat.entries()[e], $n(row, 'sc_entries_selector'), tbody, type );
+}
+
+
+function scInsertEntry( cat, entry, selector, tbody, type ) {
+       setSelectorVal( selector, scEntryCounter++, entry.value(), entry.id(), 
+                       function(){ scUpdateEntry( cat, entry, tbody, type );} );
+}
+
+
+
+function scDelete(type, id) {
+       if(!confirm($('sc_delete_confirm').innerHTML)) return;
+       var req = new Request( SC_DELETE.replace(/TYPE/,type), session, id );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       scShow(type);
+}
+
+function scCreateEntry( type, id, row ) {
+       var value = $n(row, 'sc_new_entry_name').value;
+       if(!value) return;
+       var entry;
+       if( type == ACTOR ) entry = new actsce();
+       if( type == ASSET ) entry = new asce();
+
+       entry.isnew(1);
+       entry.stat_cat(id);
+       entry.owner(user.home_ou());
+       entry.value(value);
+
+       var req = new Request( SC_ENTRY_CREATE.replace(/TYPE/, type), session, entry );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       scShow(type);
+}
+
+function scNewEntry( type, cat, tbody ) {
+       _cleanTbody(tbody);
+       var row = $('sc_new_entry_row').cloneNode(true);
+       row.setAttribute('edit', '1');
+
+       var r = $('sc_tr_' + cat.id());
+       if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
+       else{ tbody.appendChild(row); }
+
+       $n(row, 'sc_new_entry_create').onclick = 
+               function() {
+                       if( scCreateEntry( type, cat.id(), row ) )
+                               tbody.removeChild(row); };
+       $n(row, 'sc_new_entry_cancel').onclick = function(){tbody.removeChild(row);}
+
+       var org = findOrgUnit(cat.owner());
+       var myorg = findOrgUnit(user.home_ou());
+       var depth = findOrgDepth(org);
+       var mydepth = findOrgDepth(myorg);
+
+       if( depth < mydepth ) {
+               depth = mydepth;
+               org = myorg;
+       }
+
+
+       _scBuildOrgSelector( $n(row, 'sc_new_entry_lib'), org, findOrgDepth(org));
+       $n(row, 'sc_new_entry_name').focus();
+}
+
+
+function scBuildNew() {
+       var selector = $('sc_owning_lib_selector');
+       var org = findOrgUnit( user.home_ou() );
+       var offset = findOrgDepth(org);
+       _scBuildOrgSelector( selector, org, offset);
+}
+
+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() {
+
+       var name = $('sc_new_name').value;
+       var type = getSelectorVal($('sc_type_selector'));
+
+       var visible = 0;
+       if( $('sc_make_opac_visible').checked) visible = 1;
+
+       var cat;
+       if( type == ACTOR ) cat = new actsc();
+       if( type == ASSET ) cat = new asc();
+
+       cat.opac_visible(visible);
+       cat.name(name);
+       cat.owner(getSelectorVal($('sc_owning_lib_selector')));
+       cat.isnew(1);
+
+       var req = new Request( SC_CREATE.replace(/TYPE/, type), session, cat );
+
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+
+       scShow(type);
+}
+
+function scEdit( tbody, type, cat ) {
+
+       _cleanTbody(tbody);
+       var row = $('sc_edit_row').cloneNode(true);
+       row.setAttribute('edit', '1');
+
+       var r = $('sc_tr_' + cat.id());
+       if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
+       else{ tbody.appendChild(row); }
+
+       $n(row, 'sc_edit_name').value = cat.name();
+
+       var name = $n(row, 'sc_edit_cancel');
+       name.onclick = function() { tbody.removeChild(row); };
+
+       var show = $n(row, 'sc_edit_show_owning_lib');
+       
+       var myorg = findOrgUnit(user.home_ou());
+       var ownerorg = findOrgUnit(cat.owner());
+       show.appendChild(text(ownerorg.name()));
+
+       var selector = null;
+       if( myorg.children() && myorg.children().length > 0 ) {
+               selector = $n(row, 'sc_edit_owning_lib');
+               _scBuildOrgSelector( selector, myorg, findOrgDepth(myorg) );
+               setSelector( selector, cat.owner() );
+               unHideMe(selector);
+
+       } else { unHideMe(show); }
+
+       name.focus();
+       name.select();
+
+       if( cat.opac_visible() ) {
+               $n( $n(row, 'sc_edit_opac_vis'), 
+                       'sc_edit_opac_visibility').checked = true;
+       }
+       else 
+               $n( $n(row, 'sc_edit_opac_invis'), 
+                       'sc_edit_opac_visibility').checked = true;
+
+       $n(row, 'sc_edit_submit').onclick = 
+               function() { 
+                       if( scEditGo( type, cat, row, selector ) ) 
+                               tbody.removeChild(row); };
+
+       $n(row, 'sc_edit_delete').onclick = function(){ scDelete(type, cat.id()); };
+
+       var o_depth = findOrgDepth(findOrgUnit(cat.owner()));
+       var m_depth = findOrgDepth(findOrgUnit(user.home_ou()));
+
+       if(  o_depth < m_depth ) {
+               $n(row,'sc_edit_submit').disabled = true;
+               $n(row,'sc_edit_delete').disabled = true;
+       }
+
+}
+
+function scEditGo( type, cat, row, selector ) {
+       var name = $n(row, 'sc_edit_name').value;
+       var visible = 
+               $n( $n(row, 'sc_edit_opac_vis'), 'sc_edit_opac_visibility').checked;
+
+       var newlib = cat.owner();
+       if(selector) newlib = getSelectorVal( selector );
+
+       if(!name) return false;
+
+       var isvisible = false;
+       if( cat.opac_visible() ) isvisible = true;
+
+       if( (name == cat.name()) && (visible == isvisible) 
+               && (newlib == cat.owner()) ) { return true; }
+
+       cat.name( name );
+       cat.owner( newlib );
+       cat.entries(null);
+       cat.opac_visible(0);
+       if( visible ) cat.opac_visible(1);
+
+       var req = new Request( SC_UPDATE.replace(/TYPE/,type), session, cat );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       scShow(type);
+
+       return true;
+}
+
+function scUpdateEntry( cat, entry, tbody, type ) {
+       _cleanTbody(tbody);
+       var row = $('sc_edit_entry_row').cloneNode(true);
+       row.setAttribute('edit', '1');
+
+       var r = $('sc_tr_' + cat.id());
+       if(r.nextSibling) tbody.insertBefore( row, r.nextSibling );
+       else{ tbody.appendChild(row); }
+
+       $n(row, 'sc_edit_entry_owner').appendChild(text(findOrgUnit(entry.owner()).name()));
+
+       var name = $n(row, 'sc_edit_entry_name');
+       name.value = entry.value();
+       name.focus();
+       name.select();
+
+       $n(row,'sc_edit_entry_name_submit').onclick = 
+               function(){
+                       if( scEditEntry(cat, entry, name.value, type ) )
+                               tbody.removeChild(row);
+                       };
+
+       $n(row,'sc_edit_entry_cancel').onclick = function(){tbody.removeChild(row);};
+       $n(row,'sc_edit_entry_delete').onclick = 
+               function(){ scEntryDelete( cat, entry, type ); }
+
+       var o_depth = findOrgDepth( findOrgUnit(entry.owner()) );
+       var m_depth = findOrgDepth(findOrgUnit(user.home_ou()));
+
+       if(  o_depth < m_depth ) {
+               $n(row,'sc_edit_entry_name_submit').disabled = true;
+               $n(row,'sc_edit_entry_delete').disabled = true;
+       }
+               
+}
+
+function scEntryDelete( cat, entry, type ) {
+       if(!confirm($('sc_entry_delete_confirm').innerHTML)) return;
+       var req = new Request( SC_ENTRY_DELETE.replace(/TYPE/,type), session, entry.id() );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       scShow(type);
+}
+
+function scEditEntry( cat, entry, newvalue, type ) {
+       if(entry.value() == newvalue) return;
+       entry.value( newvalue );
+       var req = new Request( 
+               SC_ENTRY_UPDATE.replace(/TYPE/, type), session, entry );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       scShow(type);
+}
+
diff --git a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xml b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xml
new file mode 100644 (file)
index 0000000..251a0a6
--- /dev/null
@@ -0,0 +1,242 @@
+<?xml version='1.0'?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
+
+       <head>
+               <title>Evergreen: Statistical Category 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='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>
+
+       </head>
+
+       <body onload='try{scEditorInit();}catch(e){alert(js2JSON(e));}'>
+
+               <div style='position:absolute; top: 5px; right: 5px;'>
+                       <span>Welcome </span><b><span id='sc_user'/></b>
+               </div>
+
+               <center>
+                       <div style='font-weight: bold; font-size: 12pt;'> Statistical Category Editor</div>
+               </center>
+
+               <hr/> 
+
+               <center>
+                       <br/>
+
+                       <table class='data_grid data_grid_center' width='80%'>
+                               <thead>
+                                       <tr>
+                                               <td colspan='4'>Create a new statistical category</td>
+                                       </tr>
+                               </thead>
+                               <tbody>
+                                       <tr>
+                                               <td>Enter the name: </td>
+                                               <td>
+                                                       <input type='text' id='sc_new_name'> </input>
+                                                       <script>$('sc_new_name').focus();</script>
+                                               </td>
+                                               <td>Owning Library: </td>
+                                               <td>
+                                                       <select id='sc_owning_lib_selector'>
+                                                       </select>
+                                               </td>
+                                       </tr>
+                                       <tr>
+                                               <td>Opac Visibility: </td>
+                                               <td>    
+                                                       <span>On</span>
+                                                       <input type='radio' name='opac_visibility' id='sc_make_opac_visible'> </input>
+                                                       <span>Off</span>
+                                                       <input type='radio' name='opac_visibility' checked='checked'> </input>
+                                               </td>
+                                               <td>Type: </td>
+                                               <td>
+                                                       <select id='sc_type_selector'>
+                                                               <option value='actor'>Patron</option>
+                                                               <option value='asset'>Copy</option>
+                                                       </select>
+                                               </td>
+                                       </tr>
+                                       <tr>
+                                               <td colspan='4'>
+                                                       <input type='submit' value='Create new stat cat' onclick='scNew();'/>
+                                               </td>
+                                       </tr>
+                               </tbody>
+                       </table>
+
+                       <br/>
+                       <hr/>
+                       <br/>
+
+                       <table width='98%'>
+                               <tbody>
+                                       <tr>
+                                               <td width='20%'> </td>
+                                               <td id='sc_show_copy' width='30%' class='has_color'
+                                                       align='center'><a href='javascript:scShow("asset");'>Copy Stat Cats</a></td>
+                                               <td id='sc_show_actor' width='30%' 
+                                                       align='center'><a href='javascript:scShow("actor");'>Patron Stat Cats</a></td>
+                                               <td width='20%'> </td>
+                                       </tr>
+                               </tbody>
+                       </table>
+
+
+
+                       <br/>
+                       <div>* To edit or view information about an entry, click on the entry in the drop-down menu</div>
+                       <br/>
+
+                       <!--
+                       <div style='overflow: auto; max-height: 200px;'>
+                       -->
+                               <table width='95%' class='hide_me data_grid data_grid_center' id='sc_table'>
+                                       <thead>
+                                               <tr>
+                                                       <td>Stat Cat Name</td>
+                                                       <td>Owning Library</td>
+                                                       <td>OPAC Visiblity</td>
+                                                       <td>Entries</td>
+                                                       <td>Add Entry</td>
+                                                       <td>Edit</td>
+                                               </tr>
+                                       </thead>
+       
+                                       <tbody id='sc_tbody'>
+                                               <tr id='sc_tr'>
+                                                       <td><b name='sc_name'> </b></td>
+                                                       <td name='sc_owning_lib'> </td>
+       
+                                                       <td>
+                                                               <span class='hide_me' name='sc_opac_visible'>On</span> 
+                                                               <span class='hide_me' name='sc_opac_invisible'>Off</span> 
+                                                       </td>
+       
+                                                       <td><select class='selector' name='sc_entries_selector'><option>(none)</option></select></td>
+                                                       <td><a href='javascript:void(0);' name='sc_new_entry'>Add</a></td>
+                                                       <td><a href='javascript:void(0);' name='sc_edit'>Edit</a></td>
+                                               </tr>
+                                       </tbody>
+                               </table>
+                       <!--
+                       </div>
+                       -->
+       
+               
+
+                       
+               </center>
+
+
+               <!-- Text spans  / template +++++++++++++++++++++++++++++++++++++  -->
+               <span class='hide_me' id='sc_new_entry_text'>Enter the value for the new stat cat entry</span>
+
+               <span class='hide_me' id='sc_delete_confirm'>
+                       This will delete the selected stat cat and all attached entries
+                       Are you sure you wish to continue?
+               </span>
+
+               <span class='hide_me' id='sc_entry_delete_confirm'>
+                       Are you sure you wish to remove this stat cat entry?
+               </span>
+
+               <table class='hide_me'>
+                       <tr class='insert_row' id='sc_edit_row'>
+                               <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>
+                               </td>
+
+                               <td>
+                                       <span>On</span>
+                                       <span name='sc_edit_opac_vis'>
+                                               <input type='radio' name='sc_edit_opac_visibility'> </input>
+                                       </span>
+                                       <span>Off</span>
+                                       <span name='sc_edit_opac_invis'>
+                                               <input type='radio' name='sc_edit_opac_visibility'> </input>
+                                       </span>
+                               </td>
+                               <td colspan='4'>
+                                       <span class='padded'>
+                                               <input  type='submit' value='Update Stat Cat' name='sc_edit_submit'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input  type='submit' value='Delete Stat Cat' name='sc_edit_delete'/>
+                                       </span>
+                                       <input type='submit' name='sc_edit_cancel' value='Cancel'/>
+                               </td>
+                       </tr>
+
+                       <tr class='insert_row' id='sc_edit_entry_row'>
+                               <td colspan='7'>
+                                       <span class='padded'>
+                                               <span>Owned By </span><b name='sc_edit_entry_owner'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='text' name='sc_edit_entry_name' class='padded'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='submit' name='sc_edit_entry_name_submit' value='Update Entry Value' class='padded'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='submit' name='sc_edit_entry_delete' value='Delete Entry' class='padded'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='submit' name='sc_edit_entry_cancel' value='Cancel'/>
+                                       </span>
+                               </td>
+                       </tr>
+
+                       <tr class='insert_row' id='sc_new_entry_row'>
+                               <td colspan='7'> 
+                                       <span>Enter the value of the new entry: </span>
+                                       <span class='padded'>
+                                               <input type='text' name='sc_new_entry_name'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <select name='sc_new_entry_lib'> </select>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='submit' name='sc_new_entry_create' value='Create new entry'/>
+                                       </span>
+                                       <span class='padded'>
+                                               <input type='submit' name='sc_new_entry_cancel' value='Cancel'/>
+                                       </span>
+                               </td>
+                       </tr>
+               </table>
+
+       </body>
+</html>
+