Environment.js 66 KB

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