initalServiceScriptSubstitute.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. var resources = {
  2. "getEntityManagerContainer": function(){ return {}; },
  3. "getContext": function(){ return {}; },
  4. "getApplications": function(){ return {}; },
  5. "getOrganization": function(){
  6. return {
  7. group: function(){ return {}; },
  8. identity: function(){ return {}; },
  9. person: function(){ return {}; },
  10. personAttribute: function(){ return {}; },
  11. role: function(){ return {}; },
  12. unit: function(){ return {}; },
  13. unitAttribute: function(){ return {}; },
  14. unitDuty: function(){ return {}; }
  15. };
  16. },
  17. "getWebservicesClient": function(){ return {}; }
  18. };
  19. var effectivePerson = this.effectivePerson = {};
  20. bind = this;
  21. var library = {
  22. 'version': '4.0',
  23. "defineProperties": Object.defineProperties || function (obj, properties) {
  24. return obj;
  25. },
  26. 'typeOf': function(item){
  27. if (item == null) return 'null';
  28. if (item.$family != null) return item.$family();
  29. if (item.constructor == Array) return 'array';
  30. if (item.nodeName){
  31. if (item.nodeType == 1) return 'element';
  32. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  33. } else if (typeof item.length == 'number'){
  34. if (item.callee) return 'arguments';
  35. //if ('item' in item) return 'collection';
  36. }
  37. return typeof item;
  38. },
  39. 'JSONDecode': function(string, secure){
  40. if (!string || library.typeOf(string) != 'string') return null;
  41. return eval('(' + string + ')');
  42. },
  43. 'JSONEncode': function(obj){
  44. if (obj && obj.toJSON) obj = obj.toJSON();
  45. switch (library.typeOf(obj)){
  46. case 'string':
  47. return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
  48. case 'array':
  49. var string = [];
  50. for (var i=0; i<obj.length; i++){
  51. var json = library.JSONEncode(obj[i]);
  52. if (json) string.push(json);
  53. }
  54. return '[' + string + ']';
  55. case 'object': case 'hash':
  56. var string = [];
  57. for (key in obj){
  58. var json = library.JSONEncode(obj[key]);
  59. if (json) string.push(library.JSONEncode(key) + ':' + json);
  60. }
  61. return '{' + string + '}';
  62. case 'number': case 'boolean': return '' + obj;
  63. case 'null': return 'null';
  64. }
  65. return null;
  66. }
  67. };
  68. (function(){
  69. var o={"indexOf": {
  70. "value": function(item, from){
  71. var length = this.length >>> 0;
  72. for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
  73. if (this[i] === item) return i;
  74. }
  75. return -1;
  76. }
  77. }};
  78. library.defineProperties(Array.prototype, o);
  79. })();
  80. /********************
  81. this.entityManager; //实体管理器
  82. this.context; //上下文根
  83. this.applications;
  84. this.org; //组织访问
  85. this.service;//webSerivces客户端
  86. this.response;
  87. this.response.seeOther(url); //303跳转
  88. this.response.temporaryRedirect(url); //304跳转
  89. this.response.setBody(body); //设置返回
  90. this.requestText//请求正文
  91. this.request//请求
  92. this.currentPerson//当前用户
  93. this.Actions;
  94. this.Actions.load(root); //获取接口服务
  95. ********************/
  96. bind.entityManager = resources.getEntityManagerContainer();
  97. bind.context = resources.getContext();
  98. bind.applications = resources.getApplications();
  99. bind.organization = resources.getOrganization();
  100. bind.service = resources.getWebservicesClient();
  101. //bind.response = customResponse;
  102. //bind.customResponse = customResponse;
  103. bind.requestText = this.requestText || null;
  104. bind.request = this.request || null;
  105. if (this.effectivePerson) bind.currentPerson = bind.effectivePerson = effectivePerson;
  106. if (this.parameters) bind.parameters = JSON.parse(this.parameters); //JPQL语句传入参数
  107. if (this.customResponse){
  108. var _response = {
  109. "customResponse": this.customResponse || "",
  110. seeOther: function(url){
  111. customResponse.seeOther(url);
  112. },
  113. temporaryRedirect: function(url){
  114. customResponse.temporaryRedirect(url);
  115. },
  116. setBody: function(o, contentType){
  117. var body = o;
  118. if (typeOf(o)=="object"){
  119. body = JSON.stringify(o);
  120. }
  121. customResponse.setBody(body, contentType || "");
  122. }
  123. };
  124. bind.response = _response;
  125. }
  126. //定义方法
  127. var _define = function(name, fun, overwrite){
  128. var over = true;
  129. if (overwrite===false) over = false;
  130. var o = {};
  131. o[name] = {"value": fun, "configurable": over};
  132. library.defineProperties(bind, o);
  133. };
  134. //Action对象
  135. var restfulAcpplication = resources.getApplications();
  136. var _Action = (function(){
  137. //var actions = [];
  138. return function(root, json){
  139. this.actions = json;
  140. // Object.keys(json).forEach(function(key){
  141. // this.actions[key] = json[key];
  142. // });
  143. //Object.merge(actions[root], json);
  144. this.root = root;
  145. //this.actions = actions[root];
  146. var invokeFunction = function(service, parameters, key){
  147. var _self = this;
  148. return function(){
  149. var i = parameters.length-1;
  150. var n = arguments.length;
  151. var functionArguments = arguments;
  152. var parameter = {};
  153. var success, failure, async, data, file;
  154. if (typeOf(functionArguments[0])==="function"){
  155. i=-1;
  156. success = (n>++i) ? functionArguments[i] : null;
  157. failure = (n>++i) ? functionArguments[i] : null;
  158. parameters.each(function(p, x){
  159. parameter[p] = (n>++i) ? functionArguments[i] : null;
  160. });
  161. if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){
  162. data = (n>++i) ? functionArguments[i] : null;
  163. }
  164. }else{
  165. parameters.each(function(p, x){
  166. parameter[p] = (n>x) ? functionArguments[x] : null;
  167. });
  168. if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){
  169. data = (n>++i) ? functionArguments[i] : null;
  170. }
  171. success = (n>++i) ? functionArguments[i] : null;
  172. failure = (n>++i) ? functionArguments[i] : null;
  173. }
  174. return _self.invoke({"name": key, "data": data, "parameter": parameter, "success": success, "failure": failure});
  175. };
  176. };
  177. var createMethod = function(service, key){
  178. var jaxrsUri = service.uri;
  179. var re = new RegExp("\{.+?\}", "g");
  180. var replaceWords = jaxrsUri.match(re);
  181. var parameters = [];
  182. if (replaceWords) parameters = replaceWords.map(function(s){
  183. return s.substring(1,s.length-1);
  184. });
  185. this[key] = invokeFunction.call(this, service, parameters, key);
  186. };
  187. Object.keys(this.actions).forEach(function(key){
  188. var service = this.actions[key];
  189. if (service.uri) if (!this[key]) createMethod.call(this, service, key);
  190. }, this);
  191. this.invoke = function(option){
  192. // {
  193. // "name": "",
  194. // "data": "",
  195. // "parameter": "",,
  196. // "success": function(){}
  197. // "failure": function(){}
  198. // }
  199. if (this.actions[option.name]){
  200. var uri = this.actions[option.name].uri;
  201. var method = this.actions[option.name].method || "get";
  202. if (option.parameter){
  203. Object.keys(option.parameter).forEach(function(key){
  204. var v = option.parameter[key];
  205. uri = uri.replace("{"+key+"}", v);
  206. });
  207. }
  208. var res = null;
  209. try{
  210. print(uri);
  211. switch (method.toLowerCase()){
  212. case "get":
  213. res = bind.applications.getQuery(this.root, uri);
  214. break;
  215. case "post":
  216. res = bind.applications.postQuery(this.root, uri, JSON.stringify(option.data));
  217. break;
  218. case "put":
  219. res = bind.applications.putQuery(this.root, uri, JSON.stringify(option.data));
  220. break;
  221. case "delete":
  222. res = bind.applications.deleteQuery(this.root, uri);
  223. break;
  224. default:
  225. res = bind.applications.getQuery(this.root, uri);
  226. }
  227. if (res && res.getType().toString()==="success"){
  228. var json = JSON.parse(res.toString());
  229. if (option.success) option.success(json);
  230. }else{
  231. if (option.failure) option.failure(((res) ? JSON.parse(res.toString()) : null));
  232. }
  233. return res;
  234. }catch(e){
  235. if (option.failure) option.failure(e);
  236. }
  237. }
  238. };
  239. }
  240. })();
  241. var _Actions = {
  242. "loadedActions": {},
  243. "load": function(root){
  244. if (this.loadedActions[root]) return this.loadedActions[root];
  245. var jaxrsString = bind.applications.describeApi(root);
  246. var json = JSON.parse(jaxrsString.toString());
  247. if (json && json.jaxrs){
  248. var actionObj = {};
  249. json.jaxrs.each(function(o){
  250. if (o.methods && o.methods.length){
  251. var actions = {};
  252. o.methods.each(function(m){
  253. var o = {"uri": "/"+m.uri};
  254. if (m.method) o.method = m.method;
  255. if (m.enctype) o.enctype = m.enctype;
  256. actions[m.name] = o;
  257. }.bind(this));
  258. actionObj[o.name] = new bind.Action(root, actions);
  259. }
  260. }.bind(this));
  261. this.loadedActions[root] = actionObj;
  262. return actionObj;
  263. }
  264. return null;
  265. }
  266. };
  267. bind.Actions = _Actions;
  268. //定义所需的服务
  269. var _processActions = new _Action("x_processplatform_assemble_surface", {
  270. "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"},
  271. "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"},
  272. "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"},
  273. "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"},
  274. "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"},
  275. "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"},
  276. "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"},
  277. });
  278. var _cmsActions = new _Action("x_cms_assemble_control", {
  279. "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"},
  280. "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  281. "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  282. "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"},
  283. "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"},
  284. "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"},
  285. "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  286. "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  287. "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"},
  288. });
  289. var _portalActions = new _Action("x_portal_assemble_surface", {
  290. "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{ }","method": "POST"}
  291. });
  292. //include 引用脚本
  293. //optionsOrName : {
  294. // type : "", 默认为process, 可以为 portal process cms
  295. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  296. // name : "" // 脚本名称/别名/id
  297. //}
  298. //或者name: "" // 脚本名称/别名/id
  299. var _exec = function(code, _self){
  300. var returnValue;
  301. //try{
  302. if (!_self) _self = this;
  303. try {
  304. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  305. returnValue = f.apply(_self);
  306. }catch(e){
  307. console.log("exec", new Error("exec script error"));
  308. console.log(e);
  309. }
  310. return returnValue;
  311. }
  312. var includedScripts = this.includedScripts || {};
  313. this.includedScripts = includedScripts;
  314. var _include = function( optionsOrName , callback ){
  315. var options = optionsOrName;
  316. if( typeOf( options ) == "string" ){
  317. options = { name : options };
  318. }
  319. var name = options.name;
  320. var type = ( options.type && options.application ) ? options.type : "process";
  321. var application = options.application
  322. if (!name || !type || !application){
  323. console.log("include", new Error("can not find script. missing script name or application"));
  324. return false;
  325. }
  326. if (!includedScripts[application]) includedScripts[application] = [];
  327. if (includedScripts[application].indexOf( name )> -1){
  328. if (callback) callback.apply(this);
  329. return;
  330. }
  331. var scriptAction;
  332. var scriptData;
  333. switch ( type ){
  334. case "portal" :
  335. _portalActions.getScript( application, name, {"importedList":includedScripts[application]}, function(json){
  336. if (json.data){
  337. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  338. scriptData = json.data;
  339. }
  340. }.bind(this));
  341. break;
  342. case "process" :
  343. _processActions.getScript( name, application, {"importedList":includedScripts[application]}, function(json){
  344. if (json.data){
  345. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  346. scriptData = json.data;
  347. }
  348. }.bind(this));
  349. break;
  350. case "cms" :
  351. _cmsActions.getScript(name, application, {"importedList":includedScripts[application]}, function(json){
  352. if (json.data){
  353. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  354. scriptData = json.data;
  355. }
  356. }.bind(this));
  357. break;
  358. }
  359. includedScripts[application].push(name);
  360. if (scriptData && scriptData.text){
  361. bind.exec(scriptData.text, this);
  362. if (callback) callback.apply(this);
  363. }
  364. };
  365. var _createDict = function(application){
  366. //optionsOrName : {
  367. // type : "", //默认为process, 可以为 process cms
  368. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  369. // name : "", // 数据字典名称/别名/id
  370. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  371. //}
  372. //或者name: "" // 数据字典名称/别名/id
  373. return function(optionsOrName){
  374. var options = optionsOrName;
  375. if( typeOf( options ) == "string" ){
  376. options = { name : options };
  377. }
  378. var name = this.name = options.name;
  379. var type = ( options.type && options.application ) ? options.type : "process";
  380. var applicationId = options.application || application;
  381. var enableAnonymous = options.enableAnonymous || false;
  382. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  383. if( type == "cms" ){
  384. var action = bind.cmsActions;
  385. }else{
  386. var action = bind.processActions;
  387. }
  388. var encodePath = function( path ){
  389. var arr = path.split(/\./g);
  390. var ar = arr.map(function(v){
  391. return encodeURIComponent(v);
  392. });
  393. return ar.join("/");
  394. };
  395. this.get = function(path, success, failure){
  396. var value = null;
  397. if (path){
  398. var p = encodePath( path );
  399. action[(enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData"](encodeURIComponent(this.name), applicationId, p, function(json){
  400. value = json.data;
  401. if (success) success(json.data);
  402. }, function(xhr, text, error){
  403. if (failure) failure(xhr, text, error);
  404. });
  405. }else{
  406. action[(enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot"](encodeURIComponent(this.name), applicationId, function(json){
  407. value = json.data;
  408. if (success) success(json.data);
  409. }, function(xhr, text, error){
  410. if (failure) failure(xhr, text, error);
  411. }, false);
  412. }
  413. return value;
  414. };
  415. this.set = function(path, value, success, failure){
  416. var p = encodePath( path );
  417. //var p = path.replace(/\./g, "/");
  418. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  419. if (success) success(json.data);
  420. }, function(xhr, text, error){
  421. if (failure) failure(xhr, text, error);
  422. }, false, false);
  423. };
  424. this.add = function(path, value, success, failure){
  425. var p = encodePath( path );
  426. //var p = path.replace(/\./g, "/");
  427. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  428. if (success) success(json.data);
  429. }, function(xhr, text, error){
  430. if (failure) failure(xhr, text, error);
  431. }, false, false);
  432. };
  433. this["delete"] = function(path, success, failure){
  434. var p = encodePath( path );
  435. //var p = path.replace(/\./g, "/");
  436. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  437. if (success) success(json.data);
  438. }, function(xhr, text, error){
  439. if (failure) failure(xhr, text, error);
  440. }, false, false);
  441. };
  442. this.destory = this["delete"];
  443. }
  444. };
  445. var getNameFlag = function(name){
  446. var t = library.typeOf(name);
  447. if (t==="array"){
  448. var v = [];
  449. name.forEach(function(id){
  450. v.push((library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  451. });
  452. return v;
  453. }else{
  454. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  455. }
  456. };
  457. var _org = {
  458. "oGroup": this.organization.group(),
  459. "oIdentity": this.organization.identity(),
  460. "oPerson": this.organization.person(),
  461. "oPersonAttribute": this.organization.personAttribute(),
  462. "oRole": this.organization.role(),
  463. "oUnit": this.organization.unit(),
  464. "oUnitAttribute": this.organization.unitAttribute(),
  465. "oUnitDuty": this.organization.unitDuty(),
  466. "group": function() { return this.oGroup},
  467. "identity": function() { return this.oIdentity},
  468. "person": function() { return this.oPerson},
  469. "personAttribute": function() { return this.oPersonAttribute},
  470. "role": function() { return this.oRole},
  471. "unit": function() { return this.oUnit},
  472. "unitAttribute": function() { return this.oUnitAttribute},
  473. "unitDuty": function() { return this.oUnitDuty},
  474. "getObject": function(o, v){
  475. var arr = [];
  476. if (!v || !v.length){
  477. return null;
  478. }else{
  479. for (var i=0; i<v.length; i++){
  480. var g = o.getObject(v[i]);
  481. if (g) arr.push(JSON.parse(g.toString()));
  482. }
  483. }
  484. return arr;
  485. },
  486. //群组***************
  487. //获取群组--返回群组的对象数组
  488. getGroup: function(name){
  489. var v = this.oGroup.listObject(getNameFlag(name));
  490. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  491. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  492. },
  493. //查询下级群组--返回群组的对象数组
  494. //nested 布尔 true嵌套下级;false直接下级;默认false;
  495. listSubGroup: function(name, nested){
  496. var v = null;
  497. if (nested){
  498. v = this.oGroup.listWithGroupSubNested(getNameFlag(name));
  499. }else{
  500. v = this.oGroup.listWithGroupSubDirect(getNameFlag(name));
  501. }
  502. return this.getObject(this.oGroup, v);
  503. },
  504. //查询上级群组--返回群组的对象数组
  505. //nested 布尔 true嵌套上级;false直接上级;默认false;
  506. listSupGroup:function(name, nested){
  507. var v = null;
  508. if (nested){
  509. v = this.oGroup.listWithGroupSupNested(getNameFlag(name));
  510. }else{
  511. v = this.oGroup.listWithGroupSupDirect(getNameFlag(name));
  512. }
  513. return this.getObject(this.oGroup, v);
  514. },
  515. //人员所在群组(嵌套)--返回群组的对象数组
  516. listGroupWithPerson:function(name){
  517. var v = this.oGroup.listWithPerson(getNameFlag(name));
  518. return this.getObject(this.oGroup, v);
  519. },
  520. //群组是否拥有角色--返回true, false
  521. groupHasRole: function(name, role){
  522. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  523. return this.oGroup.hasRole(nameFlag, getNameFlag(role));
  524. },
  525. //角色***************
  526. //获取角色--返回角色的对象数组
  527. getRole: function(name){
  528. var v = this.oRole.listObject(getNameFlag(name));
  529. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  530. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  531. },
  532. //人员所有角色(嵌套)--返回角色的对象数组
  533. listRoleWithPerson:function(name){
  534. var v = this.oRole.listWithPerson(getNameFlag(name));
  535. return this.getObject(this.oRole, v);
  536. },
  537. //人员***************
  538. //人员是否拥有角色--返回true, false
  539. personHasRole: function(name, role){
  540. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  541. return this.oPerson.hasRole(nameFlag, getNameFlag(role));
  542. },
  543. //获取人员--返回人员的对象数组
  544. getPerson: function(name){
  545. var v = this.oPerson.listObject(getNameFlag(name));
  546. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  547. // if (!v || !v.length) v = null;
  548. // return (v && v.length===1) ? v[0] : v;
  549. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  550. },
  551. //查询下级人员--返回人员的对象数组
  552. //nested 布尔 true嵌套下级;false直接下级;默认false;
  553. listSubPerson: function(name, nested){
  554. var v = null;
  555. if (nested){
  556. v = this.oPerson.listWithPersonSubNested(getNameFlag(name));
  557. }else{
  558. v = this.oPerson.listWithPersonSubDirect(getNameFlag(name));
  559. }
  560. return this.getObject(this.oPerson, v);
  561. },
  562. //查询上级人员--返回人员的对象数组
  563. //nested 布尔 true嵌套上级;false直接上级;默认false;
  564. listSupPerson: function(name, nested){
  565. var v = null;
  566. if (nested){
  567. v = this.oPerson.listWithPersonSupNested(getNameFlag(name));
  568. }else{
  569. v = this.oPerson.listWithPersonSupDirect(getNameFlag(name));
  570. }
  571. return this.getObject(this.oPerson, v);
  572. },
  573. //获取群组的所有人员--返回人员的对象数组
  574. listPersonWithGroup: function(name){
  575. var v = this.oPerson.listWithGroup(getNameFlag(name));
  576. return this.getObject(this.oPerson, v);
  577. // if (!v || !v.length) v = null;
  578. // return v;
  579. // var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  580. // return v_json;
  581. },
  582. //获取角色的所有人员--返回人员的对象数组
  583. listPersonWithRole: function(name){
  584. var v = this.oPerson.listWithRole(getNameFlag(name));
  585. return this.getObject(this.oPerson, v);
  586. },
  587. //获取身份的所有人员--返回人员的对象数组
  588. listPersonWithIdentity: function(name){
  589. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  590. return this.getObject(this.oPerson, v);
  591. },
  592. //获取身份的所有人员--返回人员的对象数组
  593. getPersonWithIdentity: function(name){
  594. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  595. var arr = this.getObject(this.oPerson, v);
  596. return (arr && arr.length) ? arr[0] : null;
  597. },
  598. //查询组织成员的人员--返回人员的对象数组
  599. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  600. listPersonWithUnit: function(name, nested){
  601. var v = null;
  602. if (nested){
  603. v = this.oPerson.listWithUnitSubNested(getNameFlag(name));
  604. }else{
  605. v = this.oPerson.listWithUnitSubDirect(getNameFlag(name));
  606. }
  607. return this.getObject(this.oPerson, v);
  608. },
  609. //人员属性************
  610. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  611. appendPersonAttribute: function(person, attr, values){
  612. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  613. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  614. },
  615. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  616. setPersonAttribute: function(person, attr, values){
  617. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  618. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  619. },
  620. //获取人员属性值
  621. getPersonAttribute: function(person, attr){
  622. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  623. var v = this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  624. var v_json = [];
  625. if (v && v.length){
  626. for (var i=0; i<v.length; i++){
  627. v_json.push(v[i].toString());
  628. }
  629. }
  630. return v_json;
  631. },
  632. //列出人员所有属性的名称
  633. listPersonAttributeName: function(name){
  634. var p = getNameFlag(name);
  635. var nameList = [];
  636. for (var i=0; i<p.length; i++){
  637. var v = this.oPersonAttribute.listNameWithPerson(p[i]);
  638. if (v && v.length){
  639. for (var j=0; j<v.length; j++){
  640. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  641. }
  642. }
  643. }
  644. return nameList;
  645. },
  646. //列出人员的所有属性
  647. //listPersonAllAttribute: function(name){
  648. // getOrgActions();
  649. // var data = {"personList":getNameFlag(name)};
  650. // var v = null;
  651. // orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  652. // return v;
  653. //},
  654. //身份**********
  655. //获取身份
  656. getIdentity: function(name){
  657. var v = this.oIdentity.listObject(getNameFlag(name));
  658. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  659. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  660. // if (!v || !v.length) v = null;
  661. // return (v && v.length===1) ? v[0] : v;
  662. },
  663. //列出人员的身份
  664. listIdentityWithPerson: function(name){
  665. var v = this.oIdentity.listWithPerson(getNameFlag(name));
  666. return this.getObject(this.oIdentity, v);
  667. },
  668. //查询组织成员身份--返回身份的对象数组
  669. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  670. listIdentityWithUnit: function(name, nested){
  671. var v = null;
  672. if (nested){
  673. v = this.oIdentity.listWithUnitSubNested(getNameFlag(name));
  674. }else{
  675. v = this.oIdentity.listWithUnitSubDirect(getNameFlag(name));
  676. }
  677. return this.getObject(this.oIdentity, v);
  678. },
  679. //组织**********
  680. //获取组织
  681. getUnit: function(name){
  682. var v = this.oUnit.listObject(getNameFlag(name));
  683. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  684. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  685. // if (!v || !v.length) v = null;
  686. // return (v && v.length===1) ? v[0] : v;
  687. },
  688. //查询组织的下级--返回组织的对象数组
  689. //nested 布尔 true嵌套下级;false直接下级;默认false;
  690. listSubUnit: function(name, nested){
  691. var v = null;
  692. if (nested){
  693. v = this.oUnit.listWithUnitSubNested(getNameFlag(name));
  694. }else{
  695. v = this.oUnit.listWithUnitSubDirect(getNameFlag(name));
  696. }
  697. return this.getObject(this.oUnit, v);
  698. },
  699. //查询组织的上级--返回组织的对象数组
  700. //nested 布尔 true嵌套上级;false直接上级;默认false;
  701. listSupUnit: function(name, nested){
  702. var v = null;
  703. if (nested){
  704. v = this.oUnit.listWithUnitSupNested(getNameFlag(name));
  705. }else{
  706. v = this.oUnit.listWithUnitSupDirect(getNameFlag(name));
  707. }
  708. return this.getObject(this.oUnit, v);
  709. },
  710. //根据个人身份获取组织
  711. //flag 数字 表示获取第几层的组织
  712. // 字符串 表示获取指定类型的组织
  713. // 空 表示获取直接所在的组织
  714. getUnitByIdentity: function(name, flag){
  715. //getOrgActions();
  716. var getUnitMethod = "current";
  717. var v;
  718. if (flag){
  719. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  720. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  721. }
  722. var n = getNameFlag(name)[0];
  723. switch (getUnitMethod){
  724. case "current":
  725. v = this.oUnit.getWithIdentity(n);
  726. break;
  727. case "type":
  728. v = this.oUnit.getWithIdentityWithType(n, flag);
  729. break;
  730. case "level":
  731. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  732. break;
  733. }
  734. var o = this.getObject(this.oUnit, [v]);
  735. return (o && o.length===1) ? o[0] : o;
  736. },
  737. //列出身份所在组织的所有上级组织
  738. listAllSupUnitWithIdentity: function(name){
  739. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  740. return this.getObject(this.oUnit, v);
  741. },
  742. //获取人员所在的所有组织(直接所在组织)
  743. listUnitWithPerson: function(name){
  744. var v = this.oUnit.listWithPerson(getNameFlag(name));
  745. return this.getObject(this.oUnit, v);
  746. },
  747. //列出人员所在组织的所有上级组织
  748. listAllSupUnitWithPerson: function(name){
  749. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  750. return this.getObject(this.oUnit, v);
  751. },
  752. //根据组织属性,获取所有符合的组织
  753. listUnitWithAttribute: function(name, attribute){
  754. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  755. return this.getObject(this.oUnit, v);
  756. },
  757. //根据组织职务,获取所有符合的组织
  758. listUnitWithDuty: function(name, id){
  759. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  760. var v = this.oUnit.listWithUnitDuty(name, idflag);
  761. return this.getObject(this.oUnit, v);
  762. },
  763. //组织职务***********
  764. //获取指定的组织职务的身份
  765. getDuty: function(duty, id){
  766. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  767. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  768. return this.getObject(this.oIdentity, v);
  769. },
  770. //获取身份的所有职务名称
  771. listDutyNameWithIdentity: function(name){
  772. var ids = getNameFlag(name);
  773. var nameList = [];
  774. for (var i=0; i<ids.length; i++){
  775. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  776. if (v && v.length){
  777. for (var j=0; j<v.length; j++){
  778. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  779. }
  780. }
  781. }
  782. return nameList;
  783. },
  784. //获取组织的所有职务名称
  785. listDutyNameWithUnit: function(name){
  786. var ids = getNameFlag(name);
  787. var nameList = [];
  788. for (var i=0; i<ids.length; i++){
  789. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  790. if (v && v.length){
  791. for (var j=0; j<v.length; j++){
  792. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  793. }
  794. }
  795. }
  796. return nameList;
  797. },
  798. //获取组织的所有职务
  799. listUnitAllDuty: function(name){
  800. var u = getNameFlag(name)[0];
  801. var ds = this.oUnitDuty.listNameWithUnit(u);
  802. var o = []
  803. for (var i=0; i<ds.length; i++){
  804. v = this.oUnitDuty.listIdentityWithUnitWithName(u, ds[i]);
  805. o.push({"name": ds[i], "identityList": this.getObject(this.oIdentity, v)});
  806. }
  807. return o;
  808. },
  809. //组织属性**************
  810. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  811. appendUnitAttribute: function(unit, attr, values){
  812. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  813. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  814. },
  815. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  816. setUnitAttribute: function(unit, attr, values){
  817. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  818. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  819. },
  820. //获取组织属性值
  821. getUnitAttribute: function(unit, attr){
  822. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  823. var v = this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  824. var v_json = [];
  825. if (v && v.length){
  826. for (var i=0; i<v.length; i++){
  827. v_json.push(v[i].toString());
  828. }
  829. }
  830. return v_json;
  831. },
  832. //列出组织所有属性的名称
  833. listUnitAttributeName: function(name){
  834. var p = getNameFlag(name);
  835. var nameList = [];
  836. for (var i=0; i<p.length; i++){
  837. var v = this.oUnitAttribute.listNameWithUnit(p[i]);
  838. if (v && v.length){
  839. for (var j=0; j<v.length; j++){
  840. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  841. }
  842. }
  843. }
  844. return nameList;
  845. },
  846. //列出组织的所有属性
  847. listUnitAllAttribute: function(name){
  848. var u = getNameFlag(name)[0];
  849. var ds = this.oUnitAttribute.listNameWithUnit(u);
  850. var o = []
  851. for (var i=0; i<ds.length; i++){
  852. v = this.getUnitAttribute(u, ds[i]);
  853. o.push({"name": ds[i], "valueList":v});
  854. }
  855. return o;
  856. }
  857. };
  858. bind.org = _org;
  859. bind.library = library;
  860. bind.define = _define;
  861. bind.Action = _Action;
  862. bind.Actions = _Actions;
  863. bind.processActions = _processActions;
  864. bind.cmsActions = _cmsActions;
  865. bind.portalActions = _portalActions;
  866. bind.exec = _exec;
  867. bind.include = _include;
  868. bind.Dict = _createDict();