Finished new asset_call_number_class editor, need to test it now.
authorJoseph Lewis <joehms22@gmail.com>
Thu, 2 Jun 2011 20:07:52 +0000 (14:07 -0600)
committerJoseph Lewis <joehms22@gmail.com>
Thu, 2 Jun 2011 20:07:52 +0000 (14:07 -0600)
Open-ILS/xul/staff_client/server/admin/asset_call_number.html [deleted file]
Open-ILS/xul/staff_client/server/admin/asset_call_number.js
Open-ILS/xul/staff_client/server/admin/asset_call_number.xhtml [new file with mode: 0644]
Open-ILS/xul/staff_client/server/locale/en-US/admin.properties

diff --git a/Open-ILS/xul/staff_client/server/admin/asset_call_number.html b/Open-ILS/xul/staff_client/server/admin/asset_call_number.html
deleted file mode 100644 (file)
index 0e54175..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-<?xml version='1.0' encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC 
-    "-//W3C//DTD XHTML 1.0 Transitional//EN" 
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
-    <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
-]>
-
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
-<!-- This file is to aid in editing of the asset_call_number_class. -->
-    <head>
-        <title>Asset Call Number Editor (Not Translated)</title>
-        <link type='text/css' rel='stylesheet' href='admin.css'/>
-
-        <script type="text/javascript" djConfig="parseOnLoad: true,isDebug:false" src="/js/dojo/dojo/dojo.js"></script>
-        <script type="text/javascript" djConfig="parseOnLoad: true,isDebug:false" src="/js/dojo/dojo/openils_dojo.js"></script>
-        <script type='text/javascript' src='asset_call_number.js'> </script>
-        
-        <style>
-        body {
-                       margin:0px;
-                       padding:0px;
-               }
-               div {
-                       margin:0px;
-                       padding:0px;
-               }
-        .desc {
-                       font-weight:normal;
-                       vertical-align:top;
-                       text-align:left;
-               }
-               
-               #titleBox {
-                       display:block;
-                       width:100%;
-                       border-bottom:1px solid black;
-                       height:100%;
-               }
-               
-               #titleBoxOuter {
-                       height:10%;
-               }
-               
-               #titleBox H1{
-                       padding:10px;
-                       margin:0px;
-               }
-               
-               #selectBox {
-                       width:20%;
-                       float:left;
-                       height:90%;
-               }
-               
-               #editBox {
-                       width:80%;
-                       float:left;
-                       height:90%;
-                       
-               }
-               
-               #selectBox select { display:block; width:100%; height:100%;}
-        </style>
-    </head>
-    
-    <body onload="init_asset_call();">
-               <div id="titleBoxOuter">
-               <div id="titleBox">
-                       <h1 align="center">Classification System Editor</h1>
-        </div></div>
-        <div id="selectBox"> <select id="accselect" size="20" onchange="select_asset_call_class(this.selectedIndex);" /> </div>
-        
-        <div id='editBox'>
-                       <!-- No need to show this if there is nothing to select -->
-            
-            <table id="startHidden" class="hidden">
-                               <tr>
-                                       <td class="desc">Name:</td>
-                                       <td>
-                                               <input id="nameInput" type="text" size="22" value="Generic" />
-                                       </td>        
-                               </tr>
-                               <tr>
-                                       <td class="desc">Normalizer:</td>
-                                       <td><select size="0" id="normalizerSelect" /><br /></td>
-                               </tr>
-            <tr>
-                <td class="desc">Tag/Subfields:</td>
-                <td id="inputArea"></td>
-            </tr>
-            <tr>
-                               <td></td>
-                               <td><input type="submit" value="Add" onClick="append_input(null);"/></td>
-            </tr>
-            <tr>
-                <td></td>
-                <td align="right"><input type="submit" value="Save" onClick="submit_form();"/></td>
-            </tr>
-            </table>
-            </div>
-    </body>
-</html>
index 5451da8..b998083 100644 (file)
@@ -1,7 +1,7 @@
 dojo.require('fieldmapper.AutoIDL');
-dojo.require("fieldmapper.Fieldmapper");
-dojo.require("fieldmapper.dojoData");
-dojo.require("fieldmapper.OrgUtils");
+dojo.require('fieldmapper.Fieldmapper');
+dojo.require('fieldmapper.dojoData');
+dojo.require('fieldmapper.OrgUtils');
 dojo.require('dojo.cookie');
 dojo.require('openils.CGI');
 dojo.require('openils.User');
@@ -11,70 +11,113 @@ dojo.require('openils.widget.AutoFieldWidget');
 dojo.require('openils.widget.ProgressDialog');
 dojo.require('openils.CGI')
 dojo.require('openils.PermaCrud');
+dojo.require('openils.User');
+dojo.require('openils.Event');
+dojo.require('openils.widget.AutoFieldWidget');
+
+//dojo.require('dijit.form.Select'); // Newer DOJO
+dojo.require('dijit.form.Button');
+dojo.require('dijit.form.TextBox');
+dojo.require('dijit.layout.ContentPane');
+
+/**
+ <class id="acnc" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="asset::call_number_class" oils_persist:tablename="asset.call_number_class" reporter:label="Call number classification scheme">
+        <fields oils_persist:primary="id" oils_persist:sequence="asset.call_number_class_id_seq">
+            <field reporter:label="Call number class ID" name="id" reporter_datatype="id"/>
+            <field reporter:label="Name" name="name" reporter:datatype="text"/>
+            <field reporter:label="Normalizer function" name="normalizer" reporter:datatype="text"/>
+            <field reporter:label="Call number fields" name="field" reporter:datatype="text"/>
+        </fields>
+        <links/>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="ADMIN_CALL_NUMBER_CLASS" global_required="true"/>
+                <retrieve/>
+                <update permission="ADMIN_CALL_NUMBER_CLASS" global_required="true"/>
+                <delete permission="ADMIN_CALL_NUMBER_CLASS" global_required="true"/>
+            </actions>
+        </permacrud>
+    </class>
+*/
 
 
-var numItems = 0;
 var authtoken;
-var user;
 
 var classifications;
 var normalizers = ["asset.label_normalizer_dewey", "asset.label_normalizer_generic", "asset.label_normalizer_lc"]
-var fields = []
 
-var accselect;
 var nameInput;
 var normalizerSelect;
 var inputArea;
 
-function init_asset_call() {
-    authtoken = new openils.CGI().param('ses') || dojo.cookie('ses');
-       classifications = new openils.PermaCrud({authtoken:authtoken}).retrieveAll('acnc');
-           
-    // Get names of all elements.
-    accselect = document.getElementById('accselect');
-    nameInput = document.getElementById('nameInput');
-    normalizerSelect = document.getElementById('normalizerSelect');
-    inputArea = document.getElementById("inputArea");
-
-    
-    // Fill in the listbox.
-    var i = -1;
-    for(i in classifications) {
+var currentClassification; //The index of the current classification in classifications
+var pcrud; //The pcrud instance for this doc.
+
+function initAssetCall() {
+       authtoken       = new openils.CGI().param('ses') || dojo.cookie('ses');
+       pcrud           = new openils.PermaCrud({"authtoken":authtoken});
+       
+       classifications = pcrud.retrieveAll("acnc"); // asset.call_number_class
+               
+       if(classifications == null) // If there was a problem, don't un-hide the page, let it show an error.
+               return;
+               
+       nameInput = dojo.byId('nameInput');
+       inputArea = dojo.byId('inputArea');
+       normalizerSelect = dojo.byId('normalizerSelect');
+       
+       setUpClassifications();
+       setUpNormalizers();
+       
+       // If there is at least one element, choose it to display the form with.
+       if(classifications.length > 0)
+               selectAssetCallClass(0);
+}
+
+/**
+ * Fill up the classification listbox. (left of screen)
+ */
+function setUpClassifications() {
+       accselect = dojo.byId('accselect');
+
+       for(i in classifications) {
                var tmp = document.createElement('option');
                tmp.text = classifications[i].name();
                accselect.add(tmp, null);
        }
-       
-       // If there is at least one element, set us up with that one first.
-       if(classifications.length > 0) {
-               select_asset_call_class(0);
-       }
-    
-    // TODO fetch normalizers.
-    //normalizers = new openils.PermaCrud({authtoken:authtoken}).retrieveAll('dbf');
+}
+
 
-    
-    for( norm in normalizers ) {
+function setUpNormalizers() {
+       // FIXME fetch normalizers, need a fm_IDL function for this.
+       
+       for( norm in normalizers ) {
                var tmp = document.createElement('option');
-               names=normalizers[norm].split("_");
-               tmp.text = names[names.length -1];
-               tmp.value = normalizers[norm];
+               names           = normalizers[norm].split("_");
+               tmp.text        = names[names.length -1];
+               tmp.value       = normalizers[norm];
+               
                normalizers[norm] = tmp
                normalizerSelect.add(tmp, null);
-    }
-    
+       }
 }
 
-function select_asset_call_class(selection_index) {
-    dojo.removeClass("startHidden", "hidden");
-    
-    nameInput.value = classifications[selection_index].name();
-    update_normalizer_list(classifications[selection_index].normalizer());
-    clear_input_area();
-    generate_fields(classifications[selection_index].field());
+/**
+ * Caled when a class is chosen to set up the rest of the form.
+ */
+function selectAssetCallClass(selection_index) {
+       dojo.removeClass("startHidden", "hidden"); //The entry box.
+       dojo.addClass("startShown", "hidden"); //The error box.
+       
+       nameInput.value = classifications[selection_index].name();
+       updateNormalizerList(classifications[selection_index].normalizer());
+       clearInputArea();
+       generateFields(classifications[selection_index].field());
+       
+       currentClassification = selection_index;
 }
 
-function clear_input_area() {
+function clearInputArea() {
        inputArea.innerHTML = "";
 }
 
@@ -82,25 +125,32 @@ function clear_input_area() {
  * Generates a list of input boxes for the fields given in a csv style
  * list.
  */
-function generate_fields(csv) {
+function generateFields(csv) {
        fields = csv.split(",");
        
        for(f in fields)
-               append_input(fields[f]);
+               appendInput(fields[f]);
 }
 
-var lastid = 'a';
-/**
- * Appends an insert to the list of input boxes.
- */
-function append_input(value) {
-       
+var lastid = 'a'; //Magic code to get new inputs to work properly.
+
+function saveNodeValues() {
        nodevalue_dict = {}
        current_inputs = dojo.query(".input");
        
        current_inputs.forEach(function(node, index, arr){
                nodevalue_dict[node.id] = document.getElementById(node.id).value;
        });
+       
+       return nodevalue_dict;
+}
+
+/**
+ * Appends an insert to the list of input boxes.
+ */
+function appendInput(value) {
+       
+       nodevalue_dict = saveNodeValues();
                                
        id = value;
        if(value == null) {
@@ -109,39 +159,42 @@ function append_input(value) {
                id = lastid;
        }
        
-       // Add a new input after creating it.
+
+       inputArea.innerHTML += "<div class='input_container' id='"+id+"cont'>\
+                                                       <div id='"+id+"continner'></div>\
+                                                       <input class='input' id='"+id+"' dojoType='dijit.form.TextBox' type='text' value='"+value+"' />\
+                                   <button type='button' dojoType='dijit.form.Button' onClick='remove_input(\""+id+"cont\");'>[X]</button>\
+                                   <br /></div>";
        
-       inputArea.innerHTML += "<div class='input_container' id='"+id+"cont'>&#8597;<input class='input' id='"+id+"' type='text' value='"+value+"' />\
-               <input type='submit' value='[X]' onClick='remove_input(\""+id+"cont\");' /><br /></div>";
+       // Add a new input after creating it.
+       //new dijit.form.TextBox({ 'class':'input', 'value': value, "id":id }, id+"continner");
+               
                
        current_inputs.forEach(function(node, index, arr){
                document.getElementById(node.id).value = nodevalue_dict[node.id];
        });
 }
 
-function remove_input(id)
-{
-       alert("editing"+id);
+function removeInput(id) {
        dojo.removeClass(id, "input");
        dojo.addClass(id, "hidden");
        dojo.byId(id).innerHTML = "";
 }
 
-function update_normalizer_list(toSelect) {
-    //TODO fetch lists, and update with current 
-    
-    for( norm in normalizers )
+function updateNormalizerList(toSelect) {
+       //TODO fetch lists, and update with current 
+       
+       for( norm in normalizers )
                if(normalizers[norm].value == toSelect)
                        normalizers[norm].selected = "selected";
                else
                        normalizers[norm].selected = "";
 }
 
-function generate_csv() {
+function generateCSV() {
        csv = "";
        
        dojo.query(".input").forEach(function(node, index, arr){
-               
                temp = document.getElementById(node.id).value;
                temp = temp.replace(/[^A-Za-z0-9]+/, '');
                
@@ -150,31 +203,23 @@ function generate_csv() {
                                csv += temp;
                        else
                                csv += ","+temp; 
-               
        });
        return csv;
 }
 
-function submit_form() {
-       
+function submit() {
        name = nameInput.value;
        norm = normalizerSelect.value;
-       csv = generate_csv();
-       
-       classifications = new openils.PermaCrud({authtoken:authtoken}).retrieveAll('acnc');
-
-       //stolen code!
-       fieldmapper.standardRequest(
-        ['open-ils.actor', 'open-ils.actor.org_unit.settings.update'],
-        {   async: true,
-            params: [authtoken, osEditContextSelector.getValue(), obj],
-            oncomplete: function(r) {
-                var res = r.recv().content();
-                if(e = openils.Event.parse(res))
-                    return alert(e);
-                osDraw(obj);
-            }
-        }
-    );
+       csv = generateCSV();
+       
+       classifications[currentClassification].name(name);
+       classifications[currentClassification].normalizer(norm);
+       classifications[currentClassification].field(csv);
        
+       output = pcrud.update(classifications,  {       
+                       'async': true,
+                       'oncomplete': function(r) {
+                               selectAssetCallClass(currentClassification);
+                       }
+               });
 }
diff --git a/Open-ILS/xul/staff_client/server/admin/asset_call_number.xhtml b/Open-ILS/xul/staff_client/server/admin/asset_call_number.xhtml
new file mode 100644 (file)
index 0000000..bed8418
--- /dev/null
@@ -0,0 +1,110 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC 
+       "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
+       <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
+]>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
+<!-- This file is to aid in editing of the asset_call_number_class. -->
+       <head>
+               <title>&staff.server.admin.callnumclass.title;</title>
+               
+               <link type='text/css' rel='stylesheet' href='admin.css'/>
+               
+               <script type="text/javascript" djConfig="parseOnLoad: true,isDebug:false" src="/js/dojo/dojo/dojo.js" />
+               <script type="text/javascript" djConfig="parseOnLoad: true,isDebug:false" src="/js/dojo/dojo/openils_dojo.js" />
+               <script type='text/javascript' src='asset_call_number.js' />
+               
+               <style>
+                       body { margin:0px; padding:0px; }
+                       div { margin:0px; padding:0px; }
+                       
+                       .desc { font-weight:normal; vertical-align:top; text-align:left; }
+                       
+                       #titleBox {
+                               display:block;
+                               width:100%;
+                               border-bottom:1px solid black;
+                               height:100%;
+                       }
+                       
+                       /** Used to 1px bottom border on title box from affecting document height. **/
+                       #titleBoxOuter { height:10%; }
+                       
+                       #titleBox H1 { padding:10px; margin:0px; }
+                       
+                       /** Editing view **/
+                       #selectBox { width:20%; height:90%; float:left; }
+                       #editBox { width:80%; height:90%; float:left; }
+                       #selectBox select { display:block; width:100%; height:100%;}
+
+
+                       /** Error box **/
+                       #startShown { width:100%; height:90%; }
+               </style>
+       </head>
+       
+       <body onload="initAssetCall();">
+               
+               <div id="titleBoxOuter">
+                       <div id="titleBox">
+                               <h1 align="center">&staff.server.admin.callnumclass.title;</h1>
+                       </div>
+               </div>
+               
+               <!-- No need to show this if there is nothing to select -->
+               <div id="startHidden" class="hidden">
+               <div id="selectBox"> <select id="accselect" size="20" onchange="selectAssetCallClass(this.selectedIndex);" /> </div>
+               
+               <div id='editBox'>
+                       <table>
+                               <tr>
+                                       <td class="desc">&staff.server.admin.callnumclass.name;</td>
+                                       <td>
+                                               <input id="nameInput" type="text" size="22" dojoType='dijit.form.TextBox' />
+                                       </td>           
+                               </tr>
+                               <tr>
+                                       <td class="desc">&staff.server.admin.callnumclass.normalizer;</td>
+                                       <td><select size="1" id="normalizerSelect" /><br /></td>
+                               </tr>
+                       <tr>
+                               <td class="desc">&staff.server.admin.callnumclass.tag;</td>
+                               <td id="inputArea" dojoType="dijit.layout.ContentPane"></td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>
+                                       <button dojoType="dijit.form.Button" type="button" value="&staff.server.admin.callnumclass.add_row;" onClick="appendInput(null);"> 
+                                               &staff.server.admin.callnumclass.add_row;
+                                       </button>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td align="right">
+                                       <button dojoType="dijit.form.Button" type="button" onClick="submit();">
+                                               &staff.server.admin.callnumclass.save;
+                                       </button>
+                               </td>
+                       </tr>
+                       </table>
+                       </div>
+               </div>
+               
+               <!-- Error box just in case something goes wrong, reminscent of 
+               the old IE couldn't connect to the Internet boxes. -->
+               <div id="startShown">
+                       <h1>&staff.server.admin.callnumclass.error_title;</h1>
+                       <p>&staff.server.admin.callnumclass.error_paragraph;
+                               <ul>
+                                       <li>&staff.server.admin.callnumclass.error_perm_bullet;</li>
+                                       <li>&staff.server.admin.callnumclass.error_ses_bullet;</li>
+                                       <li>&staff.server.admin.callnumclass.error_net_bullet;</li>
+                                       <li>&staff.server.admin.callnumclass.error_unknown_bullet;</li>
+                               </ul>
+                       </p>
+               </div>
+       </body>
+</html>
index 3f0428a..33ffad4 100644 (file)
@@ -102,6 +102,18 @@ staff.admin.offline_manage_xacts.no=No
 staff.admin.offline_manage_xacts.yes=Yes
 staff.admin.staff.do_not_auto_attempt_print_setting.update_success=Setting updated
 staff.admin.staff.do_not_auto_attempt_print_setting.update_failure=Setting not updated due to error
+staff.server.admin.callnumclass.title=Asset Call Number Class Editor
+staff.server.admin.callnumclass.name=Name:
+staff.server.admin.callnumclass.normalizer=Normalizer:
+staff.server.admin.callnumclass.tag=Tags/Subfields:
+staff.server.admin.callnumclass.add_row=Add Row
+staff.server.admin.callnumclass.save=Save
+staff.server.admin.callnumclass.error_title=Error
+staff.server.admin.callnumclass.error_paragraph=There was a problem processing your request because:
+staff.server.admin.callnumclass.error_perm_bullet=You do not have permission to view this page.
+staff.server.admin.callnumclass.error_ses_bullet=Your session has expired.
+staff.server.admin.callnumclass.error_net_bullet=There was an error connecting to the network.
+staff.server.admin.callnumclass.error_unknown_bullet=An unknown error occurred.
 # 1 - workstation library shortname   2 - setting library shortname
 staff.admin.staff.do_not_auto_attempt_print_setting.current_setting_preamble=Workstation library %1$s is currently suppressing auto-print for these receipt/slip types based on a setting inherited from %2$s:
 # 1 - workstation library shortname