Actionbar.js 7.8 KB

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