sss.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. listSupUnitWithLevel: function(name, level){
  466. var supUnitList = this.listSupUnit( name, true);
  467. var unitList = this.getUnit( name );
  468. return [].concat(
  469. supUnitList,
  470. library.typeOf( unitList ) === 'object' ? [unitList] : unitList,
  471. ).filter(function (u){
  472. return u.level === level;
  473. });
  474. },
  475. listSupUnitWithType: function(name, type){
  476. var supUnitList = this.listSupUnit( name, true);
  477. var unitList = this.getUnit( name );
  478. return [].concat(
  479. supUnitList,
  480. library.typeOf( unitList ) === 'object' ? [unitList] : unitList,
  481. ).filter(function (u){
  482. return (u.typeList || []).contains( type );
  483. });
  484. },
  485. //根据个人身份获取组织
  486. //flag 数字 表示获取第几层的组织
  487. // 字符串 表示获取指定类型的组织
  488. // 空 表示获取直接所在的组织
  489. getUnitByIdentity: function(name, flag){
  490. getOrgActions();
  491. var getUnitMethod = "current";
  492. var v;
  493. if (flag){
  494. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  495. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  496. }
  497. var n = getNameFlag(name)[0];
  498. switch (getUnitMethod){
  499. case "current":
  500. v = this.oUnit.getWithIdentity(n);
  501. break;
  502. case "type":
  503. v = this.oUnit.getWithIdentityWithType(n, flag);
  504. break;
  505. case "level":
  506. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  507. break;
  508. }
  509. var o = this.oUnit.getObject(v);
  510. return o;
  511. },
  512. //列出身份所在组织的所有上级组织
  513. listAllSupUnitWithIdentity: function(name){
  514. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  515. return this.getObject(this.oUnit, v);
  516. },
  517. //获取人员所在的所有组织
  518. listUnitWithPerson: function(name){
  519. var v = this.oUnit.listWithPerson(getNameFlag(name));
  520. return this.getObject(this.oUnit, v);
  521. },
  522. //列出人员所在组织的所有上级组织
  523. listAllSupUnitWithPerson: function(name){
  524. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  525. return this.getObject(this.oUnit, v);
  526. },
  527. //根据组织属性,获取所有符合的组织
  528. listUnitWithAttribute: function(name, attribute){
  529. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  530. return this.getObject(this.oUnit, v);
  531. },
  532. //根据组织职务,获取所有符合的组织
  533. listUnitWithDuty: function(name, id){
  534. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  535. var v = this.oUnit.listWithUnitDuty(name, idflag);
  536. return this.getObject(this.oUnit, v);
  537. },
  538. //组织职务***********
  539. //获取指定的组织职务的身份
  540. getDuty: function(duty, id){
  541. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  542. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  543. return this.getObject(this.oIdentity, v);
  544. },
  545. //获取身份的所有职务名称
  546. listDutyNameWithIdentity: function(name){
  547. var ids = getNameFlag(name);
  548. var nameList = [];
  549. for (var i=0; i<ids.length; i++){
  550. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  551. if (v && v.length){
  552. for (var j=0; j<v.length; j++){
  553. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  554. }
  555. }
  556. }
  557. return nameList;
  558. },
  559. //获取组织的所有职务名称
  560. listDutyNameWithUnit: function(name){
  561. var ids = getNameFlag(name);
  562. var nameList = [];
  563. for (var i=0; i<ids.length; i++){
  564. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  565. if (v && v.length){
  566. for (var j=0; j<v.length; j++){
  567. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  568. }
  569. }
  570. }
  571. return nameList;
  572. },
  573. //获取组织的所有职务
  574. listUnitAllDuty: function(name){
  575. // getOrgActions();
  576. // var data = {"unitList":getNameFlag(name)};
  577. // var v = null;
  578. // orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  579. // return v;
  580. },
  581. //组织属性**************
  582. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  583. appendUnitAttribute: function(unit, attr, values){
  584. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  585. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  586. },
  587. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  588. setUnitAttribute: function(unit, attr, values){
  589. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  590. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  591. },
  592. //获取组织属性值
  593. getUnitAttribute: function(unit, attr){
  594. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  595. return this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  596. },
  597. //列出组织所有属性的名称
  598. listUnitAttributeName: function(name){
  599. var p = getNameFlag(name);
  600. var nameList = [];
  601. for (var i=0; i<p.length; i++){
  602. var v = this.oUnitAttribute.listNameWithUnit​(p[i]);
  603. if (v && v.length){
  604. for (var j=0; j<v.length; j++){
  605. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  606. }
  607. }
  608. }
  609. return nameList;
  610. },
  611. //列出组织的所有属性
  612. listUnitAllAttribute: function(name){
  613. // getOrgActions();
  614. // var data = {"unitList":getNameFlag(name)};
  615. // var v = null;
  616. // orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  617. // return v;
  618. }
  619. };
  620. var restfulAcpplication = this.applications;
  621. var Action = (function(){
  622. var actions = [];
  623. return function(root, json){
  624. if (!actions[root]) actions[root] = {};
  625. Object.keys(json).forEach(function(key){
  626. actions[root][key] = json[key];
  627. });
  628. //Object.merge(actions[root], json);
  629. this.root = root;
  630. this.actions = actions[root];
  631. this.invoke = function(option){
  632. // {
  633. // "name": "",
  634. // "data": "",
  635. // "parameter": "",,
  636. // "success": function(){}
  637. // "failure": function(){}
  638. // }
  639. if (this.actions[option.name]){
  640. var uri = this.actions[option.name].uri;
  641. var method = this.actions[option.name].method || "get";
  642. if (option.parameter){
  643. Object.keys(option.parameter).forEach(function(key){
  644. var v = option.parameter[key];
  645. uri = uri.replace("{"+key+"}", v);
  646. });
  647. }
  648. var res = null;
  649. try{
  650. switch (method.toLowerCase()){
  651. case "get":
  652. res = restfulAcpplication.getQuery(this.root, uri);
  653. break;
  654. case "post":
  655. res = restfulAcpplication.postQuery(this.root, uri, JSON.stringify(option.data));
  656. break;
  657. case "put":
  658. res = restfulAcpplication.putQuery(this.root, uri, JSON.stringify(option.data));
  659. break;
  660. case "delete":
  661. res = restfulAcpplication.deleteQuery(this.root, uri);
  662. break;
  663. default:
  664. res = restfulAcpplication.getQuery(this.root, uri);
  665. }
  666. if (res){
  667. var json = JSON.parse(res.toString());
  668. if (option.success) option.success(json);
  669. }else{
  670. if (option.failure) option.failure();
  671. }
  672. }catch(e){
  673. if (option.failure) option.failure(e);
  674. }
  675. }
  676. }
  677. }
  678. })();
  679. Action.applications = this.applications;
  680. var Actions = {
  681. 'get': function(root){
  682. if (loadedActions[root]) return loadedActions[root];
  683. loadedActions[root] = {
  684. "root": root,
  685. "get": function(uri, success, failure){
  686. return returnRes(estfulAcpplication.getQuery(this.root, uri), success, failure);
  687. },
  688. "post": function(uri, data, success, failure){
  689. return returnRes(estfulAcpplication.postQuery(this.root, uri, JSON.stringify(data)), success, failure);
  690. },
  691. "put": function(uri, data, success, failure){
  692. return returnRes(estfulAcpplication.putQuery(this.root, uri, JSON.stringify(data)), success, failure);
  693. },
  694. "delete": function(uri, success, failure){
  695. return returnRes(estfulAcpplication.deleteQuery(this.root, uri), success, failure);
  696. }
  697. };
  698. return loadedActions[root];
  699. }
  700. };
  701. bind.library = library;
  702. bind.data = this.data;
  703. bind.workContext = wrapWorkContext;
  704. bind.service = this.webservicesClient;
  705. bind.org = org;
  706. bind.Action = Action;
  707. bind.Actions = Actions;
  708. //bind.organization = this.organization;
  709. bind.include = include;
  710. bind.define = define;
  711. bind.Dict = Dict;
  712. bind.form = null;
  713. bind.body = {
  714. "set": function(data){
  715. if ((typeof data)==="string"){
  716. body.set(data);
  717. }
  718. if ((typeof data)==="object"){
  719. body.set(JSON.encode(data));
  720. }
  721. }
  722. };
  723. bind.parameters = this.parameters || null;
  724. bind.response = (function(){
  725. if (this.jaxrsResponse){
  726. if (this.jaxrsResponse.get()){
  727. if (JSON.validate(this.jaxrsResponse.get())){
  728. return {
  729. "status": this.jaxrsResponse.status,
  730. "value": JSON.decode(this.jaxrsResponse.get())
  731. };
  732. }else{
  733. return {
  734. "status": this.jaxrsResponse.status,
  735. "value": this.jaxrsResponse.value
  736. };
  737. }
  738. }else{
  739. return {"status": this.jaxrsResponse.status};
  740. }
  741. }
  742. return null;
  743. }).apply(this);
  744. bind.assginData = {
  745. "data": null,
  746. "get": function(){
  747. this.data = JSON.decode(assginData.get());
  748. return this.data;
  749. },
  750. "set": function(data){
  751. assginData.set(JSON.encode(data || this.data));
  752. }
  753. };
  754. bind.expire = {
  755. "setHour": function(hour){
  756. try{expire.setHour(hour);}catch(e){}
  757. },
  758. "setWorkHour": function(hour){
  759. try{expire.setWorkHour(hour);}catch(e){}
  760. },
  761. "setDate": function(date){
  762. try{expire.setDate(date);}catch(e){}
  763. }
  764. };
  765. var app = this.form.getApp();
  766. var _form = app.appForm;
  767. _form.readedWork = function(){
  768. var read = null;
  769. for (var i = 0; i < _form.businessData.readList.length; i++) {
  770. if (_form.businessData.readList[i].person === layout.session.user.distinguishedName) {
  771. read = _form.businessData.readList[i];
  772. break;
  773. }
  774. }
  775. app.action.setReaded(function () {
  776. if (layout.mobile) {
  777. _form.finishOnMobile();
  778. } else {
  779. app.reload();
  780. }
  781. }, null, read.id, read);
  782. }