Actionbar.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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.multiTools = [];
  27. //this.containers = [];
  28. //this.elements = [];
  29. },
  30. setTemplateStyles: function(styles){
  31. this.json.style = styles.style;
  32. this.json.iconType = styles.iconType;
  33. this.json.iconOverStyle = styles.iconOverStyle || "";
  34. this.json.customIconStyle = styles.customIconStyle;
  35. this.json.customIconOverStyle = styles.customIconOverStyle || "";
  36. },
  37. clearTemplateStyles: function(styles){
  38. this.json.style = "form";
  39. this.json.iconType = "";
  40. this.json.iconOverStyle = "";
  41. this.json.customIconStyle = "";
  42. this.json.customIconOverStyle = "";
  43. },
  44. setAllStyles: function(){
  45. this._resetActionbar();
  46. },
  47. _createMoveNode: function(){
  48. this.moveNode = new Element("div", {
  49. "MWFType": "actionbar",
  50. "id": this.json.id,
  51. "styles": this.css.moduleNodeMove,
  52. "events": {
  53. "selectstart": function(e){
  54. e.preventDefault();
  55. }
  56. }
  57. }).inject(this.form.container);
  58. },
  59. _createNode: function(callback){
  60. this.node = new Element("div.form-toolbar-area", {
  61. "id": this.json.id,
  62. "MWFType": "actionbar",
  63. "styles": this.css.moduleNode,
  64. "events": {
  65. "selectstart": function(e){
  66. e.preventDefault();
  67. }
  68. }
  69. }).inject(this.form.node);
  70. if (this.form.options.mode == "Mobile"){
  71. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  72. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  73. }else{
  74. this.toolbarNode = new Element("div.form-toolbar").inject(this.node);
  75. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  76. o2.xhr_get(this.path+"toolbars.json", function(xhr){
  77. var jsonStr = xhr.responseText;
  78. this.json.multiTools = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  79. this.json.multiTools = this.json.multiTools.filter(function (d) { return !d.hidden; });
  80. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.process.FormDesigner.LP.actionBar});
  81. this.multiToolsJson = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  82. this.setToolbars(this.multiToolsJson, this.toolbarNode);
  83. this.toolbarWidget.load();
  84. }.bind(this), null,null,true);
  85. // MWF.getJSON(this.path+"toolbars.json", function(json){
  86. // // this.json.defaultTools = json;
  87. //
  88. // }.bind(this), false);
  89. // if (this.json.sysTools.editTools){
  90. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  91. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  92. // }else{
  93. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  94. //// this.setToolbars(this.json.tools, this.toolbarNode);
  95. // }
  96. // this.resetIcons();
  97. }
  98. },
  99. _initModule: function(){
  100. this.setStyleTemplate();
  101. this._setNodeProperty();
  102. if (!this.form.isSubform) this._createIconAction();
  103. this._setNodeEvent();
  104. this._refreshActionbar();
  105. if( !this.json.events ){
  106. MWF.getJSON(this.path+"template.json", function(json){
  107. this.json.events = json.events;
  108. }.bind(this), false);
  109. }
  110. },
  111. _getToolbarNode: function(){
  112. return this.node.getFirst("div");
  113. },
  114. _refreshActionbar: function(){
  115. if (this.form.options.mode == "Mobile"){
  116. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  117. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  118. }else{
  119. this.toolbarNode = this._getToolbarNode();
  120. this.toolbarNode.empty();
  121. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  122. if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  123. this.toolbarWidget.css = this.json.actionStyles;
  124. this.loadMultiToolbar();
  125. // if (this.json.defaultTools){
  126. // var json = Array.clone(this.json.defaultTools);
  127. // this.setToolbars(json, this.toolbarNode);
  128. // if (this.json.tools){
  129. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  130. // }
  131. // this.toolbarWidget.load();
  132. // }else{
  133. // MWF.getJSON(this.path+"toolbars.json", function(json){
  134. // this.json.defaultTools = json;
  135. // var json = Array.clone(this.json.defaultTools);
  136. // this.setToolbars(json, this.toolbarNode);
  137. // if (this.json.tools){
  138. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  139. // }
  140. // this.toolbarWidget.load();
  141. // }.bind(this), false);
  142. // }
  143. }
  144. },
  145. _resetActionbar: function(){
  146. if (this.form.options.mode == "Mobile"){
  147. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  148. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  149. }else{
  150. this.toolbarNode = this._getToolbarNode();
  151. this.toolbarNode.empty();
  152. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  153. if (!this.json.actionStyles){
  154. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  155. }else{
  156. this.toolbarWidget.css = Object.merge( Object.clone(this.json.actionStyles), this.toolbarWidget.css );
  157. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  158. }
  159. this.loadMultiToolbar();
  160. // if (this.json.defaultTools){
  161. // var json = Array.clone(this.json.defaultTools);
  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. // }else{
  168. // MWF.getJSON(this.path+"toolbars.json", function(json){
  169. // this.json.defaultTools = json;
  170. // var json = Array.clone(this.json.defaultTools);
  171. // this.setToolbars(json, this.toolbarNode);
  172. // if (this.json.tools){
  173. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  174. // }
  175. // this.toolbarWidget.load();
  176. // //json = null;
  177. // }.bind(this), false);
  178. // }
  179. }
  180. },
  181. loadMultiToolbar : function(){
  182. if( this.json.multiTools ){
  183. if (MWF.xApplication.process.FormDesigner.LP.actionBar){
  184. var jsonStr = JSON.stringify(this.json.multiTools);
  185. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.process.FormDesigner.LP.actionBar});
  186. this.multiToolsJson = JSON.parse(jsonStr); //.map( function (d) { d.system = true; return d; });
  187. }else{
  188. this.multiToolsJson = this.json.multiTools;
  189. }
  190. var json = Array.clone(this.multiToolsJson);
  191. this.setMultiToolbars(json, this.toolbarNode);
  192. this.toolbarWidget.load();
  193. }else if( this.json.defaultTools ){
  194. this.json.multiTools = this.json.defaultTools.map( function (d) { d.system = true; return d; });
  195. if (this.json.tools){
  196. this.json.multiTools = this.json.multiTools.concat( this.json.tools )
  197. }
  198. this.setMultiToolbars( Array.clone(this.json.multiTools), this.toolbarNode);
  199. this.toolbarWidget.load();
  200. }else{
  201. o2.xhr_get(this.path+"toolbars.json", function(xhr){
  202. var jsonStr = xhr.responseText;
  203. this.json.multiTools = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  204. this.json.multiTools = this.json.multiTools.filter(function (d) { return !d.hidden; });
  205. if (MWF.xApplication.process.FormDesigner.LP.actionBar){
  206. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.process.FormDesigner.LP.actionBar});
  207. this.multiToolsJson = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  208. }else{
  209. this.multiToolsJson = this.json.multiTools;
  210. }
  211. this.multiToolsJson = this.multiToolsJson.filter(function (d) { return !d.hidden; });
  212. this.setMultiToolbars(Array.clone(this.multiToolsJson), this.toolbarNode);
  213. // this.setToolbars(this.multiToolsJson, this.toolbarNode);
  214. this.toolbarWidget.load();
  215. }.bind(this), null,null,true);
  216. // MWF.getJSON(this.path+"toolbars.json", function(json){
  217. // // this.json.multiTools = json.map( function (d) { d.system = true; return d; });
  218. // // if (this.json.tools){
  219. // // this.json.multiTools = this.json.multiTools.concat( this.json.tools )
  220. // // }
  221. // // this.setMultiToolbars(Array.clone(this.json.multiTools), this.toolbarNode);
  222. // // this.toolbarWidget.load();
  223. // // }.bind(this), false);
  224. }
  225. },
  226. setMultiToolbars: function(tools, node){
  227. tools.each(function(tool){
  228. if( tool.system ){
  229. this.setToolbars( [tool], node );
  230. }else{
  231. this.setCustomToolbars( [tool], node );
  232. }
  233. }.bind(this));
  234. },
  235. getImagePath: function(img, iscustom){
  236. if( iscustom ){
  237. var path = this.json.customIconStyle ? (this.json.customIconStyle+ "/") : "";
  238. return this.path+""+this.options.style +"/custom/"+path+img
  239. }else{
  240. return this.path+""+this.options.style+"/tools/"+(this.json.style || "default")+"/"+img;
  241. }
  242. },
  243. getImageOverPath: function(img, iscustom){
  244. if( iscustom && this.json.customIconOverStyle ){
  245. return this.path+""+this.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +img;
  246. }else{
  247. return this.path+""+this.options.style+"/tools/"+this.json.iconOverStyle+"/"+img;
  248. }
  249. },
  250. setToolbars: function(tools, node){
  251. tools.each(function(tool){
  252. var actionNode = new Element("div", {
  253. "MWFnodetype": tool.type,
  254. "MWFButtonImage": this.json.iconType==="font" ? "" : this.getImagePath(tool.img, tool.customImg),
  255. "MWFButtonIcon": tool.icon,
  256. "title": tool.title,
  257. "MWFButtonAction": tool.action,
  258. "MWFButtonText": tool.text
  259. }).inject(node);
  260. if( this.json.iconOverStyle ){
  261. actionNode.set("MWFButtonImageOver" , this.getImageOverPath(tool.img, tool.customImg) );
  262. }
  263. actionNode.isSystemTool = true;
  264. this.systemTools.push(actionNode);
  265. this.multiTools.push( actionNode );
  266. if (tool.sub){
  267. var subNode = node.getLast();
  268. this.setToolbars(tool.sub, subNode);
  269. }
  270. }.bind(this));
  271. },
  272. setCustomToolbars: function(tools, node){
  273. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  274. var path = "";
  275. if( this.json.customIconStyle ){
  276. path = this.json.customIconStyle+ "/";
  277. }
  278. tools.each(function(tool){
  279. var actionNode = new Element("div", {
  280. "MWFnodetype": tool.type,
  281. "MWFButtonImage": this.json.iconType==="font" ? "" : this.path+""+this.options.style +"/custom/"+path+tool.img,
  282. "MWFButtonIcon": tool.icon,
  283. "title": tool.title,
  284. "MWFButtonAction": tool.action,
  285. "MWFButtonText": tool.text
  286. }).inject(node);
  287. if( this.json.customIconOverStyle ){
  288. actionNode.set("MWFButtonImageOver" , this.path+""+this.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  289. }
  290. this.customTools.push(actionNode);
  291. this.multiTools.push( actionNode );
  292. if (tool.sub){
  293. var subNode = node.getLast();
  294. this.setToolbars(tool.sub, subNode);
  295. }
  296. }.bind(this));
  297. },
  298. _setEditStyle_custom: function(name){
  299. if (name=="hideSystemTools"){
  300. if (this.json.hideSystemTools){
  301. this.systemTools.each(function(tool){
  302. // tool.setStyle("display", "none");
  303. tool.hide();
  304. });
  305. }else{
  306. this.systemTools.each(function(tool){
  307. // tool.setStyle("display", "block");
  308. tool.show();
  309. });
  310. }
  311. }
  312. if (name=="defaultTools" || name=="tools" || name=="multiTools" || name==="actionStyles"){
  313. this._refreshActionbar();
  314. }
  315. }
  316. });