Actionbar.js 14 KB

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