Nearly finished with both of the asset_call_numbers all that is left is db updating...
authorJoseph Lewis <joehms22@gmail.com>
Wed, 1 Jun 2011 01:19:57 +0000 (19:19 -0600)
committerJoseph Lewis <joehms22@gmail.com>
Wed, 1 Jun 2011 01:19:57 +0000 (19:19 -0600)
Open-ILS/xul/staff_client/server/admin/asset_call_number.html
Open-ILS/xul/staff_client/server/admin/asset_call_number.js

index b01a5e5..0e54175 100644 (file)
         <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();">
-        <h1 align="center">Classification System Editor</h1>
-        <hr />
-        <table>
-            <tr>
-                <td>
-                    <select id="accselect" size="20" onchange="select_asset_call_class(this.selectedIndex, this.options[this.selectedIndex].value);">
-                    </select>
-                </td>
-                <td valign="top">
-                    <table valign="top">
-                        <tr>
-                                                       <td class="desc">Name:</td>
-                            <td>
-                            <input id="nameInput" type="text" size="22" value="Generic" />
-                            </td>
-                            <td></td>
-                                
-                        </tr>
+               <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">Normalizer:</td>
-                <td><select size="0"><option>asset.label_normalizer_generic</option></select><br /></td>
-                <td></td>
+                <td class="desc">Tag/Subfields:</td>
+                <td id="inputArea"></td>
             </tr>
             <tr>
-                <td class="desc">Tag/Subfields:</td>
-                <td id="inputArea">
-                <input type="text" value="050ab" /><br />
-                <input type="text" value="055ab" /><br />
-                <input type="text" value="060ab" /><br />
-                <input type="text" value="070ab" /><br />
-                <input type="text" value="080ab" /><br />
-                <input type="text" value="082ab" /><br />
-                <input type="text" value="086ab" /><br />
-                <input type="text" value="088ab" /><br />
-                <input type="submit" value="Add" />
-                </td>
-                <td></td>
+                               <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" /></td>
-            </tr>
-            </table>
-
-            <br />
-
-            </td>
+                <td align="right"><input type="submit" value="Save" onClick="submit_form();"/></td>
             </tr>
             </table>
+            </div>
     </body>
 </html>
index 46d69dc..5451da8 100644 (file)
@@ -12,53 +12,169 @@ dojo.require('openils.widget.ProgressDialog');
 dojo.require('openils.CGI')
 dojo.require('openils.PermaCrud');
 
+
 var numItems = 0;
 var authtoken;
 var user;
-var classifications;
 
-var normalizers = ['asset.label_normalizer']; //A list of normalizers for now...
+var classifications;
+var normalizers = ["asset.label_normalizer_dewey", "asset.label_normalizer_generic", "asset.label_normalizer_lc"]
+var fields = []
 
-// Document elements, there must be a better way like JQuery...
 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 tmp = document.createElement('option');
                tmp.text = classifications[i].name();
                accselect.add(tmp, null);
        }
-
-    
-    //TODO fetch normalizers.
+       
+       // 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 ) {
-        alert(normalizers[norm]);
+               var tmp = document.createElement('option');
+               names=normalizers[norm].split("_");
+               tmp.text = names[names.length -1];
+               tmp.value = normalizers[norm];
+               normalizers[norm] = tmp
+               normalizerSelect.add(tmp, null);
     }
     
-    //Populate listbox.
-    
-    //Populate namefield.
+}
+
+function select_asset_call_class(selection_index) {
+    dojo.removeClass("startHidden", "hidden");
     
-    //Populate 
-    nameField = document.getElementById('class_name');
+    nameInput.value = classifications[selection_index].name();
+    update_normalizer_list(classifications[selection_index].normalizer());
+    clear_input_area();
+    generate_fields(classifications[selection_index].field());
 }
 
-function select_asset_call_class(selection_index, selection_name) {
-    alert(selection_index);
-    nameField.value = selection_name;
+function clear_input_area() {
+       inputArea.innerHTML = "";
 }
 
-function update_normalizer_list() {
+/**
+ * Generates a list of input boxes for the fields given in a csv style
+ * list.
+ */
+function generate_fields(csv) {
+       fields = csv.split(",");
+       
+       for(f in fields)
+               append_input(fields[f]);
+}
+
+var lastid = 'a';
+/**
+ * Appends an insert to the list of input boxes.
+ */
+function append_input(value) {
+       
+       nodevalue_dict = {}
+       current_inputs = dojo.query(".input");
+       
+       current_inputs.forEach(function(node, index, arr){
+               nodevalue_dict[node.id] = document.getElementById(node.id).value;
+       });
+                               
+       id = value;
+       if(value == null) {
+               value = "";
+               lastid += 'a';
+               id = lastid;
+       }
+       
+       // Add a new input after creating it.
+       
+       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>";
+               
+       current_inputs.forEach(function(node, index, arr){
+               document.getElementById(node.id).value = nodevalue_dict[node.id];
+       });
+}
+
+function remove_input(id)
+{
+       alert("editing"+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 )
+               if(normalizers[norm].value == toSelect)
+                       normalizers[norm].selected = "selected";
+               else
+                       normalizers[norm].selected = "";
+}
+
+function generate_csv() {
+       csv = "";
+       
+       dojo.query(".input").forEach(function(node, index, arr){
+               
+               temp = document.getElementById(node.id).value;
+               temp = temp.replace(/[^A-Za-z0-9]+/, '');
+               
+               if(temp != "")
+                       if(csv == "")
+                               csv += temp;
+                       else
+                               csv += ","+temp; 
+               
+       });
+       return csv;
+}
+
+function submit_form() {
+       
+       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);
+            }
+        }
+    );
+       
 }