ParameterEditor.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.addEvent();
  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. addItem: function(item){
  27. this.data[item.event] = item.data;
  28. this.items.push(item);
  29. },
  30. addEvent: function(){
  31. var item = new MWF.xApplication.process.FormDesigner.widget.ParameterEditor.Item(this);
  32. item.load("", "");
  33. },
  34. deleteItem: function(item){
  35. this.items.erase(item);
  36. if (this.data[item.event]){
  37. this.data[item.event].code = "";
  38. this.data[item.event].html = "";
  39. delete this.data[item.event];
  40. }
  41. item.deleteScriptDesignerItem();
  42. if (item.container){
  43. item.container.destroy();
  44. }
  45. if (!Object.getLength(this.data)){
  46. if (this.addNewItemAction) this.addNewItemAction.setStyle("display", "block");
  47. }
  48. }
  49. });
  50. MWF.xApplication.process.FormDesigner.widget.ParameterEditor.Item = new Class({
  51. Extends: MWF.xApplication.process.FormDesigner.widget.EventsEditor.Item,
  52. createContainerTitle: function(){
  53. this.container = new Element("div", {
  54. "styles": this.editor.css.itemContainer
  55. }).inject(this.editor.eventsContainer);
  56. this.titleContainer = new Element("div", {
  57. "styles": this.editor.css.itemTitleContainer
  58. }).inject(this.container);
  59. this.iconNode = new Element("div", {
  60. "styles": this.editor.css.parIconNode
  61. }).inject(this.titleContainer);
  62. this.actionNode = new Element("div", {
  63. "styles": this.editor.css.actionNode
  64. }).inject(this.titleContainer);
  65. this.textNode = new Element("div", {
  66. "styles": this.editor.css.textNode,
  67. "text": this.event
  68. }).inject(this.titleContainer);
  69. },
  70. editCode: function(){
  71. if (this.editor.currentEditItem){
  72. if (this.editor.currentEditItem!=this) this.editor.currentEditItem.editCodeComplete();
  73. }
  74. if (this.editor.currentEditItem!=this){
  75. if (!this.codeEditor){
  76. this.codeEditor = new MWF.widget.ScriptArea(this.codeNode, {
  77. "style": "event",
  78. "title": this.event+" (S)",
  79. "maxObj": this.editor.options.maxObj,
  80. "onChange": function(){
  81. var json = this.codeEditor.toJson();
  82. this.data.code = json.code;
  83. this.data.html = json.html;
  84. this.checkIcon();
  85. }.bind(this),
  86. "onSave": function(){
  87. var json = this.codeEditor.toJson();
  88. this.data.code = json.code;
  89. this.data.html = json.html;
  90. this.checkIcon();
  91. this.editor.app.savePage();
  92. }.bind(this)
  93. });
  94. this.codeEditor.load(this.data);
  95. }
  96. if (!this.morph){
  97. this.morph = new Fx.Morph(this.codeNode, {duration: 200});
  98. }
  99. this.codeNode.setStyle("display", "block");
  100. this.morph.start({"height": [0,300]}).chain(function(){
  101. this.codeEditor.resizeContentNodeSize();
  102. this.codeEditor.focus();
  103. // this.fireEvent("postShow");
  104. }.bind(this));
  105. this.editor.currentEditItem = this;
  106. }else{
  107. this.editCodeComplete();
  108. }
  109. },
  110. bindScriptDesigner: function(){
  111. var form = this.editor.app.form || this.editor.app.page;
  112. if (form.scriptDesigner) form.scriptDesigner.addScriptItem(this.data, "code", this.editor.module, this.editor.scriptPath, this.event);
  113. },
  114. deleteScriptDesignerItem: function(){
  115. var form = this.editor.app.form || this.editor.app.page;
  116. if (form.scriptDesigner){
  117. form.scriptDesigner.deleteScriptItem(this.editor.module, this.editor.scriptPath, this.event);
  118. }
  119. },
  120. checkIcon: function(){
  121. if (this.data.code){
  122. this.iconNode.setStyle("background", "url("+this.editor.path+this.editor.options.style+"/icon/codePar.png) center center no-repeat");
  123. }else{
  124. this.iconNode.setStyle("background", "url("+this.editor.path+this.editor.options.style+"/icon/codePar_empty.png) center center no-repeat");
  125. }
  126. }
  127. });