SerialEditor.js 21 KB

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