From: Joseph Lewis Date: Thu, 2 Jun 2011 20:07:52 +0000 (-0600) Subject: Finished new asset_call_number_class editor, need to test it now. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=70f25dbd9e17152b123410bae0301768ea73ae10;p=evergreen%2Fjoelewis.git Finished new asset_call_number_class editor, need to test it now. --- 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 index 0e541753a4..0000000000 --- a/Open-ILS/xul/staff_client/server/admin/asset_call_number.html +++ /dev/null @@ -1,102 +0,0 @@ - - -]> - - - - - Asset Call Number Editor (Not Translated) - - - - - - - - - - -
-
-

Classification System Editor

-
-
- - - - Normalizer: - - - - - - - -
- - diff --git a/Open-ILS/xul/staff_client/server/admin/asset_call_number.js b/Open-ILS/xul/staff_client/server/admin/asset_call_number.js index 5451da8c89..b998083874 100644 --- a/Open-ILS/xul/staff_client/server/admin/asset_call_number.js +++ b/Open-ILS/xul/staff_client/server/admin/asset_call_number.js @@ -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'); + +/** + + + + + + + + + + + + + + + + + +*/ -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 += "
\ +
\ + \ + \ +
"; - inputArea.innerHTML += "
\ -
"; + // 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 index 0000000000..bed8418283 --- /dev/null +++ b/Open-ILS/xul/staff_client/server/admin/asset_call_number.xhtml @@ -0,0 +1,110 @@ + + +]> + + + + + &staff.server.admin.callnumclass.title; + + + +