[open-ils-commits] r9286 - in
branches/dojo-admin/Open-ILS/web/conify: global/permission
js/fieldmapper
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 9 17:39:20 EDT 2008
Author: miker
Date: 2008-04-09 17:02:01 -0400 (Wed, 09 Apr 2008)
New Revision: 9286
Added:
branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/OrgUtils.js
Modified:
branches/dojo-admin/Open-ILS/web/conify/global/permission/grp_tree.html
branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/Fieldmapper.js
Log:
toward dojo wrappers
Modified: branches/dojo-admin/Open-ILS/web/conify/global/permission/grp_tree.html
===================================================================
--- branches/dojo-admin/Open-ILS/web/conify/global/permission/grp_tree.html 2008-04-09 18:46:24 UTC (rev 9285)
+++ branches/dojo-admin/Open-ILS/web/conify/global/permission/grp_tree.html 2008-04-09 21:02:01 UTC (rev 9286)
@@ -52,8 +52,11 @@
<!-- Dojo goodness -->
<script type="text/javascript" src="/js/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
<script type="text/javascript" src="/js/dijit/dijit.js"></script>
+ <script type="text/javascript" src="/js/fieldmapper/Fieldmapper.js"></script>
<script type="text/javascript" src="grp_tree.js"></script>
+ <script language='javascript' src='/opac/common/js/OrgTree.js' type='text/javascript'></script>
+ <script type="text/javascript" src="/js/fieldmapper/OrgUtils.js"></script>
</head>
Modified: branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/Fieldmapper.js
===================================================================
--- branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/Fieldmapper.js 2008-04-09 18:46:24 UTC (rev 9285)
+++ branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/Fieldmapper.js 2008-04-09 21:02:01 UTC (rev 9286)
@@ -57,54 +57,56 @@
isnew : function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; },
ischanged : function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; },
- isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; },
+ isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
+ });
- _request : function ( meth, staff, params ) {
- var ses = OpenSRF.CachedClientSession( meth[0] );
- if (!ses) return null;
+ fieldmapper._request = function ( meth, staff, params ) {
+ var ses = OpenSRF.CachedClientSession( meth[0] );
+ if (!ses) return null;
- var result = null;
- var args = {};
+ var result = null;
+ var args = {};
- if (dojo.isObject(params)) {
- args = params;
+ if (dojo.isObject(params)) {
+ args = params;
+ } else {
+
+ if (dojo.isArray(params)) {
+ args.params = params;
} else {
+ args.params = arguments.splice(1, arguments.length - 1);
+ }
- if (dojo.isArray(params)) {
- args.params = params;
- } else {
- args.params = arguments.splice(1, arguments.length - 1);
- }
+ args.timeout = 10;
+ }
- args.timeout = 10;
+ if (!args.onerror) {
+ args.error = function (r) {
+ throw 'Error encountered! ' + r;
}
+ }
- if (!args.onerror) {
- args.error = function (r) {
- throw 'Error encountered! ' + r;
- }
+ if (!args.oncomplete) {
+ args.oncomplete = function (r) {
+ var x = r.recv();
+ if (x) result = x.content();
}
+ }
- 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';
- args.method = meth[1];
- if (staff && meth[2]) args.method += '.staff';
+ ses.request(args).send();
- ses.request(args).send();
+ return result;
+ };
- return result;
- },
+ fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
+ fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
- standardRequest : function (meth, params) { return this._request(meth, false, params) },
- staffRequest : function (meth, params) { return this._request(meth, true, params) }
+ fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
+ fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
- });
-
for( var cl in fmclasses ) {
dojo.provide( cl );
dojo.declare( cl , fieldmapper.Fieldmapper, {
@@ -213,10 +215,6 @@
FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default']
};
- fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
- return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, name );
- }
-
}
Added: branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/OrgUtils.js
===================================================================
--- branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/OrgUtils.js (rev 0)
+++ branches/dojo-admin/Open-ILS/web/conify/js/fieldmapper/OrgUtils.js 2008-04-09 21:02:01 UTC (rev 9286)
@@ -0,0 +1,171 @@
+if(!dojo._hasResource["fieldmapper.OrgUtils"]){
+
+ dojo._hasResource["fieldmapper.OrgUtils"] = true;
+ dojo.provide("fieldmapper.OrgUtils");
+ dojo.require("fieldmapper.Fieldmapper");
+
+ fieldmapper.aou.globalOrgTree = {};
+ fieldmapper.aou.OrgCache = {};
+ fieldmapper.aou.OrgCacheSN = {};
+ fieldmapper.aout.OrgTypeCache = {};
+
+ fieldmapper.aout.LoadOrgTypes = function () {
+ for (var i in fieldmapper.aout.OrgTypeCache) {
+ return;
+ }
+
+ var types = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_types.retrieve']);
+
+ for (var i in types) {
+ fieldmapper.aout.OrgTypeCache[types[i].id()] = {
+ loaded : true,
+ type : types[i]
+ };
+ }
+ }
+
+ fieldmapper.aou.LoadOrg = function (id) {
+ if (fieldmapper.aou.OrgCache[id] && fieldmapper.aou.OrgCache[id].loaded)
+ return fieldmapper.aou.OrgCache[id].org;
+
+ var o = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_unit.retrieve'],{ params: [null,id]});
+ fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o };
+ return o;
+ }
+ fieldmapper.aou.findOrgUnit = fieldmapper.aou.LoadOrg;
+
+ if (window._l) {
+ for (var i in _l) {
+ fieldmapper.aou.OrgCache[_l[i][0]] = {
+ loaded: false,
+ org : new fieldmapper.aou().fromHash({
+ id : _l[i][0],
+ ou_type : _l[i][1],
+ parent_ou : _l[i][2],
+ name : _l[i][3],
+ opac_visible : _l[i][4]
+ })
+ };
+
+ }
+
+ for (var i in fieldmapper.aou.OrgCache) {
+ var x = fieldmapper.aou.OrgCache[i].org;
+ if (x.parent_ou() == null || x.parent_ou() == '') {
+ fieldmapper.aou.globalOrgTree = x;
+ continue;
+ }
+
+ var parent = fieldmapper.aou.findOrgUnit(x.parent_ou());
+ if (!parent.children()) parent.children([]);
+ parent.children().push(x);
+ }
+
+ for (var i in globalOrgTypes) {
+ fieldmapper.aout.OrgTypeCache[globalOrgTypes[i].id()] = {
+ loaded : true,
+ type : globalOrgTypes[i]
+ };
+ }
+ }
+
+
+ /* ---------------------------------------------------------------------- */
+
+ fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
+ return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, name );
+ }
+
+ 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;
+ if (!id) return null;
+
+ var org = fieldmapper.aou.findOrgUnit(id);
+ return fieldmapper.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;
+ 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) {
+ var org = fieldmapper.aou.OrgCacheSN[sn];
+ if (!org) {
+ for (var i in fieldmapper.aou.OrgCache) {
+ var o = fieldmapper.aou.OrgCache[i];
+ if (o.loaded && o.org.shortname() == sn) {
+ fieldmapper.aou.OrgCacheSN[o.org.shortname()] = o;
+ return o.org;
+ }
+ }
+
+ org = fieldmapper.standardRequest(fieldmapper.OpenSRF.methods.FETCH_ORG_BY_SHORTNAME, sn);
+
+ fieldmapper.aou.OrgCache[org.id()] = { loaded : true, org : org };
+ fieldmapper.aou.OrgCacheSN[org.shortname()] = { loaded : true, org : org };
+
+ }
+
+ return org;
+ }
+
+ fieldmapper.aou.prototype.orgNodeTrail = function (node) {
+ if (!node) node = this;
+ if (!node) return [];
+
+ var na = [];
+
+ while( node ) {
+ na.push(node);
+ node = fieldmapper.aou.findOrgUnit(node.parent_ou());
+ }
+
+ return na.reverse();
+ }
+ fieldmapper.aou.orgNodeTrail = fieldmapper.aou.prototype.orgNodeTrail;
+
+ fieldmapper.aou.prototype.orgIsMine = function (me, org) {
+ if (this._isfieldmapper) {
+ org = me;
+ me = this;
+ }
+
+ if(!me || !org) return false;
+
+ if(me.id() == org.id()) return true;
+
+ for( var i in me.children() ) {
+ if(me.children()[i].orgIsMine(org)) return true;
+ }
+ return false;
+ }
+
+ dojo.addOnUnload( function () {
+ for (var i in fieldmapper.aou.OrgCache) {
+ x=fieldmapper.aou.OrgCache[i];
+ x.children(null);
+ x.parent_ou(null);
+ fieldmapper.aou.OrgCache[i]=null;
+ }
+ fieldmapper.aou.globalOrgTree = null;
+ fieldmapper.aou.OrgCache = null;
+ fieldmapper.aout.OrgTypeCache = null;
+ });
+}
+
+
+
More information about the open-ils-commits
mailing list