initialScriptText.js 29 KB

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