initialScriptText.js 28 KB

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