[open-ils-commits] r9169 -
branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Apr 1 00:13:37 EDT 2008
Author: miker
Date: 2008-03-31 23:37:32 -0400 (Mon, 31 Mar 2008)
New Revision: 9169
Modified:
branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromHash.js
branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromStoreItem.js
Log:
dojo-ificiation
Modified: branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromHash.js
===================================================================
--- branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromHash.js 2008-04-01 03:05:55 UTC (rev 9168)
+++ branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromHash.js 2008-04-01 03:37:32 UTC (rev 9169)
@@ -1,12 +1,33 @@
+if(!dojo._hasResource['fieldmapper.hash']){
-function _fromHash (_hash) {
- var _fields = fmclasses[this.classname];
- for ( var i=0; i < _fields.length; i++) {
- if (_hash[_fields[i]] != null)
- this[_fields[i]]( _hash[_fields[i]] );
+ dojo._hasResource['fieldmapper.hash'] = true;
+ dojo.provide('fieldmapper.hash');
+ dojo.require('fieldmapper.Fieldmapper');
+
+ function _fromHash (_hash) {
+ var _fields = fmclasses[this.classname];
+ for ( var i=0; i < _fields.length; i++) {
+ if (_hash[_fields[i]] != null)
+ this[_fields[i]]( _hash[_fields[i]] );
+ }
+ return this;
}
- return this;
-}
-for (var i in fmclasses) window[i].prototype.fromHash = _fromHash;
+ for (var i in fmclasses) {
+ window[i].prototype.fromHash = _fromHash;
+ window[i].prototype.toHash = _toHash;
+ }
+
+ function _toHash () {
+ var _hash = {};
+ var _fields = fmclasses[this.classname];
+ for ( var i=0; i < _fields.length; i++) {
+ if (this[_fields[i]]() != null)
+ _hash[_fields[i]] = '' + this[_fields[i]]();
+ }
+ return _hash;
+ }
+
+
+}
Modified: branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromStoreItem.js
===================================================================
--- branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromStoreItem.js 2008-04-01 03:05:55 UTC (rev 9168)
+++ branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/addFromStoreItem.js 2008-04-01 03:37:32 UTC (rev 9169)
@@ -1,20 +1,104 @@
+if(!dojo._hasResource['fieldmapper.dojoData']){
-function _fromStoreItem (data) {
- this.fromHash(data);
+ dojo._hasResource['fieldmapper.dojoData'] = true;
+ dojo.provide('fieldmapper.dojoData');
+ dojo.require('fieldmapper.Fieldmapper');
+ dojo.require('fieldmapper.hash');
- for (var i in this._ignore_fields)
- this[this._ignore_fields[i]](null);
- var _fields = fmclasses[this.classname];
- for ( var i=0; i < _fields.length; i++) {
- if (dojo.isArray( this[_fields[i]]() ))
- this[_fields[i]]( this[_fields[i]]()[0] );
+ function _fromStoreItem (data) {
+ this.fromHash(data);
+
+ for (var i in this._ignore_fields)
+ this[this._ignore_fields[i]](null);
+
+ var _fields = fmclasses[this.classname];
+ for ( var i=0; i < _fields.length; i++) {
+ if (dojo.isArray( this[_fields[i]]() ))
+ this[_fields[i]]( this[_fields[i]]()[0] );
+ }
+ return this;
}
- return this;
-}
-for (var i in fmclasses) window[i].prototype.fromStoreItem = _fromStoreItem;
+ function _toStoreData (list, label, params) {
-aou.prototype._ignore_fields = ['children'];
-aout.prototype._ignore_fields = ['children'];
-pgt.prototype._ignore_fields = ['children'];
+ if (!params) params = {};
+
+ // a sane default
+ if (!params.identifier) params.identifier = 'id';
+ if (!label) label = params.label;
+ if (!label) label = params.identifier;
+
+ var data = { label : label, identifier : params.identifier, items : [] };
+
+ for (var i in list) data.items.push( list[i].toHash() );
+
+ if (params.children && params.parent) {
+ var _hash_list = data.items;
+
+ var _find_root = {};
+ for (var i in _hash_list) {
+ _find_root[_hash_list[i][params.identifier]] = _hash_list[i];
+ }
+
+ var item_data = [];
+ for (var i in _hash_list) {
+ var obj = _hash_list[i]
+ obj[params.children] = [];
+
+ for (var j in _hash_list) {
+ var kid = _hash_list[j];
+ if (kid[params.parent] == obj[params.identifier]) {
+ obj[params.children].push( { _reference : kid[params.identifier] } );
+ kid._iskid = true;
+ if (_find_root[kid[params.identifier]]) delete _find_root[kid[params.identifier]];
+ }
+ }
+
+ item_data.push( obj );
+ }
+
+ for (var j in _find_root) {
+ _find_root[j]['_top'] = 'true';
+ if (!_find_root[j][params.parent])
+ _find_root[j]['_trueRoot'] = 'true';
+ }
+
+ data.items = item_data;
+ }
+
+ return data;
+ }
+
+ for (var i in fmclasses) window[i].prototype.fromStoreItem = _fromStoreItem;
+
+ aou.prototype._ignore_fields = ['children'];
+ aout.prototype._ignore_fields = ['children'];
+ pgt.prototype._ignore_fields = ['children'];
+
+ // set up the defaults
+ for (var i in fmclasses) window[i].toStoreData = _toStoreData;
+
+ aou.toStoreData = function (list, label) {
+ if (!label) label = 'shortname';
+ return _toStoreData(list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
+ }
+
+ aout.toStoreData = function (list, label) {
+ if (!label) label = 'name';
+ return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+ }
+
+ pgt.toStoreData = function (list, label) {
+ if (!label) label = 'name';
+ return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+ }
+
+ /*
+ ppl.toStoreData = function (list, label) {
+ if (!label) label = 'code';
+ return _toStoreData(list, label, {});
+ }
+ */
+
+}
More information about the open-ils-commits
mailing list