Actionbar.js 9.9 KB

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