EventsEditor.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. MWF.xApplication.cms.FormDesigner.widget = MWF.xApplication.cms.FormDesigner.widget || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", null, false);
  3. MWF.xApplication.cms.FormDesigner.widget.EventsEditor = new Class({
  4. Extends: MWF.xApplication.process.FormDesigner.widget.EventsEditor,
  5. load: function(data, module, path){
  6. this.data = data;
  7. this.module = module;
  8. this.scriptPath = path;
  9. Object.each(data, function(obj, key){
  10. var item = new MWF.xApplication.cms.FormDesigner.widget.EventsEditor.Item(this);
  11. item.load(key, obj);
  12. this.items.push(item);
  13. }.bind(this));
  14. },
  15. addEventItem: function(){
  16. var item = new MWF.xApplication.cms.FormDesigner.widget.EventsEditor.Item(this);
  17. item.load("", "");
  18. }
  19. });
  20. MWF.xApplication.cms.FormDesigner.widget.EventsEditor.Item = new Class({
  21. Extends: MWF.xApplication.process.FormDesigner.widget.EventsEditor.Item,
  22. editCode: function(){
  23. if (this.editor.currentEditItem){
  24. if (this.editor.currentEditItem!=this) this.editor.currentEditItem.editCodeComplete();
  25. }
  26. if (this.editor.currentEditItem!=this){
  27. if (!this.codeEditor){
  28. this.codeEditor = new MWF.widget.ScriptArea(this.codeNode, {
  29. "style": "event",
  30. "title": "on"+this.event+" (S)",
  31. "maxObj": this.editor.options.maxObj,
  32. "onChange": function(){
  33. var json = this.codeEditor.toJson();
  34. this.data.code = json.code;
  35. this.data.html = json.html;
  36. this.editor.fireEvent("change", [this.event, Object.clone(this.data), this.oldData]);
  37. this.checkIcon();
  38. }.bind(this),
  39. "onSave": function(){
  40. var json = this.codeEditor.toJson();
  41. this.data.code = json.code;
  42. this.data.html = json.html;
  43. this.editor.fireEvent("change", [this.event, Object.clone(this.data), this.oldData]);
  44. this.editor.app.saveForm();
  45. }.bind(this),
  46. "helpStyle" : "cms"
  47. });
  48. this.codeEditor.load(this.data);
  49. }
  50. if (!this.morph){
  51. this.morph = new Fx.Morph(this.codeNode, {duration: 200});
  52. }
  53. this.codeNode.setStyle("display", "block");
  54. this.morph.start({"height": [0,300]}).chain(function(){
  55. this.codeEditor.resizeContentNodeSize();
  56. this.codeEditor.focus();
  57. // this.fireEvent("postShow");
  58. }.bind(this));
  59. this.editor.currentEditItem = this;
  60. }else{
  61. this.editCodeComplete();
  62. }
  63. }
  64. });