initialScriptText.js 34 KB

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