EditionList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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, options){
  9. this.setOptions(options);
  10. this.application = application;
  11. this.edition = edition;
  12. this.path = "/x_component_process_ProcessDesigner/widget/$EditionList/";
  13. this.cssPath = "/x_component_process_ProcessDesigner/widget/$EditionList/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.selectedItem = null;
  16. this.items = {};
  17. },
  18. load: function(){
  19. o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.listEdition(this.application, this.edition, function(json){
  20. this.editionList = json.data;
  21. this.listEditionDlg();
  22. }.bind(this));
  23. this.node = new Element("div", {"styles": this.css.node});
  24. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.node);
  25. this.rightNode = new Element("div", {"styles": this.css.rightNode}).inject(this.node);
  26. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.leftNode);
  27. this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.rightNode);
  28. this.diffNode = new Element("div", {"styles": this.css.diffNode}).inject(this.rightNode);
  29. this.show();
  30. },
  31. show: function(){
  32. if (!this.dlg){
  33. this.dlg = o2.DL.open({
  34. "content": this.node,
  35. "isMax": true,
  36. "width": 700,
  37. "height": 500,
  38. "buttonList": [{
  39. "text": MWF.xApplication.process.ProcessDesigner.LP.ok,
  40. "action": function(){ this.close(); }
  41. }]
  42. });
  43. }
  44. },
  45. listEditionDlg: function(){
  46. this.editionList.each(function(edition){
  47. }.bind(this));
  48. },
  49. loadSelectNode: function(){
  50. this.getSerialRule(function(){
  51. this.loadSelectNodeItems();
  52. this.loadSelectedNodeItems();
  53. }.bind(this));
  54. },
  55. loadSelectedNodeItems: function(){
  56. this.data.each(function(itemData){
  57. this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem[itemData.key.capitalize()](this.items[itemData.key], itemData));
  58. }.bind(this));
  59. this.fireEvent("change");
  60. },
  61. loadSelectNodeItems: function(){
  62. Object.each(this.serialRuleJson, function(v, k){
  63. this.loadSelectNodeItem(v, k);
  64. }.bind(this));
  65. },
  66. loadSelectNodeItem: function(v, k){
  67. this.items[k] = new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.Item(v, k, this);
  68. },
  69. getSerialRule: function(callback){
  70. if (!this.serialRuleJson){
  71. var serialConifgUrl = "/x_component_process_ProcessDesigner/$Process/serialRule.json";
  72. MWF.getJSON(serialConifgUrl, function(json){
  73. this.serialRuleJson = json;
  74. if (callback) callback();
  75. }.bind(this));
  76. }else{
  77. if (callback) callback();
  78. }
  79. },
  80. getData: function(){
  81. var data = [];
  82. this.selectedItems.each(function(item){
  83. data.push(item.getData());
  84. });
  85. this.data = data;
  86. return data;
  87. }
  88. });
  89. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.Item = new Class({
  90. initialize: function(value, key, editor){
  91. this.editor = editor;
  92. this.json = value;
  93. this.key = key;
  94. this.css = this.editor.css;
  95. this.load();
  96. },
  97. load: function(){
  98. this.node = new Element("div", {"styles": this.css.itemNode}).inject(this.editor.selectNode);
  99. this.iconNode = new Element("div", {"styles": this.css.itemIconNode}).inject(this.node);
  100. this.textNode = new Element("div", {"styles": this.css.itemTextNode}).inject(this.node);
  101. this.textNode.set({
  102. "text": this.json.text,
  103. "title": this.json.description
  104. });
  105. this.node.addEvents({
  106. "mouseover": function(){this.node.setStyles(this.css.itemNode_over); this.iconNode.setStyles(this.css.itemIconNode_over);}.bind(this),
  107. "mouseout": function(){this.node.setStyles(this.css.itemNode); this.iconNode.setStyles(this.css.itemIconNode);}.bind(this),
  108. "click": function(){this.selectNumberItem();}.bind(this)
  109. });
  110. },
  111. selectNumberItem: function(){
  112. this.editor.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem[this.key.capitalize()](this));
  113. this.editor.fireEvent("change");
  114. }
  115. });
  116. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem = new Class({
  117. initialize: function(item, itemData){
  118. this.item = item;
  119. this.json = item.json;
  120. this.key = item.key;
  121. this.editor = item.editor;
  122. this.css = this.editor.css;
  123. this.data = itemData;
  124. this.load();
  125. },
  126. load: function(){
  127. this.node = new Element("div", {"styles": this.css.selectedItemNode}).inject(this.editor.showNode);
  128. this.textNode = new Element("div", {"styles": this.css.selectedItemTextNode}).inject(this.node);
  129. this.textNode.set({
  130. "text": this.json.text,
  131. "title": this.json.description
  132. });
  133. this.node.addEvents({
  134. "mouseover": function(){
  135. if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode_over);
  136. }.bind(this),
  137. "mouseout": function(){
  138. if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode);
  139. }.bind(this),
  140. "click": function(){this.selectItem();}.bind(this)
  141. });
  142. this.closeNode = new Element("div", {"styles": this.css.selectedItemCloseNode}).inject(this.node);
  143. this.closeNode.addEvent("click", function(){
  144. this.deleteItem();
  145. }.bind(this));
  146. this.loadProperty();
  147. this.selectItem();
  148. },
  149. loadProperty: function(){},
  150. deleteItem: function(){
  151. this.node.destroy();
  152. if (this.propertyNode) this.propertyNode.destroy();
  153. this.editor.selectedItems.erase(this);
  154. if (this.editor.currentItem === this) this.editor.currentItem = null;
  155. this.editor.fireEvent("change");
  156. MWF.release(this);
  157. },
  158. selectItem: function(){
  159. if (this.editor.currentItem) this.editor.currentItem.unSelectItem();
  160. if (this.propertyNode){
  161. this.propertyNode.setStyle("display", "block");
  162. if (this.key==="number"){
  163. this.loadNumberBy();
  164. }
  165. }
  166. this.node.setStyles(this.css.selectedItemNode_check);
  167. this.editor.currentItem = this;
  168. },
  169. unSelectItem: function(){
  170. this.node.setStyles(this.css.selectedItemNode);
  171. if (this.propertyNode) this.propertyNode.setStyle("display", "none");
  172. this.editor.currentItem = null;
  173. }
  174. });
  175. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Text = new Class({
  176. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  177. loadProperty: function(){
  178. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  179. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  180. this.propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialTextTitle);
  181. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  182. this.propertyInputNode = new Element("input", {
  183. "type": "text",
  184. "value": (this.data) ? this.data.value: "",
  185. "styles": this.css.propertyInputNode
  186. }).inject(this.propertyInputDivNode);
  187. this.changeText();
  188. this.propertyInputNode.addEvents({
  189. "change": function(){
  190. this.changeText();
  191. }.bind(this),
  192. "blur": function(){},
  193. });
  194. },
  195. changeText: function(){
  196. var value = this.propertyInputNode.get("value");
  197. if (value){
  198. this.textNode.set("text", "\""+value+"\"");
  199. }else{
  200. this.textNode.set("text", this.json.text);
  201. }
  202. this.editor.fireEvent("change");
  203. },
  204. getData: function(){
  205. var value = this.propertyInputNode.get("value");
  206. var key = this.key;
  207. var script = "return serial.text(\""+value+"\")";
  208. return {
  209. "key": key,
  210. "value": value,
  211. "script": script
  212. }
  213. }
  214. });
  215. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year = new Class({
  216. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  217. loadProperty: function(){
  218. this.value = "created";
  219. var i = Math.random();
  220. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  221. var propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  222. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialDateTitle);
  223. var propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  224. var v = (this.data) ? this.data.value: "created";
  225. html = "<input name=\"serialDateSelect"+i+"\" "+((v=="created") ? "checked" : "")+" type=\"radio\" value=\"created\"/>" + MWF.xApplication.process.ProcessDesigner.LP.serialCreatedDateTitle;
  226. html += "<input name=\"serialDateSelect"+i+"\" "+((v=="current") ? "checked" : "")+" type=\"radio\" value=\"current\"/>" + MWF.xApplication.process.ProcessDesigner.LP.serialCurrentDateTitle;
  227. propertyInputDivNode.set("html", html);
  228. this.changeText((this.data) ? this.data.value: "created");
  229. propertyInputDivNode.getElements("input").addEvent("click", function(e){
  230. if (e.target.checked){
  231. var v = e.target.get("value");
  232. this.changeText(v);
  233. }
  234. }.bind(this));
  235. },
  236. changeText: function(v){
  237. var text = MWF.xApplication.process.ProcessDesigner.LP.serialCreated;
  238. if (v=="current"){
  239. text = MWF.xApplication.process.ProcessDesigner.LP.serialCurrent;
  240. }
  241. this.value = v;
  242. this.textNode.set("text", this.json.text+"("+text+")");
  243. this.editor.fireEvent("change");
  244. },
  245. getData: function(){
  246. var key = this.key;
  247. var f = (this.value=="current") ? "year" : "createYear";
  248. var script = "return serial."+f+"(\"yyyy\")";
  249. return {
  250. "key": key,
  251. "value": this.value,
  252. "script": script
  253. }
  254. }
  255. });
  256. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Month = new Class({
  257. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,
  258. getData: function(){
  259. var key = this.key;
  260. var f = (this.value=="current") ? "month" : "createMonth";
  261. var script = "return serial."+f+"(\"MM\")";
  262. return {
  263. "key": key,
  264. "value": this.value,
  265. "script": script
  266. }
  267. }
  268. });
  269. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Day = new Class({
  270. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,
  271. getData: function(){
  272. var key = this.key;
  273. var f = (this.value=="current") ? "day" : "createDay";
  274. var script = "return serial."+f+"(\"dd\")";
  275. return {
  276. "key": key,
  277. "value": this.value,
  278. "script": script
  279. }
  280. }
  281. });
  282. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Company = new Class({
  283. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  284. getData: function(){
  285. var key = this.key;
  286. var script = "return serial.company()";
  287. return {
  288. "key": key,
  289. "value": "",
  290. "script": script
  291. }
  292. }
  293. });
  294. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Department = new Class({
  295. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  296. getData: function(){
  297. var key = this.key;
  298. var script = "return serial.department()";
  299. return {
  300. "key": key,
  301. "value": "",
  302. "script": script
  303. }
  304. }
  305. });
  306. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute = new Class({
  307. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  308. loadProperty: function(){
  309. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  310. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  311. this.propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialAttributeTitle);
  312. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  313. this.propertyInputNode = new Element("input", {
  314. "type": "text",
  315. "value": (this.data) ? this.data.value: "",
  316. "styles": this.css.propertyInputNode
  317. }).inject(this.propertyInputDivNode);
  318. this.changeText();
  319. this.propertyInputNode.addEvents({
  320. "change": function(){
  321. this.changeText();
  322. }.bind(this),
  323. "blur": function(){},
  324. });
  325. },
  326. changeText: function(){
  327. var value = this.propertyInputNode.get("value");
  328. if (value){
  329. this.textNode.set("text", this.json.text+"("+value+")");
  330. }else{
  331. this.textNode.set("text", this.json.text);
  332. }
  333. this.editor.fireEvent("change");
  334. },
  335. getData: function(){
  336. var value = this.propertyInputNode.get("value");
  337. var key = this.key;
  338. var script = "return serial.companyAttribute(\""+value+"\")";
  339. return {
  340. "key": key,
  341. "value": value,
  342. "script": script
  343. }
  344. }
  345. });
  346. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.DepartmentAttribute = new Class({
  347. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute,
  348. getData: function(){
  349. var value = this.propertyInputNode.get("value");
  350. var key = this.key;
  351. var script = "return serial.departmentAttribute(\""+value+"\")";
  352. return {
  353. "key": key,
  354. "value": value,
  355. "script": script
  356. }
  357. }
  358. });
  359. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Number = new Class({
  360. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  361. loadProperty: function(){
  362. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  363. var lineNode = new Element("div", {"styles": this.css.lineNode}).inject(this.propertyNode);
  364. var propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(lineNode);
  365. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialNumberByTitle);
  366. this.propertyNumberByDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(lineNode);
  367. this.loadNumberBy();
  368. lineNode = new Element("div", {"styles": this.css.lineNode}).inject(this.propertyNode);
  369. propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(lineNode);
  370. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialNumberLongTitle);
  371. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(lineNode);
  372. this.propertyInputNode = new Element("select").inject(this.propertyInputDivNode);
  373. var value = (this.data) ? this.data.value: {};
  374. var numberLong = value.lng || 0;
  375. var optionsHtml = "<option "+((numberLong==0) ? "selected": "")+" value=\"0\">auto</option>";
  376. optionsHtml += "<option "+((numberLong==2) ? "selected": "")+" value=\"2\">2</option>";
  377. optionsHtml += "<option "+((numberLong==3) ? "selected": "")+" value=\"3\">3</option>";
  378. optionsHtml += "<option "+((numberLong==4) ? "selected": "")+" value=\"4\">4</option>";
  379. optionsHtml += "<option "+((numberLong==5) ? "selected": "")+" value=\"5\">5</option>";
  380. optionsHtml += "<option "+((numberLong==6) ? "selected": "")+" value=\"6\">6</option>";
  381. optionsHtml += "<option "+((numberLong==7) ? "selected": "")+" value=\"7\">7</option>";
  382. optionsHtml += "<option "+((numberLong==8) ? "selected": "")+" value=\"8\">8</option>";
  383. optionsHtml += "<option "+((numberLong==9) ? "selected": "")+" value=\"9\">9</option>";
  384. this.propertyInputNode.set("html", optionsHtml);
  385. this.propertyInputNode.addEvents({
  386. "change": function(){
  387. this.editor.fireEvent("change");
  388. }.bind(this)
  389. });
  390. },
  391. loadNumberBy: function(){
  392. this.propertyNumberByDivNode.empty();
  393. var i = Math.random();
  394. var value = (this.data) ? this.data.value: {};
  395. var numberBy = value.by || [];
  396. var html = "";
  397. this.editor.selectedItems.each(function(item, n){
  398. if (item.key!="number"){
  399. var check = (numberBy.indexOf(n)==-1)? "" : "checked"
  400. html += "<input "+check+" name=\"serialNumberBySelect"+i+"\" type=\"checkbox\" value=\""+n+"\"/>" + item.json.text;
  401. }
  402. });
  403. this.propertyNumberByDivNode.set("html", html);
  404. this.propertyNumberByDivNode.getElements("input").addEvent("click", function(e){
  405. this.editor.fireEvent("change");
  406. }.bind(this));
  407. },
  408. getData: function(){
  409. var numberLong = this.propertyInputNode.options[this.propertyInputNode.selectedIndex].value;
  410. var numberBy = [];
  411. var inputs = this.propertyNumberByDivNode.getElements("input");
  412. inputs.each(function(input){
  413. if (input.checked) numberBy.push(input.get("value").toInt());
  414. }.bind(this));
  415. var value = {"lng": numberLong, "by": numberBy};
  416. var code = "return serial.nextSerialNumber("+JSON.encode(numberBy)+", "+numberLong+")"
  417. return {
  418. "key": this.key,
  419. "value": value,
  420. "script": code
  421. }
  422. }
  423. });
  424. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Script = new Class({
  425. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  426. loadProperty: function(){
  427. debugger;
  428. this.code = (this.data) ? this.data.value: "";
  429. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  430. this.scriptNode = new Element("div", {"styles": this.css.scriptNode}).inject(this.propertyNode);
  431. this.scriptNode.set("title", MWF.xApplication.process.ProcessDesigner.LP.serialScriptTitle);
  432. this.scriptArea = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, (this.data) ? this.data.value: "", this.editor.process.designer, {
  433. "maskNode": this.editor.process.designer.content,
  434. "maxObj": this.editor.process.designer.paperNode,
  435. "onChange": function(code){
  436. this.code = code;
  437. this.editor.fireEvent("change");
  438. }.bind(this)
  439. });
  440. },
  441. getData: function(){
  442. var value = this.code;
  443. var key = this.key;
  444. return {
  445. "key": key,
  446. "value": value,
  447. "script": value
  448. }
  449. }
  450. });
  451. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Unit = new Class({
  452. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  453. getData: function(){
  454. var key = this.key;
  455. var script = "return serial.unit()";
  456. return {
  457. "key": key,
  458. "value": "",
  459. "script": script
  460. }
  461. }
  462. });
  463. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Unit = new Class({
  464. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  465. getData: function(){
  466. var key = this.key;
  467. var script = "return serial.unit()";
  468. return {
  469. "key": key,
  470. "value": "",
  471. "script": script
  472. }
  473. }
  474. });
  475. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.UnitAttribute = new Class({
  476. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute,
  477. getData: function(){
  478. var value = this.propertyInputNode.get("value");
  479. var key = this.key;
  480. var script = "return serial.unitAttribute(\""+value+"\")";
  481. return {
  482. "key": key,
  483. "value": value,
  484. "script": script
  485. }
  486. }
  487. });