Actionbar.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. MWF.xDesktop.requireApp("process.Xform", "Actionbar", null, false);
  2. MWF.xApplication.cms.Xform.Actionbar = MWF.CMSActionbar = new Class({
  3. Extends: MWF.APPActionbar,
  4. reload : function(){
  5. this._loadUserInterface();
  6. },
  7. _loadUserInterface: function(){
  8. //if (this.form.json.mode == "Mobile"){
  9. // this.node.empty();
  10. //}else if (COMMON.Browser.Platform.isMobile){
  11. // this.node.empty();
  12. //}else{
  13. this.toolbarNode = this.node.getFirst("div");
  14. if (!this.toolbarNode) this.toolbarNode = this.node;
  15. if (this.toolbarNode) this.toolbarNode.empty();
  16. //this.node.empty();
  17. MWF.require("MWF.widget.SimpleToolbar", function(){
  18. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {
  19. "style": this.json.style,
  20. "onPostLoad" : function(){
  21. this.fireEvent("afterLoad");
  22. }.bind(this)
  23. }, this);
  24. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  25. //var json = this.readonly ? this.json.sysTools.readTools : this.json.sysTools.editTools;
  26. //if( this.json.style == "xform_red_simple" ){
  27. // json.each( function( j ){
  28. // var names = j.img.split(".");
  29. // j.img = names[0] + "_red." + names[1];
  30. // });
  31. //}
  32. //this.setToolbars(json, this.toolbarNode);
  33. //this.setCustomToolbars(this.json.tools, this.toolbarNode);
  34. //
  35. //this.toolbarWidget.load();
  36. if (this.json.hideSystemTools){
  37. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  38. this.toolbarWidget.load();
  39. }else{
  40. if (this.json.defaultTools){
  41. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  42. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  43. this.toolbarWidget.load();
  44. }else{
  45. MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  46. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  47. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  48. this.toolbarWidget.load();
  49. }.bind(this), false);
  50. }
  51. //MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  52. // this.setToolbars(json, this.toolbarNode, this.readonly);
  53. // this.setCustomToolbars(this.json.tools, this.toolbarNode);
  54. //
  55. // this.toolbarWidget.load();
  56. //}.bind(this), false);
  57. }
  58. }.bind(this));
  59. //}
  60. },
  61. setCustomToolbars: function(tools, node){
  62. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  63. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  64. var style;
  65. if( this.json.customIconStyle ){
  66. style = this.json.customIconStyle;
  67. }else{
  68. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  69. }
  70. var style_over = this.json.customIconOverStyle || "white";
  71. tools.each(function(tool){
  72. var flag = true;
  73. if (this.readonly){
  74. flag = tool.readShow;
  75. }else{
  76. flag = tool.editShow;
  77. }
  78. if (flag){
  79. flag = true;
  80. if (tool.control){
  81. flag = this.form.businessData.control[tool.control]
  82. }
  83. if (tool.condition){
  84. var hideFlag = this.form.Macro.exec(tool.condition, this);
  85. flag = !hideFlag;
  86. }
  87. if (flag){
  88. var actionNode = new Element("div", {
  89. "id": tool.id,
  90. "MWFnodetype": tool.type,
  91. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+ style + "/" +tool.img,
  92. "MWFButtonImageOver": path+""+this.form.options.style+"/custom/" + style_over + "/"+tool.img,
  93. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  94. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  95. "title": tool.title,
  96. "MWFButtonAction": "runCustomAction",
  97. "MWFButtonText": tool.text
  98. }).inject(node);
  99. if( tool.properties ){
  100. actionNode.set(tool.properties);
  101. }
  102. if (tool.actionScript){
  103. actionNode.store("script", tool.actionScript);
  104. }
  105. if (tool.sub){
  106. var subNode = node.getLast();
  107. this.setCustomToolbars(tool.sub, subNode);
  108. }
  109. }
  110. }
  111. }.bind(this));
  112. },
  113. setToolbars: function(tools, node, readonly, noCondition){
  114. tools.each(function(tool){
  115. var flag = true;
  116. if (tool.control){
  117. flag = this.form.businessData.control[tool.control]
  118. }
  119. if (!noCondition) if (tool.condition){
  120. var hideFlag = this.form.Macro.exec(tool.condition, this);
  121. flag = flag && (!hideFlag);
  122. }
  123. //if (tool.id == "action_processWork"){
  124. // if (!this.form.businessData.task){
  125. // flag = false;
  126. // }
  127. //}
  128. if (readonly){
  129. if (!tool.read) flag = false;
  130. }else{
  131. if (!tool.edit) flag = false;
  132. }
  133. if (this.json.hideSetPopularDocumentTool && tool.id == "action_popular"){
  134. flag = false;
  135. }
  136. if (flag){
  137. var actionNode = new Element("div", {
  138. "id": tool.id,
  139. "MWFnodetype": tool.type,
  140. "MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  141. "MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  142. "title": tool.title,
  143. "MWFButtonAction": tool.action,
  144. "MWFButtonText": tool.text
  145. }).inject(node);
  146. if (tool.sub){
  147. var subNode = node.getLast();
  148. this.setToolbars(tool.sub, subNode);
  149. }
  150. }
  151. }.bind(this));
  152. },
  153. runCustomAction: function(bt){
  154. var script = bt.node.retrieve("script");
  155. this.form.Macro.exec(script, this);
  156. },
  157. saveDocument: function(){
  158. this.form.saveDocument();
  159. },
  160. saveDraftDocument: function(){
  161. this.form.saveDocument();
  162. },
  163. closeDocument: function(){
  164. this.form.closeDocument();
  165. },
  166. publishDocument: function(){
  167. this.form.publishDocument();
  168. },
  169. archiveDocument: function(){
  170. this.form.archiveDocument();
  171. },
  172. redraftDocument: function(){
  173. this.form.redraftDocument();
  174. },
  175. deleteDocument: function(){
  176. this.form.deleteDocument();
  177. },
  178. editDocument: function(){
  179. this.form.editDocument();
  180. },
  181. setPopularDocument: function(){
  182. this.form.setPopularDocument();
  183. },
  184. printDocument: function(){
  185. this.form.printDocument();
  186. }
  187. });