initialScriptText.js 29 KB

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