initalServiceScriptSubstitute.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. switch (method.toLowerCase()){
  211. case "get":
  212. res = bind.applications.getQuery(this.root, uri);
  213. break;
  214. case "post":
  215. res = bind.applications.postQuery(this.root, uri, JSON.stringify(option.data));
  216. break;
  217. case "put":
  218. res = bind.applications.putQuery(this.root, uri, JSON.stringify(option.data));
  219. break;
  220. case "delete":
  221. res = bind.applications.deleteQuery(this.root, uri);
  222. break;
  223. default:
  224. res = bind.applications.getQuery(this.root, uri);
  225. }
  226. if (res && res.getType().toString()==="success"){
  227. var json = JSON.parse(res.toString());
  228. if (option.success) option.success(json);
  229. }else{
  230. if (option.failure) option.failure(((res) ? JSON.parse(res.toString()) : null));
  231. }
  232. return res;
  233. }catch(e){
  234. if (option.failure) option.failure(e);
  235. }
  236. }
  237. };
  238. }
  239. })();
  240. var _Actions = {
  241. "loadedActions": {},
  242. "load": function(root){
  243. if (this.loadedActions[root]) return this.loadedActions[root];
  244. var jaxrsString = bind.applications.describeApi(root);
  245. var json = JSON.parse(jaxrsString.toString());
  246. if (json && json.jaxrs){
  247. var actionObj = {};
  248. json.jaxrs.each(function(o){
  249. if (o.methods && o.methods.length){
  250. var actions = {};
  251. o.methods.each(function(m){
  252. var o = {"uri": "/"+m.uri};
  253. if (m.method) o.method = m.method;
  254. if (m.enctype) o.enctype = m.enctype;
  255. actions[m.name] = o;
  256. }.bind(this));
  257. actionObj[o.name] = new bind.Action(root, actions);
  258. }
  259. }.bind(this));
  260. this.loadedActions[root] = actionObj;
  261. return actionObj;
  262. }
  263. return null;
  264. }
  265. };
  266. bind.Actions = _Actions;
  267. //定义所需的服务
  268. var _processActions = new _Action("x_processplatform_assemble_surface", {
  269. "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"},
  270. "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"},
  271. "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"},
  272. "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"},
  273. "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"},
  274. "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"},
  275. "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"},
  276. });
  277. var _cmsActions = new _Action("x_cms_assemble_control", {
  278. "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"},
  279. "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  280. "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  281. "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"},
  282. "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"},
  283. "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"},
  284. "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  285. "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  286. "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"},
  287. });
  288. var _portalActions = new _Action("x_portal_assemble_surface", {
  289. "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{ }","method": "POST"}
  290. });
  291. //include 引用脚本
  292. //optionsOrName : {
  293. // type : "", 默认为process, 可以为 portal process cms
  294. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  295. // name : "" // 脚本名称/别名/id
  296. //}
  297. //或者name: "" // 脚本名称/别名/id
  298. var _exec = function(code, _self){
  299. var returnValue;
  300. //try{
  301. if (!_self) _self = this;
  302. try {
  303. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  304. returnValue = f.apply(_self);
  305. }catch(e){
  306. console.log("exec", new Error("exec script error"));
  307. console.log(e);
  308. }
  309. return returnValue;
  310. }
  311. var includedScripts = this.includedScripts || {};
  312. this.includedScripts = includedScripts;
  313. var _include = function( optionsOrName , callback ){
  314. var options = optionsOrName;
  315. if( typeOf( options ) == "string" ){
  316. options = { name : options };
  317. }
  318. var name = options.name;
  319. var type = ( options.type && options.application ) ? options.type : "process";
  320. var application = options.application
  321. if (!name || !type || !application){
  322. console.log("include", new Error("can not find script. missing script name or application"));
  323. return false;
  324. }
  325. if (!includedScripts[application]) includedScripts[application] = [];
  326. if (includedScripts[application].indexOf( name )> -1){
  327. if (callback) callback.apply(this);
  328. return;
  329. }
  330. var scriptAction;
  331. var scriptData;
  332. switch ( type ){
  333. case "portal" :
  334. _portalActions.getScript( application, name, {"importedList":includedScripts[application]}, function(json){
  335. if (json.data){
  336. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  337. scriptData = json.data;
  338. }
  339. }.bind(this));
  340. break;
  341. case "process" :
  342. _processActions.getScript( name, application, {"importedList":includedScripts[application]}, function(json){
  343. if (json.data){
  344. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  345. scriptData = json.data;
  346. }
  347. }.bind(this));
  348. break;
  349. case "cms" :
  350. _cmsActions.getScript(name, application, {"importedList":includedScripts[application]}, function(json){
  351. if (json.data){
  352. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  353. scriptData = json.data;
  354. }
  355. }.bind(this));
  356. break;
  357. }
  358. includedScripts[application].push(name);
  359. if (scriptData && scriptData.text){
  360. bind.exec(scriptData.text, this);
  361. if (callback) callback.apply(this);
  362. }
  363. };
  364. var _createDict = function(application){
  365. //optionsOrName : {
  366. // type : "", //默认为process, 可以为 process cms
  367. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  368. // name : "", // 数据字典名称/别名/id
  369. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  370. //}
  371. //或者name: "" // 数据字典名称/别名/id
  372. return function(optionsOrName){
  373. var options = optionsOrName;
  374. if( typeOf( options ) == "string" ){
  375. options = { name : options };
  376. }
  377. var name = this.name = options.name;
  378. var type = ( options.type && options.application ) ? options.type : "process";
  379. var applicationId = options.application || application;
  380. var enableAnonymous = options.enableAnonymous || false;
  381. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  382. if( type == "cms" ){
  383. var action = bind.cmsActions;
  384. }else{
  385. var action = bind.processActions;
  386. }
  387. var encodePath = function( path ){
  388. var arr = path.split(/\./g);
  389. var ar = arr.map(function(v){
  390. return encodeURIComponent(v);
  391. });
  392. return ar.join("/");
  393. };
  394. this.get = function(path, success, failure){
  395. var value = null;
  396. if (path){
  397. var p = encodePath( path );
  398. action[(enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData"](encodeURIComponent(this.name), applicationId, p, function(json){
  399. value = json.data;
  400. if (success) success(json.data);
  401. }, function(xhr, text, error){
  402. if (failure) failure(xhr, text, error);
  403. });
  404. }else{
  405. action[(enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot"](encodeURIComponent(this.name), applicationId, function(json){
  406. value = json.data;
  407. if (success) success(json.data);
  408. }, function(xhr, text, error){
  409. if (failure) failure(xhr, text, error);
  410. }, false);
  411. }
  412. return value;
  413. };
  414. this.set = function(path, value, success, failure){
  415. var p = encodePath( path );
  416. //var p = path.replace(/\./g, "/");
  417. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  418. if (success) success(json.data);
  419. }, function(xhr, text, error){
  420. if (failure) failure(xhr, text, error);
  421. }, false, false);
  422. };
  423. this.add = function(path, value, success, failure){
  424. var p = encodePath( path );
  425. //var p = path.replace(/\./g, "/");
  426. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  427. if (success) success(json.data);
  428. }, function(xhr, text, error){
  429. if (failure) failure(xhr, text, error);
  430. }, false, false);
  431. };
  432. this["delete"] = function(path, success, failure){
  433. var p = encodePath( path );
  434. //var p = path.replace(/\./g, "/");
  435. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  436. if (success) success(json.data);
  437. }, function(xhr, text, error){
  438. if (failure) failure(xhr, text, error);
  439. }, false, false);
  440. };
  441. this.destory = this["delete"];
  442. }
  443. };
  444. var getNameFlag = function(name){
  445. var t = library.typeOf(name);
  446. if (t==="array"){
  447. var v = [];
  448. name.forEach(function(id){
  449. v.push((library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  450. });
  451. return v;
  452. }else{
  453. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  454. }
  455. };
  456. var _org = {
  457. "oGroup": this.organization.group(),
  458. "oIdentity": this.organization.identity(),
  459. "oPerson": this.organization.person(),
  460. "oPersonAttribute": this.organization.personAttribute(),
  461. "oRole": this.organization.role(),
  462. "oUnit": this.organization.unit(),
  463. "oUnitAttribute": this.organization.unitAttribute(),
  464. "oUnitDuty": this.organization.unitDuty(),
  465. "group": function() { return this.oGroup},
  466. "identity": function() { return this.oIdentity},
  467. "person": function() { return this.oPerson},
  468. "personAttribute": function() { return this.oPersonAttribute},
  469. "role": function() { return this.oRole},
  470. "unit": function() { return this.oUnit},
  471. "unitAttribute": function() { return this.oUnitAttribute},
  472. "unitDuty": function() { return this.oUnitDuty},
  473. "getObject": function(o, v){
  474. var arr = [];
  475. if (!v || !v.length){
  476. return null;
  477. }else{
  478. for (var i=0; i<v.length; i++){
  479. var g = o.getObject(v[i]);
  480. if (g) arr.push(JSON.parse(g.toString()));
  481. }
  482. }
  483. return arr;
  484. },
  485. //群组***************
  486. //获取群组--返回群组的对象数组
  487. getGroup: function(name){
  488. var v = this.oGroup.listObject(getNameFlag(name));
  489. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  490. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  491. },
  492. //查询下级群组--返回群组的对象数组
  493. //nested 布尔 true嵌套下级;false直接下级;默认false;
  494. listSubGroup: function(name, nested){
  495. var v = null;
  496. if (nested){
  497. v = this.oGroup.listWithGroupSubNested(getNameFlag(name));
  498. }else{
  499. v = this.oGroup.listWithGroupSubDirect(getNameFlag(name));
  500. }
  501. return this.getObject(this.oGroup, v);
  502. },
  503. //查询上级群组--返回群组的对象数组
  504. //nested 布尔 true嵌套上级;false直接上级;默认false;
  505. listSupGroup:function(name, nested){
  506. var v = null;
  507. if (nested){
  508. v = this.oGroup.listWithGroupSupNested(getNameFlag(name));
  509. }else{
  510. v = this.oGroup.listWithGroupSupDirect(getNameFlag(name));
  511. }
  512. return this.getObject(this.oGroup, v);
  513. },
  514. //人员所在群组(嵌套)--返回群组的对象数组
  515. listGroupWithPerson:function(name){
  516. var v = this.oGroup.listWithPerson(getNameFlag(name));
  517. return this.getObject(this.oGroup, v);
  518. },
  519. //群组是否拥有角色--返回true, false
  520. groupHasRole: function(name, role){
  521. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  522. return this.oGroup.hasRole(nameFlag, getNameFlag(role));
  523. },
  524. //角色***************
  525. //获取角色--返回角色的对象数组
  526. getRole: function(name){
  527. var v = this.oRole.listObject(getNameFlag(name));
  528. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  529. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  530. },
  531. //人员所有角色(嵌套)--返回角色的对象数组
  532. listRoleWithPerson:function(name){
  533. var v = this.oRole.listWithPerson(getNameFlag(name));
  534. return this.getObject(this.oRole, v);
  535. },
  536. //人员***************
  537. //人员是否拥有角色--返回true, false
  538. personHasRole: function(name, role){
  539. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  540. return this.oPerson.hasRole(nameFlag, getNameFlag(role));
  541. },
  542. //获取人员--返回人员的对象数组
  543. getPerson: function(name){
  544. var v = this.oPerson.listObject(getNameFlag(name));
  545. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  546. // if (!v || !v.length) v = null;
  547. // return (v && v.length===1) ? v[0] : v;
  548. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  549. },
  550. //查询下级人员--返回人员的对象数组
  551. //nested 布尔 true嵌套下级;false直接下级;默认false;
  552. listSubPerson: function(name, nested){
  553. var v = null;
  554. if (nested){
  555. v = this.oPerson.listWithPersonSubNested(getNameFlag(name));
  556. }else{
  557. v = this.oPerson.listWithPersonSubDirect(getNameFlag(name));
  558. }
  559. return this.getObject(this.oPerson, v);
  560. },
  561. //查询上级人员--返回人员的对象数组
  562. //nested 布尔 true嵌套上级;false直接上级;默认false;
  563. listSupPerson: function(name, nested){
  564. var v = null;
  565. if (nested){
  566. v = this.oPerson.listWithPersonSupNested(getNameFlag(name));
  567. }else{
  568. v = this.oPerson.listWithPersonSupDirect(getNameFlag(name));
  569. }
  570. return this.getObject(this.oPerson, v);
  571. },
  572. //获取群组的所有人员--返回人员的对象数组
  573. listPersonWithGroup: function(name){
  574. var v = this.oPerson.listWithGroup(getNameFlag(name));
  575. return this.getObject(this.oPerson, v);
  576. // if (!v || !v.length) v = null;
  577. // return v;
  578. // var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  579. // return v_json;
  580. },
  581. //获取角色的所有人员--返回人员的对象数组
  582. listPersonWithRole: function(name){
  583. var v = this.oPerson.listWithRole(getNameFlag(name));
  584. return this.getObject(this.oPerson, v);
  585. },
  586. //获取身份的所有人员--返回人员的对象数组
  587. listPersonWithIdentity: function(name){
  588. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  589. return this.getObject(this.oPerson, v);
  590. },
  591. //获取身份的所有人员--返回人员的对象数组
  592. getPersonWithIdentity: function(name){
  593. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  594. var arr = this.getObject(this.oPerson, v);
  595. return (arr && arr.length) ? arr[0] : null;
  596. },
  597. //查询组织成员的人员--返回人员的对象数组
  598. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  599. listPersonWithUnit: function(name, nested){
  600. var v = null;
  601. if (nested){
  602. v = this.oPerson.listWithUnitSubNested(getNameFlag(name));
  603. }else{
  604. v = this.oPerson.listWithUnitSubDirect(getNameFlag(name));
  605. }
  606. return this.getObject(this.oPerson, v);
  607. },
  608. //人员属性************
  609. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  610. appendPersonAttribute: function(person, attr, values){
  611. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  612. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  613. },
  614. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  615. setPersonAttribute: function(person, attr, values){
  616. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  617. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  618. },
  619. //获取人员属性值
  620. getPersonAttribute: function(person, attr){
  621. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  622. var v = this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  623. var v_json = [];
  624. if (v && v.length){
  625. for (var i=0; i<v.length; i++){
  626. v_json.push(v[i].toString());
  627. }
  628. }
  629. return v_json;
  630. },
  631. //列出人员所有属性的名称
  632. listPersonAttributeName: function(name){
  633. var p = getNameFlag(name);
  634. var nameList = [];
  635. for (var i=0; i<p.length; i++){
  636. var v = this.oPersonAttribute.listNameWithPerson(p[i]);
  637. if (v && v.length){
  638. for (var j=0; j<v.length; j++){
  639. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  640. }
  641. }
  642. }
  643. return nameList;
  644. },
  645. //列出人员的所有属性
  646. //listPersonAllAttribute: function(name){
  647. // getOrgActions();
  648. // var data = {"personList":getNameFlag(name)};
  649. // var v = null;
  650. // orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  651. // return v;
  652. //},
  653. //身份**********
  654. //获取身份
  655. getIdentity: function(name){
  656. var v = this.oIdentity.listObject(getNameFlag(name));
  657. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  658. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  659. // if (!v || !v.length) v = null;
  660. // return (v && v.length===1) ? v[0] : v;
  661. },
  662. //列出人员的身份
  663. listIdentityWithPerson: function(name){
  664. var v = this.oIdentity.listWithPerson(getNameFlag(name));
  665. return this.getObject(this.oIdentity, v);
  666. },
  667. //查询组织成员身份--返回身份的对象数组
  668. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  669. listIdentityWithUnit: function(name, nested){
  670. var v = null;
  671. if (nested){
  672. v = this.oIdentity.listWithUnitSubNested(getNameFlag(name));
  673. }else{
  674. v = this.oIdentity.listWithUnitSubDirect(getNameFlag(name));
  675. }
  676. return this.getObject(this.oIdentity, v);
  677. },
  678. //组织**********
  679. //获取组织
  680. getUnit: function(name){
  681. var v = this.oUnit.listObject(getNameFlag(name));
  682. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  683. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  684. // if (!v || !v.length) v = null;
  685. // return (v && v.length===1) ? v[0] : v;
  686. },
  687. //查询组织的下级--返回组织的对象数组
  688. //nested 布尔 true嵌套下级;false直接下级;默认false;
  689. listSubUnit: function(name, nested){
  690. var v = null;
  691. if (nested){
  692. v = this.oUnit.listWithUnitSubNested(getNameFlag(name));
  693. }else{
  694. v = this.oUnit.listWithUnitSubDirect(getNameFlag(name));
  695. }
  696. return this.getObject(this.oUnit, v);
  697. },
  698. //查询组织的上级--返回组织的对象数组
  699. //nested 布尔 true嵌套上级;false直接上级;默认false;
  700. listSupUnit: function(name, nested){
  701. var v = null;
  702. if (nested){
  703. v = this.oUnit.listWithUnitSupNested(getNameFlag(name));
  704. }else{
  705. v = this.oUnit.listWithUnitSupDirect(getNameFlag(name));
  706. }
  707. return this.getObject(this.oUnit, v);
  708. },
  709. //根据个人身份获取组织
  710. //flag 数字 表示获取第几层的组织
  711. // 字符串 表示获取指定类型的组织
  712. // 空 表示获取直接所在的组织
  713. getUnitByIdentity: function(name, flag){
  714. //getOrgActions();
  715. var getUnitMethod = "current";
  716. var v;
  717. if (flag){
  718. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  719. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  720. }
  721. var n = getNameFlag(name)[0];
  722. switch (getUnitMethod){
  723. case "current":
  724. v = this.oUnit.getWithIdentity(n);
  725. break;
  726. case "type":
  727. v = this.oUnit.getWithIdentityWithType(n, flag);
  728. break;
  729. case "level":
  730. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  731. break;
  732. }
  733. var o = this.getObject(this.oUnit, [v]);
  734. return (o && o.length===1) ? o[0] : o;
  735. },
  736. //列出身份所在组织的所有上级组织
  737. listAllSupUnitWithIdentity: function(name){
  738. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  739. return this.getObject(this.oUnit, v);
  740. },
  741. //获取人员所在的所有组织(直接所在组织)
  742. listUnitWithPerson: function(name){
  743. var v = this.oUnit.listWithPerson(getNameFlag(name));
  744. return this.getObject(this.oUnit, v);
  745. },
  746. //列出人员所在组织的所有上级组织
  747. listAllSupUnitWithPerson: function(name){
  748. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  749. return this.getObject(this.oUnit, v);
  750. },
  751. //根据组织属性,获取所有符合的组织
  752. listUnitWithAttribute: function(name, attribute){
  753. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  754. return this.getObject(this.oUnit, v);
  755. },
  756. //根据组织职务,获取所有符合的组织
  757. listUnitWithDuty: function(name, id){
  758. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  759. var v = this.oUnit.listWithUnitDuty(name, idflag);
  760. return this.getObject(this.oUnit, v);
  761. },
  762. //组织职务***********
  763. //获取指定的组织职务的身份
  764. getDuty: function(duty, id){
  765. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  766. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  767. return this.getObject(this.oIdentity, v);
  768. },
  769. //获取身份的所有职务名称
  770. listDutyNameWithIdentity: function(name){
  771. var ids = getNameFlag(name);
  772. var nameList = [];
  773. for (var i=0; i<ids.length; i++){
  774. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  775. if (v && v.length){
  776. for (var j=0; j<v.length; j++){
  777. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  778. }
  779. }
  780. }
  781. return nameList;
  782. },
  783. //获取组织的所有职务名称
  784. listDutyNameWithUnit: function(name){
  785. var ids = getNameFlag(name);
  786. var nameList = [];
  787. for (var i=0; i<ids.length; i++){
  788. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  789. if (v && v.length){
  790. for (var j=0; j<v.length; j++){
  791. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  792. }
  793. }
  794. }
  795. return nameList;
  796. },
  797. //获取组织的所有职务
  798. listUnitAllDuty: function(name){
  799. var u = getNameFlag(name)[0];
  800. var ds = this.oUnitDuty.listNameWithUnit(u);
  801. var o = []
  802. for (var i=0; i<ds.length; i++){
  803. v = this.oUnitDuty.listIdentityWithUnitWithName(u, ds[i]);
  804. o.push({"name": ds[i], "identityList": this.getObject(this.oIdentity, v)});
  805. }
  806. return o;
  807. },
  808. //组织属性**************
  809. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  810. appendUnitAttribute: function(unit, attr, values){
  811. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  812. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  813. },
  814. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  815. setUnitAttribute: function(unit, attr, values){
  816. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  817. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  818. },
  819. //获取组织属性值
  820. getUnitAttribute: function(unit, attr){
  821. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  822. var v = this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  823. var v_json = [];
  824. if (v && v.length){
  825. for (var i=0; i<v.length; i++){
  826. v_json.push(v[i].toString());
  827. }
  828. }
  829. return v_json;
  830. },
  831. //列出组织所有属性的名称
  832. listUnitAttributeName: function(name){
  833. var p = getNameFlag(name);
  834. var nameList = [];
  835. for (var i=0; i<p.length; i++){
  836. var v = this.oUnitAttribute.listNameWithUnit(p[i]);
  837. if (v && v.length){
  838. for (var j=0; j<v.length; j++){
  839. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  840. }
  841. }
  842. }
  843. return nameList;
  844. },
  845. //列出组织的所有属性
  846. listUnitAllAttribute: function(name){
  847. var u = getNameFlag(name)[0];
  848. var ds = this.oUnitAttribute.listNameWithUnit(u);
  849. var o = []
  850. for (var i=0; i<ds.length; i++){
  851. v = this.getUnitAttribute(u, ds[i]);
  852. o.push({"name": ds[i], "valueList":v});
  853. }
  854. return o;
  855. }
  856. };
  857. print = function(str, type){}
  858. bind.print = print;
  859. bind.org = _org;
  860. bind.library = library;
  861. bind.define = _define;
  862. bind.Action = _Action;
  863. bind.Actions = _Actions;
  864. bind.processActions = _processActions;
  865. bind.cmsActions = _cmsActions;
  866. bind.portalActions = _portalActions;
  867. bind.exec = _exec;
  868. bind.include = _include;
  869. bind.Dict = _createDict();