[open-ils-commits] r19731 - branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 14 00:24:00 EDT 2011
Author: dbs
Date: 2011-03-14 00:23:57 -0400 (Mon, 14 Mar 2011)
New Revision: 19731
Modified:
branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/IDL.js
branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js
branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/dojoData.js
branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/hash.js
Log:
Apply jshint suggestions for cleanup to dojo.fieldmapper
Mostly consisting of missing semicolons and avoiding the redeclaration
of variables (generally for iterators) within the same function scope.
Some tightening of null and '' checks to avoid implicit type-casting.
Modified: branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
===================================================================
--- branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js 2011-03-14 04:21:20 UTC (rev 19730)
+++ branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js 2011-03-14 04:23:57 UTC (rev 19731)
@@ -26,7 +26,7 @@
called 'fmclasses' to be fleshed with the classes we need to build */
function FMEX(message) { this.message = message; }
- FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
+ FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; };
dojo.declare( "fieldmapper.Fieldmapper", null, {
@@ -47,14 +47,14 @@
for( var i in this.a ) {
var thing = this.a[i];
- if(thing == null) continue;
+ if(thing === null) continue;
if( thing._isfieldmapper ) {
obj.a[i] = thing.clone();
} else {
if(dojo.isArray(thing)) {
- obj.a[i] = new Array();
+ obj.a[i] = [];
for( var j in thing ) {
@@ -100,12 +100,13 @@
this.classname = this.declaredClass;
this._fields = [];
+ var p, f;
if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
- this.Structure = fieldmapper.IDL.fmclasses[this.classname]
+ this.Structure = fieldmapper.IDL.fmclasses[this.classname];
- for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
+ for (f in fieldmapper.IDL.fmclasses[this.classname].fields) {
var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
- var p = field.array_position;
+ p = field.array_position;
this._fields.push( field.name );
this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
}
@@ -113,8 +114,8 @@
this._fields = fmclasses[this.classname];
for( var pos = 0; pos < this._fields.length; pos++ ) {
- var p = parseInt(pos);
- var f = this._fields[pos];
+ p = parseInt(pos, 10);
+ f = this._fields[pos];
this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
}
}
@@ -130,7 +131,7 @@
fieldmapper[cl].prototype.fromStoreItem = _fromStoreItem;
fieldmapper[cl].toStoreData = _toStoreData;
fieldmapper[cl].toStoreItem = _toStoreItem;
- fieldmapper[cl].prototype.toStoreItem = function ( args ) { return _toStoreItem(this, args) };
+ fieldmapper[cl].prototype.toStoreItem = function ( args ) { return _toStoreItem(this, args); };
fieldmapper[cl].initStoreData = _initStoreData;
fieldmapper[cl].prototype.toHash = _toHash;
fieldmapper[cl].toHash = _toHash;
@@ -162,27 +163,27 @@
if(!args.onmethoderror) {
args.onmethoderror = function(r, stat, stat_text) {
throw new Error('Method error: ' + r.stat + ' : ' + stat_text);
+ };
}
- }
if(!args.ontransporterror) {
args.ontransporterror = function(xreq) {
throw new Error('Transport error method='+args.method+', status=' + xreq.status);
+ };
}
- }
if (!args.onerror) {
args.onerror = function (r) {
throw new Error('Request error encountered! ' + r);
+ };
}
- }
if (!args.oncomplete) {
args.oncomplete = function (r) {
var x = r.recv();
if (x) result = x.content();
+ };
}
- }
args.method = meth[1];
if (staff && meth[2]) args.method += '.staff';
@@ -192,10 +193,10 @@
return result;
};
- fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
+ fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params); };
fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
- fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
+ fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params); };
fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
fieldmapper.OpenSRF = {};
@@ -214,7 +215,7 @@
//** FROM HASH **/
function _fromHash (_hash) {
for ( var i=0; i < this._fields.length; i++) {
- if (_hash[this._fields[i]] != null)
+ if (_hash[this._fields[i]] !== null)
this[this._fields[i]]( _hash[this._fields[i]] );
}
return this;
@@ -222,9 +223,10 @@
function _toHash (includeNulls, virtFields) {
var _hash = {};
- for ( var i=0; i < this._fields.length; i++) {
- if (includeNulls || this[this._fields[i]]() != null) {
- if (this[this._fields[i]]() == null)
+ var i;
+ for (i=0; i < this._fields.length; i++) {
+ if (includeNulls || this[this._fields[i]]() !== null) {
+ if (this[this._fields[i]]() === null)
_hash[this._fields[i]] = null;
else
_hash[this._fields[i]] = '' + this[this._fields[i]]();
@@ -232,7 +234,7 @@
}
if (virtFields && virtFields.length > 0) {
- for (var i = 0; i < virtFields.length; i++) {
+ for (i = 0; i < virtFields.length; i++) {
if (!_hash[virtFields[i]])
_hash[virtFields[i]] = null;
}
@@ -247,10 +249,11 @@
function _fromStoreItem (data) {
this.fromHash(data);
- for (var i = 0; this._ignore_fields && i < this._ignore_fields.length; i++)
+ var i;
+ for (i = 0; this._ignore_fields && i < this._ignore_fields.length; i++)
this[this._ignore_fields[i]](null);
- for (var i = 0; this._fields && i < this._fields.length; i++) {
+ for (i = 0; this._fields && i < this._fields.length; i++) {
if (dojo.isArray( this[this._fields[i]]() ))
this[this._fields[i]]( this[this._fields[i]]()[0] );
}
@@ -274,22 +277,23 @@
if (!params) params = {};
var data = this.initStoreData(label, params);
- for (var i = 0; list && i < list.length; i++) data.items.push( list[i].toHash(true, params.virtualFields) );
+ var i, j;
+ for (i = 0; list && i < list.length; i++) data.items.push( list[i].toHash(true, params.virtualFields) );
if (params.children && params.parent) {
var _hash_list = data.items;
var _find_root = {};
- for (var i = 0; _hash_list && i < _hash_list.length; i++) {
+ for (i = 0; _hash_list && i < _hash_list.length; i++) {
_find_root[_hash_list[i][params.identifier]] = _hash_list[i];
}
var item_data = [];
- for (var i = 0; _hash_list && i < _hash_list.length; i++) {
- var obj = _hash_list[i]
+ for (i = 0; _hash_list && i < _hash_list.length; i++) {
+ var obj = _hash_list[i];
obj[params.children] = [];
- for (var j = 0; _hash_list && j < _hash_list.length; j++) {
+ for (j = 0; _hash_list && j < _hash_list.length; j++) {
var kid = _hash_list[j];
if (kid[params.parent] == obj[params.identifier]) {
obj[params.children].push( { _reference : kid[params.identifier] } );
@@ -301,7 +305,7 @@
item_data.push( obj );
}
- for (var j in _find_root) {
+ for (j in _find_root) {
_find_root[j]['_top'] = 'true';
if (!_find_root[j][params.parent])
_find_root[j]['_trueRoot'] = 'true';
@@ -364,17 +368,17 @@
fieldmapper.aou.toStoreData = function (list, label) {
if (!label) label = 'shortname';
return _toStoreData.call(this, list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
- }
+ };
fieldmapper.aout.toStoreData = function (list, label) {
if (!label) label = 'name';
return _toStoreData.call(this, list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
+ };
fieldmapper.pgt.toStoreData = function (list, label) {
if (!label) label = 'name';
return _toStoreData.call(this, list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
+ };
/** FROM dojoData **/
Modified: branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/IDL.js
===================================================================
--- branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/IDL.js 2011-03-14 04:21:20 UTC (rev 19730)
+++ branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/IDL.js 2011-03-14 04:23:57 UTC (rev 19731)
@@ -22,7 +22,7 @@
fieldmapper.IDL.fmclasses[c] = window._preload_fieldmapper_IDL[c];
window.fmclasses[c] = [];
- dojo.forEach(fieldmapper.IDL.fmclasses[c].fields, function(obj){ window.fmclasses[c].push(obj.name) });
+ dojo.forEach(fieldmapper.IDL.fmclasses[c].fields, function(obj){ window.fmclasses[c].push(obj.name); });
if (classlist && classlist.length)
classlist = dojo.filter(classlist, function(x){return x != c;});
@@ -221,14 +221,17 @@
};
window.fmclasses = {};
- fieldmapper.IDL.load = function (list) { if (!list) list = []; return new fieldmapper.IDL(list); };
+ fieldmapper.IDL.load = function (list) {
+ if (!list) list = [];
+ return new fieldmapper.IDL(list);
+ };
fieldmapper.IDL.loaded = false;
JSON2js.fallbackObjectifier = function (arg, key_name, val_name) {
console.log("Firing IDL loader for " + arg[key_name]);
fieldmapper.IDL.load([arg[key_name]]);
return decodeJS(arg);
- }
+ };
}
Modified: branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js
===================================================================
--- branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js 2011-03-14 04:21:20 UTC (rev 19730)
+++ branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js 2011-03-14 04:23:57 UTC (rev 19731)
@@ -30,22 +30,23 @@
fieldmapper.aout.OrgTypeCache = {};
fieldmapper.aout.LoadOrgTypes = function () {
- for (var i in fieldmapper.aout.OrgTypeCache) {
+ var i;
+ for (i in fieldmapper.aout.OrgTypeCache) {
return;
}
var types = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_types.retrieve']);
- for (var i = 0; i < types.length; i++) {
+ for (i = 0; i < types.length; i++) {
fieldmapper.aout.OrgTypeCache[types[i].id()] = {
loaded : true,
type : types[i]
};
}
- }
+ };
fieldmapper.aou.LoadOrg = function (id, slim_ok) {
- if (slim_ok == null) slim_ok = fieldmapper.aou.slim_ok;
+ if (slim_ok === null) slim_ok = fieldmapper.aou.slim_ok;
var slim_o = fieldmapper.aou.OrgCache[id];
if (slim_o && (slim_ok || slim_o.loaded))
@@ -58,7 +59,7 @@
o.children = fieldmapper.aou.OrgCache[o.id()].children;
fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o };
return o;
- }
+ };
fieldmapper.aou.findOrgUnit = fieldmapper.aou.LoadOrg;
if (window._l) {
@@ -79,7 +80,7 @@
for (var i in fieldmapper.aou.OrgCache) {
var x = fieldmapper.aou.OrgCache[i].org;
- if (x.parent_ou() == null || x.parent_ou() == '') {
+ if (x.parent_ou() === null || x.parent_ou() === '') {
fieldmapper.aou.globalOrgTree = x;
continue;
}
@@ -103,24 +104,24 @@
fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, [this.id(), name] );
- }
+ };
fieldmapper.aou.prototype.fetchOrgSettingBatch = function (nameList) {
return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING_BATCH, [this.id(), nameList] );
- }
+ };
fieldmapper.aou.fetchOrgSettingDefault = function (orgId, name) {
return fieldmapper.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, [orgId, name] );
- }
+ };
fieldmapper.aou.fetchOrgSettingBatch = function (orgId, nameList) {
return fieldmapper.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING_BATCH, [orgId, nameList] );
- }
+ };
fieldmapper.aout.findOrgType = function (id) {
fieldmapper.aout.LoadOrgTypes();
return fieldmapper.aout.OrgTypeCache[id].type;
- }
+ };
fieldmapper.aou.prototype.findOrgDepth = function (id) {
if (!id) id = this.id;
@@ -130,21 +131,21 @@
return fieldmapper.aout.findOrgType(
fieldmapper.aou.findOrgUnit(id).ou_type()
).depth();
- }
+ };
fieldmapper.aou.findOrgDepth = fieldmapper.aou.prototype.findOrgDepth;
fieldmapper.aout.findOrgTypeFromDepth = function (depth) {
- if( depth == null ) return null;
+ if( depth === null ) return null;
fieldmapper.aout.LoadOrgTypes();
for( var i in fieldmapper.aout.OrgTypeCache ) {
var t = fieldmapper.aout.OrgTypeCache[i].type;
if( t.depth() == depth ) return t;
}
return null;
- }
+ };
fieldmapper.aou.findOrgUnitSN = function (sn, slim_ok) {
- if (slim_ok == null) slim_ok = fieldmapper.aou.slim_ok;
+ if (slim_ok === null) slim_ok = fieldmapper.aou.slim_ok;
var org = fieldmapper.aou.OrgCacheSN[sn];
if (!org) {
for (var i in fieldmapper.aou.OrgCache) {
@@ -166,7 +167,7 @@
}
return org;
- }
+ };
fieldmapper.aou.prototype.orgNodeTrail = function(node, asId) {
if (!node) node = this;
@@ -185,7 +186,7 @@
na.reverse();
if (asId) return na.map(function(o) { return o.id(); });
else return na;
- }
+ };
fieldmapper.aou.orgNodeTrail = fieldmapper.aou.prototype.orgNodeTrail;
fieldmapper.aou.prototype.orgIsMine = function (me, org) {
@@ -202,7 +203,7 @@
if(me.children()[i].orgIsMine(org)) return true;
}
return false;
- }
+ };
/** Given an org id, returns an array of org units including
* the org for the ID provided and all descendant orgs */
@@ -223,17 +224,17 @@
}
addNode(fieldmapper.aou.findOrgUnit(orgId));
return list;
- }
+ };
fieldmapper.aou.fullPath = function(orgId, asId) {
var orgList = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(orgId));
orgList.pop(); // prevent dupes
- orgList = orgList.concat(fieldmapper.aou.descendantNodeList(orgId))
+ orgList = orgList.concat(fieldmapper.aou.descendantNodeList(orgId));
if(!asId) return orgList;
return orgList.map( function(node) { return node.id(); } );
- }
+ };
dojo.addOnUnload( function () {
for (var i in fieldmapper.aou.OrgCache) {
Modified: branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/dojoData.js
===================================================================
--- branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/dojoData.js 2011-03-14 04:21:20 UTC (rev 19730)
+++ branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/dojoData.js 2011-03-14 04:23:57 UTC (rev 19731)
@@ -31,10 +31,11 @@
function _fromStoreItem (data) {
this.fromHash(data);
- for (var i = 0; this._ignore_fields && i < this._ignore_fields.length; i++)
+ var i;
+ for (i = 0; this._ignore_fields && i < this._ignore_fields.length; i++)
this[this._ignore_fields[i]](null);
- for (var i = 0; this._fields && i < this._fields.length; i++) {
+ for (i = 0; this._fields && i < this._fields.length; i++) {
if (dojo.isArray( this[this._fields[i]]() ))
this[this._fields[i]]( this[this._fields[i]]()[0] );
}
@@ -58,22 +59,23 @@
if (!params) params = {};
var data = this.initStoreData(label, params);
- for (var i = 0; list && i < list.length; i++) data.items.push( list[i].toHash(true, params.virtualFields) );
+ var i, j;
+ for (i = 0; list && i < list.length; i++) data.items.push( list[i].toHash(true, params.virtualFields) );
if (params.children && params.parent) {
var _hash_list = data.items;
var _find_root = {};
- for (var i = 0; _hash_list && i < _hash_list.length; i++) {
+ for (i = 0; _hash_list && i < _hash_list.length; i++) {
_find_root[_hash_list[i][params.identifier]] = _hash_list[i];
}
var item_data = [];
- for (var i = 0; _hash_list && i < _hash_list.length; i++) {
- var obj = _hash_list[i]
+ for (i = 0; _hash_list && i < _hash_list.length; i++) {
+ var obj = _hash_list[i];
obj[params.children] = [];
- for (var j = 0; _hash_list && j < _hash_list.length; j++) {
+ for (j = 0; _hash_list && j < _hash_list.length; j++) {
var kid = _hash_list[j];
if (kid[params.parent] == obj[params.identifier]) {
obj[params.children].push( { _reference : kid[params.identifier] } );
@@ -85,7 +87,7 @@
item_data.push( obj );
}
- for (var j in _find_root) {
+ for (j in _find_root) {
_find_root[j]['_top'] = 'true';
if (!_find_root[j][params.parent])
_find_root[j]['_trueRoot'] = 'true';
@@ -101,7 +103,7 @@
fieldmapper[i].prototype.fromStoreItem = _fromStoreItem;
fieldmapper[i].toStoreData = _toStoreData;
fieldmapper[i].toStoreItem = _toStoreItem;
- fieldmapper[i].prototype.toStoreItem = function ( args ) { return _toStoreItem(this, args) };
+ fieldmapper[i].prototype.toStoreItem = function ( args ) { return _toStoreItem(this, args); };
fieldmapper[i].initStoreData = _initStoreData;
}
@@ -112,17 +114,17 @@
fieldmapper.aou.toStoreData = function (list, label) {
if (!label) label = 'shortname';
return _toStoreData.call(this, list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
- }
+ };
fieldmapper.aout.toStoreData = function (list, label) {
if (!label) label = 'name';
return _toStoreData.call(this, list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
+ };
fieldmapper.pgt.toStoreData = function (list, label) {
if (!label) label = 'name';
return _toStoreData.call(this, list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
+ };
/*
ppl.toStoreData = function (list, label) {
Modified: branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/hash.js
===================================================================
--- branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/hash.js 2011-03-14 04:21:20 UTC (rev 19730)
+++ branches/rel_2_1/Open-ILS/web/js/dojo/fieldmapper/hash.js 2011-03-14 04:23:57 UTC (rev 19731)
@@ -25,9 +25,10 @@
/* XXX Content loaded in Fieldmapper */
/* XXX deprecate this file **/
+ var i;
function _fromHash (_hash) {
- for ( var i=0; i < this._fields.length; i++) {
- if (_hash[this._fields[i]] != null)
+ for (i = 0; i < this._fields.length; i++) {
+ if (_hash[this._fields[i]] !== null)
this[this._fields[i]]( _hash[this._fields[i]] );
}
return this;
@@ -35,9 +36,9 @@
function _toHash (includeNulls, virtFields) {
var _hash = {};
- for ( var i=0; i < this._fields.length; i++) {
- if (includeNulls || this[this._fields[i]]() != null) {
- if (this[this._fields[i]]() == null)
+ for (i = 0; i < this._fields.length; i++) {
+ if (includeNulls || this[this._fields[i]]() !== null) {
+ if (this[this._fields[i]]() === null)
_hash[this._fields[i]] = null;
else
_hash[this._fields[i]] = '' + this[this._fields[i]]();
@@ -45,7 +46,7 @@
}
if (virtFields && virtFields.length > 0) {
- for (var i = 0; i < virtFields.length; i++) {
+ for (i = 0; i < virtFields.length; i++) {
if (!_hash[virtFields[i]])
_hash[virtFields[i]] = null;
}
More information about the open-ils-commits
mailing list