initalScriptSubstitute.js 42 KB

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