Actionbar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. debugger;
  9. //if (this.form.json.mode == "Mobile"){
  10. // this.node.empty();
  11. //}else if (COMMON.Browser.Platform.isMobile){
  12. // this.node.empty();
  13. //}else{
  14. this.toolbarNode = this.node.getFirst("div");
  15. if (!this.toolbarNode) this.toolbarNode = this.node;
  16. if (this.toolbarNode) this.toolbarNode.empty();
  17. //this.node.empty();
  18. MWF.require("MWF.widget.SimpleToolbar", function(){
  19. this.toolbarWidget = new MWF.widget.SimpleToolbar(this.toolbarNode, {
  20. "style": this.json.style,
  21. "onPostLoad" : function(){
  22. this.fireEvent("afterLoad");
  23. }.bind(this)
  24. }, this);
  25. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  26. //var json = this.readonly ? this.json.sysTools.readTools : this.json.sysTools.editTools;
  27. //if( this.json.style == "xform_red_simple" ){
  28. // json.each( function( j ){
  29. // var names = j.img.split(".");
  30. // j.img = names[0] + "_red." + names[1];
  31. // });
  32. //}
  33. //this.setToolbars(json, this.toolbarNode);
  34. //this.setCustomToolbars(this.json.tools, this.toolbarNode);
  35. //
  36. //this.toolbarWidget.load();
  37. if( this.json.multiTools ){
  38. var jsonStr = JSON.stringify(this.json.multiTools);
  39. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.Xform.LP.form});
  40. this.json.multiTools = JSON.parse(jsonStr);
  41. this.json.multiTools.each( function (tool) {
  42. if( tool.system ){
  43. if( !this.json.hideSystemTools ){
  44. this.setToolbars( [tool], this.toolbarNode, this.readonly);
  45. }
  46. }else{
  47. this.setCustomToolbars([tool], this.toolbarNode);
  48. }
  49. }.bind(this));
  50. this.toolbarWidget.load();
  51. }else{
  52. if (this.json.hideSystemTools){
  53. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  54. this.toolbarWidget.load();
  55. }else{
  56. if (this.json.defaultTools){
  57. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  58. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  59. this.toolbarWidget.load();
  60. }else{
  61. MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  62. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  63. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  64. this.toolbarWidget.load();
  65. }.bind(this), false);
  66. }
  67. //MWF.getJSON("../x_component_cms_Xform/$Form/toolbars.json", function(json){
  68. // this.setToolbars(json, this.toolbarNode, this.readonly);
  69. // this.setCustomToolbars(this.json.tools, this.toolbarNode);
  70. //
  71. // this.toolbarWidget.load();
  72. //}.bind(this), false);
  73. }
  74. }
  75. }.bind(this));
  76. //}
  77. },
  78. setCustomToolbars: function(tools, node){
  79. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  80. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  81. var style;
  82. if( this.json.customIconStyle ){
  83. style = this.json.customIconStyle;
  84. }else{
  85. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  86. }
  87. var style_over = this.json.customIconOverStyle || "white";
  88. tools.each(function(tool){
  89. var flag = true;
  90. if (this.readonly){
  91. flag = tool.readShow;
  92. }else{
  93. flag = tool.editShow;
  94. }
  95. if (flag){
  96. flag = true;
  97. if (tool.control){
  98. flag = this.form.businessData.control[tool.control]
  99. }
  100. if (tool.condition){
  101. var hideFlag = this.form.Macro.exec(tool.condition, this);
  102. flag = !hideFlag;
  103. }
  104. if (flag){
  105. var actionNode = new Element("div", {
  106. "id": tool.id,
  107. "MWFnodetype": tool.type,
  108. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+ style + "/" +tool.img,
  109. "MWFButtonImageOver": path+""+this.form.options.style+"/custom/" + style_over + "/"+tool.img,
  110. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  111. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  112. "title": tool.title,
  113. "MWFButtonAction": "runCustomAction",
  114. "MWFButtonText": tool.text
  115. }).inject(node);
  116. if( tool.properties ){
  117. actionNode.set(tool.properties);
  118. }
  119. if (tool.actionScript){
  120. actionNode.store("script", tool.actionScript);
  121. }
  122. if (tool.sub){
  123. var subNode = node.getLast();
  124. this.setCustomToolbars(tool.sub, subNode);
  125. }
  126. }
  127. }
  128. }.bind(this));
  129. },
  130. getImagePath: function(img, iscustom){
  131. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  132. if( iscustom ){
  133. var style;
  134. if( this.json.customIconStyle ){
  135. style = this.json.customIconStyle;
  136. }else{
  137. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  138. }
  139. return path+""+this.form.options.style+"/custom/"+ style + "/" +img;
  140. }else{
  141. return path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+img
  142. }
  143. },
  144. getImageOverPath: function(img_over, img, iscustom){
  145. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  146. if( iscustom ){
  147. var style_over = this.json.customIconOverStyle || "white";
  148. return path+""+this.form.options.style+"/custom/" + style_over + "/"+ img;
  149. }else{
  150. return path+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+img_over;
  151. }
  152. },
  153. setToolbars: function(tools, node, readonly, noCondition){
  154. tools.each(function(tool){
  155. var flag = true;
  156. if (tool.control){
  157. flag = this.form.businessData.control[tool.control]
  158. }
  159. if (!noCondition) if (tool.condition){
  160. var hideFlag = this.form.Macro.exec(tool.condition, this);
  161. flag = flag && (!hideFlag);
  162. }
  163. //if (tool.id == "action_processWork"){
  164. // if (!this.form.businessData.task){
  165. // flag = false;
  166. // }
  167. //}
  168. if (readonly){
  169. if (!tool.read) flag = false;
  170. }else{
  171. if (!tool.edit) flag = false;
  172. }
  173. if (this.json.hideSetPopularDocumentTool && tool.id == "action_popular"){
  174. flag = false;
  175. }
  176. if (flag){
  177. var actionNode = new Element("div", {
  178. "id": tool.id,
  179. "MWFnodetype": tool.type,
  180. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  181. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  182. "MWFButtonImage": this.getImagePath(tool.img, tool.customImg),
  183. "MWFButtonImageOver": this.getImageOverPath(tool.img_over, tool.img, tool.customImg),
  184. "title": tool.title,
  185. "MWFButtonAction": tool.action,
  186. "MWFButtonText": tool.text
  187. }).inject(node);
  188. if (tool.sub){
  189. var subNode = node.getLast();
  190. this.setToolbars(tool.sub, subNode);
  191. }
  192. }
  193. }.bind(this));
  194. },
  195. runCustomAction: function(bt){
  196. var script = bt.node.retrieve("script");
  197. this.form.Macro.exec(script, this);
  198. },
  199. saveDocument: function(){
  200. this.form.saveDocument();
  201. },
  202. saveDraftDocument: function(){
  203. this.form.saveDocument();
  204. },
  205. closeDocument: function(){
  206. this.form.closeDocument();
  207. },
  208. publishDocument: function(){
  209. this.form.publishDocument();
  210. },
  211. publishDocumentDelayed: function(){
  212. this.form.publishDocumentDelayed();
  213. },
  214. archiveDocument: function(){
  215. this.form.archiveDocument();
  216. },
  217. redraftDocument: function(){
  218. this.form.redraftDocument();
  219. },
  220. deleteDocument: function(){
  221. this.form.deleteDocument();
  222. },
  223. editDocument: function(){
  224. this.form.editDocument();
  225. },
  226. setPopularDocument: function(){
  227. this.form.setPopularDocument();
  228. },
  229. printDocument: function(){
  230. this.form.printDocument();
  231. },
  232. setTop: function(){
  233. this.form.setTop();
  234. },
  235. cancelTop: function(){
  236. this.form.cancelTop();
  237. },
  238. downloadAll: function(){
  239. this.form.downloadAll();
  240. },
  241. });