Actionbar.js 10 KB

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