SerialEditor.js 21 KB

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