From 17e659eec3e23caf5d301b33aa5019b672ecd0e8 Mon Sep 17 00:00:00 2001 From: dbs Date: Mon, 14 Mar 2011 04:21:20 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19730 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js | 66 +++++++++++++------------ Open-ILS/web/js/dojo/fieldmapper/IDL.js | 9 ++-- Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js | 43 ++++++++-------- Open-ILS/web/js/dojo/fieldmapper/dojoData.js | 26 +++++----- Open-ILS/web/js/dojo/fieldmapper/hash.js | 13 ++--- 5 files changed, 84 insertions(+), 73 deletions(-) diff --git a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js index c537b42f47..154935eb8c 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js +++ b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js @@ -26,7 +26,7 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ //** 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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(!dojo._hasResource["fieldmapper.Fieldmapper"]){ } 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 **/ diff --git a/Open-ILS/web/js/dojo/fieldmapper/IDL.js b/Open-ILS/web/js/dojo/fieldmapper/IDL.js index 3fa3162758..d90e121143 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/IDL.js +++ b/Open-ILS/web/js/dojo/fieldmapper/IDL.js @@ -22,7 +22,7 @@ if(!dojo._hasResource["fieldmapper.IDL"]) { 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 @@ if(!dojo._hasResource["fieldmapper.IDL"]) { }; 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); - } + }; } diff --git a/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js b/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js index c548e6af57..d305a8d6e0 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js +++ b/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js @@ -30,22 +30,23 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ } return org; - } + }; fieldmapper.aou.prototype.orgNodeTrail = function(node, asId) { if (!node) node = this; @@ -185,7 +186,7 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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(!dojo._hasResource["fieldmapper.OrgUtils"]){ 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 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ } 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) { diff --git a/Open-ILS/web/js/dojo/fieldmapper/dojoData.js b/Open-ILS/web/js/dojo/fieldmapper/dojoData.js index 428359a6ff..3ebcafcd07 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/dojoData.js +++ b/Open-ILS/web/js/dojo/fieldmapper/dojoData.js @@ -31,10 +31,11 @@ if(!dojo._hasResource['fieldmapper.dojoData']){ 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(!dojo._hasResource['fieldmapper.dojoData']){ 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 @@ if(!dojo._hasResource['fieldmapper.dojoData']){ 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 @@ if(!dojo._hasResource['fieldmapper.dojoData']){ 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 @@ if(!dojo._hasResource['fieldmapper.dojoData']){ 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) { diff --git a/Open-ILS/web/js/dojo/fieldmapper/hash.js b/Open-ILS/web/js/dojo/fieldmapper/hash.js index 0cfea4b00e..21bb370444 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/hash.js +++ b/Open-ILS/web/js/dojo/fieldmapper/hash.js @@ -25,9 +25,10 @@ if(!dojo._hasResource['fieldmapper.hash']){ /* 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 @@ if(!dojo._hasResource['fieldmapper.hash']){ 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(!dojo._hasResource['fieldmapper.hash']){ } 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; } -- 2.11.0