Actionbar.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.multiTools ){
  37. this.json.multiTools.each( function (tool) {
  38. if( tool.system ){
  39. if( !this.json.hideSystemTools ){
  40. this.setToolbars( [tool], this.toolbarNode, this.readonly);
  41. }
  42. }else{
  43. this.setCustomToolbars([tool], this.toolbarNode);
  44. }
  45. }.bind(this));
  46. this.toolbarWidget.load();
  47. }else{
  48. if (this.json.hideSystemTools){
  49. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  50. this.toolbarWidget.load();
  51. }else{
  52. if (this.json.defaultTools){
  53. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  54. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  55. this.toolbarWidget.load();
  56. }else{
  57. MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  58. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  59. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  60. this.toolbarWidget.load();
  61. }.bind(this), false);
  62. }
  63. //MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  64. // this.setToolbars(json, this.toolbarNode, this.readonly);
  65. // this.setCustomToolbars(this.json.tools, this.toolbarNode);
  66. //
  67. // this.toolbarWidget.load();
  68. //}.bind(this), false);
  69. }
  70. }
  71. }.bind(this));
  72. //}
  73. },
  74. setCustomToolbars: function(tools, node){
  75. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  76. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  77. var style;
  78. if( this.json.customIconStyle ){
  79. style = this.json.customIconStyle;
  80. }else{
  81. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  82. }
  83. var style_over = this.json.customIconOverStyle || "white";
  84. tools.each(function(tool){
  85. var flag = true;
  86. if (this.readonly){
  87. flag = tool.readShow;
  88. }else{
  89. flag = tool.editShow;
  90. }
  91. if (flag){
  92. flag = true;
  93. if (tool.control){
  94. flag = this.form.businessData.control[tool.control]
  95. }
  96. if (tool.condition){
  97. var hideFlag = this.form.Macro.exec(tool.condition, this);
  98. flag = !hideFlag;
  99. }
  100. if (flag){
  101. var actionNode = new Element("div", {
  102. "id": tool.id,
  103. "MWFnodetype": tool.type,
  104. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+ style + "/" +tool.img,
  105. "MWFButtonImageOver": path+""+this.form.options.style+"/custom/" + style_over + "/"+tool.img,
  106. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  107. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  108. "title": tool.title,
  109. "MWFButtonAction": "runCustomAction",
  110. "MWFButtonText": tool.text
  111. }).inject(node);
  112. if( tool.properties ){
  113. actionNode.set(tool.properties);
  114. }
  115. if (tool.actionScript){
  116. actionNode.store("script", tool.actionScript);
  117. }
  118. if (tool.sub){
  119. var subNode = node.getLast();
  120. this.setCustomToolbars(tool.sub, subNode);
  121. }
  122. }
  123. }
  124. }.bind(this));
  125. },
  126. setToolbars: function(tools, node, readonly, noCondition){
  127. tools.each(function(tool){
  128. var flag = true;
  129. if (tool.control){
  130. flag = this.form.businessData.control[tool.control]
  131. }
  132. if (!noCondition) if (tool.condition){
  133. var hideFlag = this.form.Macro.exec(tool.condition, this);
  134. flag = flag && (!hideFlag);
  135. }
  136. //if (tool.id == "action_processWork"){
  137. // if (!this.form.businessData.task){
  138. // flag = false;
  139. // }
  140. //}
  141. if (readonly){
  142. if (!tool.read) flag = false;
  143. }else{
  144. if (!tool.edit) flag = false;
  145. }
  146. if (this.json.hideSetPopularDocumentTool && tool.id == "action_popular"){
  147. flag = false;
  148. }
  149. if (flag){
  150. var actionNode = new Element("div", {
  151. "id": tool.id,
  152. "MWFnodetype": tool.type,
  153. "MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  154. "MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  155. "title": tool.title,
  156. "MWFButtonAction": tool.action,
  157. "MWFButtonText": tool.text
  158. }).inject(node);
  159. if (tool.sub){
  160. var subNode = node.getLast();
  161. this.setToolbars(tool.sub, subNode);
  162. }
  163. }
  164. }.bind(this));
  165. },
  166. runCustomAction: function(bt){
  167. var script = bt.node.retrieve("script");
  168. this.form.Macro.exec(script, this);
  169. },
  170. saveDocument: function(){
  171. this.form.saveDocument();
  172. },
  173. saveDraftDocument: function(){
  174. this.form.saveDocument();
  175. },
  176. closeDocument: function(){
  177. this.form.closeDocument();
  178. },
  179. publishDocument: function(){
  180. this.form.publishDocument();
  181. },
  182. archiveDocument: function(){
  183. this.form.archiveDocument();
  184. },
  185. redraftDocument: function(){
  186. this.form.redraftDocument();
  187. },
  188. deleteDocument: function(){
  189. this.form.deleteDocument();
  190. },
  191. editDocument: function(){
  192. this.form.editDocument();
  193. },
  194. setPopularDocument: function(){
  195. this.form.setPopularDocument();
  196. },
  197. printDocument: function(){
  198. this.form.printDocument();
  199. }
  200. });