[open-ils-commits] r11796 - trunk/Open-ILS/web/js/dojo/openils/widget
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jan 12 11:03:36 EST 2009
Author: erickson
Date: 2009-01-12 11:03:34 -0500 (Mon, 12 Jan 2009)
New Revision: 11796
Modified:
trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js
Log:
allow the caller to define the field sort order, either a full list or the initial subset
Modified: trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js 2009-01-12 16:02:52 UTC (rev 11795)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js 2009-01-12 16:03:34 UTC (rev 11796)
@@ -19,6 +19,7 @@
fmClass : '',
fmObject : null,
mode : 'update',
+ fieldOrder : null, // ordered list of field names, optional.
/**
* Builds a basic table of key / value pairs. Keys are IDL display labels.
@@ -27,7 +28,7 @@
startup : function() {
this.inherited(arguments);
this.fmClass = (this.fmObject) ? this.fmObject.classname : this.fmClass;
- fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
+ this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
var table = document.createElement('table');
var tbody = document.createElement('tbody');
@@ -35,13 +36,15 @@
table.appendChild(tbody);
this.limitPerms = [];
- if(fmIDL.permacrud && fmIDL.permacrud[this.mode])
- this.limitPerms = fmIDL.permacrud[this.mode].perms;
+ if(this.fmIDL.permacrud && this.fmIDL.permacrud[this.mode])
+ this.limitPerms = this.fmIDL.permacrud[this.mode].perms;
- for(var f in fmIDL.fields) {
- var field = fmIDL.fields[f];
- if(field.virtual) continue;
+ this._buildSortedFieldList()
+ for(var f in this.sortedFieldList) {
+ var field = this.sortedFieldList[f];
+ if(!field || field.virtual) continue;
+
var row = document.createElement('tr');
var nameTd = document.createElement('td');
var valTd = document.createElement('td');
@@ -61,6 +64,57 @@
openils.Util.addCSSClass(table, 'oils-fm-edit-dialog');
},
+
+ _buildSortedFieldList : function() {
+ this.sortedFieldList = [];
+
+ if(this.fieldOrder) {
+
+ for(var idx in this.fieldOrder) {
+ var name = this.fieldOrder[idx];
+ for(var idx2 in this.fmIDL.fields) {
+ if(this.fmIDL.fields[idx2].name == name) {
+ this.sortedFieldList.push(this.fmIDL.fields[idx2]);
+ break;
+ }
+ }
+ }
+
+ // if the user-defined order does not list all fields,
+ // shove the extras on the end.
+ var anonFields = [];
+ for(var idx in this.fmIDL.fields) {
+ var name = this.fmIDL.fields[idx].name;
+ if(this.fieldOrder.indexOf(name) < 0) {
+ anonFields.push(this.fmIDL.fields[idx]);
+ }
+ }
+
+ anonFields = anonFields.sort(
+ function(a, b) {
+ if(a.label > b.label) return 1;
+ if(a.label < b.label) return -1;
+ return 0;
+ }
+ );
+
+ this.sortedFieldList = this.sortedFieldList.concat(anonFields);
+
+ } else {
+ // no sort order defined, sort all fields on display label
+
+ for(var f in this.fmIDL.fields)
+ this.sortedFieldList.push(this.fmIDL.fields[f]);
+ this.sortedFieldList = this.sortedFieldList.sort(
+ // by default, sort on label
+ function(a, b) {
+ if(a.label > b.label) return 1;
+ if(a.label < b.label) return -1;
+ return 0;
+ }
+ );
+ }
+ }
}
);
}
More information about the open-ils-commits
mailing list