ParameterEditor.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", null, false);
  2. MWF.xApplication.process.FormDesigner.widget.ParameterEditor = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.xApplication.process.FormDesigner.widget.EventsEditor,
  5. options: {
  6. "style": "default",
  7. "maxObj": document.body
  8. },
  9. load: function(data, module, path){
  10. this.data = data || {};
  11. this.module = module;
  12. this.scriptPath = path;
  13. //if (!Object.getLength(this.data)){
  14. this.addNewItemAction = new Element("div", {"styles": this.css.addNewItemAction, "text": "+"}).inject(this.node);
  15. this.addNewItemAction.addEvent("click", function(){
  16. this.addEventItem();
  17. this.addNewItemAction.setStyle("display", "none");
  18. }.bind(this));
  19. //}
  20. Object.each(data, function(obj, key){
  21. var item = new MWF.xApplication.process.FormDesigner.widget.ParameterEditor.Item(this);
  22. item.load(key, obj);
  23. this.items.push(item);
  24. }.bind(this));
  25. },
  26. deleteItem: function(item){
  27. var oldValue = item.oldData;
  28. this.items.erase(item);
  29. var data;
  30. if (this.data[item.event]){
  31. data = Object.clone( this.data[item.event] );
  32. this.data[item.event].code = "";
  33. this.data[item.event].html = "";
  34. delete this.data[item.event];
  35. }
  36. item.deleteScriptDesignerItem();
  37. this.fireEvent("change", [item.event, null, data, item.event+" [delete]"]);
  38. if (item.container){
  39. item.container.destroy();
  40. }
  41. if (!Object.getLength(this.data)){
  42. if (this.addNewItemAction) this.addNewItemAction.setStyle("display", "block");
  43. }
  44. },
  45. addItem: function(item){
  46. this.data[item.event] = item.data;
  47. this.fireEvent("change", [item.event, Object.clone(item.data)]);
  48. this.items.push(item);
  49. },
  50. addEventItem: function(){
  51. var item = new MWF.xApplication.process.FormDesigner.widget.ParameterEditor.Item(this);
  52. item.load("", "");
  53. }
  54. });
  55. MWF.xApplication.process.FormDesigner.widget.ParameterEditor.Item = new Class({
  56. Extends: MWF.xApplication.process.FormDesigner.widget.EventsEditor.Item,
  57. createContainerTitle: function(){
  58. this.container = new Element("div", {
  59. "styles": this.editor.css.itemContainer
  60. }).inject(this.editor.eventsContainer);
  61. this.titleContainer = new Element("div", {
  62. "styles": this.editor.css.itemTitleContainer
  63. }).inject(this.container);
  64. this.iconNode = new Element("div", {
  65. "styles": this.editor.css.parIconNode
  66. }).inject(this.titleContainer);
  67. this.actionNode = new Element("div", {
  68. "styles": this.editor.css.actionNode
  69. }).inject(this.titleContainer);
  70. this.textNode = new Element("div", {
  71. "styles": this.editor.css.textNode,
  72. "text": this.event
  73. }).inject(this.titleContainer);
  74. },
  75. editCode: function(){
  76. if (this.editor.currentEditItem){
  77. if (this.editor.currentEditItem!=this) this.editor.currentEditItem.editCodeComplete();
  78. }
  79. if (this.editor.currentEditItem!=this){
  80. if (!this.codeEditor){
  81. this.codeEditor = new MWF.widget.ScriptArea(this.codeNode, {
  82. "style": "event",
  83. "isbind": false,
  84. "title": this.event+" (S)",
  85. "maxObj": this.editor.options.maxObj,
  86. "onChange": function(){
  87. var json = this.codeEditor.toJson();
  88. this.data.code = json.code;
  89. this.data.html = json.html;
  90. this.editor.fireEvent("change", [this.event, Object.clone(this.data), this.oldData]);
  91. this.checkIcon();
  92. }.bind(this),
  93. "onSave": function(){
  94. var json = this.codeEditor.toJson();
  95. this.data.code = json.code;
  96. this.data.html = json.html;
  97. this.checkIcon();
  98. this.editor.fireEvent("change", [this.event, Object.clone(this.data), this.oldData]);
  99. this.editor.app.savePage();
  100. }.bind(this)
  101. });
  102. this.codeEditor.load(this.data);
  103. }
  104. if (!this.morph){
  105. this.morph = new Fx.Morph(this.codeNode, {duration: 200});
  106. }
  107. this.codeNode.setStyle("display", "block");
  108. this.morph.start({"height": [0,300]}).chain(function(){
  109. this.codeEditor.resizeContentNodeSize();
  110. this.codeEditor.focus();
  111. // this.fireEvent("postShow");
  112. }.bind(this));
  113. this.editor.currentEditItem = this;
  114. }else{
  115. this.editCodeComplete();
  116. }
  117. },
  118. bindScriptDesigner: function(){
  119. var form = this.editor.app.form || this.editor.app.page;
  120. if (form.scriptDesigner) form.scriptDesigner.addScriptItem(this.data, "code", this.editor.module, this.editor.scriptPath, this.event);
  121. },
  122. deleteScriptDesignerItem: function(){
  123. var form = this.editor.app.form || this.editor.app.page;
  124. if (form.scriptDesigner){
  125. form.scriptDesigner.deleteScriptItem(this.editor.module, this.editor.scriptPath, this.event);
  126. }
  127. },
  128. checkIcon: function(){
  129. if (this.data.code){
  130. this.iconNode.setStyle("background", "url("+this.editor.path+this.editor.options.style+"/icon/codePar.png) center center no-repeat");
  131. }else{
  132. this.iconNode.setStyle("background", "url("+this.editor.path+this.editor.options.style+"/icon/codePar_empty.png) center center no-repeat");
  133. }
  134. }
  135. });