Actionbar.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. this._resetActionbar();
  38. },
  39. _createNode: function(callback){
  40. this.node = new Element("div", {
  41. "id": this.json.id,
  42. "MWFType": "actionbar",
  43. "styles": this.css.moduleNode,
  44. "events": {
  45. "selectstart": function(e){
  46. e.preventDefault();
  47. }
  48. }
  49. }).inject(this.form.node);
  50. if (this.form.options.mode == "Mobile"){
  51. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  52. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  53. }else{
  54. this.toolbarNode = new Element("div").inject(this.node);
  55. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  56. MWF.getJSON(this.path+"toolbars.json", function(json){
  57. this.json.defaultTools = json;
  58. this.setToolbars(json, this.toolbarNode);
  59. this.toolbarWidget.load();
  60. this._setEditStyle_custom( "hideSystemTools" );
  61. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  62. }.bind(this), false);
  63. // if (this.json.sysTools.editTools){
  64. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  65. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  66. // }else{
  67. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  68. //// this.setToolbars(this.json.tools, this.toolbarNode);
  69. // }
  70. // this.resetIcons();
  71. }
  72. },
  73. _refreshActionbar: function(){
  74. if (this.form.options.mode == "Mobile"){
  75. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  76. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  77. }else{
  78. this.toolbarNode = this.node.getFirst("div");
  79. this.toolbarNode.empty();
  80. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  81. if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  82. this.toolbarWidget.css = this.json.actionStyles;
  83. if (this.json.defaultTools){
  84. var json = Array.clone(this.json.defaultTools);
  85. this.setToolbars(json, this.toolbarNode);
  86. //if (this.json.tools) json.append(this.json.tools);
  87. //this.setToolbars(json, this.toolbarNode);
  88. if (this.json.tools){
  89. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  90. }
  91. this.toolbarWidget.load();
  92. this._setEditStyle_custom( "hideSystemTools" );
  93. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  94. //json = null;
  95. }else{
  96. MWF.getJSON(this.path+"toolbars.json", function(json){
  97. this.json.defaultTools = json;
  98. var json = Array.clone(this.json.defaultTools);
  99. this.setToolbars(json, this.toolbarNode);
  100. //if (this.json.tools) json.append(this.json.tools);
  101. //this.setToolbars(json, this.toolbarNode);
  102. if (this.json.tools){
  103. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  104. }
  105. this.toolbarWidget.load();
  106. this._setEditStyle_custom( "hideSystemTools" );
  107. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  108. //json = null;
  109. }.bind(this), false);
  110. }
  111. // if (this.json.sysTools.editTools){
  112. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  113. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  114. // }else{
  115. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  116. //// this.setToolbars(this.json.tools, this.toolbarNode);
  117. // }
  118. }
  119. },
  120. //_refreshActionbar: function(){
  121. // if (this.form.options.mode == "Mobile"){
  122. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  123. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  124. // }else{
  125. // this.toolbarNode = this.node.getFirst("div");
  126. // this.toolbarNode.empty();
  127. // this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  128. //
  129. // MWF.getJSON(this.path+"toolbars.json", function(json){
  130. // this.setToolbars(json, this.toolbarNode);
  131. // this.toolbarWidget.load();
  132. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  133. // }.bind(this), false);
  134. // }
  135. //
  136. //},
  137. _resetActionbar: function(){
  138. if (this.form.options.mode == "Mobile"){
  139. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  140. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  141. }else{
  142. this.toolbarNode = this.node.getFirst("div");
  143. this.toolbarNode.empty();
  144. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  145. // this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  146. if (!this.json.actionStyles){
  147. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  148. }else{
  149. this.toolbarWidget.css = Object.merge( Object.clone(this.json.actionStyles), this.toolbarWidget.css );
  150. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  151. }
  152. if (this.json.defaultTools){
  153. var json = Array.clone(this.json.defaultTools);
  154. //if (this.json.tools) json.append(this.json.tools);
  155. this.setToolbars(json, this.toolbarNode);
  156. if (this.json.tools){
  157. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  158. }
  159. this.toolbarWidget.load();
  160. //json = null;
  161. }else{
  162. MWF.getJSON(this.path+"toolbars.json", function(json){
  163. this.json.defaultTools = json;
  164. var json = Array.clone(this.json.defaultTools);
  165. //if (this.json.tools) json.append(this.json.tools);
  166. this.setToolbars(json, this.toolbarNode);
  167. if (this.json.tools){
  168. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  169. }
  170. this.toolbarWidget.load();
  171. //json = null;
  172. }.bind(this), false);
  173. }
  174. }
  175. },
  176. setToolbars: function(tools, node){
  177. tools.each(function(tool){
  178. var actionNode = new Element("div", {
  179. "MWFnodetype": tool.type,
  180. "MWFButtonImage": this.path+""+this.options.style +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  181. "MWFButtonImageOver": this.path+""+this.options.style+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  182. "title": tool.title,
  183. "MWFButtonAction": tool.action,
  184. "MWFButtonText": tool.text
  185. }).inject(node);
  186. this.systemTools.push(actionNode);
  187. if (tool.sub){
  188. var subNode = node.getLast();
  189. this.setToolbars(tool.sub, subNode);
  190. }
  191. }.bind(this));
  192. },
  193. setCustomToolbars: function(tools, node){
  194. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  195. var style;
  196. if( this.json.customIconStyle ){
  197. style = this.json.customIconStyle;
  198. }else{
  199. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  200. }
  201. var style_over = this.json.customIconOverStyle || "white";
  202. tools.each(function(tool){
  203. var actionNode = new Element("div", {
  204. "MWFnodetype": tool.type,
  205. "MWFButtonImage": this.path+""+this.options.style +"/custom/"+ style +"/"+tool.img,
  206. "MWFButtonImageOver": this.path+""+this.options.style+"/custom/"+ style_over +"/"+tool.img,
  207. "title": tool.title,
  208. "MWFButtonAction": tool.action,
  209. "MWFButtonText": tool.text
  210. }).inject(node);
  211. this.customTools.push(actionNode);
  212. if (tool.sub){
  213. var subNode = node.getLast();
  214. this.setToolbars(tool.sub, subNode);
  215. }
  216. }.bind(this));
  217. },
  218. _setEditStyle_custom: function(name){
  219. if (name=="hideSystemTools"){
  220. if (this.json.hideSystemTools){
  221. this.systemTools.each(function(tool){
  222. tool.setStyle("display", "none");
  223. });
  224. }else{
  225. this.systemTools.each(function(tool){
  226. tool.setStyle("display", "block");
  227. });
  228. }
  229. }
  230. if (name=="hideSetPopularDocumentTool"){
  231. if (this.json.hideSetPopularDocumentTool){
  232. this.systemTools.each(function(tool){
  233. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  234. tool.setStyle("display", "none");
  235. }
  236. });
  237. }else{
  238. this.systemTools.each(function(tool){
  239. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  240. tool.setStyle("display", "block");
  241. }
  242. });
  243. }
  244. }
  245. if (name=="defaultTools" || name=="tools" || name==="actionStyles"){
  246. this._refreshActionbar();
  247. }
  248. }
  249. });