Actionbar.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. this.toolbarNode.empty();
  12. MWF.require("MWF.widget.SimpleToolbar", function(){
  13. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {"style": this.json.style}, this);
  14. //var json = this.readonly ? this.json.sysTools.readTools : this.json.sysTools.editTools;
  15. //if( this.json.style == "xform_red_simple" ){
  16. // json.each( function( j ){
  17. // var names = j.img.split(".");
  18. // j.img = names[0] + "_red." + names[1];
  19. // });
  20. //}
  21. //this.setToolbars(json, this.toolbarNode);
  22. //this.setCustomToolbars(this.json.tools, this.toolbarNode);
  23. //
  24. //this.toolbarWidget.load();
  25. if (this.json.hideSystemTools){
  26. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  27. this.toolbarWidget.load();
  28. }else{
  29. if (this.json.defaultTools){
  30. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  31. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  32. this.toolbarWidget.load();
  33. }else{
  34. MWF.getJSON("/x_component_cms_Xform/$Form/toolbars.json", function(json){
  35. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  36. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  37. this.toolbarWidget.load();
  38. }.bind(this), false);
  39. }
  40. //MWF.getJSON("/x_component_cms_Xform/$Form/toolbars.json", function(json){
  41. // this.setToolbars(json, this.toolbarNode, this.readonly);
  42. // this.setCustomToolbars(this.json.tools, this.toolbarNode);
  43. //
  44. // this.toolbarWidget.load();
  45. //}.bind(this), false);
  46. }
  47. }.bind(this));
  48. //}
  49. },
  50. setCustomToolbars: function(tools, node){
  51. var path = "/x_component_cms_FormDesigner/Module/Actionbar/";
  52. var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  53. tools.each(function(tool){
  54. var flag = true;
  55. if (this.readonly){
  56. flag = tool.readShow;
  57. }else{
  58. flag = tool.editShow;
  59. }
  60. if (flag){
  61. flag = true;
  62. if (tool.control){
  63. flag = this.form.businessData.control[tool.control]
  64. }
  65. if (tool.condition){
  66. var hideFlag = this.form.Macro.exec(tool.condition, this);
  67. flag = !hideFlag;
  68. }
  69. if (flag){
  70. var actionNode = new Element("div", {
  71. "id": tool.id,
  72. "MWFnodetype": tool.type,
  73. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+ style + "/" +tool.img,
  74. "MWFButtonImageOver": path+""+this.form.options.style+"/custom/white/"+tool.img,
  75. //"MWFButtonImage": "/x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  76. //"MWFButtonImageOver": "/x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  77. "title": tool.title,
  78. "MWFButtonAction": "runCustomAction",
  79. "MWFButtonText": tool.text
  80. }).inject(node);
  81. if (tool.actionScript){
  82. actionNode.store("script", tool.actionScript);
  83. }
  84. if (tool.sub){
  85. var subNode = node.getLast();
  86. this.setCustomToolbars(tool.sub, subNode);
  87. }
  88. }
  89. }
  90. }.bind(this));
  91. },
  92. setToolbars: function(tools, node, readonly, noCondition){
  93. tools.each(function(tool){
  94. var flag = true;
  95. if (tool.control){
  96. flag = this.form.businessData.control[tool.control]
  97. }
  98. if (!noCondition) if (tool.condition){
  99. var hideFlag = this.form.Macro.exec(tool.condition, this);
  100. flag = !hideFlag;
  101. }
  102. //if (tool.id == "action_processWork"){
  103. // if (!this.form.businessData.task){
  104. // flag = false;
  105. // }
  106. //}
  107. if (readonly){
  108. if (!tool.read) flag = false;
  109. }else{
  110. if (!tool.edit) flag = false;
  111. }
  112. if (this.json.hideSetPopularDocumentTool && tool.id == "action_popular"){
  113. flag = false;
  114. }
  115. if (flag){
  116. var actionNode = new Element("div", {
  117. "id": tool.id,
  118. "MWFnodetype": tool.type,
  119. "MWFButtonImage": "/x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  120. "MWFButtonImageOver": "/x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  121. "title": tool.title,
  122. "MWFButtonAction": tool.action,
  123. "MWFButtonText": tool.text
  124. }).inject(node);
  125. if (tool.sub){
  126. var subNode = node.getLast();
  127. this.setToolbars(tool.sub, subNode);
  128. }
  129. }
  130. }.bind(this));
  131. },
  132. runCustomAction: function(bt){
  133. var script = bt.node.retrieve("script");
  134. this.form.Macro.exec(script, this);
  135. },
  136. saveDocument: function(){
  137. this.form.saveDocument();
  138. },
  139. closeDocument: function(){
  140. this.form.closeDocument();
  141. },
  142. publishDocument: function(){
  143. this.form.publishDocument();
  144. },
  145. archiveDocument: function(){
  146. this.form.archiveDocument();
  147. },
  148. redraftDocument: function(){
  149. this.form.redraftDocument();
  150. },
  151. deleteDocument: function(){
  152. this.form.deleteDocument();
  153. },
  154. editDocument: function(){
  155. this.form.editDocument();
  156. },
  157. setPopularDocument: function(){
  158. this.form.setPopularDocument();
  159. }
  160. });