|
|
@@ -1642,7 +1642,195 @@ MWF.xScript.JSONData = function(data, callback, key, parent, _form){
|
|
|
// this.destory = this["delete"];
|
|
|
// }
|
|
|
//};
|
|
|
-var dictLoaded = {};
|
|
|
+// var dictLoaded = {};
|
|
|
+MWF.xScript.dictLoaded = {};
|
|
|
+
|
|
|
+MWF.xScript.addDictToCache = function ( options, path, json ) {
|
|
|
+
|
|
|
+ debugger;
|
|
|
+
|
|
|
+ // if( !key ){
|
|
|
+ // var name = options.name || options.id || options.alias;
|
|
|
+ // var type = options.appType || "process";
|
|
|
+ // var application = options.appName || options.appId || options.application || options.appAlias;
|
|
|
+ // var enableAnonymous = options.enableAnonymous || false;
|
|
|
+ // key = name+type+application+enableAnonymous;
|
|
|
+ // }
|
|
|
+
|
|
|
+ if( !path )path = "root";
|
|
|
+ if( path.indexOf("root") !== 0 )path = "root." + path ;
|
|
|
+
|
|
|
+ // if( MWF.xScript.dictLoaded[key] ){
|
|
|
+ // var dicts = MWF.xScript.dictLoaded[key];
|
|
|
+ // var arr = path.split(/\./g);
|
|
|
+ // var p;
|
|
|
+ // for( var i=0 ; i<arr.length; i++ ){
|
|
|
+ // p = i === 0 ? arr[0] : ( p + "." + arr[i] );
|
|
|
+ // if( dicts[ p ] )return; //如果上级路径存在,则返回
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if( MWF.xScript.dictLoaded[key] && MWF.xScript.dictLoaded[key][path]){
|
|
|
+ // MWF.xScript.dictLoaded[key][path] = json;
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ var type = options.appType || "process";
|
|
|
+ var enableAnonymous = options.enableAnonymous || false;
|
|
|
+
|
|
|
+ var appFlagList = [];
|
|
|
+ if( options.application )appFlagList.push( options.application );
|
|
|
+ if( options.appId )appFlagList.push( options.appId );
|
|
|
+ if( options.appName )appFlagList.push( options.appName );
|
|
|
+ if( options.appAlias )appFlagList.push( options.appAlias );
|
|
|
+
|
|
|
+ var dictFlagList = [];
|
|
|
+ if( options.id )dictFlagList.push( options.id );
|
|
|
+ if( options.name )dictFlagList.push( options.name );
|
|
|
+ if( options.alias )dictFlagList.push( options.alias );
|
|
|
+
|
|
|
+ var cache = {};
|
|
|
+ cache[path] = json;
|
|
|
+
|
|
|
+ for( var i=0; i<appFlagList.length; i++ ){
|
|
|
+ for( var j=0; j<dictFlagList.length; j++ ){
|
|
|
+ var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
|
|
|
+ if( !MWF.xScript.dictLoaded[k] ){
|
|
|
+ MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
|
|
|
+ // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
|
|
|
+ }else if( i===0 && j===0 ){
|
|
|
+ MWF.xScript.setDictToCache( k, path ,json );
|
|
|
+ var arr = path.split(/\./g);
|
|
|
+ var p;
|
|
|
+ var cache = MWF.xScript.dictLoaded[k];
|
|
|
+ for( var l=0 ; l<arr.length; l++ ){
|
|
|
+ p = l === 0 ? arr[0] : ( p + "." + arr[l] );
|
|
|
+ if( cache[ p ] )break;
|
|
|
+ }
|
|
|
+ if( p ){
|
|
|
+ var mathP = p+".";
|
|
|
+ Object.keys( cache ).each( function( path, idx){
|
|
|
+ if( path.indexOf( mathP ) === 0 )delete cache[path];
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+MWF.xScript.getMatchedDict = function(key, path){
|
|
|
+
|
|
|
+ debugger;
|
|
|
+
|
|
|
+ if( !path )path = "root";
|
|
|
+ if( path.indexOf("root") !== 0 )path = "root." + path ;
|
|
|
+
|
|
|
+ var arr = path.split(/\./g);
|
|
|
+ if( MWF.xScript.dictLoaded[key] ){
|
|
|
+ var dicts = MWF.xScript.dictLoaded[key];
|
|
|
+ var list = Array.clone(arr);
|
|
|
+ var p;
|
|
|
+ var dict;
|
|
|
+ for( var i=0 ; i<arr.length; i++ ){
|
|
|
+ p = i === 0 ? arr[0] : ( p + "." + arr[i] );
|
|
|
+ list.shift();
|
|
|
+ if( dicts[ p ] ){
|
|
|
+ dict = dicts[ p ];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ dict : dict,
|
|
|
+ unmatchedPathList : list
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ dict : null,
|
|
|
+ unmatchedPathList : list
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+MWF.xScript.insertDictToCache = function(key, path, json){
|
|
|
+ if( MWF.xScript.dictLoaded[key] ){
|
|
|
+ var matchedDict = MWF.xScript.getMatchedDict( key, path );
|
|
|
+ var dict = matchedDict.dict;
|
|
|
+ var list = matchedDict.unmatchedPathList;
|
|
|
+ if( !dict ){
|
|
|
+ MWF.xScript.dictLoaded[key][path] = json;
|
|
|
+ }else{
|
|
|
+ for( var j=0; j<list.length-1; j++ ){
|
|
|
+ if( !dict[ list[j] ] ){
|
|
|
+ dict[ list[j] ] = {};
|
|
|
+ }
|
|
|
+ dict = dict[ list[j] ];
|
|
|
+ }
|
|
|
+ var lastPath = list[list.length-1];
|
|
|
+ if( !dict[lastPath] ){
|
|
|
+ dict[lastPath] = json;
|
|
|
+ }else if( typeOf( dict[lastPath] ) === "array" ){
|
|
|
+ dict[lastPath].push( json );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ MWF.xScript.dictLoaded[key] = {};
|
|
|
+ MWF.xScript.dictLoaded[key][path] = json;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+MWF.xScript.setDictToCache = function(key, path, json){
|
|
|
+ if( MWF.xScript.dictLoaded[key] ){
|
|
|
+ var matchedDict = MWF.xScript.getMatchedDict( key, path );
|
|
|
+ var dict = matchedDict.dict;
|
|
|
+ var list = matchedDict.unmatchedPathList;
|
|
|
+ if( !dict ){
|
|
|
+ MWF.xScript.dictLoaded[key][path] = json;
|
|
|
+ }else{
|
|
|
+ for( var j=0; j<list.length-1; j++ ){
|
|
|
+ if( !dict[ list[j] ] ){
|
|
|
+ dict[ list[j] ] = {};
|
|
|
+ }
|
|
|
+ dict = dict[ list[j] ];
|
|
|
+ }
|
|
|
+ dict[list[list.length-1]] = json;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ MWF.xScript.dictLoaded[key] = {};
|
|
|
+ MWF.xScript.dictLoaded[key][path] = json;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+MWF.xScript.getDictFromCache = function( key, path ){
|
|
|
+ debugger;
|
|
|
+ var matchedDict = MWF.xScript.getMatchedDict( key, path );
|
|
|
+ var dict = matchedDict.dict;
|
|
|
+ var list = matchedDict.unmatchedPathList;
|
|
|
+ if( dict ){
|
|
|
+ for( var j=0; j<list.length; j++ ){
|
|
|
+ dict = dict[ list[j] ];
|
|
|
+ if( !dict )return null;
|
|
|
+ }
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+};
|
|
|
+
|
|
|
+MWF.xScript.deleteDictToCache = function(key, path){
|
|
|
+
|
|
|
+ debugger;
|
|
|
+ var matchedDict = MWF.xScript.getMatchedDict( key, path );
|
|
|
+ var dict = matchedDict.dict;
|
|
|
+ var list = matchedDict.unmatchedPathList;
|
|
|
+
|
|
|
+ if( dict){
|
|
|
+ for( var j=0; j<list.length-1; j++ ){
|
|
|
+ dict = dict[ list[j] ];
|
|
|
+ if( !dict )return;
|
|
|
+ }
|
|
|
+ delete dict[list[list.length-1]];
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
MWF.xScript.createDict = function(application){
|
|
|
//optionsOrName : {
|
|
|
// type : "", //默认为process, 可以为 process cms
|
|
|
@@ -1661,9 +1849,16 @@ MWF.xScript.createDict = function(application){
|
|
|
var applicationId = options.application || application;
|
|
|
var enableAnonymous = options.enableAnonymous || false;
|
|
|
|
|
|
- var key = name+type+applicationId+enableAnonymous
|
|
|
- if (!dictLoaded[key]) dictLoaded[key] = {};
|
|
|
- this.dictData = dictLoaded[key];
|
|
|
+ var opt = {
|
|
|
+ "appType" : type,
|
|
|
+ "name" : name,
|
|
|
+ "appId" : applicationId,
|
|
|
+ "enableAnonymous" : enableAnonymous
|
|
|
+ };
|
|
|
+
|
|
|
+ var key = name+type+applicationId+enableAnonymous;
|
|
|
+ // if (!dictLoaded[key]) dictLoaded[key] = {};
|
|
|
+ // this.dictData = dictLoaded[key];
|
|
|
|
|
|
//MWF.require("MWF.xScript.Actions.DictActions", null, false);
|
|
|
if( type == "cms" ){
|
|
|
@@ -1682,29 +1877,31 @@ MWF.xScript.createDict = function(application){
|
|
|
|
|
|
this.get = function(path, success, failure, async, refresh){
|
|
|
var value = null;
|
|
|
- if (path){
|
|
|
- if (!refresh && this.dictData[path]){
|
|
|
- if (success) success(this.dictData[path]);
|
|
|
- return this.dictData[path];
|
|
|
+ if (!refresh ){
|
|
|
+ var data = MWF.xScript.getDictFromCache( key, path );
|
|
|
+ if( data ){
|
|
|
+ if (success) success( data );
|
|
|
+ return data;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ if (path){
|
|
|
|
|
|
var p = encodePath( path );
|
|
|
//var p = path.replace(/\./g, "/");
|
|
|
action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
|
|
|
value = json.data;
|
|
|
- this.dictData[path] = value;
|
|
|
+ // this.dictData[path] = value;
|
|
|
+ MWF.xScript.addDictToCache(opt, path, value);
|
|
|
if (success) success(json.data);
|
|
|
}.bind(this), function(xhr, text, error){
|
|
|
if (failure) failure(xhr, text, error);
|
|
|
}, !!async, false);
|
|
|
}else{
|
|
|
- if (this.dictData["root"]){
|
|
|
- if (success) success(this.dictData["root"]);
|
|
|
- return this.dictData["root"];
|
|
|
- }
|
|
|
action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
|
|
|
value = json.data;
|
|
|
- this.dictData["root"] = value;
|
|
|
+ // this.dictData["root"] = value;
|
|
|
+ MWF.xScript.addDictToCache(opt, path, value);
|
|
|
if (success) success(json.data);
|
|
|
}.bind(this), function(xhr, text, error){
|
|
|
if (failure) failure(xhr, text, error);
|
|
|
@@ -1718,6 +1915,7 @@ MWF.xScript.createDict = function(application){
|
|
|
var p = encodePath( path );
|
|
|
//var p = path.replace(/\./g, "/");
|
|
|
action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
|
|
|
+ MWF.xScript.setDictToCache(key, path, value);
|
|
|
if (success) success(json.data);
|
|
|
}, function(xhr, text, error){
|
|
|
if (failure) failure(xhr, text, error);
|
|
|
@@ -1727,6 +1925,7 @@ MWF.xScript.createDict = function(application){
|
|
|
var p = encodePath( path );
|
|
|
//var p = path.replace(/\./g, "/");
|
|
|
action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
|
|
|
+ MWF.xScript.insertDictToCache(key, path, value);
|
|
|
if (success) success(json.data);
|
|
|
}, function(xhr, text, error){
|
|
|
if (failure) failure(xhr, text, error);
|
|
|
@@ -1736,6 +1935,7 @@ MWF.xScript.createDict = function(application){
|
|
|
var p = encodePath( path );
|
|
|
//var p = path.replace(/\./g, "/");
|
|
|
action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
|
|
|
+ MWF.xScript.deleteDictToCache(key, path);
|
|
|
if (success) success(json.data);
|
|
|
}, function(xhr, text, error){
|
|
|
if (failure) failure(xhr, text, error);
|