Environment.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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.id, 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.id, 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. //name string 属性名
  388. //value string 属性值
  389. listPersonWithAttribute: function(name, value){
  390. getOrgActions();
  391. var data = {"name": name, "attribute": value};
  392. var v = null;
  393. orgActions.listPersonWithAttribute(data, function(json){v = json.data;}, null, false);
  394. return v;
  395. },
  396. //根据属性查询人员--返回人员的全称数组
  397. //name string 属性名
  398. //value string 属性值
  399. listPersonNameWithAttribute: function(name, value){
  400. getOrgActions();
  401. var data = {"name": name, "attribute": value};
  402. var v = null;
  403. orgActions.listPersonWithAttributeValue(data, function(json){v = json.data.personList;}, null, false);
  404. return v;
  405. },
  406. //人员属性************
  407. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  408. appendPersonAttribute: function(person, attr, values){
  409. getOrgActions();
  410. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  411. var data = {"attributeList":values,"name":attr,"person":personFlag};
  412. orgActions.appendPersonAttribute(data, function(json){
  413. if (json.data.value){
  414. if (success) success();
  415. }else{
  416. if (failure) failure(null, "", "append values failed");
  417. }
  418. }, function(xhr, text, error){
  419. if (failure) failure(xhr, text, error);
  420. }, false);
  421. },
  422. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  423. setPersonAttribute: function(person, attr, values){
  424. getOrgActions();
  425. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  426. var data = {"attributeList":values,"name":attr,"person":personFlag};
  427. orgActions.setPersonAttribute(data, function(json){
  428. if (json.data.value){
  429. if (success) success();
  430. }else{
  431. if (failure) failure(null, "", "append values failed");
  432. }
  433. }, function(xhr, text, error){
  434. if (failure) failure(xhr, text, error);
  435. }, false);
  436. },
  437. //获取人员属性值
  438. getPersonAttribute: function(person, attr){
  439. getOrgActions();
  440. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  441. var data = {"name":attr,"person":personFlag};
  442. var v = null;
  443. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  444. return v;
  445. },
  446. //列出人员所有属性的名称
  447. listPersonAttributeName: function(name){
  448. getOrgActions();
  449. var data = {"personList":getNameFlag(name)};
  450. var v = null;
  451. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  452. return v;
  453. },
  454. //列出人员的所有属性
  455. listPersonAllAttribute: function(name){
  456. getOrgActions();
  457. var data = {"personList":getNameFlag(name)};
  458. var v = null;
  459. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  460. return v;
  461. },
  462. //身份**********
  463. //获取身份
  464. getIdentity: function(name){
  465. getOrgActions();
  466. var data = {"identityList":getNameFlag(name)};
  467. var v = null;
  468. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  469. return (v && v.length===1) ? v[0] : v;
  470. },
  471. //列出人员的身份
  472. listIdentityWithPerson: function(name){
  473. getOrgActions();
  474. var data = {"personList":getNameFlag(name)};
  475. var v = null;
  476. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  477. return v;
  478. },
  479. //查询组织成员身份--返回身份的对象数组
  480. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  481. listIdentityWithUnit: function(name, nested){
  482. getOrgActions();
  483. var data = {"unitList": getNameFlag(name)};
  484. var v = null;
  485. if (nested){
  486. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  487. }else{
  488. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  489. }
  490. return v;
  491. },
  492. //组织**********
  493. //获取组织
  494. getUnit: function(name){
  495. getOrgActions();
  496. var data = {"unitList":getNameFlag(name)};
  497. var v = null;
  498. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  499. return (v && v.length===1) ? v[0] : v;
  500. },
  501. //查询组织的下级--返回组织的对象数组
  502. //nested 布尔 true嵌套下级;false直接下级;默认false;
  503. listSubUnit: function(name, nested){
  504. getOrgActions();
  505. var data = {"unitList": getNameFlag(name)};
  506. var v = null;
  507. if (nested){
  508. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  509. }else{
  510. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  511. }
  512. return v;
  513. },
  514. //查询组织的上级--返回组织的对象数组
  515. //nested 布尔 true嵌套上级;false直接上级;默认false;
  516. listSupUnit: function(name, nested){
  517. getOrgActions();
  518. var data = {"unitList": getNameFlag(name)};
  519. var v = null;
  520. if (nested){
  521. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  522. }else{
  523. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  524. }
  525. return v;
  526. },
  527. //根据个人身份获取组织
  528. //flag 数字 表示获取第几层的组织
  529. // 字符串 表示获取指定类型的组织
  530. // 空 表示获取直接所在的组织
  531. getUnitByIdentity: function(name, flag){
  532. getOrgActions();
  533. var getUnitMethod = "current";
  534. var v;
  535. if (flag){
  536. if (typeOf(flag)==="string") getUnitMethod = "type";
  537. if (typeOf(flag)==="number") getUnitMethod = "level";
  538. }
  539. switch (getUnitMethod){
  540. case "current":
  541. var data = {"identityList":getNameFlag(name)};
  542. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, null, false);
  543. break;
  544. case "type":
  545. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  546. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  547. break;
  548. case "level":
  549. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  550. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  551. break;
  552. }
  553. return v;
  554. },
  555. //列出身份所在组织的所有上级组织
  556. listAllSupUnitWithIdentity: function(name){
  557. getOrgActions();
  558. var data = {"identityList":getNameFlag(name)};
  559. var v = null;
  560. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  561. return v;
  562. },
  563. //获取人员所在的所有组织
  564. listUnitWithPerson: function(name){
  565. getOrgActions();
  566. var data = {"personList":getNameFlag(name)};
  567. var v = null;
  568. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  569. return v;
  570. },
  571. //列出人员所在组织的所有上级组织
  572. listAllSupUnitWithPerson: function(name){
  573. getOrgActions();
  574. var data = {"personList":getNameFlag(name)};
  575. var v = null;
  576. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  577. return v;
  578. },
  579. //根据组织属性,获取所有符合的组织
  580. listUnitWithAttribute: function(name, attribute){
  581. getOrgActions();
  582. var data = {"name":name,"attribute":attribute};
  583. var v = null;
  584. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  585. return v;
  586. },
  587. //根据组织职务,获取所有符合的组织
  588. listUnitWithDuty: function(name, id){
  589. getOrgActions();
  590. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  591. var v = null;
  592. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  593. return v;
  594. },
  595. //组织职务***********
  596. //获取指定的组织职务的身份
  597. getDuty: function(duty, id){
  598. getOrgActions();
  599. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  600. var v = null;
  601. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  602. return v;
  603. },
  604. //获取身份的所有职务名称
  605. listDutyNameWithIdentity: function(name){
  606. getOrgActions();
  607. var data = {"identityList":getNameFlag(name)};
  608. var v = null;
  609. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  610. return v;
  611. },
  612. //获取组织的所有职务名称
  613. listDutyNameWithUnit: function(name){
  614. getOrgActions();
  615. var data = {"unitList":getNameFlag(name)};
  616. var v = null;
  617. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  618. return v;
  619. },
  620. //获取组织的所有职务
  621. listUnitAllDuty: function(name){
  622. getOrgActions();
  623. var data = {"unitList":getNameFlag(name)};
  624. var v = null;
  625. orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  626. return v;
  627. },
  628. //列出顶层组织
  629. listTopUnit: function(){
  630. var action = MWF.Actions.get("x_organization_assemble_control");
  631. var v = null;
  632. action.listTopUnit(function(json){
  633. v = json.data;
  634. }, null, false);
  635. return v;
  636. },
  637. //组织属性**************
  638. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  639. appendUnitAttribute: function(unit, attr, values){
  640. getOrgActions();
  641. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  642. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  643. orgActions.appendUnitAttribute(data, function(json){
  644. if (json.data.value){
  645. if (success) success();
  646. }else{
  647. if (failure) failure(null, "", "append values failed");
  648. }
  649. }, function(xhr, text, error){
  650. if (failure) failure(xhr, text, error);
  651. }, false);
  652. },
  653. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  654. setUnitAttribute: function(unit, attr, values){
  655. getOrgActions();
  656. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  657. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  658. orgActions.setUnitAttribute(data, function(json){
  659. if (json.data.value){
  660. if (success) success();
  661. }else{
  662. if (failure) failure(null, "", "append values failed");
  663. }
  664. }, function(xhr, text, error){
  665. if (failure) failure(xhr, text, error);
  666. }, false);
  667. },
  668. //获取组织属性值
  669. getUnitAttribute: function(unit, attr){
  670. getOrgActions();
  671. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  672. var data = {"name":attr,"unit":unitFlag};
  673. var v = null;
  674. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  675. return v;
  676. },
  677. //列出组织所有属性的名称
  678. listUnitAttributeName: function(name){
  679. getOrgActions();
  680. var data = {"unitList":getNameFlag(name)};
  681. var v = null;
  682. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  683. return v;
  684. },
  685. //列出组织的所有属性
  686. listUnitAllAttribute: function(name){
  687. getOrgActions();
  688. var data = {"unitList":getNameFlag(name)};
  689. var v = null;
  690. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  691. return v;
  692. }
  693. };
  694. this.Action = (function(){
  695. var actions = [];
  696. return function(root, json){
  697. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  698. action.getActions = function(callback){
  699. if (!this.actions) this.actions = {};
  700. Object.merge(this.actions, json);
  701. if (callback) callback();
  702. };
  703. this.invoke = function(option){
  704. action.invoke(option)
  705. }
  706. }
  707. })();
  708. this.service = {
  709. "jaxwsClient":{},
  710. "jaxrsClient":{}
  711. };
  712. var lookupAction = null;
  713. var getLookupAction = function(callback){
  714. if (!lookupAction){
  715. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  716. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  717. lookupAction.getActions = function(actionCallback){
  718. this.actions = {
  719. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  720. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  721. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  722. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  723. };
  724. if (actionCallback) actionCallback();
  725. };
  726. if (callback) callback();
  727. });
  728. }else{
  729. if (callback) callback();
  730. }
  731. };
  732. this.view = {
  733. "lookup": function(view, callback, async){
  734. var filterList = {"filterList": (view.filter || null)};
  735. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  736. var data = {
  737. "grid": json.data.grid || json.data.groupGrid,
  738. "groupGrid": json.data.groupGrid
  739. };
  740. if (callback) callback(data);
  741. }, null, async);
  742. },
  743. "lookupV1": function(view, callback){
  744. getLookupAction(function(){
  745. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  746. var data = {
  747. "grid": json.data.grid,
  748. "groupGrid": json.data.groupGrid
  749. };
  750. if (callback) callback(data);
  751. }.bind(this)});
  752. }.bind(this));
  753. },
  754. "select": function(view, callback, options){
  755. if (view.view){
  756. var viewJson = {
  757. "application": view.application || _form.json.application,
  758. "viewName": view.view || "",
  759. "isTitle": (view.isTitle===false) ? "no" : "yes",
  760. "select": (view.isMulti===false) ? "single" : "multi",
  761. "filter": view.filter
  762. };
  763. if (!options) options = {};
  764. options.width = view.width;
  765. options.height = view.height;
  766. options.title = view.caption;
  767. var width = options.width || "700";
  768. var height = options.height || "400";
  769. if (layout.mobile){
  770. var size = document.body.getSize();
  771. width = size.x;
  772. height = size.y;
  773. options.style = "viewmobile";
  774. }
  775. width = width.toInt();
  776. height = height.toInt();
  777. var size = _form.app.content.getSize();
  778. var x = (size.x-width)/2;
  779. var y = (size.y-height)/2;
  780. if (x<0) x = 0;
  781. if (y<0) y = 0;
  782. if (layout.mobile){
  783. x = 20;
  784. y = 0;
  785. }
  786. var _self = this;
  787. MWF.require("MWF.xDesktop.Dialog", function(){
  788. var dlg = new MWF.xDesktop.Dialog({
  789. "title": options.title || "select view",
  790. "style": options.style || "view",
  791. "top": y,
  792. "left": x-20,
  793. "fromTop":y,
  794. "fromLeft": x-20,
  795. "width": width,
  796. "height": height,
  797. "html": "<div style='height: 100%;'></div>",
  798. "maskNode": _form.app.content,
  799. "container": _form.app.content,
  800. "buttonList": [
  801. {
  802. "text": MWF.LP.process.button.ok,
  803. "action": function(){
  804. //if (callback) callback(_self.view.selectedItems);
  805. if (callback) callback(_self.view.getData());
  806. this.close();
  807. }
  808. },
  809. {
  810. "text": MWF.LP.process.button.cancel,
  811. "action": function(){this.close();}
  812. }
  813. ]
  814. });
  815. dlg.show();
  816. if (layout.mobile){
  817. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  818. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  819. if (backAction) backAction.addEvent("click", function(e){
  820. dlg.close();
  821. }.bind(this));
  822. if (okAction) okAction.addEvent("click", function(e){
  823. //if (callback) callback(this.view.selectedItems);
  824. if (callback) callback(this.view.getData());
  825. dlg.close();
  826. }.bind(this));
  827. }
  828. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  829. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  830. }.bind(this));
  831. }.bind(this));
  832. }
  833. }
  834. };
  835. //include 引用脚本
  836. //optionsOrName : {
  837. // type : "", 默认为process, 可以为 portal process cms
  838. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  839. // name : "" // 脚本名称/别名/id
  840. //}
  841. //或者name: "" // 脚本名称/别名/id
  842. if( !window.includedScripts ){
  843. var includedScripts = window.includedScripts = [];
  844. }else{
  845. var includedScripts = window.includedScripts;
  846. }
  847. this.include = function( optionsOrName , callback ){
  848. var options = optionsOrName;
  849. if( typeOf( options ) == "string" ){
  850. options = { name : options };
  851. }
  852. var name = options.name;
  853. var type = ( options.type && options.application ) ? options.type : "process";
  854. var application = options.application || _form.json.application;
  855. if (includedScripts.indexOf( name )> -1){
  856. if (callback) callback.apply(this);
  857. return;
  858. }
  859. var scriptAction;
  860. switch ( type ){
  861. case "portal" :
  862. if( this.scriptActionPortal ){
  863. scriptAction = this.scriptActionPortal;
  864. }else{
  865. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  866. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  867. }
  868. break;
  869. case "process" :
  870. if( this.scriptActionProcess ){
  871. scriptAction = this.scriptActionProcess;
  872. }else{
  873. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  874. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  875. }
  876. break;
  877. case "cms" :
  878. if( this.scriptActionCMS ){
  879. scriptAction = this.scriptActionCMS;
  880. }else{
  881. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  882. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  883. }
  884. break;
  885. }
  886. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  887. if (json.data){
  888. includedScripts = includedScripts.concat(json.data.importedList);
  889. MWF.Macro.exec(json.data.text, this);
  890. if (callback) callback.apply(this);
  891. }else{
  892. if (callback) callback.apply(this);
  893. }
  894. }.bind(this), null, false);
  895. };
  896. this.define = function(name, fun, overwrite){
  897. var over = true;
  898. if (overwrite===false) over = false;
  899. var o = {};
  900. o[name] = {"value": fun, "configurable": over};
  901. MWF.defineProperties(this, o);
  902. }.bind(this);
  903. //仅前台对象-----------------------------------------
  904. //form
  905. this.form = {
  906. "getInfor": function(){return ev.formInfor;},
  907. "infor": ev.formInfor,
  908. "getApp": function(){return _form.app;},
  909. "app": _form.app,
  910. "node": function(){return _form.node;},
  911. "readonly": _form.options.readonly,
  912. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  913. "getField": function(name){return _forms[name];},
  914. "getAction": function(){return _form.workAction},
  915. "getDesktop": function(){return _form.app.desktop},
  916. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  917. "save": function(callback){_form.saveWork(callback);},
  918. "close": function(){_form.closeWork();},
  919. "verify": function(){
  920. return !(!_form.formCustomValidation("", "") | !_form.formValidation("", ""));
  921. },
  922. "process": function(option){
  923. var op = _form.getOpinion();
  924. var mds = op.medias;
  925. if (option){
  926. _form.submitWork(option.routeName, option.opinion, mds, option.callback);
  927. }else{
  928. _form.processWork();
  929. }
  930. },
  931. "reset": function(option){
  932. if (!option){
  933. if (_form.businessData.control["allowReset"]) _form.resetWork();
  934. }else{
  935. _form.resetWorkToPeson(option.names, option.opinion, opinion.success, opinion.failure);
  936. }
  937. },
  938. "retract": function(option){
  939. if (!option){
  940. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  941. }else{
  942. _form.doRetractWork(opinion.success, opinion.failure);
  943. }
  944. },
  945. "addSplit": function(option){
  946. if (!option){
  947. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  948. }else{
  949. _form.addSplitWork(option.value, opinion.success, opinion.failure);
  950. }
  951. },
  952. "rollback": function(option){
  953. if (!option){
  954. if (_form.businessData.control["allowRollback"]) _form.rollback();
  955. }else{
  956. _form.doRollbackActionInvoke(option.log, opinion.success, opinion.failure);
  957. }
  958. },
  959. "print": function(application, form){
  960. if (arguments.length){
  961. var app = (arguments.length>1) ? arguments[0] : null;
  962. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  963. _form.printWork(app, formName);
  964. }else{
  965. _form.printWork();
  966. }
  967. },
  968. "deleteWork": function(option){
  969. if (!option){
  970. if (_form.businessData.control["allowDeleteWork"]) _form.deleteWork();
  971. }else{
  972. _form.doDeleteWork(opinion.success, opinion.failure);
  973. }
  974. },
  975. "confirm": function(type, title, text, width, height, ok, cancel, callback){
  976. var p = MWF.getCenter({"x": width, "y": height});
  977. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  978. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  979. },
  980. "notice": function(content, type, target, where){
  981. _form.notice(content, type, target, where);
  982. },
  983. "addEvent": function(e, f){_form.addEvent(e, f);},
  984. "openWindow": function(application, form){
  985. if (arguments.length){
  986. var app = (arguments.length>1) ? arguments[0] : null;
  987. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  988. _form.openWindow(formName, app);
  989. }else{
  990. _form.openWindow();
  991. }
  992. },
  993. "openWork": function(id, completedId, title, options){
  994. var op = options || {};
  995. op.workId = id;
  996. op.workCompletedId = completedId;
  997. op.docTitle = title;
  998. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  999. layout.desktop.openApplication(this.event, "process.Work", op);
  1000. },
  1001. "openJob": function(id, choice, options){
  1002. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1003. var len = json.data.workList.length + json.data.workCompletedList.length;
  1004. if (len){
  1005. if (len>1 && choice){
  1006. //@todo.........
  1007. //.............
  1008. //.............//.............
  1009. //.............//.............
  1010. }else{
  1011. if (json.data.workList.length){
  1012. var work = json.data.workList[0];
  1013. this.openWork(work.id, null, work.title, options);
  1014. }else{
  1015. var work = json.data.workCompletedList[0];
  1016. this.openWork(null, work.id, work.title, options);
  1017. }
  1018. }
  1019. }
  1020. }.bind(this));
  1021. // var op = options || {};
  1022. // op.workId = id;
  1023. // op.workCompletedId = completedId;
  1024. // op.docTitle = title;
  1025. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1026. // layout.desktop.openApplication(this.event, "process.Work", op);
  1027. },
  1028. "openDocument": function(id, title, options){
  1029. var op = options || {};
  1030. op.documentId = id;
  1031. op.docTitle = title;
  1032. layout.desktop.openApplication(this.event, "cms.Document", op);
  1033. },
  1034. "openPortal": function(name, page, par){
  1035. var action = MWF.Actions.get("x_portal_assemble_surface");
  1036. action.getApplication(name, function(json){
  1037. if (json.data){
  1038. if (page){
  1039. action.getPageByName(page, json.data.id, function(pageJson){
  1040. layout.desktop.openApplication(null, "portal.Portal", {
  1041. "portalId": json.data.id,
  1042. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1043. "parameters": par,
  1044. "appId": "portal.Portal"+json.data.id
  1045. })
  1046. });
  1047. }else{
  1048. layout.desktop.openApplication(null, "portal.Portal", {
  1049. "portalId": json.data.id,
  1050. "parameters": par,
  1051. "appId": "portal.Portal"+json.data.id
  1052. })
  1053. }
  1054. }
  1055. });
  1056. },
  1057. "openCMS": function(name){
  1058. var action = MWF.Actions.get("x_cms_assemble_control");
  1059. action.getColumn(name, function(json){
  1060. if (json.data){
  1061. layout.desktop.openApplication(null, "cms.Module", {
  1062. "columnId": json.data.id,
  1063. "appId": "cms.Module"+json.data.id
  1064. });
  1065. }
  1066. });
  1067. },
  1068. "openProcess": function(name){
  1069. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1070. action.getApplication(name, function(json){
  1071. if (json.data){
  1072. layout.desktop.openApplication(null, "process.Application", {
  1073. "id": json.data.id,
  1074. "appId": "process.Application"+json.data.id
  1075. });
  1076. }
  1077. });
  1078. },
  1079. "openApplication":function(name, options){
  1080. layout.desktop.openApplication(null, name, options);
  1081. },
  1082. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  1083. var column = columnOrOptions;
  1084. if( typeOf( columnOrOptions ) == "object" ){
  1085. column = columnOrOptions.column;
  1086. category = columnOrOptions.category;
  1087. data = columnOrOptions.data;
  1088. identity = columnOrOptions.identity;
  1089. callback = columnOrOptions.callback;
  1090. target = columnOrOptions.target;
  1091. latest = columnOrOptions.latest;
  1092. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1093. ignoreTitle = columnOrOptions.ignoreTitle;
  1094. }
  1095. if (target){
  1096. if (layout.app && layout.app.inBrowser){
  1097. layout.app.content.empty();
  1098. layout.app = null;
  1099. }
  1100. }
  1101. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  1102. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1103. "documentData": data,
  1104. "identity": identity,
  1105. "ignoreTitle" : ignoreTitle === true,
  1106. "ignoreDrafted" : latest === false,
  1107. "selectColumnEnable" : !category || selectColumnEnable === true,
  1108. "restrictToColumn" : !!category && selectColumnEnable !== true,
  1109. "categoryFlag" : category, //category id or name
  1110. "columnFlag" : column, //column id or name,
  1111. "onStarted" : function( documentId, data ){
  1112. if(callback)callback();
  1113. },
  1114. "onPostLoad" : function(){
  1115. },
  1116. "onPostPublish" : function(){
  1117. }
  1118. });
  1119. starter.load();
  1120. })
  1121. },
  1122. "startProcess": function(app, process, data, identity, callback, target, latest){
  1123. if (arguments.length>2){
  1124. for (var i=2; i<arguments.length; i++){
  1125. if (typeOf(arguments[i])=="boolean"){
  1126. target = arguments[i];
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. if (target){
  1132. if (layout.app && layout.app.inBrowser){
  1133. layout.app.content.empty();
  1134. layout.app = null;
  1135. }
  1136. }
  1137. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1138. if (json.data){
  1139. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1140. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1141. "workData": data,
  1142. "identity": identity,
  1143. "latest": latest,
  1144. "onStarted": function(data, title, processName){
  1145. var currentTask = [];
  1146. data.each(function(work){
  1147. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1148. }.bind(this));
  1149. if (currentTask.length==1){
  1150. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1151. layout.desktop.openApplication(null, "process.Work", options);
  1152. }else{}
  1153. if (callback) callback(data);
  1154. }.bind(this)
  1155. });
  1156. starter.load();
  1157. }.bind(this));
  1158. }
  1159. });
  1160. }
  1161. };
  1162. this.form.currentRouteName = _form.json.currentRouteName;
  1163. this.form.opinion = _form.json.opinion;
  1164. this.target = ev.target;
  1165. this.event = ev.event;
  1166. this.status = ev.status;
  1167. this.session = layout.desktop.session;
  1168. this.Actions = o2.Actions;
  1169. this.query = function(option){
  1170. // options = {
  1171. // "name": "statementName",
  1172. // "data": "json data",
  1173. // "firstResult": 1,
  1174. // "maxResults": 100,
  1175. // "success": function(){},
  1176. // "error": function(){},
  1177. // "async": true or false, default is true
  1178. // }
  1179. if (option){
  1180. var json = (option.data) || {};
  1181. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1182. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1183. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1184. }
  1185. }
  1186. this.Table = MWF.xScript.createTable();
  1187. };
  1188. MWF.xScript.createTable = function(){
  1189. return function(name){
  1190. this.name = name;
  1191. this.action = o2.Actions.get("x_query_assemble_surface");
  1192. this.listRowNext = function(id, count, success, error, async){
  1193. this.action.listRowNext(this.name, id, count, success, error, async);
  1194. };
  1195. this.listRowPrev = function(id, count, success, error, async){
  1196. this.action.listRowPrev(this.name, id, count, success, error, async);
  1197. };
  1198. this.listRowPrev = function(id, count, success, error, async){
  1199. this.action.listRowPrev(this.name, id, count, success, error, async);
  1200. };
  1201. this.listRowSelectWhere = function(where, success, error, async){
  1202. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1203. };
  1204. this.listRowCountWhere = function(where, success, error, async){
  1205. this.action.listRowCountWhere(this.name, where, success, error, async);
  1206. };
  1207. this.deleteRow = function(id, success, error, async){
  1208. this.action.deleteRow(this.name, id, success, error, async);
  1209. };
  1210. this.deleteAllRow = function(success, error, async){
  1211. this.action.deleteAllRow(this.name, success, error, async);
  1212. };
  1213. this.getRow = function(id, success, error, async){
  1214. this.action.getRow(this.name, id, success, error, async);
  1215. };
  1216. this.insertRow = function(data, success, error, async){
  1217. this.action.insertRow(this.name, data, success, error, async);
  1218. };
  1219. this.updateRow = function(id, data, success, error, async){
  1220. this.action.updateRow(this.name, id, data, success, error, async);
  1221. };
  1222. }
  1223. };
  1224. MWF.xScript.JSONData = function(data, callback, key, parent){
  1225. var getter = function(data, callback, k, _self){
  1226. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self);};
  1227. };
  1228. var setter = function(data, callback, k, _self){
  1229. return function(v){
  1230. data[k] = v;
  1231. //debugger;
  1232. //this.add(k, v, true);
  1233. if (callback) callback(data, k, _self);
  1234. }
  1235. };
  1236. var define = function(){
  1237. var o = {};
  1238. 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])};
  1239. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1240. MWF.defineProperties(this, o);
  1241. var methods = {
  1242. "getKey": {"value": function(){ return key; }},
  1243. "getParent": {"value": function(){ return parent; }},
  1244. "toString": {"value": function() { return data.toString();}},
  1245. "add": {"value": function(newKey, newValue, overwrite){
  1246. var flag = true;
  1247. var type = typeOf(data);
  1248. if (type==="array"){
  1249. if (arguments.length<2){
  1250. data.push(newKey);
  1251. newValue = newKey;
  1252. newKey = data.length-1;
  1253. }else{
  1254. if (!newKey && newKey!==0){
  1255. data.push(newValue);
  1256. newKey = data.length-1;
  1257. }else{
  1258. flag = false;
  1259. }
  1260. }
  1261. if (flag){
  1262. var o = {};
  1263. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1264. MWF.defineProperties(this, o);
  1265. }
  1266. this[newKey] = newValue;
  1267. }else if (type==="object"){
  1268. if (!this.hasOwnProperty(newKey)){
  1269. data[newKey] = newValue;
  1270. if (flag){
  1271. var o = {};
  1272. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1273. MWF.defineProperties(this, o);
  1274. }
  1275. this[newKey] = newValue;
  1276. }else{
  1277. if (overwrite) this[newKey] = newValue;
  1278. }
  1279. }
  1280. return this[newKey];
  1281. }},
  1282. "del": {"value": function(delKey){
  1283. if (!this.hasOwnProperty(delKey)) return null;
  1284. delete data[delKey];
  1285. delete this[delKey];
  1286. return this;
  1287. }}
  1288. };
  1289. MWF.defineProperties(this, methods);
  1290. //this.getKey = function(){ return key; };
  1291. //this.getParent = function(){ return parent; };
  1292. //this.toString = function() { return data.toString();};
  1293. //this.add = function(newKey, newValue, overwrite){
  1294. // var flag = true;
  1295. // var type = typeOf(data);
  1296. // if (!this.hasOwnProperty(newKey)){
  1297. // if (type=="array"){
  1298. // if (arguments.length<2){
  1299. // data.push(newKey);
  1300. // newValue = newKey;
  1301. // newKey = data.length-1;
  1302. // }else{
  1303. // debugger;
  1304. // if (!newKey && newKey!=0){
  1305. // data.push(newValue);
  1306. // newKey = data.length-1;
  1307. // }else{
  1308. // flag == false;
  1309. // }
  1310. // }
  1311. // }else{
  1312. // data[newKey] = newValue;
  1313. // }
  1314. // //var valueType = typeOf(newValue);
  1315. // //var newValueData = newValue;
  1316. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1317. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1318. // if (flag){
  1319. // var o = {};
  1320. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1321. // MWF.defineProperties(this, o);
  1322. // }
  1323. // this[newKey] = newValue;
  1324. // }else{
  1325. // if (overwrite) this[newKey] = newValue;
  1326. // }
  1327. //
  1328. // //var valueType = typeOf(newValue);
  1329. // //var newValueData = newValue;
  1330. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1331. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1332. // //
  1333. // //this[newKey] = newValueData;
  1334. //
  1335. // return this[newKey];
  1336. //};
  1337. //this.del = function(delKey){
  1338. // if (!this.hasOwnProperty(delKey)) return null;
  1339. // delete data[newKey];
  1340. // delete this[newKey];
  1341. // return this;
  1342. //};
  1343. };
  1344. var type = typeOf(data);
  1345. if (type==="object" || type==="array") define.apply(this);
  1346. };
  1347. //MWF.xScript.createDict = function(application){
  1348. // return function(name){
  1349. // var applicationId = application;
  1350. // this.name = name;
  1351. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1352. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1353. //
  1354. // this.get = function(path, success, failure){
  1355. // debugger;
  1356. // var value = null;
  1357. // if (path){
  1358. // var arr = path.split(/\./g);
  1359. // var ar = arr.map(function(v){
  1360. // return encodeURIComponent(v);
  1361. // });
  1362. // //var p = path.replace(/\./g, "/");
  1363. // var p = ar.join("/");
  1364. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1365. // value = json.data;
  1366. // if (success) success(json.data);
  1367. // }, function(xhr, text, error){
  1368. // if (failure) failure(xhr, text, error);
  1369. // }, false);
  1370. // }else{
  1371. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1372. // value = json.data;
  1373. // if (success) success(json.data);
  1374. // }, function(xhr, text, error){
  1375. // if (failure) failure(xhr, text, error);
  1376. // }, false);
  1377. // }
  1378. //
  1379. // return value;
  1380. // };
  1381. //
  1382. // this.set = function(path, value, success, failure){
  1383. // var p = path.replace(/\./g, "/");
  1384. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1385. // if (success) success(json.data);
  1386. // }, function(xhr, text, error){
  1387. // if (failure) failure(xhr, text, error);
  1388. // });
  1389. // };
  1390. // this.add = function(path, value, success, failure){
  1391. // var p = path.replace(/\./g, "/");
  1392. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1393. // if (success) success(json.data);
  1394. // }, function(xhr, text, error){
  1395. // if (failure) failure(xhr, text, error);
  1396. // });
  1397. // };
  1398. // this["delete"] = function(path, success, failure){
  1399. // var p = path.replace(/\./g, "/");
  1400. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1401. // if (success) success(json.data);
  1402. // }, function(xhr, text, error){
  1403. // if (failure) failure(xhr, text, error);
  1404. // });
  1405. // };
  1406. // this.destory = this["delete"];
  1407. // }
  1408. //};
  1409. MWF.xScript.createDict = function(application){
  1410. //optionsOrName : {
  1411. // type : "", //默认为process, 可以为 process cms
  1412. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1413. // name : "", // 数据字典名称/别名/id
  1414. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1415. //}
  1416. //或者name: "" // 数据字典名称/别名/id
  1417. return function(optionsOrName){
  1418. var options = optionsOrName;
  1419. if( typeOf( options ) == "string" ){
  1420. options = { name : options };
  1421. }
  1422. var name = this.name = options.name;
  1423. var type = ( options.type && options.application ) ? options.type : "process";
  1424. var applicationId = options.application || application;
  1425. var enableAnonymous = options.enableAnonymous || false;
  1426. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1427. if( type == "cms" ){
  1428. var action = MWF.Actions.get("x_cms_assemble_control");
  1429. }else{
  1430. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1431. }
  1432. var encodePath = function( path ){
  1433. var arr = path.split(/\./g);
  1434. var ar = arr.map(function(v){
  1435. return encodeURIComponent(v);
  1436. });
  1437. return ar.join("/");
  1438. };
  1439. this.get = function(path, success, failure){
  1440. var value = null;
  1441. if (path){
  1442. var p = encodePath( path );
  1443. //var p = path.replace(/\./g, "/");
  1444. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1445. value = json.data;
  1446. if (success) success(json.data);
  1447. }, function(xhr, text, error){
  1448. if (failure) failure(xhr, text, error);
  1449. }, false, false);
  1450. }else{
  1451. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1452. value = json.data;
  1453. if (success) success(json.data);
  1454. }, function(xhr, text, error){
  1455. if (failure) failure(xhr, text, error);
  1456. }, false);
  1457. }
  1458. return value;
  1459. };
  1460. this.set = function(path, value, success, failure){
  1461. var p = encodePath( path );
  1462. //var p = path.replace(/\./g, "/");
  1463. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1464. if (success) success(json.data);
  1465. }, function(xhr, text, error){
  1466. if (failure) failure(xhr, text, error);
  1467. }, false, false);
  1468. };
  1469. this.add = function(path, value, success, failure){
  1470. var p = encodePath( path );
  1471. //var p = path.replace(/\./g, "/");
  1472. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1473. if (success) success(json.data);
  1474. }, function(xhr, text, error){
  1475. if (failure) failure(xhr, text, error);
  1476. }, false, false);
  1477. };
  1478. this["delete"] = function(path, success, failure){
  1479. var p = encodePath( path );
  1480. //var p = path.replace(/\./g, "/");
  1481. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1482. if (success) success(json.data);
  1483. }, function(xhr, text, error){
  1484. if (failure) failure(xhr, text, error);
  1485. }, false, false);
  1486. };
  1487. this.destory = this["delete"];
  1488. }
  1489. };