Sidebar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. _preprocessingModuleData: function(){
  74. },
  75. _recoveryModuleData: function(){
  76. },
  77. _initModule: function(){
  78. this.setStyleTemplate();
  79. this._setNodeProperty();
  80. if (!this.form.isSubform) this._createIconAction();
  81. this._setNodeEvent();
  82. if(this.json.styles)this.node.setStyles( this.json.styles );
  83. this._refreshActionbar();
  84. this.loadPosition();
  85. this.form.designer.designNode.addEvent("scroll", function(){
  86. }.bind(this));
  87. },
  88. position: function(){
  89. if (this.parentContainer){
  90. this.sideNode = this.parentContainer.node;
  91. //var p = this.sideNode.getStyles(["top", "left", "bottom", "right", "width", "height"]);
  92. var p = this.sideNode.getPosition();
  93. var s = this.sideNode.getSize();
  94. 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)){
  95. this.loadPosition();
  96. }
  97. }
  98. },
  99. loadPosition: function(){
  100. this.sideNode = this.parentContainer.node;
  101. var size = this.form.designer.designNode.getSize();
  102. var scroll = this.form.designer.designNode.getScroll();
  103. var sideSize = this.sideNode.getSize();
  104. var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
  105. var nodeSize = this.node.getSize();
  106. if (sideSize.y>size.y){
  107. var center = (size.y/2-nodeSize.y/2);
  108. if (center<sidePosition.y){
  109. this.node.setStyle("top", ""+sidePosition.y+"px");
  110. }else if (center>(sidePosition.y+sideSize.y)){
  111. var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
  112. this.node.setStyle("top", ""+tmp+"px");
  113. }else{
  114. this.node.setStyle("top", ""+center+"px");
  115. }
  116. }else{
  117. var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
  118. if (top>size.y){
  119. if (sidePosition.y+nodeSize.y>size.y){
  120. this.node.setStyle("top", ""+sidePosition.y+"px");
  121. }else{
  122. var tmp = size.y-nodeSize.y;
  123. this.node.setStyle("top", ""+tmp+"px");
  124. }
  125. }else if(top<=45){
  126. if(sidePosition.y+sideSize.y<nodeSize.y+45){
  127. var tmp = sidePosition.y+sideSize.y-nodeSize.y;
  128. this.node.setStyle("top", ""+tmp+"px");
  129. }else{
  130. this.node.setStyle("top", "45px");
  131. }
  132. }else{
  133. this.node.setStyle("top", ""+top+"px");
  134. }
  135. }
  136. var left = sideSize.x+sidePosition.x+5;
  137. this.node.setStyle("left", ""+left+"px");
  138. this.node.setStyle("position", "absolute");
  139. // var y=0, x=5;
  140. // if (sideSize.y>size.y) y = (scroll.y+size.y/2)-sideSize.y/2;
  141. //
  142. // var position = "centerRight";
  143. // var edge = "centerLeft";
  144. // if (this.parentContainer.moduleType==="form"){
  145. // edge = "centerRight";
  146. // x = -5;
  147. // }
  148. //
  149. // if (this.json.barPosition=="left"){
  150. // position = "centerLeft";
  151. // edge = "centerRight";
  152. // x = -5;
  153. // if (this.parentContainer.moduleType==="form"){
  154. // edge = "centerLeft";
  155. // x = 5;
  156. // }
  157. // }
  158. //
  159. // this.node.position({
  160. // "relativeTo": this.sideNode,
  161. // "position": position,
  162. // "edge": edge,
  163. // "offset" : {"y": y}
  164. // });
  165. // this.json.styles.top = top;
  166. // if (top) this.node.setStyle("top", top);
  167. var styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
  168. this.json.styles = Object.merge(this.json.styles, styles);
  169. this.json.styles.bottom = "auto";
  170. this.json.styles.right = "auto";
  171. var p = this.sideNode.getPosition();
  172. var s = this.sideNode.getSize();
  173. this.sidePosition = {"p": p, "s": s};
  174. this.node.setStyles({"right": "auto", "bottom": "auto"});
  175. //
  176. // var p = this.node.getPosition(offsetParentNode);
  177. // var s = this.node.getSize();
  178. // var pSize = offsetParentNode.getSize();
  179. // var right = pSize.x-p.x-s.x;
  180. // this.node.setStyles({"right": right, "left": "auto"});
  181. //
  182. //
  183. },
  184. _refreshActionbar: function(){
  185. if (this.form.options.mode == "Mobile"){
  186. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  187. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  188. }else{
  189. this.toolbarNode = this.node.getFirst("div");
  190. this.toolbarNode.empty();
  191. debugger;
  192. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  193. if (this.json.defaultTools){
  194. var json = Array.clone(this.json.defaultTools);
  195. if (this.json.tools) json.append(this.json.tools);
  196. this.setToolbars(json, this.toolbarNode);
  197. this.toolbarWidget.load();
  198. //json = null;
  199. }else{
  200. MWF.getJSON(this.path+"toolbars.json", function(json){
  201. this.json.defaultTools = json;
  202. var json = Array.clone(this.json.defaultTools);
  203. if (this.json.tools) json.append(this.json.tools);
  204. this.setToolbars(json, this.toolbarNode);
  205. this.toolbarWidget.load();
  206. //json = null;
  207. }.bind(this), false);
  208. }
  209. // if (this.json.sysTools.editTools){
  210. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  211. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  212. // }else{
  213. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  214. //// this.setToolbars(this.json.tools, this.toolbarNode);
  215. // }
  216. }
  217. },
  218. setToolbars: function(tools, node){
  219. tools.each(function(tool){
  220. var actionNode = new Element("div", {
  221. "MWFnodetype": tool.type,
  222. "MWFButtonImage": this.path+""+this.options.style+"/tools/"+tool.img,
  223. "title": tool.title,
  224. "MWFButtonAction": tool.action,
  225. "MWFButtonText": tool.text
  226. }).inject(node);
  227. this.systemTools.push(actionNode);
  228. if (tool.sub){
  229. var subNode = node.getLast();
  230. this.setToolbars(tool.sub, subNode);
  231. }
  232. }.bind(this));
  233. },
  234. _setEditStyle_custom: function(name){
  235. if (name=="hideSystemTools"){
  236. if (this.json.hideSystemTools){
  237. this.systemTools.each(function(tool){
  238. tool.setStyle("display", "none");
  239. });
  240. }else{
  241. this.systemTools.each(function(tool){
  242. tool.setStyle("display", "block");
  243. });
  244. }
  245. }
  246. // if (name=="barPosition"){
  247. // this.loadPosition();
  248. // }
  249. if (name=="barPosition" || name=="styles"){
  250. // var top = this.json.styles.top;
  251. this.loadPosition();
  252. // this.json.styles.top = top;
  253. // if (top) this.node.setStyle("top", top);
  254. }
  255. if (name=="defaultTools" || name=="tools"){
  256. this._refreshActionbar();
  257. }
  258. }
  259. });