Actionbar.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. MWF.xApplication.cms.FormDesigner.Module = MWF.xApplication.cms.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.Actionbar", null, false);
  3. MWF.require("MWF.widget.SimpleToolbar", null, false);
  4. MWF.xApplication.cms.FormDesigner.Module.Actionbar = MWF.CMSFCActionbar = new Class({
  5. Extends: MWF.FCActionbar,
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_cms_FormDesigner/Module/Actionbar/actionbar.html"
  9. },
  10. Implements : [MWF.CMSFCMI],
  11. initialize: function(form, options){
  12. this.setOptions(options);
  13. this.path = "/x_component_cms_FormDesigner/Module/Actionbar/";
  14. this.cssPath = "/x_component_cms_FormDesigner/Module/Actionbar/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. this.moduleType = "component";
  17. this.moduleName = "actionbar";
  18. this.Node = null;
  19. this.form = form;
  20. this.container = null;
  21. this.containerNode = null;
  22. this.systemTools = [];
  23. this.customTools = [];
  24. },
  25. setTemplateStyles: function(styles){
  26. this.json.style = styles.style;
  27. this.json.customIconStyle = styles.customIconStyle;
  28. this.json.customIconOverStyle = styles.customIconOverStyle;
  29. },
  30. clearTemplateStyles: function(styles){
  31. this.json.style = "form";
  32. this.json.customIconStyle = "blue";
  33. this.json.customIconOverStyle = "white";
  34. },
  35. setAllStyles: function(){
  36. this._refreshActionbar();
  37. },
  38. _createNode: function(callback){
  39. this.node = new Element("div", {
  40. "id": this.json.id,
  41. "MWFType": "actionbar",
  42. "styles": this.css.moduleNode,
  43. "events": {
  44. "selectstart": function(e){
  45. e.preventDefault();
  46. }
  47. }
  48. }).inject(this.form.node);
  49. if (this.form.options.mode == "Mobile"){
  50. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  51. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  52. }else{
  53. this.toolbarNode = new Element("div").inject(this.node);
  54. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  55. MWF.getJSON(this.path+"toolbars.json", function(json){
  56. this.json.defaultTools = json;
  57. this.setToolbars(json, this.toolbarNode);
  58. this.toolbarWidget.load();
  59. this._setEditStyle_custom( "hideSystemTools" );
  60. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  61. }.bind(this), false);
  62. // if (this.json.sysTools.editTools){
  63. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  64. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  65. // }else{
  66. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  67. //// this.setToolbars(this.json.tools, this.toolbarNode);
  68. // }
  69. // this.resetIcons();
  70. }
  71. },
  72. _refreshActionbar: function(){
  73. if (this.form.options.mode == "Mobile"){
  74. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  75. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  76. }else{
  77. this.toolbarNode = this.node.getFirst("div");
  78. this.toolbarNode.empty();
  79. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  80. //if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  81. //this.toolbarWidget.css = this.json.actionStyles;
  82. if (this.json.defaultTools){
  83. var json = Array.clone(this.json.defaultTools);
  84. this.setToolbars(json, this.toolbarNode);
  85. //if (this.json.tools) json.append(this.json.tools);
  86. //this.setToolbars(json, this.toolbarNode);
  87. if (this.json.tools){
  88. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  89. }
  90. this.toolbarWidget.load();
  91. this._setEditStyle_custom( "hideSystemTools" );
  92. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  93. //json = null;
  94. }else{
  95. MWF.getJSON(this.path+"toolbars.json", function(json){
  96. this.json.defaultTools = json;
  97. var json = Array.clone(this.json.defaultTools);
  98. this.setToolbars(json, this.toolbarNode);
  99. //if (this.json.tools) json.append(this.json.tools);
  100. //this.setToolbars(json, this.toolbarNode);
  101. if (this.json.tools){
  102. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  103. }
  104. this.toolbarWidget.load();
  105. this._setEditStyle_custom( "hideSystemTools" );
  106. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  107. //json = null;
  108. }.bind(this), false);
  109. }
  110. // if (this.json.sysTools.editTools){
  111. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  112. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  113. // }else{
  114. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  115. //// this.setToolbars(this.json.tools, this.toolbarNode);
  116. // }
  117. }
  118. },
  119. //_refreshActionbar: function(){
  120. // if (this.form.options.mode == "Mobile"){
  121. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  122. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  123. // }else{
  124. // this.toolbarNode = this.node.getFirst("div");
  125. // this.toolbarNode.empty();
  126. // this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  127. //
  128. // MWF.getJSON(this.path+"toolbars.json", function(json){
  129. // this.setToolbars(json, this.toolbarNode);
  130. // this.toolbarWidget.load();
  131. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  132. // }.bind(this), false);
  133. // }
  134. //
  135. //},
  136. setToolbars: function(tools, node){
  137. tools.each(function(tool){
  138. var actionNode = new Element("div", {
  139. "MWFnodetype": tool.type,
  140. "MWFButtonImage": this.path+""+this.options.style +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  141. "MWFButtonImageOver": this.path+""+this.options.style+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  142. "title": tool.title,
  143. "MWFButtonAction": tool.action,
  144. "MWFButtonText": tool.text
  145. }).inject(node);
  146. this.systemTools.push(actionNode);
  147. if (tool.sub){
  148. var subNode = node.getLast();
  149. this.setToolbars(tool.sub, subNode);
  150. }
  151. }.bind(this));
  152. },
  153. setCustomToolbars: function(tools, node){
  154. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  155. var style;
  156. if( this.json.customIconStyle ){
  157. style = this.json.customIconStyle;
  158. }else{
  159. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  160. }
  161. var style_over = this.json.customIconOverStyle || "white";
  162. tools.each(function(tool){
  163. var actionNode = new Element("div", {
  164. "MWFnodetype": tool.type,
  165. "MWFButtonImage": this.path+""+this.options.style +"/custom/"+ style +"/"+tool.img,
  166. "MWFButtonImageOver": this.path+""+this.options.style+"/custom/"+ style_over +"/"+tool.img,
  167. "title": tool.title,
  168. "MWFButtonAction": tool.action,
  169. "MWFButtonText": tool.text
  170. }).inject(node);
  171. this.customTools.push(actionNode);
  172. if (tool.sub){
  173. var subNode = node.getLast();
  174. this.setToolbars(tool.sub, subNode);
  175. }
  176. }.bind(this));
  177. },
  178. _setEditStyle_custom: function(name){
  179. if (name=="hideSystemTools"){
  180. if (this.json.hideSystemTools){
  181. this.systemTools.each(function(tool){
  182. tool.setStyle("display", "none");
  183. });
  184. }else{
  185. this.systemTools.each(function(tool){
  186. tool.setStyle("display", "block");
  187. });
  188. }
  189. }
  190. if (name=="hideSetPopularDocumentTool"){
  191. if (this.json.hideSetPopularDocumentTool){
  192. this.systemTools.each(function(tool){
  193. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  194. tool.setStyle("display", "none");
  195. }
  196. });
  197. }else{
  198. this.systemTools.each(function(tool){
  199. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  200. tool.setStyle("display", "block");
  201. }
  202. });
  203. }
  204. }
  205. if (name=="defaultTools" || name=="tools" || name==="actionStyles"){
  206. this._refreshActionbar();
  207. }
  208. }
  209. });