Sidebar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.require("MWF.widget.Toolbar", null, false);
  4. MWF.xApplication.process.FormDesigner.Module.Sidebar = MWF.FCSidebar = new Class({
  5. Extends: MWF.FC$Element,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "propertyPath": "/x_component_process_FormDesigner/Module/Sidebar/sidebar.html"
  10. },
  11. addAction: function(){
  12. },
  13. initialize: function(form, options){
  14. this.setOptions(options);
  15. this.path = "/x_component_process_FormDesigner/Module/Sidebar/";
  16. this.cssPath = "/x_component_process_FormDesigner/Module/Sidebar/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.moduleType = "component";
  19. this.moduleName = "sidebar";
  20. this.Node = null;
  21. this.form = form;
  22. this.container = null;
  23. this.containerNode = null;
  24. this.systemTools = [];
  25. //this.containers = [];
  26. //this.elements = [];
  27. },
  28. setTemplateStyles: function(styles){
  29. this.json.style = styles.style;
  30. },
  31. clearTemplateStyles: function(styles){
  32. this.json.style = "xform_side_blue_simple";
  33. },
  34. setAllStyles: function(){
  35. this._refreshActionbar();
  36. },
  37. _createMoveNode: function(){
  38. this.moveNode = new Element("div", {
  39. "MWFType": "sidebar",
  40. "id": this.json.id,
  41. "styles": this.css.moduleNodeMove,
  42. "events": {
  43. "selectstart": function(e){
  44. e.preventDefault();
  45. }
  46. }
  47. }).inject(this.form.container);
  48. },
  49. _createNode: function(callback){
  50. this.node = new Element("div", {
  51. "id": this.json.id,
  52. "MWFType": "actionbar",
  53. "styles": this.css.moduleNode,
  54. "events": {
  55. "selectstart": function(e){
  56. e.preventDefault();
  57. }
  58. }
  59. }).inject(this.form.node);
  60. if (this.form.options.mode == "Mobile"){
  61. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  62. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  63. }else{
  64. this.toolbarNode = new Element("div").inject(this.node);
  65. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  66. MWF.getJSON(this.path+"toolbars.json", function(json){
  67. this.json.defaultTools = json;
  68. this.setToolbars(json, this.toolbarNode);
  69. this.toolbarWidget.load();
  70. }.bind(this), false);
  71. }
  72. },
  73. _initModule: function(){
  74. this.setStyleTemplate();
  75. this._setNodeProperty();
  76. if (!this.form.isSubform) this._createIconAction();
  77. this._setNodeEvent();
  78. this._refreshActionbar();
  79. this.loadPosition();
  80. this.form.designer.designNode.addEvent("scroll", function(){
  81. }.bind(this));
  82. },
  83. position: function(){
  84. if (this.parentContainer){
  85. this.sideNode = this.parentContainer.node;
  86. //var p = this.sideNode.getStyles(["top", "left", "bottom", "right", "width", "height"]);
  87. var p = this.sideNode.getPosition();
  88. var s = this.sideNode.getSize();
  89. if (!this.sidePosition || !(this.sidePosition.p.x==p.x && this.sidePosition.p.y==p.y && this.sidePosition.s.x==s.x && this.sidePosition.s.y==s.y)){
  90. this.loadPosition();
  91. }
  92. }
  93. },
  94. loadPosition: function(){
  95. this.sideNode = this.parentContainer.node;
  96. var size = this.form.designer.designNode.getSize();
  97. var scroll = this.form.designer.designNode.getScroll();
  98. var sideSize = this.sideNode.getSize();
  99. var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
  100. var nodeSize = this.node.getSize();
  101. if (sideSize.y>size.y){
  102. var center = (size.y/2-nodeSize.y/2);
  103. if (center<sidePosition.y){
  104. this.node.setStyle("top", ""+sidePosition.y+"px");
  105. }else if (center>(sidePosition.y+sideSize.y)){
  106. var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
  107. this.node.setStyle("top", ""+tmp+"px");
  108. }else{
  109. this.node.setStyle("top", ""+center+"px");
  110. }
  111. }else{
  112. var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
  113. if (top>size.y){
  114. if (sidePosition.y+nodeSize.y>size.y){
  115. this.node.setStyle("top", ""+sidePosition.y+"px");
  116. }else{
  117. var tmp = size.y-nodeSize.y;
  118. this.node.setStyle("top", ""+tmp+"px");
  119. }
  120. }else if(top<=45){
  121. if(sidePosition.y+sideSize.y<nodeSize.y+45){
  122. var tmp = sidePosition.y+sideSize.y-nodeSize.y;
  123. this.node.setStyle("top", ""+tmp+"px");
  124. }else{
  125. this.node.setStyle("top", "45px");
  126. }
  127. }else{
  128. this.node.setStyle("top", ""+top+"px");
  129. }
  130. }
  131. var left = sideSize.x+sidePosition.x+5;
  132. this.node.setStyle("left", ""+left+"px");
  133. this.node.setStyle("position", "absolute");
  134. // var y=0, x=5;
  135. // if (sideSize.y>size.y) y = (scroll.y+size.y/2)-sideSize.y/2;
  136. //
  137. // var position = "centerRight";
  138. // var edge = "centerLeft";
  139. // if (this.parentContainer.moduleType==="form"){
  140. // edge = "centerRight";
  141. // x = -5;
  142. // }
  143. //
  144. // if (this.json.barPosition=="left"){
  145. // position = "centerLeft";
  146. // edge = "centerRight";
  147. // x = -5;
  148. // if (this.parentContainer.moduleType==="form"){
  149. // edge = "centerLeft";
  150. // x = 5;
  151. // }
  152. // }
  153. //
  154. // this.node.position({
  155. // "relativeTo": this.sideNode,
  156. // "position": position,
  157. // "edge": edge,
  158. // "offset" : {"y": y}
  159. // });
  160. // this.json.styles.top = top;
  161. // if (top) this.node.setStyle("top", top);
  162. this.json.styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
  163. this.json.styles.bottom = "auto";
  164. this.json.styles.right = "auto";
  165. var p = this.sideNode.getPosition();
  166. var s = this.sideNode.getSize();
  167. this.sidePosition = {"p": p, "s": s};
  168. this.node.setStyles({"right": "auto", "bottom": "auto"});
  169. //
  170. // var p = this.node.getPosition(offsetParentNode);
  171. // var s = this.node.getSize();
  172. // var pSize = offsetParentNode.getSize();
  173. // var right = pSize.x-p.x-s.x;
  174. // this.node.setStyles({"right": right, "left": "auto"});
  175. //
  176. //
  177. },
  178. _refreshActionbar: function(){
  179. if (this.form.options.mode == "Mobile"){
  180. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  181. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  182. }else{
  183. this.toolbarNode = this.node.getFirst("div");
  184. this.toolbarNode.empty();
  185. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  186. if (this.json.defaultTools){
  187. var json = Array.clone(this.json.defaultTools);
  188. if (this.json.tools) json.append(this.json.tools);
  189. this.setToolbars(json, this.toolbarNode);
  190. this.toolbarWidget.load();
  191. //json = null;
  192. }else{
  193. MWF.getJSON(this.path+"toolbars.json", function(json){
  194. this.json.defaultTools = json;
  195. var json = Array.clone(this.json.defaultTools);
  196. if (this.json.tools) json.append(this.json.tools);
  197. this.setToolbars(json, this.toolbarNode);
  198. this.toolbarWidget.load();
  199. //json = null;
  200. }.bind(this), false);
  201. }
  202. // if (this.json.sysTools.editTools){
  203. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  204. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  205. // }else{
  206. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  207. //// this.setToolbars(this.json.tools, this.toolbarNode);
  208. // }
  209. }
  210. },
  211. setToolbars: function(tools, node){
  212. tools.each(function(tool){
  213. var actionNode = new Element("div", {
  214. "MWFnodetype": tool.type,
  215. "MWFButtonImage": this.path+""+this.options.style+"/tools/"+tool.img,
  216. "title": tool.title,
  217. "MWFButtonAction": tool.action,
  218. "MWFButtonText": tool.text
  219. }).inject(node);
  220. this.systemTools.push(actionNode);
  221. if (tool.sub){
  222. var subNode = node.getLast();
  223. this.setToolbars(tool.sub, subNode);
  224. }
  225. }.bind(this));
  226. },
  227. _setEditStyle_custom: function(name){
  228. if (name=="hideSystemTools"){
  229. if (this.json.hideSystemTools){
  230. this.systemTools.each(function(tool){
  231. tool.setStyle("display", "none");
  232. });
  233. }else{
  234. this.systemTools.each(function(tool){
  235. tool.setStyle("display", "block");
  236. });
  237. }
  238. }
  239. // if (name=="barPosition"){
  240. // this.loadPosition();
  241. // }
  242. if (name=="barPosition" || name=="styles"){
  243. // var top = this.json.styles.top;
  244. this.loadPosition();
  245. // this.json.styles.top = top;
  246. // if (top) this.node.setStyle("top", top);
  247. }
  248. if (name=="defaultTools" || name=="tools"){
  249. this._refreshActionbar();
  250. }
  251. }
  252. });