Environment.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Environment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. this.power = {
  9. "isManager": MWF.AC.isProcessManager() || _form.businessData.control.allowReroute,
  10. "isReseter": _form.businessData.control.allowReset,
  11. "isDelete": _form.businessData.control.allowDeleteWork,
  12. "isPront": true,
  13. "isPrint": true
  14. };
  15. //data
  16. var getJSONData = function(jData){
  17. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  18. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  19. while (p && !_forms[p.getKey()]) p = p.getParent();
  20. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  21. }, "", null, _form);
  22. };
  23. this.setData = function(data){
  24. this.data = getJSONData(data);
  25. this.data.save = function(callback){
  26. _form.saveFormData(callback)
  27. // var formData = {
  28. // "data": data,
  29. // "sectionList": _form.getSectionList()
  30. // };
  31. // _form.workAction.saveSectionData(function(){if (callback) callback();}.bind(this), null, (ev.work.id || ev.workCompleted.id), formData);
  32. }
  33. };
  34. this.setData(_data);
  35. //task
  36. //this.task = ev.task;
  37. //this.task.process = function(routeName, opinion, callback){
  38. // _form.submitWork(routeName, opinion, callback);
  39. //};
  40. //inquiredRouteList
  41. //this.inquiredRouteList = null;
  42. //workContext
  43. this.workContext = {
  44. "getTask": function(){return ev.task || null;},
  45. "getWork": function(){return ev.work || ev.workCompleted;},
  46. "getActivity": function(){return ev.activity || null;},
  47. "getTaskList": function(callback, error){
  48. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  49. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  50. var list;
  51. o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  52. list = json.data;
  53. if (cb) cb(list);
  54. }, ecb, !!cb);
  55. return list;
  56. },
  57. "getTaskListByJob": function(callback, error){
  58. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  59. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  60. var list;
  61. o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  62. list = json.data;
  63. if (cb) cb(list);
  64. }, ecb, !!cb);
  65. return list;
  66. },
  67. "getReadList": function(callback, error){
  68. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  69. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  70. var list;
  71. o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  72. list = json.data;
  73. if (cb) cb(list);
  74. }, ecb, !!cb);
  75. return list;
  76. },
  77. "getReadListByJob": function(callback, error){
  78. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  79. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  80. var list;
  81. o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  82. list = json.data;
  83. if (cb) cb(list);
  84. }, ecb, !!cb);
  85. return list;
  86. },
  87. "getTaskCompletedList": function(callback, error){
  88. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  89. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  90. var list;
  91. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  92. list = json.data;
  93. if (cb) cb(list);
  94. }, ecb, !!cb);
  95. return list;
  96. },
  97. "getTaskCompletedListByJob": function(callback, error){
  98. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  99. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  100. var list;
  101. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  102. list = json.data;
  103. if (cb) cb(list);
  104. }, ecb, !!cb);
  105. return list;
  106. },
  107. "getReadCompletedList": function(callback, error){
  108. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  109. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  110. var list;
  111. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  112. list = json.data;
  113. if (cb) cb(list);
  114. }, ecb, !!cb);
  115. return list;
  116. },
  117. "getReadCompletedListByJob": function(callback, error){
  118. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  119. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  120. var list;
  121. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  122. list = json.data;
  123. if (cb) cb(list);
  124. }, ecb, !!cb);
  125. return list;
  126. },
  127. "getJobTaskList": this.getTaskListByJob,
  128. "getJobReadList": this.getReadListByJob,
  129. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  130. "getJobReadCompletedList": this.getReadCompletedListByJob,
  131. "getControl": function(){return ev.control;},
  132. "getWorkLogList": function(){return ev.workLogList;},
  133. "getAttachmentList": function(){return ev.attachmentList;},
  134. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  135. "getInquiredRouteList": function(){return null;},
  136. "setTitle": function(title){
  137. if (!this.workAction){
  138. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  139. this.workAction = new MWF.xScript.Actions.WorkActions();
  140. }
  141. this.workAction.setTitle(ev.work.id, {"title": title});
  142. }
  143. };
  144. this.workContent = this.workContext;
  145. var _redefineWorkProperties = function(work){
  146. if (work){
  147. work.creatorPersonDn = work.creatorPerson ||"";
  148. work.creatorUnitDn = work.creatorUnit ||"";
  149. work.creatorUnitDnList = work.creatorUnitList ||"";
  150. work.creatorIdentityDn = work.creatorIdentity ||"";
  151. var o = {
  152. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  153. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  154. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  155. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  156. // "creatorUnitList": {
  157. // "get": function(){
  158. // var v = [];
  159. // this.creatorUnitDnList.each(function(dn){
  160. // v.push(dn.substring(0, dn.indexOf("@")))
  161. // });
  162. // return v;
  163. // }
  164. // },
  165. "creatorCompany": {"get": function(){
  166. if (this.creatorUnitLevel){
  167. var level = this.creatorUnitLevel.split("/");
  168. return level[0];
  169. }else{
  170. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  171. }
  172. }}
  173. };
  174. MWF.defineProperties(work, o);
  175. }
  176. return work;
  177. };
  178. var _redefineTaskProperties = function(task){
  179. if (task){
  180. task.personDn = task.person || "";
  181. task.unitDn = task.unit || "";
  182. task.unitDnList = task.unitList || "";
  183. task.identityDn = task.identity || "";
  184. var o = {
  185. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  186. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  187. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  188. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  189. // "unitList": {
  190. // "get": function(){
  191. // var v = [];
  192. // this.unitDnList.each(function(dn){
  193. // v.push(dn.substring(0, dn.indexOf("@")))
  194. // });
  195. // return v;
  196. // }
  197. // },
  198. "company": {"get": function(){return this.unitList[0];}}
  199. };
  200. MWF.defineProperties(task, o);
  201. }
  202. return task;
  203. };
  204. _redefineWorkProperties(this.workContext.getWork());
  205. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  206. //dict
  207. this.Dict = MWF.xScript.createDict(_form.json.application);
  208. //unit
  209. var orgActions = null;
  210. var getOrgActions = function(){
  211. // if (!orgActions){
  212. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  213. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  214. // }
  215. if (!orgActions){
  216. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  217. orgActions = new MWF.xScript.Actions.UnitActions();
  218. }
  219. };
  220. var getNameFlag = function(name){
  221. var t = typeOf(name);
  222. if (t==="array"){
  223. var v = [];
  224. name.each(function(id){
  225. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  226. });
  227. return v;
  228. }else{
  229. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  230. }
  231. };
  232. this.org = {
  233. //群组***************
  234. //获取群组--返回群组的对象数组
  235. getGroup: function(name){
  236. getOrgActions();
  237. var data = {"groupList": getNameFlag(name)};
  238. var v = null;
  239. orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  240. return (v && v.length===1) ? v[0] : v;
  241. },
  242. //查询下级群组--返回群组的对象数组
  243. //nested 布尔 true嵌套下级;false直接下级;默认false;
  244. listSubGroup: function(name, nested){
  245. getOrgActions();
  246. var data = {"groupList": getNameFlag(name)};
  247. var v = null;
  248. if (nested){
  249. orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  250. }else{
  251. orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  252. }
  253. return v;
  254. },
  255. //查询上级群组--返回群组的对象数组
  256. //nested 布尔 true嵌套上级;false直接上级;默认false;
  257. listSupGroup:function(name, nested){
  258. getOrgActions();
  259. var data = {"groupList": getNameFlag(name)};
  260. var v = null;
  261. if (nested){
  262. orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  263. }else{
  264. orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  265. }
  266. return v;
  267. },
  268. //人员所在群组(嵌套)--返回群组的对象数组
  269. listGroupWithPerson:function(name){
  270. getOrgActions();
  271. var data = {"personList": getNameFlag(name)};
  272. var v = null;
  273. orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  274. return v;
  275. },
  276. //群组是否拥有角色--返回true, false
  277. groupHasRole: function(name, role){
  278. getOrgActions();
  279. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  280. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  281. var v = false;
  282. orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  283. return v;
  284. },
  285. //角色***************
  286. //获取角色--返回角色的对象数组
  287. getRole: function(name){
  288. getOrgActions();
  289. var data = {"roleList": getNameFlag(name)};
  290. var v = null;
  291. orgActions.listRole(data, function(json){v = json.data;}, null, false);
  292. return (v && v.length===1) ? v[0] : v;
  293. },
  294. //人员所有角色(嵌套)--返回角色的对象数组
  295. listRoleWithPerson:function(name){
  296. getOrgActions();
  297. var data = {"personList": getNameFlag(name)};
  298. var v = null;
  299. orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  300. return v;
  301. },
  302. //人员***************
  303. //人员是否拥有角色--返回true, false
  304. personHasRole: function(name, role){
  305. getOrgActions();
  306. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  307. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  308. var v = false;
  309. orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  310. return v;
  311. },
  312. //获取人员--返回人员的对象数组
  313. getPerson: function(name){
  314. getOrgActions();
  315. var data = {"personList": getNameFlag(name)};
  316. var v = null;
  317. orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  318. return (v && v.length===1) ? v[0] : v;;
  319. },
  320. //查询下级人员--返回人员的对象数组
  321. //nested 布尔 true嵌套下级;false直接下级;默认false;
  322. listSubPerson: function(name, nested){
  323. getOrgActions();
  324. var data = {"personList": getNameFlag(name)};
  325. var v = null;
  326. if (nested){
  327. orgActions.listPersonSubNested(data, function(json){v = json.data;}, null, false);
  328. }else{
  329. orgActions.listPersonSubDirect(data, function(json){v = json.data;}, null, false);
  330. }
  331. return v;
  332. },
  333. //查询上级人员--返回人员的对象数组
  334. //nested 布尔 true嵌套上级;false直接上级;默认false;
  335. listSupPerson: function(name, nested){
  336. getOrgActions();
  337. var data = {"personList": getNameFlag(name)};
  338. var v = null;
  339. if (nested){
  340. orgActions.listPersonSupNested(data, function(json){v = json.data;}, null, false);
  341. }else{
  342. orgActions.listPersonSupDirect(data, function(json){v = json.data;}, null, false);
  343. }
  344. return v;
  345. },
  346. //获取群组的所有人员--返回人员的对象数组
  347. listPersonWithGroup: function(name){
  348. getOrgActions();
  349. var data = {"groupList": getNameFlag(name)};
  350. var v = null;
  351. orgActions.listPersonWithGroup(data, function(json){v = json.data;}, null, false);
  352. return v;
  353. },
  354. //获取角色的所有人员--返回人员的对象数组
  355. listPersonWithRole: function(name){
  356. getOrgActions();
  357. var data = {"roleList": getNameFlag(name)};
  358. var v = null;
  359. orgActions.listPersonWithRole(data, function(json){v = json.data;}, null, false);
  360. return v;
  361. },
  362. //获取身份的所有人员--返回人员的对象数组
  363. listPersonWithIdentity: function(name){
  364. getOrgActions();
  365. var data = {"identityList": getNameFlag(name)};
  366. var v = null;
  367. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  368. return v;
  369. },
  370. //获取身份的所有人员--返回人员的对象数组或人员对象
  371. getPersonWithIdentity: function(name){
  372. getOrgActions();
  373. var data = {"identityList": getNameFlag(name)};
  374. var v = null;
  375. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  376. return (v && v.length===1) ? v[0] : v;
  377. },
  378. //查询组织成员的人员--返回人员的对象数组
  379. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  380. listPersonWithUnit: function(name, nested){
  381. getOrgActions();
  382. var data = {"unitList": getNameFlag(name)};
  383. var v = null;
  384. if (nested){
  385. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  386. }else{
  387. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  388. }
  389. return v;
  390. },
  391. //根据属性查询人员--返回人员的对象数组
  392. //name string 属性名
  393. //value string 属性值
  394. listPersonWithAttribute: function(name, value){
  395. getOrgActions();
  396. var data = {"name": name, "attribute": value};
  397. var v = null;
  398. orgActions.listPersonWithAttribute(data, function(json){v = json.data;}, null, false);
  399. return v;
  400. },
  401. //根据属性查询人员--返回人员的全称数组
  402. //name string 属性名
  403. //value string 属性值
  404. listPersonNameWithAttribute: function(name, value){
  405. getOrgActions();
  406. var data = {"name": name, "attribute": value};
  407. var v = null;
  408. orgActions.listPersonWithAttributeValue(data, function(json){v = json.data.personList;}, null, false);
  409. return v;
  410. },
  411. //人员属性************
  412. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  413. appendPersonAttribute: function(person, attr, values, success, failure){
  414. getOrgActions();
  415. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  416. var data = {"attributeList":values,"name":attr,"person":personFlag};
  417. orgActions.appendPersonAttribute(data, function(json){
  418. if (json.data.value){
  419. if (success) success();
  420. }else{
  421. if (failure) failure(null, "", "append values failed");
  422. }
  423. }, function(xhr, text, error){
  424. if (failure) failure(xhr, text, error);
  425. }, false);
  426. },
  427. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  428. setPersonAttribute: function(person, attr, values, success, failure){
  429. getOrgActions();
  430. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  431. var data = {"attributeList":values,"name":attr,"person":personFlag};
  432. orgActions.setPersonAttribute(data, function(json){
  433. if (json.data.value){
  434. if (success) success();
  435. }else{
  436. if (failure) failure(null, "", "append values failed");
  437. }
  438. }, function(xhr, text, error){
  439. if (failure) failure(xhr, text, error);
  440. }, false);
  441. },
  442. //获取人员属性值
  443. getPersonAttribute: function(person, attr){
  444. getOrgActions();
  445. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  446. var data = {"name":attr,"person":personFlag};
  447. var v = null;
  448. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  449. return v;
  450. },
  451. //列出人员所有属性的名称
  452. listPersonAttributeName: function(name){
  453. getOrgActions();
  454. var data = {"personList":getNameFlag(name)};
  455. var v = null;
  456. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  457. return v;
  458. },
  459. //列出人员的所有属性
  460. listPersonAllAttribute: function(name){
  461. getOrgActions();
  462. var data = {"personList":getNameFlag(name)};
  463. var v = null;
  464. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  465. return v;
  466. },
  467. //身份**********
  468. //获取身份
  469. getIdentity: function(name){
  470. getOrgActions();
  471. var data = {"identityList":getNameFlag(name)};
  472. var v = null;
  473. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  474. return (v && v.length===1) ? v[0] : v;
  475. },
  476. //列出人员的身份
  477. listIdentityWithPerson: function(name){
  478. getOrgActions();
  479. var data = {"personList":getNameFlag(name)};
  480. var v = null;
  481. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  482. return v;
  483. },
  484. //查询组织成员身份--返回身份的对象数组
  485. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  486. listIdentityWithUnit: function(name, nested){
  487. getOrgActions();
  488. var data = {"unitList": getNameFlag(name)};
  489. var v = null;
  490. if (nested){
  491. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  492. }else{
  493. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  494. }
  495. return v;
  496. },
  497. //组织**********
  498. //获取组织
  499. getUnit: function(name){
  500. getOrgActions();
  501. var data = {"unitList":getNameFlag(name)};
  502. var v = null;
  503. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  504. return (v && v.length===1) ? v[0] : v;
  505. },
  506. //查询组织的下级--返回组织的对象数组
  507. //nested 布尔 true嵌套下级;false直接下级;默认false;
  508. listSubUnit: function(name, nested){
  509. getOrgActions();
  510. var data = {"unitList": getNameFlag(name)};
  511. var v = null;
  512. if (nested){
  513. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  514. }else{
  515. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  516. }
  517. return v;
  518. },
  519. //查询组织的上级--返回组织的对象数组
  520. //nested 布尔 true嵌套上级;false直接上级;默认false;
  521. listSupUnit: function(name, nested){
  522. getOrgActions();
  523. var data = {"unitList": getNameFlag(name)};
  524. var v = null;
  525. if (nested){
  526. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  527. }else{
  528. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  529. }
  530. return v;
  531. },
  532. //根据个人身份获取组织
  533. //flag 数字 表示获取第几层的组织
  534. // 字符串 表示获取指定类型的组织
  535. // 空 表示获取直接所在的组织
  536. getUnitByIdentity: function(name, flag){
  537. getOrgActions();
  538. var getUnitMethod = "current";
  539. var v;
  540. if (flag){
  541. if (typeOf(flag)==="string") getUnitMethod = "type";
  542. if (typeOf(flag)==="number") getUnitMethod = "level";
  543. }
  544. switch (getUnitMethod){
  545. case "current":
  546. var data = {"identityList":getNameFlag(name)};
  547. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, null, false);
  548. break;
  549. case "type":
  550. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  551. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  552. break;
  553. case "level":
  554. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  555. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  556. break;
  557. }
  558. return v;
  559. },
  560. //列出身份所在组织的所有上级组织
  561. listAllSupUnitWithIdentity: function(name){
  562. getOrgActions();
  563. var data = {"identityList":getNameFlag(name)};
  564. var v = null;
  565. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  566. return v;
  567. },
  568. //获取人员所在的所有组织
  569. listUnitWithPerson: function(name){
  570. getOrgActions();
  571. var data = {"personList":getNameFlag(name)};
  572. var v = null;
  573. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  574. return v;
  575. },
  576. //列出人员所在组织的所有上级组织
  577. listAllSupUnitWithPerson: function(name){
  578. getOrgActions();
  579. var data = {"personList":getNameFlag(name)};
  580. var v = null;
  581. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  582. return v;
  583. },
  584. //根据组织属性,获取所有符合的组织
  585. listUnitWithAttribute: function(name, attribute){
  586. getOrgActions();
  587. var data = {"name":name,"attribute":attribute};
  588. var v = null;
  589. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  590. return v;
  591. },
  592. //根据组织职务,获取所有符合的组织
  593. listUnitWithDuty: function(name, id){
  594. getOrgActions();
  595. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  596. var v = null;
  597. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  598. return v;
  599. },
  600. //组织职务***********
  601. //获取指定的组织职务的身份
  602. getDuty: function(duty, id){
  603. getOrgActions();
  604. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  605. var v = null;
  606. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  607. return v;
  608. },
  609. //获取身份的所有职务名称
  610. listDutyNameWithIdentity: function(name){
  611. getOrgActions();
  612. var data = {"identityList":getNameFlag(name)};
  613. var v = null;
  614. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  615. return v;
  616. },
  617. //获取组织的所有职务名称
  618. listDutyNameWithUnit: function(name){
  619. getOrgActions();
  620. var data = {"unitList":getNameFlag(name)};
  621. var v = null;
  622. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  623. return v;
  624. },
  625. //获取组织的所有职务
  626. listUnitAllDuty: function(name){
  627. getOrgActions();
  628. var data = {"unitList":getNameFlag(name)};
  629. var v = null;
  630. orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  631. return v;
  632. },
  633. //列出顶层组织
  634. listTopUnit: function(){
  635. var action = MWF.Actions.get("x_organization_assemble_control");
  636. var v = null;
  637. action.listTopUnit(function(json){
  638. v = json.data;
  639. }, null, false);
  640. return v;
  641. },
  642. //组织属性**************
  643. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  644. appendUnitAttribute: function(unit, attr, values, success, failure){
  645. getOrgActions();
  646. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  647. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  648. orgActions.appendUnitAttribute(data, function(json){
  649. if (json.data.value){
  650. if (success) success();
  651. }else{
  652. if (failure) failure(null, "", "append values failed");
  653. }
  654. }, function(xhr, text, error){
  655. if (failure) failure(xhr, text, error);
  656. }, false);
  657. },
  658. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  659. setUnitAttribute: function(unit, attr, values, success, failure){
  660. getOrgActions();
  661. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  662. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  663. orgActions.setUnitAttribute(data, function(json){
  664. if (json.data.value){
  665. if (success) success();
  666. }else{
  667. if (failure) failure(null, "", "append values failed");
  668. }
  669. }, function(xhr, text, error){
  670. if (failure) failure(xhr, text, error);
  671. }, false);
  672. },
  673. //获取组织属性值
  674. getUnitAttribute: function(unit, attr){
  675. getOrgActions();
  676. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  677. var data = {"name":attr,"unit":unitFlag};
  678. var v = null;
  679. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  680. return v;
  681. },
  682. //列出组织所有属性的名称
  683. listUnitAttributeName: function(name){
  684. getOrgActions();
  685. var data = {"unitList":getNameFlag(name)};
  686. var v = null;
  687. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  688. return v;
  689. },
  690. //列出组织的所有属性
  691. listUnitAllAttribute: function(name){
  692. getOrgActions();
  693. var data = {"unitList":getNameFlag(name)};
  694. var v = null;
  695. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  696. return v;
  697. }
  698. };
  699. this.Action = (function(){
  700. var actions = [];
  701. return function(root, json){
  702. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  703. action.getActions = function(callback){
  704. if (!this.actions) this.actions = {};
  705. Object.merge(this.actions, json);
  706. if (callback) callback();
  707. };
  708. this.invoke = function(option){
  709. action.invoke(option)
  710. }
  711. }
  712. })();
  713. this.service = {
  714. "jaxwsClient":{},
  715. "jaxrsClient":{}
  716. };
  717. var lookupAction = null;
  718. var getLookupAction = function(callback){
  719. if (!lookupAction){
  720. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  721. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  722. lookupAction.getActions = function(actionCallback){
  723. this.actions = {
  724. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  725. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  726. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  727. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  728. };
  729. if (actionCallback) actionCallback();
  730. };
  731. if (callback) callback();
  732. });
  733. }else{
  734. if (callback) callback();
  735. }
  736. };
  737. this.view = {
  738. "lookup": function(view, callback, async){
  739. var filterList = {"filterList": (view.filter || null)};
  740. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  741. var data = {
  742. "grid": json.data.grid || json.data.groupGrid,
  743. "groupGrid": json.data.groupGrid
  744. };
  745. if (callback) callback(data);
  746. }, null, async);
  747. },
  748. "lookupV1": function(view, callback){
  749. getLookupAction(function(){
  750. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  751. var data = {
  752. "grid": json.data.grid,
  753. "groupGrid": json.data.groupGrid
  754. };
  755. if (callback) callback(data);
  756. }.bind(this)});
  757. }.bind(this));
  758. },
  759. "select": function(view, callback, options){
  760. if (view.view){
  761. var viewJson = {
  762. "application": view.application || _form.json.application,
  763. "viewName": view.view || "",
  764. "isTitle": (view.isTitle===false) ? "no" : "yes",
  765. "select": (view.isMulti===false) ? "single" : "multi",
  766. "filter": view.filter
  767. };
  768. if (!options) options = {};
  769. options.width = view.width;
  770. options.height = view.height;
  771. options.title = view.caption;
  772. var width = options.width || "700";
  773. var height = options.height || "400";
  774. if (layout.mobile){
  775. var size = document.body.getSize();
  776. width = size.x;
  777. height = size.y;
  778. options.style = "viewmobile";
  779. }
  780. width = width.toInt();
  781. height = height.toInt();
  782. var size = _form.app.content.getSize();
  783. var x = (size.x-width)/2;
  784. var y = (size.y-height)/2;
  785. if (x<0) x = 0;
  786. if (y<0) y = 0;
  787. if (layout.mobile){
  788. x = 20;
  789. y = 0;
  790. }
  791. var _self = this;
  792. MWF.require("MWF.xDesktop.Dialog", function(){
  793. var dlg = new MWF.xDesktop.Dialog({
  794. "title": options.title || "select view",
  795. "style": options.style || "view",
  796. "top": y,
  797. "left": x-20,
  798. "fromTop":y,
  799. "fromLeft": x-20,
  800. "width": width,
  801. "height": height,
  802. "html": "<div style='height: 100%;'></div>",
  803. "maskNode": _form.app.content,
  804. "container": _form.app.content,
  805. "buttonList": [
  806. {
  807. "text": MWF.LP.process.button.ok,
  808. "action": function(){
  809. //if (callback) callback(_self.view.selectedItems);
  810. if (callback) callback(_self.view.getData());
  811. this.close();
  812. }
  813. },
  814. {
  815. "text": MWF.LP.process.button.cancel,
  816. "action": function(){this.close();}
  817. }
  818. ]
  819. });
  820. dlg.show();
  821. if (layout.mobile){
  822. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  823. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  824. if (backAction) backAction.addEvent("click", function(e){
  825. dlg.close();
  826. }.bind(this));
  827. if (okAction) okAction.addEvent("click", function(e){
  828. //if (callback) callback(this.view.selectedItems);
  829. if (callback) callback(this.view.getData());
  830. dlg.close();
  831. }.bind(this));
  832. }
  833. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  834. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  835. }.bind(this));
  836. }.bind(this));
  837. }
  838. }
  839. };
  840. //include 引用脚本
  841. //optionsOrName : {
  842. // type : "", 默认为process, 可以为 portal process cms
  843. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  844. // name : "" // 脚本名称/别名/id
  845. //}
  846. //或者name: "" // 脚本名称/别名/id
  847. // if( !window.includedScripts ){
  848. // var includedScripts = window.includedScripts = [];
  849. // }else{
  850. // var includedScripts = window.includedScripts;
  851. // }
  852. var includedScripts = [];
  853. this.include = function( optionsOrName , callback ){
  854. var options = optionsOrName;
  855. if( typeOf( options ) == "string" ){
  856. options = { name : options };
  857. }
  858. var name = options.name;
  859. var type = ( options.type && options.application ) ? options.type : "process";
  860. var application = options.application || _form.json.application;
  861. var key = type +"-" + application + "-" + name;
  862. if (includedScripts.indexOf( key )> -1){
  863. if (callback) callback.apply(this);
  864. return;
  865. }
  866. //if (includedScripts.indexOf( name )> -1){
  867. // if (callback) callback.apply(this);
  868. // return;
  869. //}
  870. var scriptAction;
  871. switch ( type ){
  872. case "portal" :
  873. if( this.scriptActionPortal ){
  874. scriptAction = this.scriptActionPortal;
  875. }else{
  876. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  877. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  878. }
  879. break;
  880. case "process" :
  881. if( this.scriptActionProcess ){
  882. scriptAction = this.scriptActionProcess;
  883. }else{
  884. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  885. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  886. }
  887. break;
  888. case "cms" :
  889. if( this.scriptActionCMS ){
  890. scriptAction = this.scriptActionCMS;
  891. }else{
  892. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  893. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  894. }
  895. break;
  896. }
  897. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  898. if (json.data){
  899. includedScripts.push( key );
  900. includedScripts = includedScripts.concat(json.data.importedList);
  901. MWF.Macro.exec(json.data.text, this);
  902. if (callback) callback.apply(this);
  903. }else{
  904. if (callback) callback.apply(this);
  905. }
  906. }.bind(this), null, false);
  907. };
  908. this.define = function(name, fun, overwrite){
  909. var over = true;
  910. if (overwrite===false) over = false;
  911. var o = {};
  912. o[name] = {"value": fun, "configurable": over};
  913. MWF.defineProperties(this, o);
  914. }.bind(this);
  915. //仅前台对象-----------------------------------------
  916. //form
  917. this.form = {
  918. "getInfor": function(){return ev.formInfor;},
  919. "infor": ev.formInfor,
  920. "getApp": function(){return _form.app;},
  921. "app": _form.app,
  922. "node": function(){return _form.node;},
  923. "readonly": _form.options.readonly,
  924. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  925. "getField": function(name){return _forms[name];},
  926. "getAction": function(){return _form.workAction},
  927. "getDesktop": function(){return _form.app.desktop},
  928. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  929. "save": function(callback){_form.saveWork(callback);},
  930. "close": function(){_form.closeWork();},
  931. "verify": function(){
  932. return !(!_form.formCustomValidation("", "") | !_form.formValidation("", ""));
  933. },
  934. "process": function(option){
  935. var op = _form.getOpinion();
  936. var mds = op.medias;
  937. if (option){
  938. _form.submitWork(option.routeName, option.opinion, mds, option.callback, option.processor, null, option.appendTaskIdentityList);
  939. }else{
  940. _form.processWork();
  941. }
  942. },
  943. "reset": function(option){
  944. if (!option){
  945. if (_form.businessData.control["allowReset"]) _form.resetWork();
  946. }else{
  947. _form.resetWorkToPeson(option.names, option.opinion, option.success, option.failure);
  948. }
  949. },
  950. "retract": function(option){
  951. if (!option){
  952. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  953. }else{
  954. _form.doRetractWork(option.success, option.failure);
  955. }
  956. },
  957. "addSplit": function(option){
  958. if (!option){
  959. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  960. }else{
  961. _form.addSplitWork(option.value, option.success, option.failure);
  962. }
  963. },
  964. "rollback": function(option){
  965. if (!option){
  966. if (_form.businessData.control["allowRollback"]) _form.rollback();
  967. }else{
  968. _form.doRollbackActionInvoke(option.log, option.success, option.failure);
  969. }
  970. },
  971. "print": function(application, form){
  972. if (arguments.length){
  973. var app = (arguments.length>1) ? arguments[0] : null;
  974. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  975. _form.printWork(app, formName);
  976. }else{
  977. _form.printWork();
  978. }
  979. },
  980. "deleteWork": function(option){
  981. if (!option){
  982. if (_form.businessData.control["allowDeleteWork"]) _form.deleteWork();
  983. }else{
  984. _form.doDeleteWork(option.success, option.failure);
  985. }
  986. },
  987. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  988. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  989. var p = MWF.getCenter({"x": width, "y": height});
  990. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  991. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  992. }else{
  993. e = (arguments.length>1) ? arguments[1] : null;
  994. title = (arguments.length>2) ? arguments[2] : null;
  995. text = (arguments.length>3) ? arguments[3] : null;
  996. width = (arguments.length>4) ? arguments[4] : null;
  997. height = (arguments.length>5) ? arguments[5] : null;
  998. ok = (arguments.length>6) ? arguments[6] : null;
  999. cancel = (arguments.length>7) ? arguments[7] : null;
  1000. callback = (arguments.length>8) ? arguments[8] : null;
  1001. mask = (arguments.length>9) ? arguments[9] : null;
  1002. style = (arguments.length>10) ? arguments[10] : null;
  1003. // var p = MWF.getCenter({"x": width, "y": height});
  1004. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1005. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1006. }
  1007. },
  1008. "alert": function(type, title, text, width, height){
  1009. _form.alert(type, title, text, width, height);
  1010. },
  1011. "notice": function(content, type, target, where, offset, option){
  1012. _form.notice(content, type, target, where, offset, option);
  1013. },
  1014. "addEvent": function(e, f){_form.addEvent(e, f);},
  1015. "openWindow": function(application, form){
  1016. if (arguments.length){
  1017. var app = (arguments.length>1) ? arguments[0] : null;
  1018. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1019. _form.openWindow(formName, app);
  1020. }else{
  1021. _form.openWindow();
  1022. }
  1023. },
  1024. "openWork": function(id, completedId, title, options){
  1025. var op = options || {};
  1026. op.workId = id;
  1027. op.workCompletedId = completedId;
  1028. op.docTitle = title;
  1029. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1030. return layout.desktop.openApplication(this.event, "process.Work", op);
  1031. },
  1032. "openJob": function(id, choice, options){
  1033. var workData = null;
  1034. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1035. if (json.data) workData = json.data;
  1036. }.bind(this), null, false);
  1037. if (workData){
  1038. var len = workData.workList.length + workData.workCompletedList.length;
  1039. if (len){
  1040. if (len>1 && choice){
  1041. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1042. workData.workList.each(function(work){
  1043. var workNode = new Element("div", {
  1044. "styles": {
  1045. "background": "#ffffff",
  1046. "border-radius": "10px",
  1047. "clear": "both",
  1048. "margin-bottom": "10px",
  1049. "height": "40px",
  1050. "padding": "10px 10px"
  1051. }
  1052. }).inject(node);
  1053. var html = "<div style='height: 40px; width: 40px; float: left; background: url(/x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1054. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1055. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1056. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1057. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1058. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1059. workNode.set("html", html);
  1060. var action = workNode.getElement(".MWFAction");
  1061. action.store("work", work);
  1062. action.addEvent("click", function(e){
  1063. var work = e.target.retrieve("work");
  1064. if (work) this.openWork(work.id, null, work.title, options);
  1065. dlg.close();
  1066. }.bind(this));
  1067. }.bind(this));
  1068. workData.workCompletedList.each(function(work){
  1069. var workNode = new Element("div", {
  1070. "styles": {
  1071. "background": "#ffffff",
  1072. "border-radius": "10px",
  1073. "clear": "both",
  1074. "margin-bottom": "10px",
  1075. "height": "40px",
  1076. "padding": "10px 10px"
  1077. }
  1078. }).inject(node);
  1079. var html = "<div style='height: 40px; width: 40px; float: left; background: url(/x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1080. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1081. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1082. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1083. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1084. workNode.set("html", html);
  1085. var action = workNode.getElement(".MWFAction");
  1086. action.store("work", work);
  1087. action.addEvent("click", function(e){
  1088. var work = e.target.retrieve("work");
  1089. if (work) this.openWork(null, work.id, work.title, options);
  1090. dlg.close();
  1091. }.bind(this));
  1092. }.bind(this));
  1093. var height = node.getSize().y+20;
  1094. if (height>600) height = 600;
  1095. var dlg = o2.DL.open({
  1096. "title": o2.LP.widget.choiceWork,
  1097. "style" : "user",
  1098. "isResize": false,
  1099. "content": node,
  1100. "buttonList": [
  1101. {
  1102. "type" : "cancel",
  1103. "text": o2.LP.widget.close,
  1104. "action": function(){dlg.close();}
  1105. }
  1106. ]
  1107. });
  1108. }else{
  1109. if (workData.workList.length){
  1110. var work = workData.workList[0];
  1111. return this.openWork(work.id, null, work.title, options);
  1112. }else{
  1113. var work = workData.workCompletedList[0];
  1114. return this.openWork(null, work.id, work.title, options);
  1115. }
  1116. }
  1117. }
  1118. }
  1119. // var op = options || {};
  1120. // op.workId = id;
  1121. // op.workCompletedId = completedId;
  1122. // op.docTitle = title;
  1123. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1124. // layout.desktop.openApplication(this.event, "process.Work", op);
  1125. },
  1126. "openDocument": function(id, title, options){
  1127. var op = options || {};
  1128. op.documentId = id;
  1129. op.docTitle = title;
  1130. layout.desktop.openApplication(this.event, "cms.Document", op);
  1131. },
  1132. "openPortal": function(name, page, par){
  1133. var action = MWF.Actions.get("x_portal_assemble_surface");
  1134. action.getApplication(name, function(json){
  1135. if (json.data){
  1136. if (page){
  1137. action.getPageByName(page, json.data.id, function(pageJson){
  1138. layout.desktop.openApplication(null, "portal.Portal", {
  1139. "portalId": json.data.id,
  1140. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1141. "parameters": par,
  1142. "appId": "portal.Portal"+json.data.id
  1143. })
  1144. });
  1145. }else{
  1146. layout.desktop.openApplication(null, "portal.Portal", {
  1147. "portalId": json.data.id,
  1148. "parameters": par,
  1149. "appId": "portal.Portal"+json.data.id
  1150. })
  1151. }
  1152. }
  1153. });
  1154. },
  1155. "openCMS": function(name){
  1156. var action = MWF.Actions.get("x_cms_assemble_control");
  1157. action.getColumn(name, function(json){
  1158. if (json.data){
  1159. layout.desktop.openApplication(null, "cms.Module", {
  1160. "columnId": json.data.id,
  1161. "appId": "cms.Module"+json.data.id
  1162. });
  1163. }
  1164. });
  1165. },
  1166. "openProcess": function(name){
  1167. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1168. action.getApplication(name, function(json){
  1169. if (json.data){
  1170. layout.desktop.openApplication(null, "process.Application", {
  1171. "id": json.data.id,
  1172. "appId": "process.Application"+json.data.id
  1173. });
  1174. }
  1175. });
  1176. },
  1177. "openApplication":function(name, options){
  1178. layout.desktop.openApplication(null, name, options);
  1179. },
  1180. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  1181. var column = columnOrOptions;
  1182. if( typeOf( columnOrOptions ) == "object" ){
  1183. column = columnOrOptions.column;
  1184. category = columnOrOptions.category;
  1185. data = columnOrOptions.data;
  1186. identity = columnOrOptions.identity;
  1187. callback = columnOrOptions.callback;
  1188. target = columnOrOptions.target;
  1189. latest = columnOrOptions.latest;
  1190. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1191. ignoreTitle = columnOrOptions.ignoreTitle;
  1192. }
  1193. if (target){
  1194. if (layout.app && layout.app.inBrowser){
  1195. layout.app.content.empty();
  1196. layout.app = null;
  1197. }
  1198. }
  1199. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  1200. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1201. "documentData": data,
  1202. "identity": identity,
  1203. "ignoreTitle" : ignoreTitle === true,
  1204. "ignoreDrafted" : latest === false,
  1205. "selectColumnEnable" : !category || selectColumnEnable === true,
  1206. "restrictToColumn" : !!category && selectColumnEnable !== true,
  1207. "categoryFlag" : category, //category id or name
  1208. "columnFlag" : column, //column id or name,
  1209. "onStarted" : function( documentId, data ){
  1210. if(callback)callback();
  1211. },
  1212. "onPostLoad" : function(){
  1213. },
  1214. "onPostPublish" : function(){
  1215. }
  1216. });
  1217. starter.load();
  1218. })
  1219. },
  1220. "startProcess": function(app, process, data, identity, callback, target, latest){
  1221. if (arguments.length>2){
  1222. for (var i=2; i<arguments.length; i++){
  1223. if (typeOf(arguments[i])=="boolean"){
  1224. target = arguments[i];
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. if (target){
  1230. if (layout.app && layout.app.inBrowser){
  1231. //layout.app.content.empty();
  1232. layout.app.$openWithSelf = true;
  1233. }
  1234. }
  1235. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1236. if (json.data){
  1237. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1238. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1239. "workData": data,
  1240. "identity": identity,
  1241. "latest": latest,
  1242. "onStarted": function(data, title, processName){
  1243. var currentTask = [];
  1244. data.each(function(work){
  1245. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1246. }.bind(this));
  1247. if (currentTask.length==1){
  1248. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1249. layout.desktop.openApplication(null, "process.Work", options);
  1250. }else{}
  1251. if (callback) callback(data);
  1252. }.bind(this)
  1253. });
  1254. starter.load();
  1255. }.bind(this));
  1256. }
  1257. });
  1258. }
  1259. };
  1260. this.form.currentRouteName = _form.json.currentRouteName;
  1261. this.form.opinion = _form.json.opinion;
  1262. this.target = ev.target;
  1263. this.event = ev.event;
  1264. this.status = ev.status;
  1265. this.session = layout.desktop.session;
  1266. this.Actions = o2.Actions;
  1267. this.query = function(option){
  1268. // options = {
  1269. // "name": "statementName",
  1270. // "data": "json data",
  1271. // "firstResult": 1,
  1272. // "maxResults": 100,
  1273. // "success": function(){},
  1274. // "error": function(){},
  1275. // "async": true or false, default is true
  1276. // }
  1277. if (option){
  1278. var json = (option.data) || {};
  1279. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1280. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1281. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1282. }
  1283. }
  1284. this.Table = MWF.xScript.createTable();
  1285. };
  1286. MWF.xScript.createTable = function(){
  1287. return function(name){
  1288. this.name = name;
  1289. this.action = o2.Actions.get("x_query_assemble_surface");
  1290. this.listRowNext = function(id, count, success, error, async){
  1291. this.action.listRowNext(this.name, id, count, success, error, async);
  1292. };
  1293. this.listRowPrev = function(id, count, success, error, async){
  1294. this.action.listRowPrev(this.name, id, count, success, error, async);
  1295. };
  1296. this.listRowPrev = function(id, count, success, error, async){
  1297. this.action.listRowPrev(this.name, id, count, success, error, async);
  1298. };
  1299. this.listRowSelectWhere = function(where, success, error, async){
  1300. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1301. };
  1302. this.listRowCountWhere = function(where, success, error, async){
  1303. this.action.listRowCountWhere(this.name, where, success, error, async);
  1304. };
  1305. this.deleteRow = function(id, success, error, async){
  1306. this.action.deleteRow(this.name, id, success, error, async);
  1307. };
  1308. this.deleteAllRow = function(success, error, async){
  1309. this.action.deleteAllRow(this.name, success, error, async);
  1310. };
  1311. this.getRow = function(id, success, error, async){
  1312. this.action.getRow(this.name, id, success, error, async);
  1313. };
  1314. this.insertRow = function(data, success, error, async){
  1315. this.action.insertRow(this.name, data, success, error, async);
  1316. };
  1317. this.updateRow = function(id, data, success, error, async){
  1318. this.action.updateRow(this.name, id, data, success, error, async);
  1319. };
  1320. }
  1321. };
  1322. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1323. var getter = function(data, callback, k, _self){
  1324. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1325. };
  1326. var setter = function(data, callback, k, _self){
  1327. return function(v){
  1328. data[k] = v;
  1329. //debugger;
  1330. //this.add(k, v, true);
  1331. if (callback) callback(data, k, _self);
  1332. }
  1333. };
  1334. var define = function(){
  1335. var o = {};
  1336. for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
  1337. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1338. MWF.defineProperties(this, o);
  1339. var methods = {
  1340. "getKey": {"value": function(){ return key; }},
  1341. "getParent": {"value": function(){ return parent; }},
  1342. "toString": {"value": function() { return data.toString();}},
  1343. "setSection": {"value": function(newKey, newValue){
  1344. this.add(newKey, newValue, true);
  1345. try {
  1346. var path = [this.getKey()];
  1347. p = this.getParent();
  1348. while (p && p.getKey()){
  1349. path.unshift(p.getKey());
  1350. p = p.getParent();
  1351. }
  1352. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1353. }catch(e){
  1354. debugger;
  1355. }
  1356. }},
  1357. "add": {"value": function(newKey, newValue, overwrite){
  1358. var flag = true;
  1359. var type = typeOf(data);
  1360. if (type==="array"){
  1361. if (arguments.length<2){
  1362. data.push(newKey);
  1363. newValue = newKey;
  1364. newKey = data.length-1;
  1365. }else{
  1366. if (!newKey && newKey!==0){
  1367. data.push(newValue);
  1368. newKey = data.length-1;
  1369. }else{
  1370. flag = false;
  1371. }
  1372. }
  1373. if (flag){
  1374. var o = {};
  1375. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1376. MWF.defineProperties(this, o);
  1377. }
  1378. this[newKey] = newValue;
  1379. }else if (type==="object"){
  1380. if (!this.hasOwnProperty(newKey)){
  1381. data[newKey] = newValue;
  1382. if (flag){
  1383. var o = {};
  1384. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1385. MWF.defineProperties(this, o);
  1386. }
  1387. this[newKey] = newValue;
  1388. }else{
  1389. if (overwrite) this[newKey] = newValue;
  1390. }
  1391. }
  1392. return this[newKey];
  1393. }},
  1394. "del": {"value": function(delKey){
  1395. if (!this.hasOwnProperty(delKey)) return null;
  1396. delete data[delKey];
  1397. delete this[delKey];
  1398. return this;
  1399. }}
  1400. };
  1401. MWF.defineProperties(this, methods);
  1402. //this.getKey = function(){ return key; };
  1403. //this.getParent = function(){ return parent; };
  1404. //this.toString = function() { return data.toString();};
  1405. //this.add = function(newKey, newValue, overwrite){
  1406. // var flag = true;
  1407. // var type = typeOf(data);
  1408. // if (!this.hasOwnProperty(newKey)){
  1409. // if (type=="array"){
  1410. // if (arguments.length<2){
  1411. // data.push(newKey);
  1412. // newValue = newKey;
  1413. // newKey = data.length-1;
  1414. // }else{
  1415. // debugger;
  1416. // if (!newKey && newKey!=0){
  1417. // data.push(newValue);
  1418. // newKey = data.length-1;
  1419. // }else{
  1420. // flag == false;
  1421. // }
  1422. // }
  1423. // }else{
  1424. // data[newKey] = newValue;
  1425. // }
  1426. // //var valueType = typeOf(newValue);
  1427. // //var newValueData = newValue;
  1428. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1429. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1430. // if (flag){
  1431. // var o = {};
  1432. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1433. // MWF.defineProperties(this, o);
  1434. // }
  1435. // this[newKey] = newValue;
  1436. // }else{
  1437. // if (overwrite) this[newKey] = newValue;
  1438. // }
  1439. //
  1440. // //var valueType = typeOf(newValue);
  1441. // //var newValueData = newValue;
  1442. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1443. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1444. // //
  1445. // //this[newKey] = newValueData;
  1446. //
  1447. // return this[newKey];
  1448. //};
  1449. //this.del = function(delKey){
  1450. // if (!this.hasOwnProperty(delKey)) return null;
  1451. // delete data[newKey];
  1452. // delete this[newKey];
  1453. // return this;
  1454. //};
  1455. };
  1456. var type = typeOf(data);
  1457. if (type==="object" || type==="array") define.apply(this);
  1458. };
  1459. //MWF.xScript.createDict = function(application){
  1460. // return function(name){
  1461. // var applicationId = application;
  1462. // this.name = name;
  1463. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1464. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1465. //
  1466. // this.get = function(path, success, failure){
  1467. // debugger;
  1468. // var value = null;
  1469. // if (path){
  1470. // var arr = path.split(/\./g);
  1471. // var ar = arr.map(function(v){
  1472. // return encodeURIComponent(v);
  1473. // });
  1474. // //var p = path.replace(/\./g, "/");
  1475. // var p = ar.join("/");
  1476. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1477. // value = json.data;
  1478. // if (success) success(json.data);
  1479. // }, function(xhr, text, error){
  1480. // if (failure) failure(xhr, text, error);
  1481. // }, false);
  1482. // }else{
  1483. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1484. // value = json.data;
  1485. // if (success) success(json.data);
  1486. // }, function(xhr, text, error){
  1487. // if (failure) failure(xhr, text, error);
  1488. // }, false);
  1489. // }
  1490. //
  1491. // return value;
  1492. // };
  1493. //
  1494. // this.set = function(path, value, success, failure){
  1495. // var p = path.replace(/\./g, "/");
  1496. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1497. // if (success) success(json.data);
  1498. // }, function(xhr, text, error){
  1499. // if (failure) failure(xhr, text, error);
  1500. // });
  1501. // };
  1502. // this.add = function(path, value, success, failure){
  1503. // var p = path.replace(/\./g, "/");
  1504. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1505. // if (success) success(json.data);
  1506. // }, function(xhr, text, error){
  1507. // if (failure) failure(xhr, text, error);
  1508. // });
  1509. // };
  1510. // this["delete"] = function(path, success, failure){
  1511. // var p = path.replace(/\./g, "/");
  1512. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1513. // if (success) success(json.data);
  1514. // }, function(xhr, text, error){
  1515. // if (failure) failure(xhr, text, error);
  1516. // });
  1517. // };
  1518. // this.destory = this["delete"];
  1519. // }
  1520. //};
  1521. MWF.xScript.createDict = function(application){
  1522. //optionsOrName : {
  1523. // type : "", //默认为process, 可以为 process cms
  1524. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1525. // name : "", // 数据字典名称/别名/id
  1526. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1527. //}
  1528. //或者name: "" // 数据字典名称/别名/id
  1529. return function(optionsOrName){
  1530. var options = optionsOrName;
  1531. if( typeOf( options ) == "string" ){
  1532. options = { name : options };
  1533. }
  1534. var name = this.name = options.name;
  1535. var type = ( options.type && options.application ) ? options.type : "process";
  1536. var applicationId = options.application || application;
  1537. var enableAnonymous = options.enableAnonymous || false;
  1538. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1539. if( type == "cms" ){
  1540. var action = MWF.Actions.get("x_cms_assemble_control");
  1541. }else{
  1542. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1543. }
  1544. var encodePath = function( path ){
  1545. var arr = path.split(/\./g);
  1546. var ar = arr.map(function(v){
  1547. return encodeURIComponent(v);
  1548. });
  1549. return ar.join("/");
  1550. };
  1551. this.get = function(path, success, failure){
  1552. var value = null;
  1553. if (path){
  1554. var p = encodePath( path );
  1555. //var p = path.replace(/\./g, "/");
  1556. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1557. value = json.data;
  1558. if (success) success(json.data);
  1559. }, function(xhr, text, error){
  1560. if (failure) failure(xhr, text, error);
  1561. }, false, false);
  1562. }else{
  1563. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1564. value = json.data;
  1565. if (success) success(json.data);
  1566. }, function(xhr, text, error){
  1567. if (failure) failure(xhr, text, error);
  1568. }, false);
  1569. }
  1570. return value;
  1571. };
  1572. this.set = function(path, value, success, failure){
  1573. var p = encodePath( path );
  1574. //var p = path.replace(/\./g, "/");
  1575. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1576. if (success) success(json.data);
  1577. }, function(xhr, text, error){
  1578. if (failure) failure(xhr, text, error);
  1579. }, false, false);
  1580. };
  1581. this.add = function(path, value, success, failure){
  1582. var p = encodePath( path );
  1583. //var p = path.replace(/\./g, "/");
  1584. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1585. if (success) success(json.data);
  1586. }, function(xhr, text, error){
  1587. if (failure) failure(xhr, text, error);
  1588. }, false, false);
  1589. };
  1590. this["delete"] = function(path, success, failure){
  1591. var p = encodePath( path );
  1592. //var p = path.replace(/\./g, "/");
  1593. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1594. if (success) success(json.data);
  1595. }, function(xhr, text, error){
  1596. if (failure) failure(xhr, text, error);
  1597. }, false, false);
  1598. };
  1599. this.destory = this["delete"];
  1600. }
  1601. };