Tab$Page.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. MWF.xApplication.cms.FormDesigner.Module = MWF.xApplication.cms.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("cms.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.cms.FormDesigner.Module.Tab$Page = MWF.CMSFCTab$Page = new Class({
  4. Extends: MWF.CMSFC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_cms_FormDesigner/Module/Tab$Page/tab$Page.html",
  9. "actions": [
  10. {
  11. "name": "move",
  12. "icon": "move1.png",
  13. "event": "mousedown",
  14. "action": "move",
  15. "title": MWF.CMSFD.LP.formAction.move
  16. },
  17. //{
  18. // "name": "copy",
  19. // "icon": "copy1.png",
  20. // "event": "click",
  21. // "action": "copy",
  22. // "title": MWF.CMSFD.LP.formAction.copy
  23. //},
  24. {
  25. "name": "add",
  26. "icon": "add.png",
  27. "event": "click",
  28. "action": "addPage",
  29. "title": MWF.CMSFD.LP.formAction.add
  30. },
  31. {
  32. "name": "delete",
  33. "icon": "delete1.png",
  34. "event": "click",
  35. "action": "delete",
  36. "title": MWF.CMSFD.LP.formAction["delete"]
  37. }
  38. ]
  39. },
  40. initialize: function(tab, page, options){
  41. this.setOptions(options);
  42. this.path = "/x_component_cms_FormDesigner/Module/Tab$Page/";
  43. this.cssPath = "/x_component_cms_FormDesigner/Module/Tab$Page/"+this.options.style+"/css.wcss";
  44. this._loadCss();
  45. this.moduleType = "element";
  46. this.moduleName = "tab$Page";
  47. this.form = tab.form;
  48. this.tab = tab;
  49. this.page = page;
  50. },
  51. _initModule: function(){
  52. this._setNodeProperty();
  53. this._createIconAction();
  54. this._setNodeEvent();
  55. if (this.form.moduleElementNodeList.indexOf(this.node)!=-1) this.form.moduleElementNodeList.erase(this.node);
  56. },
  57. load : function(json, node, parent){
  58. this.json = json;
  59. this.node= node;
  60. this.node.store("module", this);
  61. this.node.setStyles(this.css.moduleNode);
  62. if (!this.json.id){
  63. var id = this._getNewId(parent.json.id);
  64. this.json.id = id;
  65. }
  66. if (this.json.name) this.page.textNode.set("text", this.json.name);
  67. node.set({
  68. "MWFType": "tab$Page",
  69. "id": this.json.id
  70. });
  71. if (!this.form.json.moduleList[this.json.id]){
  72. this.form.json.moduleList[this.json.id] = this.json;
  73. }
  74. this._initModule();
  75. this._loadTreeNode(parent);
  76. this.parentContainer = this.treeNode.parentNode.module;
  77. this.page.setOptions({
  78. "onPostShow": function(){
  79. this.initialStyles = this.page.tab.css.tabNodeCurrent;
  80. this.node.store("normalBorder", this.page.tab.css.tabNodeCurrent);
  81. }.bind(this),
  82. "onPostHide": function(){
  83. this.initialStyles = this.page.tab.css.tabNode;
  84. this.node.store("normalBorder", this.page.tab.css.tabNode);
  85. }.bind(this)
  86. });
  87. this._setEditStyle_custom("id");
  88. },
  89. //_dragIn: function(module){
  90. //this.treeNode.parentNode.module._dragIn(module);
  91. //},
  92. _setEditStyle_custom: function(name){
  93. if (name=="width"){
  94. if (this.json.width){
  95. if (this.json.width.toInt()>60) this.node.setStyle("width", ""+this.json.width+"px");
  96. }
  97. }
  98. if (name=="name"){
  99. this.page.textNode.set("text", this.json.name);
  100. }
  101. },
  102. "addPage": function(){
  103. var page = this.tab.addPage();
  104. page.tabNode.inject(this.page.tabNode, "before");
  105. page.showTabIm();
  106. },
  107. "delete": function(e){
  108. var module = this;
  109. this.form.designer.confirm("warn", e, MWF.CMSFD.LP.notice.deleteElementTitle, MWF.CMSFD.LP.notice.deleteElement, 300, 120, function(){
  110. if (module.tab.containers.length<=1){
  111. module.tab.destroy();
  112. }else{
  113. var contentModule = module.page.contentNode.retrieve("module");
  114. module.destroy();
  115. module.tab.elements.erase(module);
  116. contentModule.destroy();
  117. module.tab.containers.erase(contentModule);
  118. module.page.closeTab();
  119. }
  120. this.close();
  121. }, function(){
  122. this.close();
  123. }, null);
  124. },
  125. destroy: function(){
  126. this.form.moduleList.erase(this);
  127. this.form.moduleNodeList.erase(this.node);
  128. this.form.moduleElementNodeList.erase(this.node);
  129. //this.tab.elements.erase(this);
  130. this.node.destroy();
  131. this.actionArea.destroy();
  132. delete this.form.json.moduleList[this.json.id];
  133. this.json = null;
  134. delete this.json;
  135. this.treeNode.destroy();
  136. },
  137. move: function(e){
  138. var pageNodes = [];
  139. this.tab.tabWidget.pages.each(function(page){
  140. if (page!=this.page){
  141. pageNodes.push(page.tabNode);
  142. }
  143. }.bind(this));
  144. this._createMoveNode();
  145. this._setNodeMove(pageNodes, e);
  146. },
  147. _createMoveNode: function(){
  148. this.moveNode = this.node.clone();
  149. this.moveNode.inject(this.form.node);
  150. this.moveNode.setStyles({
  151. "border": "2px dashed #ffa200",
  152. "opacity": 0.7,
  153. "position": "absolute"
  154. });
  155. },
  156. _onEnterOther: function(){
  157. // this.copyNode.setStyles(this.tab.tabWidget.css.tabNode);
  158. // this.copyNode.setStyles(this.css.moduleNodeShow);
  159. },
  160. _createCopyNode: function(){
  161. this.copyNode = new Element("div");
  162. this.copyNode.setStyles(this.css.moduleNodeShow);
  163. this.copyNode.addEvent("selectstart", function(){
  164. return false;
  165. });
  166. },
  167. _setNodeMove: function(droppables, e){
  168. this._setMoveNodePosition(e);
  169. var movePosition = this.moveNode.getPosition();
  170. var moveSize = this.moveNode.getSize();
  171. var tabPosition = this.tab.node.getPosition();
  172. var tabSize = this.tab.node.getSize();
  173. var nodeDrag = new Drag.Move(this.moveNode, {
  174. "droppables": droppables,
  175. "limit": {
  176. "x": [tabPosition.x, tabPosition.x+tabSize.x],
  177. "y": [movePosition.y, movePosition.y+moveSize.y]
  178. },
  179. "onEnter": function(dragging, inObj){
  180. var module = inObj.retrieve("module");
  181. if (module) module._dragIn(this);
  182. this._onEnterOther(dragging, inObj);
  183. }.bind(this),
  184. "onLeave": function(dragging, inObj){
  185. var module = inObj.retrieve("module");
  186. if (module) module._dragOut(this);
  187. this._onLeaveOther(dragging, inObj);
  188. }.bind(this),
  189. "onDrop": function(dragging, inObj){
  190. if (inObj){
  191. var module = inObj.retrieve("module");
  192. if (module) module._dragDrop(this);
  193. this._nodeDrop();
  194. }else{
  195. this._dragCancel(dragging);
  196. }
  197. }.bind(this),
  198. "onCancel": function(dragging){
  199. this._dragCancel(dragging);
  200. }.bind(this)
  201. });
  202. nodeDrag.start(e);
  203. this.form.moveModule = this;
  204. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  205. this.form.selected();
  206. }
  207. });