sss.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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. "oGroup": this.organization.group(),
  233. "oUnit": this.organization.unit(),
  234. "oUnitAttribute": this.organization.unitAttribute(),
  235. "oUnitDuty": this.organization.unitDuty(),
  236. "group": function() { return this.oGroup},
  237. "identity": function() { return this.oIdentity},
  238. "person": function() { return this.oPerson},
  239. "personAttribute": function() { return this.oPersonAttribute},
  240. "role": function() { return this.oRole},
  241. "group": function() { return this.oGroup},
  242. "unit": function() { return this.oUnit},
  243. "unitAttribute": function() { return this.oUnitAttribute},
  244. "unitDuty": function() { return this.oUnitDuty},
  245. "getObject": function(o, v){
  246. var arr = [];
  247. if (!v || !v.length){
  248. return null;
  249. }else{
  250. for (var i=0; i<v.length; i++){
  251. var g = this.o.getObject​(v[i]);
  252. if (g) arr.push(g);
  253. }
  254. }
  255. return arr;
  256. },
  257. //群组***************
  258. //获取群组--返回群组的对象数组
  259. getGroup: function(name){
  260. var v = this.oGroup.listObject​(getNameFlag(name));
  261. if (!v || !v.length) v = null;
  262. return (v && v.length===1) ? v[0] : v;
  263. },
  264. //查询下级群组--返回群组的对象数组
  265. //nested 布尔 true嵌套下级;false直接下级;默认false;
  266. listSubGroup: function(name, nested){
  267. var v = null;
  268. if (nested){
  269. var v = this.oGroup.listWithGroupSubNested(getNameFlag(name));
  270. }else{
  271. var v = this.oGroup.listWithGroupSubDirect(getNameFlag(name));
  272. }
  273. return this.getObject(this.oGroup, v);
  274. },
  275. //查询上级群组--返回群组的对象数组
  276. //nested 布尔 true嵌套上级;false直接上级;默认false;
  277. listSupGroup:function(name, nested){
  278. var v = null;
  279. if (nested){
  280. var v = this.oGroup.listWithGroupSupNested(getNameFlag(name));
  281. }else{
  282. var v = this.oGroup.listWithGroupSupDirect(getNameFlag(name));
  283. }
  284. return this.getObject(this.oGroup, v);
  285. },
  286. //人员所在群组(嵌套)--返回群组的对象数组
  287. listGroupWithPerson:function(name){
  288. var v = this.oGroup.listWithPerson(getNameFlag(name));
  289. return this.getObject(this.oGroup, v);
  290. },
  291. //群组是否拥有角色--返回true, false
  292. groupHasRole: function(name, role){
  293. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  294. return this.oGroup.hasRole(nameFlag, getNameFlag(role));
  295. },
  296. //角色***************
  297. //获取角色--返回角色的对象数组
  298. getRole: function(name){
  299. var v = this.oRole.listObject(getNameFlag(name));
  300. if (!v || !v.length) v = null;
  301. return (v && v.length===1) ? v[0] : v;
  302. },
  303. //人员所有角色(嵌套)--返回角色的对象数组
  304. listRoleWithPerson:function(name){
  305. var v = this.oRole.listWithPerson​(getNameFlag(name));
  306. return this.getObject(this.oRole, v);
  307. },
  308. //人员***************
  309. //人员是否拥有角色--返回true, false
  310. personHasRole: function(name, role){
  311. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  312. return this.oPerson.hasRole(nameFlag, getNameFlag(role));
  313. },
  314. //获取人员--返回人员的对象数组
  315. getPerson: function(name){
  316. var v = this.oPerson.listObject(getNameFlag(name));
  317. if (!v || !v.length) v = null;
  318. return (v && v.length===1) ? v[0] : v;
  319. },
  320. //查询下级人员--返回人员的对象数组
  321. //nested 布尔 true嵌套下级;false直接下级;默认false;
  322. listSubPerson: function(name, nested){
  323. var v = null;
  324. if (nested){
  325. var v = this.oPerson.listWithPersonSubNested(getNameFlag(name));
  326. }else{
  327. var v = this.oPerson.listWithPersonSubDirect(getNameFlag(name));
  328. }
  329. return this.getObject(this.oPerson, v);
  330. },
  331. //查询上级人员--返回人员的对象数组
  332. //nested 布尔 true嵌套上级;false直接上级;默认false;
  333. listSupPerson: function(name, nested){
  334. var v = null;
  335. if (nested){
  336. var v = this.oPerson.listWithPersonSupNested(getNameFlag(name));
  337. }else{
  338. var v = this.oPerson.listWithPersonSupDirect(getNameFlag(name));
  339. }
  340. return this.getObject(this.oPerson, v);
  341. },
  342. //获取群组的所有人员--返回人员的对象数组
  343. listPersonWithGroup: function(name){
  344. var v = this.oPerson.listWithGroup(getNameFlag(name));
  345. if (!v || !v.length) v = null;
  346. return v;
  347. },
  348. //获取角色的所有人员--返回人员的对象数组
  349. listPersonWithRole: function(name){
  350. var v = this.oPerson.listWithRole​(getNameFlag(name));
  351. return this.getObject(this.oPerson, v);
  352. },
  353. //获取身份的所有人员--返回人员的对象数组
  354. listPersonWithIdentity: function(name){
  355. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  356. return this.getObject(this.oPerson, v);
  357. },
  358. //获取身份的所有人员--返回人员的对象数组
  359. getPersonWithIdentity: function(name){
  360. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  361. var arr = this.getObject(this.oPerson, v);
  362. return (arr && arr.length) ? arr[0] : null;
  363. },
  364. //查询组织成员的人员--返回人员的对象数组
  365. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  366. listPersonWithUnit: function(name, nested){
  367. var v = null;
  368. if (nested){
  369. var v = this.oPerson.listWithUnitSubNested(getNameFlag(name));
  370. }else{
  371. var v = this.oPerson.listWithUnitSubDirect(getNameFlag(name));
  372. }
  373. return this.getObject(this.oPerson, v);
  374. },
  375. //人员属性************
  376. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  377. appendPersonAttribute: function(person, attr, values){
  378. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  379. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  380. },
  381. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  382. setPersonAttribute: function(person, attr, values){
  383. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  384. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  385. },
  386. //获取人员属性值
  387. getPersonAttribute: function(person, attr){
  388. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  389. return this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  390. },
  391. //列出人员所有属性的名称
  392. listPersonAttributeName: function(name){
  393. var p = getNameFlag(name);
  394. var nameList = [];
  395. for (var i=0; i<p.length; i++){
  396. var v = this.oPersonAttribute.listNameWithPerson(p[i]);
  397. if (v && v.length){
  398. for (var j=0; j<v.length; j++){
  399. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  400. }
  401. }
  402. }
  403. return nameList;
  404. },
  405. //列出人员的所有属性
  406. listPersonAllAttribute: function(name){
  407. // getOrgActions();
  408. // var data = {"personList":getNameFlag(name)};
  409. // var v = null;
  410. // orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  411. // return v;
  412. },
  413. //身份**********
  414. //获取身份
  415. getIdentity: function(name){
  416. var v = this.oIdentity.listObject​(getNameFlag(name));
  417. if (!v || !v.length) v = null;
  418. return (v && v.length===1) ? v[0] : v;
  419. },
  420. //列出人员的身份
  421. listIdentityWithPerson: function(name){
  422. var v = this.oIdentity.listWithPerson​(getNameFlag(name));
  423. return this.getObject(this.oIdentity, v);
  424. },
  425. //查询组织成员身份--返回身份的对象数组
  426. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  427. listIdentityWithUnit: function(name, nested){
  428. var v = null;
  429. if (nested){
  430. var v = this.oIdentity.listWithUnitSubNested(getNameFlag(name));
  431. }else{
  432. var v = this.oIdentity.listWithUnitSubDirect(getNameFlag(name));
  433. }
  434. return this.getObject(this.oIdentity, v);
  435. },
  436. //组织**********
  437. //获取组织
  438. getUnit: function(name){
  439. var v = this.oUnit.listObject(getNameFlag(name));
  440. if (!v || !v.length) v = null;
  441. return (v && v.length===1) ? v[0] : v;
  442. },
  443. //查询组织的下级--返回组织的对象数组
  444. //nested 布尔 true嵌套下级;false直接下级;默认false;
  445. listSubUnit: function(name, nested){
  446. var v = null;
  447. if (nested){
  448. var v = this.oUnit.listWithUnitSubNested(getNameFlag(name));
  449. }else{
  450. var v = this.oUnit.listWithUnitSubDirect(getNameFlag(name));
  451. }
  452. return this.getObject(this.oUnit, v);
  453. },
  454. //查询组织的上级--返回组织的对象数组
  455. //nested 布尔 true嵌套上级;false直接上级;默认false;
  456. listSupUnit: function(name, nested){
  457. var v = null;
  458. if (nested){
  459. var v = this.oUnit.listWithUnitSupNested(getNameFlag(name));
  460. }else{
  461. var v = this.oUnit.listWithUnitSupDirect(getNameFlag(name));
  462. }
  463. return this.getObject(this.oUnit, v);
  464. },
  465. //根据个人身份获取组织
  466. //flag 数字 表示获取第几层的组织
  467. // 字符串 表示获取指定类型的组织
  468. // 空 表示获取直接所在的组织
  469. getUnitByIdentity: function(name, flag){
  470. getOrgActions();
  471. var getUnitMethod = "current";
  472. var v;
  473. if (flag){
  474. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  475. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  476. }
  477. var n = getNameFlag(name)[0];
  478. switch (getUnitMethod){
  479. case "current":
  480. v = this.oUnit.getWithIdentity(n);
  481. break;
  482. case "type":
  483. v = this.oUnit.getWithIdentityWithType(n, flag);
  484. break;
  485. case "level":
  486. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  487. break;
  488. }
  489. var o = this.oUnit.getObject(v);
  490. return o;
  491. },
  492. //列出身份所在组织的所有上级组织
  493. listAllSupUnitWithIdentity: function(name){
  494. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  495. return this.getObject(this.oUnit, v);
  496. },
  497. //获取人员所在的所有组织
  498. listUnitWithPerson: function(name){
  499. var v = this.oUnit.listWithPerson(getNameFlag(name));
  500. return this.getObject(this.oUnit, v);
  501. },
  502. //列出人员所在组织的所有上级组织
  503. listAllSupUnitWithPerson: function(name){
  504. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  505. return this.getObject(this.oUnit, v);
  506. },
  507. //根据组织属性,获取所有符合的组织
  508. listUnitWithAttribute: function(name, attribute){
  509. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  510. return this.getObject(this.oUnit, v);
  511. },
  512. //根据组织职务,获取所有符合的组织
  513. listUnitWithDuty: function(name, id){
  514. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  515. var v = this.oUnit.listWithUnitDuty(name, idflag);
  516. return this.getObject(this.oUnit, v);
  517. },
  518. //组织职务***********
  519. //获取指定的组织职务的身份
  520. getDuty: function(duty, id){
  521. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  522. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  523. return this.getObject(this.oIdentity, v);
  524. },
  525. //获取身份的所有职务名称
  526. listDutyNameWithIdentity: function(name){
  527. var ids = getNameFlag(name);
  528. var nameList = [];
  529. for (var i=0; i<ids.length; i++){
  530. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  531. if (v && v.length){
  532. for (var j=0; j<v.length; j++){
  533. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  534. }
  535. }
  536. }
  537. return nameList;
  538. },
  539. //获取组织的所有职务名称
  540. listDutyNameWithUnit: function(name){
  541. var ids = getNameFlag(name);
  542. var nameList = [];
  543. for (var i=0; i<ids.length; i++){
  544. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  545. if (v && v.length){
  546. for (var j=0; j<v.length; j++){
  547. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  548. }
  549. }
  550. }
  551. return nameList;
  552. },
  553. //获取组织的所有职务
  554. listUnitAllDuty: function(name){
  555. // getOrgActions();
  556. // var data = {"unitList":getNameFlag(name)};
  557. // var v = null;
  558. // orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  559. // return v;
  560. },
  561. //组织属性**************
  562. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  563. appendUnitAttribute: function(unit, attr, values){
  564. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  565. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  566. },
  567. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  568. setUnitAttribute: function(unit, attr, values){
  569. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  570. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  571. },
  572. //获取组织属性值
  573. getUnitAttribute: function(unit, attr){
  574. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  575. return this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  576. },
  577. //列出组织所有属性的名称
  578. listUnitAttributeName: function(name){
  579. var p = getNameFlag(name);
  580. var nameList = [];
  581. for (var i=0; i<p.length; i++){
  582. var v = this.oUnitAttribute.listNameWithUnit​(p[i]);
  583. if (v && v.length){
  584. for (var j=0; j<v.length; j++){
  585. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  586. }
  587. }
  588. }
  589. return nameList;
  590. },
  591. //列出组织的所有属性
  592. listUnitAllAttribute: function(name){
  593. // getOrgActions();
  594. // var data = {"unitList":getNameFlag(name)};
  595. // var v = null;
  596. // orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  597. // return v;
  598. }
  599. };
  600. var restfulAcpplication = this.applications;
  601. var Action = (function(){
  602. var actions = [];
  603. return function(root, json){
  604. if (!actions[root]) actions[root] = {};
  605. Object.keys(json).forEach(function(key){
  606. actions[root][key] = json[key];
  607. });
  608. //Object.merge(actions[root], json);
  609. this.root = root;
  610. this.actions = actions[root];
  611. this.invoke = function(option){
  612. // {
  613. // "name": "",
  614. // "data": "",
  615. // "parameter": "",,
  616. // "success": function(){}
  617. // "failure": function(){}
  618. // }
  619. if (this.actions[option.name]){
  620. var uri = this.actions[option.name].uri;
  621. var method = this.actions[option.name].method || "get";
  622. if (option.parameter){
  623. Object.keys(option.parameter).forEach(function(key){
  624. var v = option.parameter[key];
  625. uri = uri.replace("{"+key+"}", v);
  626. });
  627. }
  628. var res = null;
  629. try{
  630. switch (method.toLowerCase()){
  631. case "get":
  632. res = restfulAcpplication.getQuery(this.root, uri);
  633. break;
  634. case "post":
  635. res = restfulAcpplication.postQuery(this.root, uri, JSON.stringify(option.data));
  636. break;
  637. case "put":
  638. res = restfulAcpplication.putQuery(this.root, uri, JSON.stringify(option.data));
  639. break;
  640. case "delete":
  641. res = restfulAcpplication.deleteQuery(this.root, uri);
  642. break;
  643. default:
  644. res = restfulAcpplication.getQuery(this.root, uri);
  645. }
  646. if (res){
  647. var json = JSON.parse(res.toString());
  648. if (option.success) option.success(json);
  649. }else{
  650. if (option.failure) option.failure();
  651. }
  652. }catch(e){
  653. if (option.failure) option.failure(e);
  654. }
  655. }
  656. }
  657. }
  658. })();
  659. Action.applications = this.applications;
  660. var Actions = {
  661. 'get': function(root){
  662. if (loadedActions[root]) return loadedActions[root];
  663. loadedActions[root] = {
  664. "root": root,
  665. "get": function(uri, success, failure){
  666. return returnRes(estfulAcpplication.getQuery(this.root, uri), success, failure);
  667. },
  668. "post": function(uri, data, success, failure){
  669. return returnRes(estfulAcpplication.postQuery(this.root, uri, JSON.stringify(data)), success, failure);
  670. },
  671. "put": function(uri, data, success, failure){
  672. return returnRes(estfulAcpplication.putQuery(this.root, uri, JSON.stringify(data)), success, failure);
  673. },
  674. "delete": function(uri, success, failure){
  675. return returnRes(estfulAcpplication.deleteQuery(this.root, uri), success, failure);
  676. }
  677. };
  678. return loadedActions[root];
  679. }
  680. };
  681. bind.library = library;
  682. bind.data = this.data;
  683. bind.workContext = wrapWorkContext;
  684. bind.service = this.webservicesClient;
  685. bind.org = org;
  686. bind.Action = Action;
  687. bind.Actions = Actions;
  688. //bind.organization = this.organization;
  689. bind.include = include;
  690. bind.define = define;
  691. bind.Dict = Dict;
  692. bind.form = null;
  693. bind.body = {
  694. "set": function(data){
  695. if ((typeof data)==="string"){
  696. body.set(data);
  697. }
  698. if ((typeof data)==="object"){
  699. body.set(JSON.encode(data));
  700. }
  701. }
  702. };
  703. bind.parameters = this.parameters || null;
  704. bind.response = (function(){
  705. if (this.jaxrsResponse){
  706. if (this.jaxrsResponse.get()){
  707. if (JSON.validate(this.jaxrsResponse.get())){
  708. return {
  709. "status": this.jaxrsResponse.status,
  710. "value": JSON.decode(this.jaxrsResponse.get())
  711. };
  712. }else{
  713. return {
  714. "status": this.jaxrsResponse.status,
  715. "value": this.jaxrsResponse.value
  716. };
  717. }
  718. }else{
  719. return {"status": this.jaxrsResponse.status};
  720. }
  721. }
  722. return null;
  723. }).apply(this);
  724. bind.assginData = {
  725. "data": null,
  726. "get": function(){
  727. this.data = JSON.decode(assginData.get());
  728. return this.data;
  729. },
  730. "set": function(data){
  731. assginData.set(JSON.encode(data || this.data));
  732. }
  733. };
  734. bind.expire = {
  735. "setHour": function(hour){
  736. try{expire.setHour(hour);}catch(e){}
  737. },
  738. "setWorkHour": function(hour){
  739. try{expire.setWorkHour(hour);}catch(e){}
  740. },
  741. "setDate": function(date){
  742. try{expire.setDate(date);}catch(e){}
  743. }
  744. };
  745. var app = this.form.getApp();
  746. var _form = app.appForm;
  747. _form.readedWork = function(){
  748. var read = null;
  749. for (var i = 0; i < _form.businessData.readList.length; i++) {
  750. if (_form.businessData.readList[i].person === layout.session.user.distinguishedName) {
  751. read = _form.businessData.readList[i];
  752. break;
  753. }
  754. }
  755. app.action.setReaded(function () {
  756. if (layout.mobile) {
  757. _form.finishOnMobile();
  758. } else {
  759. app.reload();
  760. }
  761. }, null, read.id, read);
  762. }