From a9e718bac163cb640c07b89eb4356dfdfc91be0e Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 23 Jan 2009 23:33:07 +0000 Subject: [PATCH] added a default gettier for common fieldmapper datatypes git-svn-id: svn://svn.open-ils.org/ILS/trunk@11941 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/dojo/openils/widget/AutoFieldWidget.js | 26 ++++++++++++++++++---- Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 15 +++++++++++++ .../js/dojo/openils/widget/FilteringTreeSelect.js | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index 1f3d5cfb97..484f6f15fe 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -29,7 +29,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { if(!this.idlField) { if(this.fmObject) this.fmClass = this.fmObject.classname; - var fields = fieldmapper.IDL.fmclasses[this.fmClass][fields]; + var fields = fieldmapper.IDL.fmclasses[this.fmClass].fields; for(var f in fields) if(fields[f].name == this.fmField) this.idlField = fields[f]; @@ -50,17 +50,35 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { return value; } }, + + getDisplayString : function() { + var value = this.widgetValue; + switch(this.idlField.datatype) { + case 'bool': + return (value) ? 'True' : 'False'; // XXX i18n! + case 'timestamp': + dojo.require('dojo.date.locale'); + dojo.require('dojo.date.stamp'); + var date = dojo.date.stamp.fromISOString(value); + return dojo.date.locale.format(date, {formatLength:'short'}); + case 'org_unit': + return fieldmapper.aou.findOrgUnit(value).shortname(); + default: + return value; + } + }, build : function(onload) { this.onload = onload; - this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null; + if(this.widgetValue == null) + this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null; switch(this.idlField.datatype) { case 'id': dojo.require('dijit.form.TextBox'); this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode); - this.widget.setDisabled(true); // never allow editing of IDs + this.widget.attr('disabled', true); // never allow editing of IDs break; case 'org_unit': @@ -99,7 +117,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { * For widgets that run asynchronously, provide a callback for finishing up */ _widgetLoaded : function(value) { - if(this.fmObject) + if(this.widgetValue != null) this.widget.attr('value', this.widgetValue); if(this.onload) this.onload(this.widget, self); diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 8d3a6fe1bb..c8bb10fefb 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -2,6 +2,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { dojo.provide('openils.widget.AutoGrid'); dojo.require('dojox.grid.DataGrid'); dojo.require('openils.widget.AutoWidget'); + dojo.require('openils.widget.AutoFieldWidget'); dojo.require('openils.Util'); dojo.declare( @@ -20,12 +21,26 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { if(entry) entry.name = field.label; else entry = {field:field.name, name:field.label}; fields.push(entry); + if(!entry.get) + entry.get = openils.widget.AutoGrid.defaultGetter } this.setStructure([{cells: [fields]}]); this.setStore(this.buildAutoStore()); }, + } ); openils.widget.AutoGrid.markupFactory = dojox.grid.DataGrid.markupFactory; + + openils.widget.AutoGrid.defaultGetter = function(rowIndex, item) { + if(!item) return ''; + var val = this.grid.store.getValue(item, this.field); + var autoWidget = new openils.widget.AutoFieldWidget({ + fmClass: this.grid.fmClass, + fmField: this.field, + widgetValue : val, + }); + return autoWidget.getDisplayString(); + } } diff --git a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js index 30e1a81f31..b6f9636f05 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js +++ b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js @@ -42,7 +42,7 @@ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ this.inherited(arguments); }, - // Compile the tree down to a dept-first list of nodes + // Compile the tree down to a depth-first list of nodes _makeNodeList : function(node) { this.dataList.push(node); for(var i in node[this.childField]()) -- 2.11.0