Actionbar.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. _initModule: function(){
  27. this._checkProcessTool();
  28. this.setStyleTemplate();
  29. this._setNodeProperty();
  30. if (!this.form.isSubform) this._createIconAction();
  31. this._setNodeEvent();
  32. this._refreshActionbar();
  33. if( !this.json.events ){
  34. MWF.getJSON(this.path+"template.json", function(json){
  35. this.json.events = json.events;
  36. }.bind(this), false);
  37. }
  38. },
  39. _checkProcessTool: function(){
  40. //删除从流程拷贝过来的系统按钮
  41. debugger;
  42. var processTools = ( this.json.multiTools || [] ).filter( function (tool) {
  43. return ["closeWork","saveWork","processWork","rerouteWork","resetWork","addTask","addSplit","retractWork","rollback",
  44. "deleteWork","printWork","pressWork","pauseTask","resumeTask"].contains( tool.action )
  45. });
  46. processTools.each(function (tool) {
  47. var actionNode = this.node.getElement("[mwfbuttonaction='"+tool.action+"']");
  48. if(actionNode)actionNode.destroy();
  49. this.json.multiTools.erase(tool);
  50. }.bind(this));
  51. var toolList = this.json.multiTools;
  52. if( processTools.length > 0 && this.form.options.mode !== "Mobile"){
  53. this.json.style = this.form.json.formStyleType.contains("red") ? "xform_blue_simple" : "xform_red_simple";
  54. this.json.customIconStyle = this.form.json.formStyleType.contains("red") ? "red" : "blue";
  55. this.json.customIconOverStyle = "white";
  56. this.json.actionStyles = null;
  57. o2.xhr_get(this.path+"toolbars.json", function(xhr){
  58. var multiTools = JSON.parse(xhr.responseText).map( function (d) { d.system = true; return d; });
  59. this.json.multiTools = multiTools.concat( toolList );
  60. debugger;
  61. }.bind(this), null,null,true);
  62. }
  63. },
  64. setTemplateStyles: function(styles){
  65. this.json.style = styles.style;
  66. this.json.customIconStyle = styles.customIconStyle;
  67. this.json.customIconOverStyle = styles.customIconOverStyle;
  68. },
  69. clearTemplateStyles: function(styles){
  70. this.json.style = "form";
  71. this.json.customIconStyle = "blue";
  72. this.json.customIconOverStyle = "white";
  73. },
  74. setAllStyles: function(){
  75. //this._refreshActionbar();
  76. this._resetActionbar();
  77. },
  78. _createNode: function(callback){
  79. this.node = new Element("div", {
  80. "id": this.json.id,
  81. "MWFType": "actionbar",
  82. "styles": this.css.moduleNode,
  83. "events": {
  84. "selectstart": function(e){
  85. e.preventDefault();
  86. }
  87. }
  88. }).inject(this.form.node);
  89. if (this.form.options.mode == "Mobile"){
  90. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  91. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  92. }else{
  93. this.toolbarNode = new Element("div").inject(this.node);
  94. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  95. o2.xhr_get(this.path+"toolbars.json", function(xhr){
  96. var jsonStr = xhr.responseText;
  97. this.json.multiTools = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  98. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.FormDesigner.LP.actionBar});
  99. this.multiToolsJson = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  100. this.setToolbars(this.multiToolsJson, this.toolbarNode);
  101. this.toolbarWidget.load();
  102. this._setEditStyle_custom( "hideSystemTools" );
  103. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  104. }.bind(this), null,null,true);
  105. //MWF.getJSON(this.path+"toolbars.json", function(json){
  106. //this.json.defaultTools = json;
  107. // this.json.multiTools = json.map( function (d) { d.system = true; return d; });
  108. // this.setToolbars(json, this.toolbarNode);
  109. // this.toolbarWidget.load();
  110. // this._setEditStyle_custom( "hideSystemTools" );
  111. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  112. //}.bind(this), false);
  113. // if (this.json.sysTools.editTools){
  114. // this.setToolbars(this.json.sysTools.editTools, this.toolbarNode);
  115. //// this.setToolbars(this.json.tools.editTools, this.toolbarNode);
  116. // }else{
  117. // this.setToolbars(this.json.sysTools, this.toolbarNode);
  118. //// this.setToolbars(this.json.tools, this.toolbarNode);
  119. // }
  120. // this.resetIcons();
  121. }
  122. },
  123. _refreshActionbar: function(){
  124. if (this.form.options.mode == "Mobile"){
  125. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  126. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  127. }else{
  128. this.toolbarNode = this.node.getFirst("div");
  129. this.toolbarNode.empty();
  130. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  131. if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  132. this.toolbarWidget.css = this.json.actionStyles;
  133. this.loadMultiToolbar();
  134. // if (this.json.defaultTools){
  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. // this._setEditStyle_custom( "hideSystemTools" );
  142. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  143. // }else{
  144. // MWF.getJSON(this.path+"toolbars.json", function(json){
  145. // this.json.defaultTools = json;
  146. // var json = Array.clone(this.json.defaultTools);
  147. // this.setToolbars(json, this.toolbarNode);
  148. // if (this.json.tools){
  149. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  150. // }
  151. // this.toolbarWidget.load();
  152. // this._setEditStyle_custom( "hideSystemTools" );
  153. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  154. // }.bind(this), false);
  155. // }
  156. }
  157. },
  158. _resetActionbar: function(){
  159. if (this.form.options.mode == "Mobile"){
  160. this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  161. this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  162. }else{
  163. this.toolbarNode = this.node.getFirst("div");
  164. this.toolbarNode.empty();
  165. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  166. // this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  167. if (!this.json.actionStyles){
  168. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  169. }else{
  170. this.toolbarWidget.css = Object.merge( Object.clone(this.json.actionStyles), this.toolbarWidget.css );
  171. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  172. }
  173. this.loadMultiToolbar();
  174. // if (this.json.defaultTools){
  175. // var json = Array.clone(this.json.defaultTools);
  176. // this.setToolbars(json, this.toolbarNode);
  177. // if (this.json.tools){
  178. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  179. // }
  180. // this.toolbarWidget.load();
  181. // }else{
  182. // MWF.getJSON(this.path+"toolbars.json", function(json){
  183. // this.json.defaultTools = json;
  184. // var json = Array.clone(this.json.defaultTools);
  185. // this.setToolbars(json, this.toolbarNode);
  186. // if (this.json.tools){
  187. // this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  188. // }
  189. // this.toolbarWidget.load();
  190. // }.bind(this), false);
  191. // }
  192. }
  193. },
  194. loadMultiToolbar : function(){
  195. if( this.json.multiTools ){
  196. if (MWF.xApplication.cms.FormDesigner.LP.actionBar){
  197. var jsonStr = JSON.stringify(this.json.multiTools);
  198. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.FormDesigner.LP.actionBar});
  199. this.multiToolsJson = JSON.parse(jsonStr); //.map( function (d) { return d; });
  200. }else{
  201. this.multiToolsJson = this.json.multiTools;
  202. }
  203. var json = Array.clone(this.multiToolsJson);
  204. //var json = Array.clone(this.json.multiTools);
  205. this.setMultiToolbars(json, this.toolbarNode);
  206. this.toolbarWidget.load();
  207. this._setEditStyle_custom( "hideSystemTools" );
  208. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  209. }else if( this.json.defaultTools ){
  210. this.json.multiTools = this.json.defaultTools.map( function (d) { d.system = true; return d; });
  211. if (this.json.tools){
  212. this.json.multiTools = this.json.multiTools.concat( this.json.tools )
  213. }
  214. this.setMultiToolbars( Array.clone(this.json.multiTools), this.toolbarNode);
  215. this.toolbarWidget.load();
  216. this._setEditStyle_custom( "hideSystemTools" );
  217. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  218. }else{
  219. o2.xhr_get(this.path+"toolbars.json", function(xhr){
  220. var jsonStr = xhr.responseText;
  221. this.json.multiTools = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  222. if (MWF.xApplication.cms.FormDesigner.LP.actionBar){
  223. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.FormDesigner.LP.actionBar});
  224. this.multiToolsJson = JSON.parse(jsonStr).map( function (d) { d.system = true; return d; });
  225. }else{
  226. this.multiToolsJson = this.json.multiTools;
  227. }
  228. //this.json.multiTools = json.map( function (d) { d.system = true; return d; });
  229. if (this.json.tools){
  230. this.multiToolsJson = this.multiToolsJson.concat( this.json.tools )
  231. }
  232. this.setMultiToolbars(Array.clone(this.multiToolsJson), this.toolbarNode);
  233. this.toolbarWidget.load();
  234. this._setEditStyle_custom( "hideSystemTools" );
  235. this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  236. }.bind(this), null,null,true);
  237. //MWF.getJSON(this.path+"toolbars.json", function(json){
  238. // this.json.multiTools = json.map( function (d) { d.system = true; return d; });
  239. // if (this.json.tools){
  240. // this.json.multiTools = this.json.multiTools.concat( this.json.tools )
  241. // }
  242. // this.setMultiToolbars(Array.clone(this.json.multiTools), this.toolbarNode);
  243. // this.toolbarWidget.load();
  244. // this._setEditStyle_custom( "hideSystemTools" );
  245. // this._setEditStyle_custom( "hideSetPopularDocumentTool" );
  246. //}.bind(this), false);
  247. }
  248. },
  249. setMultiToolbars: function(tools, node){
  250. tools.each(function(tool){
  251. if( tool.system ){
  252. this.setToolbars( [tool], node );
  253. }else{
  254. this.setCustomToolbars( [tool], node );
  255. }
  256. }.bind(this));
  257. },
  258. getImagePath: function(img, iscustom){
  259. if( iscustom ){
  260. var style;
  261. if( this.json.customIconStyle ){
  262. style = this.json.customIconStyle;
  263. }else{
  264. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  265. }
  266. return this.path+""+this.options.style +"/custom/"+ style +"/"+ img;
  267. }else{
  268. return this.path+""+this.options.style +"/tools/"+ (this.json.style || "default") +"/"+img;
  269. }
  270. },
  271. getImageOverPath: function(img_over, img, iscustom){
  272. if( iscustom ){
  273. var style_over = this.json.customIconOverStyle || "white";
  274. return this.path+""+this.options.style+"/custom/"+ style_over +"/"+img;
  275. }else{
  276. return this.path+""+this.options.style+"/tools/"+ (this.json.style || "default") +"/"+ img_over;
  277. }
  278. },
  279. setToolbars: function(tools, node){
  280. tools.each(function(tool){
  281. var actionNode = new Element("div", {
  282. "MWFnodetype": tool.type,
  283. //"MWFButtonImage": this.path+""+this.options.style +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  284. //"MWFButtonImageOver": this.path+""+this.options.style+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  285. "MWFButtonImage": this.getImagePath(tool.img, tool.customImg),
  286. "MWFButtonImageOver": this.getImageOverPath(tool.img_over, tool.img, tool.customImg),
  287. "title": tool.title,
  288. "MWFButtonAction": tool.action,
  289. "MWFButtonText": tool.text
  290. }).inject(node);
  291. this.systemTools.push(actionNode);
  292. this.multiTools.push( actionNode );
  293. if (tool.sub){
  294. var subNode = node.getLast();
  295. this.setToolbars(tool.sub, subNode);
  296. }
  297. }.bind(this));
  298. },
  299. setCustomToolbars: function(tools, node){
  300. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  301. var style;
  302. if( this.json.customIconStyle ){
  303. style = this.json.customIconStyle;
  304. }else{
  305. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  306. }
  307. var style_over = this.json.customIconOverStyle || "white";
  308. tools.each(function(tool){
  309. var actionNode = new Element("div", {
  310. "MWFnodetype": tool.type,
  311. "MWFButtonImage": this.path+""+this.options.style +"/custom/"+ style +"/"+tool.img,
  312. "MWFButtonImageOver": this.path+""+this.options.style+"/custom/"+ style_over +"/"+tool.img,
  313. "title": tool.title,
  314. "MWFButtonAction": tool.action,
  315. "MWFButtonText": tool.text
  316. }).inject(node);
  317. this.customTools.push(actionNode);
  318. this.multiTools.push( actionNode );
  319. if (tool.sub){
  320. var subNode = node.getLast();
  321. this.setToolbars(tool.sub, subNode);
  322. }
  323. }.bind(this));
  324. },
  325. _setEditStyle_custom: function(name){
  326. if (name=="hideSystemTools"){
  327. if (this.json.hideSystemTools){
  328. this.systemTools.each(function(tool){
  329. tool.setStyle("display", "none");
  330. });
  331. }else{
  332. this.systemTools.each(function(tool){
  333. tool.setStyle("display", "block");
  334. });
  335. }
  336. }
  337. if (name=="hideSetPopularDocumentTool"){
  338. if (this.json.hideSetPopularDocumentTool){
  339. this.systemTools.each(function(tool){
  340. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  341. tool.setStyle("display", "none");
  342. }
  343. });
  344. }else{
  345. this.systemTools.each(function(tool){
  346. if( tool.get("MWFButtonAction") == "setPopularDocument" ){
  347. tool.setStyle("display", "block");
  348. }
  349. });
  350. }
  351. }
  352. if (name=="defaultTools" || name=="tools" || name=="multiTools" || name==="actionStyles"){
  353. this._refreshActionbar();
  354. }
  355. }
  356. });