--- /dev/null
+dojo.require('fieldmapper.AutoIDL');
+dojo.require('fieldmapper.Fieldmapper');
+dojo.require('fieldmapper.dojoData');
+dojo.require('fieldmapper.OrgUtils');
+dojo.require('dojo.cookie');
+dojo.require('openils.CGI');
+dojo.require('openils.User');
+dojo.require('openils.Event');
+dojo.require('openils.PermaCrud');
+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 authtoken;
+
+var classifications;
+var normalizers = ["asset.label_normalizer_dewey", "asset.label_normalizer_generic", "asset.label_normalizer_lc"]
+
+var nameInput;
+var normalizerSelect;
+var inputArea;
+
+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);
+ }
+}
+
+
+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];
+
+ normalizers[norm] = tmp
+ normalizerSelect.add(tmp, null);
+ }
+}
+
+/**
+ * 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 clearInputArea() {
+ inputArea.innerHTML = "";
+}
+
+/**
+ * Generates a list of input boxes for the fields given in a csv style
+ * list.
+ */
+function generateFields(csv) {
+ fields = csv.split(",");
+
+ for(f in fields)
+ appendInput(fields[f]);
+}
+
+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) {
+ value = "";
+ lastid += 'a';
+ id = lastid;
+ }
+
+
+ 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>";
+
+ // 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 removeInput(id) {
+ dojo.removeClass(id, "input");
+ dojo.addClass(id, "hidden");
+ dojo.byId(id).innerHTML = "";
+}
+
+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 generateCSV() {
+ 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() {
+ name = nameInput.value;
+ norm = normalizerSelect.value;
+ 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);
+ }
+ });
+}
--- /dev/null
+<?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>