EditionList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  2. MWF.xApplication.process.ProcessDesigner.widget.EditionList = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.widget.Common,
  5. options: {
  6. "style": "default"
  7. },
  8. initialize: function(application, edition, process, options){
  9. this.setOptions(options);
  10. this.application = application;
  11. this.edition = edition;
  12. this.process = process;
  13. this.path = "/x_component_process_ProcessDesigner/widget/$EditionList/";
  14. this.cssPath = "/x_component_process_ProcessDesigner/widget/$EditionList/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. this.currentItem = null;
  17. this.items = [];
  18. this.lp = MWF.xApplication.process.ProcessDesigner.LP;
  19. },
  20. load: function(){
  21. o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.listEdition(this.application, this.edition, function(json){
  22. this.editionList = json.data;
  23. this.listEditionDlg();
  24. }.bind(this));
  25. this.node = new Element("div", {"styles": this.css.node});
  26. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.node);
  27. this.rightNode = new Element("div", {"styles": this.css.rightNode}).inject(this.node);
  28. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.leftNode);
  29. this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.rightNode);
  30. this.diffNode = new Element("div", {"styles": this.css.diffNode}).inject(this.rightNode);
  31. this.createListTable();
  32. this.show();
  33. },
  34. createListTable: function(){
  35. var tableHtml = "<table width='100%' cellspacing='0' cellpadding='3'><tr>" +
  36. "<th></th>" +
  37. "<th>"+this.lp.edition_list.number+"</th>" +
  38. "<th>"+this.lp.edition_list.update+"</th>" +
  39. "<th>"+this.lp.edition_list.updatePerson+"</th>" +
  40. "<th>"+this.lp.edition_list.enabled+"</th>" +
  41. "<th>"+this.lp.edition_list.description+"</th>" +
  42. "<th>"+this.lp.edition_list.action+"</th>" +
  43. "</tr></table>";
  44. this.listNode.set("html", tableHtml);
  45. this.listTable = this.listNode.getElement("table");
  46. this.listTable.setStyles(this.css.listTable);
  47. var ths = this.listNode.getElements("th").setStyles(this.css.listTable_th);
  48. ths[ths.length-1].setStyles(this.css.listTable_td_right);
  49. },
  50. reloadList: function(){
  51. debugger;
  52. this.items = [];
  53. this.listNode.empty();
  54. this.diffNode.empty();
  55. this.createListTable();
  56. o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.listEdition(this.application, this.edition, function(json){
  57. this.editionList = json.data;
  58. this.listEditionDlg();
  59. }.bind(this));
  60. },
  61. show: function(){
  62. if (!this.dlg){
  63. this.dlg = o2.DL.open({
  64. "title": this.lp.edition_list.editionList,
  65. "content": this.node,
  66. "offset": {"y": -100},
  67. "isMax": true,
  68. "width": 900,
  69. "height": 500,
  70. "buttonList": [
  71. {
  72. "text": this.lp.edition_list.open,
  73. "action": function(){ this.openCurrentEdition(); this.dlg.close();}.bind(this),
  74. "title": this.lp.edition_list.openInfor
  75. },
  76. {
  77. "text": MWF.xApplication.process.ProcessDesigner.LP.close,
  78. "action": function(){ this.close(); }
  79. }
  80. ],
  81. "onPostShow": function(){
  82. this.setEvent();
  83. }.bind(this)
  84. });
  85. }
  86. },
  87. listEditionDlg: function(){
  88. this.editionList.each(function(edition){
  89. var item = new MWF.xApplication.process.ProcessDesigner.widget.EditionList.Item(this, edition);
  90. this.items.push(item);
  91. }.bind(this));
  92. },
  93. setEvent: function(){
  94. var buttons = this.dlg.button.getElements("input");
  95. this.openCurrentEditionButton = buttons[0];
  96. var display = this.openCurrentEditionButton.getStyle("display");
  97. this.openCurrentEditionButton.store("dsp", display);
  98. this.openCurrentEditionButton.setStyle("display", "none");
  99. var size, leftSize;
  100. var drag = new Drag(this.resizeNode, {
  101. "onSnap": function(el){
  102. el.setStyle("background", "#cccccc");
  103. },
  104. "onStart": function(el, e){
  105. size = this.node.getSize();
  106. leftSize = this.leftNode.getSize();
  107. drag.x = e.event.x;
  108. }.bind(this),
  109. "onComplete": function(el){
  110. el.setStyle("background-color", "transparent");
  111. },
  112. "onDrag": function(el, e){
  113. var x = drag.x - e.event.x;
  114. var w = leftSize.x-x;
  115. w = (w/size.x)*100;
  116. if (w<30) w = 30;
  117. if (w>70) w = 70;
  118. this.leftNode.setStyle("width", ""+w+"%");
  119. w = 100-w;
  120. this.rightNode.setStyle("width", ""+w+"%");
  121. }.bind(this)
  122. });
  123. },
  124. openCurrentEdition: function(){
  125. if (this.currentItem && this.currentItem.edition.fullProcess.id != this.process.process.id){
  126. this.process.save(function(){
  127. this.process.reload(this.currentItem.edition.fullProcess);
  128. }.bind(this));
  129. }
  130. },
  131. checkButtonDisable: function(){
  132. if (this.currentItem && this.currentItem.edition.fullProcess.id != this.process.process.id){
  133. this.openCurrentEditionButton.setStyle("display", this.openCurrentEditionButton.retrieve("dsp"));
  134. }else{
  135. this.openCurrentEditionButton.setStyle("display", "none");
  136. }
  137. }
  138. });
  139. MWF.xApplication.process.ProcessDesigner.widget.EditionList.Item = new Class({
  140. initialize: function(list, edition){
  141. this.list = list;
  142. this.edition = edition;
  143. this.table = this.list.listTable;
  144. this.css = this.list.css;
  145. this.lp = this.list.lp;
  146. this.isCurrentEdition = (this.list.process.process.id == this.edition.id);
  147. this.load();
  148. },
  149. load: function(){
  150. this.node = new Element("tr").inject(this.table);
  151. var html = "<td></td>" +
  152. "<td>"+this.edition.editionNumber+"</td>" +
  153. "<td>"+this.edition.updateTime+"</td>" +
  154. "<td>"+o2.name.cn(this.edition.lastUpdatePerson)+"</td>" +
  155. "<td>"+(this.edition.editionEnable ? this.lp.edition_list.yes : this.lp.edition_list.no)+"</td>"+
  156. "<td>"+(this.edition.editionDes || "")+"</td>"+
  157. "<td></td>";
  158. this.node.set("html", html);
  159. var tds = this.node.getElements("td").setStyles((this.isCurrentEdition) ? this.css.listTable_td_current : this.css.listTable_td);
  160. tds[tds.length-1].setStyles(this.css.listTable_td_right);
  161. this.iconTd = tds[0].setStyles(this.css.listTable_td_icon);
  162. this.selectIconNode = new Element("div", {"styles": this.css.unselectIcon}).inject(this.iconTd);
  163. this.actionTd = tds[tds.length-1].setStyles(this.css.listTable_td_action);
  164. this.createActions();
  165. this.setEvent();
  166. },
  167. createActions: function(){
  168. if (!this.edition.editionEnable){
  169. this.enableAction = new Element("div.mainColor_bg", {"styles": this.css.enableAction, "text": this.lp.edition_list.enable}).inject(this.actionTd);
  170. var text = this.lp.edition_list.enableInfor.replace(/{v}/, this.edition.editionNumber);
  171. this.enableAction.set("title", text);
  172. }
  173. if (!this.isCurrentEdition && !this.edition.editionEnable){
  174. this.delAction = new Element("div", {"styles": this.css.delAction, "text": this.lp.edition_list.del}).inject(this.actionTd);
  175. text = this.lp.edition_list.delInfor.replace(/{v}/, this.edition.editionNumber);
  176. this.delAction.set("title", text);
  177. }
  178. },
  179. setEvent: function(){
  180. this.node.addEvent("click", function(){
  181. this.selected();
  182. }.bind(this));
  183. if (this.enableAction) this.enableAction.addEvents({
  184. "click": function(e){ this.enable(e); e.stopPropagation();}.bind(this),
  185. });
  186. if (this.delAction) this.delAction.addEvents({
  187. "click": function(e){ this.del(e); e.stopPropagation();}.bind(this),
  188. });
  189. },
  190. enable: function(e){
  191. var actions = o2.Actions.load("x_processplatform_assemble_designer").ProcessAction;
  192. var _self = this;
  193. this.list.process.designer.confirm("infor", e, this.lp.edition_list.enabledProcessTitle, {"html": this.lp.edition_list.enabledProcessInfor}, 600, 120, function(){
  194. _self.list.process.save(function(){
  195. actions.enableProcess(this.edition.id, function(json){
  196. this.list.reloadList();
  197. actions.get(this.list.process.process.id, function(processJson){
  198. this.list.process.reload(processJson.data);
  199. }.bind(this));
  200. }.bind(this));
  201. }.bind(_self));
  202. this.close();
  203. },function(){this.close();})
  204. },
  205. del: function(e){
  206. var _self = this;
  207. var infor = this.lp.edition_list.deleteEditionInfor.replace(/{v}/g, this.edition.editionNumber);
  208. this.list.process.designer.confirm("warn", e, this.lp.edition_list.deleteEditionTitle, infor, 460, 120, function(){
  209. _self.deleteEdition();
  210. this.close();
  211. }, function(){
  212. this.close();
  213. });
  214. },
  215. deleteEdition: function(callback){
  216. o2.Actions.load("x_processplatform_assemble_designer").ProcessAction["delete"](this.edition.id, "true", function(){
  217. this.unSelected();
  218. this.node.destroy();
  219. if (callback) callback();
  220. }.bind(this));
  221. },
  222. selected: function(){
  223. if (this.list.currentItem) this.list.currentItem.unSelected();
  224. this.node.setStyles(this.css.itemTr_selected).addClass("lightColor_bg");
  225. this.selectIconNode.setStyles(this.css.selectIcon).addClass("mainColor_bg");
  226. this.list.currentItem = this;
  227. this.checkDiff();
  228. this.list.checkButtonDisable();
  229. },
  230. unSelected: function(){
  231. this.node.setStyles(this.css.itemTr).removeClass("lightColor_bg");
  232. this.selectIconNode.setStyles(this.css.unselectIcon).removeClass("mainColor_bg");
  233. this.list.currentItem = null;
  234. this.list.diffNode.empty();
  235. },
  236. checkDiff: function(){
  237. this.getFullProcess(function(){
  238. var prevItem = this.getPrevItem();
  239. if (prevItem){
  240. prevItem.getFullProcess();
  241. var diffs = this.getDiffWithProcess(prevItem.edition.fullProcess);
  242. if (diffs.length){
  243. this.appendDiffLine(this.lp.edition_list.hasDiffs);
  244. //for (var i=0; i<10; i++){
  245. diffs.each(function(v){
  246. this.appendDiffLine(v);
  247. }.bind(this));
  248. //}
  249. }else{
  250. this.appendDiffLine(this.lp.edition_list.noDiffs);
  251. }
  252. }else{
  253. this.appendDiffLine(this.lp.edition_list.newProcess);
  254. this.appendDiffLine(this.getNewProcessInfor());
  255. }
  256. }.bind(this));
  257. },
  258. appendDiffLine: function(text){
  259. new Element("div", {"styles": this.css.diffLine, "html": text}).inject(this.list.diffNode);
  260. },
  261. getDiffWithProcess: function(process){
  262. debugger;
  263. var diffs = [];
  264. var notDiffFields = ["id", "editionName", "editionEnable", "editionNumber", "createTime", "updateTime", "creatorPerson", "lastUpdateTime", "lastUpdatePerson"];
  265. Object.each(process, function(v, k){
  266. var t = o2.typeOf(v);
  267. if (t!="array" && t!="object"){
  268. if (this.edition.fullProcess[k]!=v){
  269. if (notDiffFields.indexOf(k)==-1){
  270. var infor = this.lp.edition_list.modifyProcess;
  271. var oldV = (v.length>60) ? v.substring(0,60)+" ..." : v;
  272. var newV = (this.edition.fullProcess[k].length>60) ? this.edition.fullProcess[k].substring(0,60)+" ..." : this.edition.fullProcess[k];
  273. infor = infor.replace(/\{field\}/, k).replace(/\{old\}/, oldV).replace(/\{new\}/, newV);
  274. diffs.push(infor);
  275. }
  276. }
  277. }
  278. }.bind(this));
  279. diffs = diffs.concat(this.getDiffActivityListCount(process, diffs));
  280. return diffs;
  281. },
  282. getDiffActivityListCount: function(process){
  283. var diffs = [];
  284. diffs = diffs.concat(this.getDiffActivityCount(process.endList, this.edition.fullProcess.endList));
  285. diffs = diffs.concat(this.getDiffActivityCount(process.manualList, this.edition.fullProcess.manualList));
  286. return diffs;
  287. },
  288. getDiffActivityCount: function(prevList, currentList){
  289. var diffs = [];
  290. var prevNames = prevList.map(function(item){ return item.name; });
  291. var currentNames = currentList.map(function(item){ return item.name; });
  292. var deleteNames = prevNames.filter(function(name){
  293. var i = currentNames.indexOf(name);
  294. if (i!=-1){
  295. currentNames.splice(i, 1);
  296. return false;
  297. }
  298. return true;
  299. });
  300. currentNames.each(function(name){
  301. var infor = this.lp.edition_list.addActivity;
  302. infor = infor.replace(/\{name\}/, name);
  303. diffs.push(infor);
  304. }.bind(this));
  305. deleteNames.each(function(name){
  306. var infor = this.lp.edition_list.deleteActivity;
  307. infor = infor.replace(/\{name\}/, name);
  308. diffs.push(infor);
  309. }.bind(this));
  310. return diffs;
  311. },
  312. getNewProcessInfor: function(){
  313. //this.getFullProcess(function(){
  314. var process = this.edition.fullProcess;
  315. var activityInfor = "";
  316. var an = this.lp.edition_list.an;
  317. activityInfor = "1 "+an+this.lp.menu.newActivityType.begin;
  318. if (process.endList && process.endList.length) activityInfor += ", "+process.endList.length + " "+an +this.lp.menu.newActivityType.end;
  319. if (process.agentList && process.agentList.length) activityInfor += ", "+process.agentList.length + " "+an +this.lp.menu.newActivityType.agent;
  320. if (process.manualList && process.manualList.length) activityInfor += ", "+process.manualList.length + " "+an +this.lp.menu.newActivityType.manual;
  321. if (process.conditionList && process.conditionList.length) activityInfor += ", "+process.conditionList.length + " "+an +this.lp.menu.newActivityType.condition;
  322. if (process.choiceList && process.choiceList.length) activityInfor += ", "+process.choiceList.length + " "+an +this.lp.menu.newActivityType.choice;
  323. if (process.parallelList && process.parallelList.length) activityInfor += ", "+process.parallelList.length + " "+an +this.lp.menu.newActivityType.parallel;
  324. if (process.splitList && process.splitList.length) activityInfor += ", "+process.splitList.length + " "+an +this.lp.menu.newActivityType.split;
  325. if (process.mergeList && process.mergeList.length) activityInfor += ", "+process.mergeList.length + " "+an +this.lp.menu.newActivityType.merge;
  326. if (process.embedList && process.embedList.length) activityInfor += ", "+process.embedList.length + " "+an +this.lp.menu.newActivityType.embed;
  327. if (process.invokeList && process.invokeList.length) activityInfor += ", "+process.invokeList.length + " "+an +this.lp.menu.newActivityType.invoke;
  328. if (process.cancelList && process.cancelList.length) activityInfor += ", "+process.cancelList.length + " "+an +this.lp.menu.newActivityType.cancel;
  329. if (process.delayList && process.delayList.length) activityInfor += ", "+process.delayList.length + " "+an +this.lp.menu.newActivityType.delay;
  330. if (process.messageList && process.messageList.length) activityInfor += ", "+process.messageList.length + " "+an +this.lp.menu.newActivityType.message;
  331. if (process.serviceList && process.serviceList.length) activityInfor += ", "+process.serviceList.length + " "+an +this.lp.menu.newActivityType.service;
  332. return activityInfor;
  333. //}.bind(this));
  334. },
  335. getFullProcess: function(callback, async){
  336. if (this.edition.fullProcess){
  337. if (callback) callback();
  338. }else{
  339. var asyncGet = !!async;
  340. o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.get(this.edition.id, function(json){
  341. this.edition.fullProcess = json.data;
  342. if (callback) callback();
  343. }.bind(this), null, asyncGet);
  344. }
  345. },
  346. getPrevItem: function(){
  347. var idx = this.list.items.indexOf(this);
  348. idx++;
  349. if (idx<this.list.items.length) return this.list.items[idx];
  350. return null;
  351. }
  352. });