SerialEditor.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. MWF.release(this);
  142. },
  143. selectItem: function(){
  144. if (this.editor.currentItem) this.editor.currentItem.unSelectItem();
  145. if (this.propertyNode){
  146. this.propertyNode.setStyle("display", "block");
  147. if (this.key=="number"){
  148. this.loadNumberBy();
  149. }
  150. }
  151. this.node.setStyles(this.css.selectedItemNode_check);
  152. this.editor.currentItem = this;
  153. },
  154. unSelectItem: function(){
  155. this.node.setStyles(this.css.selectedItemNode);
  156. if (this.propertyNode) this.propertyNode.setStyle("display", "none");
  157. this.editor.currentItem = null;
  158. }
  159. });
  160. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Text = new Class({
  161. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  162. loadProperty: function(){
  163. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  164. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  165. this.propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialTextTitle);
  166. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  167. this.propertyInputNode = new Element("input", {
  168. "type": "text",
  169. "value": (this.data) ? this.data.value: "",
  170. "styles": this.css.propertyInputNode
  171. }).inject(this.propertyInputDivNode);
  172. this.changeText();
  173. this.propertyInputNode.addEvents({
  174. "change": function(){
  175. this.changeText();
  176. }.bind(this),
  177. "blur": function(){},
  178. });
  179. },
  180. changeText: function(){
  181. var value = this.propertyInputNode.get("value");
  182. if (value){
  183. this.textNode.set("text", "\""+value+"\"");
  184. }else{
  185. this.textNode.set("text", this.json.text);
  186. }
  187. this.editor.fireEvent("change");
  188. },
  189. getData: function(){
  190. var value = this.propertyInputNode.get("value");
  191. var key = this.key;
  192. var script = "return serial.text(\""+value+"\")";
  193. return {
  194. "key": key,
  195. "value": value,
  196. "script": script
  197. }
  198. }
  199. });
  200. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year = new Class({
  201. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  202. loadProperty: function(){
  203. this.value = "created";
  204. var i = Math.random();
  205. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  206. var propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  207. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialDateTitle);
  208. var propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  209. var v = (this.data) ? this.data.value: "created";
  210. html = "<input name=\"serialDateSelect"+i+"\" "+((v=="created") ? "checked" : "")+" type=\"radio\" value=\"created\"/>" + MWF.xApplication.process.ProcessDesigner.LP.serialCreatedDateTitle;
  211. html += "<input name=\"serialDateSelect"+i+"\" "+((v=="current") ? "checked" : "")+" type=\"radio\" value=\"current\"/>" + MWF.xApplication.process.ProcessDesigner.LP.serialCurrentDateTitle;
  212. propertyInputDivNode.set("html", html);
  213. this.changeText((this.data) ? this.data.value: "created");
  214. propertyInputDivNode.getElements("input").addEvent("click", function(e){
  215. if (e.target.checked){
  216. var v = e.target.get("value");
  217. this.changeText(v);
  218. }
  219. }.bind(this));
  220. },
  221. changeText: function(v){
  222. var text = MWF.xApplication.process.ProcessDesigner.LP.serialCreated;
  223. if (v=="current"){
  224. text = MWF.xApplication.process.ProcessDesigner.LP.serialCurrent;
  225. }
  226. this.value = v;
  227. this.textNode.set("text", this.json.text+"("+text+")");
  228. this.editor.fireEvent("change");
  229. },
  230. getData: function(){
  231. var key = this.key;
  232. var f = (this.value=="current") ? "year" : "createYear";
  233. var script = "return serial."+f+"(\"yyyy\")";
  234. return {
  235. "key": key,
  236. "value": this.value,
  237. "script": script
  238. }
  239. }
  240. });
  241. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Month = new Class({
  242. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,
  243. getData: function(){
  244. var key = this.key;
  245. var f = (this.value=="current") ? "month" : "createMonth";
  246. var script = "return serial."+f+"(\"MM\")";
  247. return {
  248. "key": key,
  249. "value": this.value,
  250. "script": script
  251. }
  252. }
  253. });
  254. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Day = new Class({
  255. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,
  256. getData: function(){
  257. var key = this.key;
  258. var f = (this.value=="current") ? "day" : "createDay";
  259. var script = "return serial."+f+"(\"dd\")";
  260. return {
  261. "key": key,
  262. "value": this.value,
  263. "script": script
  264. }
  265. }
  266. });
  267. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Company = new Class({
  268. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  269. getData: function(){
  270. var key = this.key;
  271. var script = "return serial.company()";
  272. return {
  273. "key": key,
  274. "value": "",
  275. "script": script
  276. }
  277. }
  278. });
  279. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Department = new Class({
  280. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  281. getData: function(){
  282. var key = this.key;
  283. var script = "return serial.department()";
  284. return {
  285. "key": key,
  286. "value": "",
  287. "script": script
  288. }
  289. }
  290. });
  291. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute = new Class({
  292. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  293. loadProperty: function(){
  294. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  295. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  296. this.propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialAttributeTitle);
  297. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(this.propertyNode);
  298. this.propertyInputNode = new Element("input", {
  299. "type": "text",
  300. "value": (this.data) ? this.data.value: "",
  301. "styles": this.css.propertyInputNode
  302. }).inject(this.propertyInputDivNode);
  303. this.changeText();
  304. this.propertyInputNode.addEvents({
  305. "change": function(){
  306. this.changeText();
  307. }.bind(this),
  308. "blur": function(){},
  309. });
  310. },
  311. changeText: function(){
  312. var value = this.propertyInputNode.get("value");
  313. if (value){
  314. this.textNode.set("text", this.json.text+"("+value+")");
  315. }else{
  316. this.textNode.set("text", this.json.text);
  317. }
  318. this.editor.fireEvent("change");
  319. },
  320. getData: function(){
  321. var value = this.propertyInputNode.get("value");
  322. var key = this.key;
  323. var script = "return serial.companyAttribute(\""+value+"\")";
  324. return {
  325. "key": key,
  326. "value": value,
  327. "script": script
  328. }
  329. }
  330. });
  331. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.DepartmentAttribute = new Class({
  332. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute,
  333. getData: function(){
  334. var value = this.propertyInputNode.get("value");
  335. var key = this.key;
  336. var script = "return serial.departmentAttribute(\""+value+"\")";
  337. return {
  338. "key": key,
  339. "value": value,
  340. "script": script
  341. }
  342. }
  343. });
  344. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Number = new Class({
  345. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  346. loadProperty: function(){
  347. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  348. var lineNode = new Element("div", {"styles": this.css.lineNode}).inject(this.propertyNode);
  349. var propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(lineNode);
  350. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialNumberByTitle);
  351. this.propertyNumberByDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(lineNode);
  352. this.loadNumberBy();
  353. lineNode = new Element("div", {"styles": this.css.lineNode}).inject(this.propertyNode);
  354. propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(lineNode);
  355. propertyTitleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.serialNumberLongTitle);
  356. this.propertyInputDivNode = new Element("div", {"styles": this.css.propertyInputDivNode}).inject(lineNode);
  357. this.propertyInputNode = new Element("select").inject(this.propertyInputDivNode);
  358. var value = (this.data) ? this.data.value: {};
  359. var numberLong = value.lng || 0;
  360. var optionsHtml = "<option "+((numberLong==0) ? "selected": "")+" value=\"0\">auto</option>";
  361. optionsHtml += "<option "+((numberLong==2) ? "selected": "")+" value=\"2\">2</option>";
  362. optionsHtml += "<option "+((numberLong==3) ? "selected": "")+" value=\"3\">3</option>";
  363. optionsHtml += "<option "+((numberLong==4) ? "selected": "")+" value=\"4\">4</option>";
  364. optionsHtml += "<option "+((numberLong==5) ? "selected": "")+" value=\"5\">5</option>";
  365. optionsHtml += "<option "+((numberLong==6) ? "selected": "")+" value=\"6\">6</option>";
  366. optionsHtml += "<option "+((numberLong==7) ? "selected": "")+" value=\"7\">7</option>";
  367. optionsHtml += "<option "+((numberLong==8) ? "selected": "")+" value=\"8\">8</option>";
  368. optionsHtml += "<option "+((numberLong==9) ? "selected": "")+" value=\"9\">9</option>";
  369. this.propertyInputNode.set("html", optionsHtml);
  370. this.propertyInputNode.addEvents({
  371. "change": function(){
  372. this.editor.fireEvent("change");
  373. }.bind(this)
  374. });
  375. },
  376. loadNumberBy: function(){
  377. this.propertyNumberByDivNode.empty();
  378. var i = Math.random();
  379. var value = (this.data) ? this.data.value: {};
  380. var numberBy = value.by || [];
  381. var html = "";
  382. this.editor.selectedItems.each(function(item, n){
  383. if (item.key!="number"){
  384. var check = (numberBy.indexOf(n)==-1)? "" : "checked"
  385. html += "<input "+check+" name=\"serialNumberBySelect"+i+"\" type=\"checkbox\" value=\""+n+"\"/>" + item.json.text;
  386. }
  387. });
  388. this.propertyNumberByDivNode.set("html", html);
  389. this.propertyNumberByDivNode.getElements("input").addEvent("click", function(e){
  390. this.editor.fireEvent("change");
  391. }.bind(this));
  392. },
  393. getData: function(){
  394. debugger;
  395. var numberLong = this.propertyInputNode.options[this.propertyInputNode.selectedIndex].value;
  396. var numberBy = [];
  397. var inputs = this.propertyNumberByDivNode.getElements("input");
  398. inputs.each(function(input){
  399. if (input.checked) numberBy.push(input.get("value").toInt());
  400. }.bind(this));
  401. var value = {"lng": numberLong, "by": numberBy};
  402. var code = "return serial.nextSerialNumber("+JSON.encode(numberBy)+", "+numberLong+")"
  403. return {
  404. "key": this.key,
  405. "value": value,
  406. "script": code
  407. }
  408. }
  409. });
  410. MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Script = new Class({
  411. Extends: MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,
  412. loadProperty: function(){
  413. this.code = "";
  414. this.propertyNode = new Element("div", {"styles": this.css.itemPropertyNode}).inject(this.editor.propertyNode);
  415. this.scriptNode = new Element("div", {"styles": this.css.scriptNode}).inject(this.propertyNode);
  416. this.scriptNode.set("title", MWF.xApplication.process.ProcessDesigner.LP.serialScriptTitle);
  417. this.scriptArea = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, (this.data) ? this.data.value: "", this.editor.process.designer, {
  418. "maskNode": this.editor.process.designer.content,
  419. "maxObj": this.editor.process.designer.paperNode,
  420. "onChange": function(code){
  421. this.code = code;
  422. this.editor.fireEvent("change");
  423. }.bind(this)
  424. });
  425. },
  426. getData: function(){
  427. var value = this.code;
  428. var key = this.key;
  429. return {
  430. "key": key,
  431. "value": value,
  432. "script": value
  433. }
  434. }
  435. });