Actionbar.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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": this.json.iconType==="font" ? "" : path+""+this.form.options.style+"/custom/"+ style + "/" +tool.img,
  109. "MWFButtonIcon": tool.icon,
  110. "MWFButtonImageOver": path+""+this.form.options.style+"/custom/" + style_over + "/"+tool.img,
  111. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  112. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+ (this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  113. "title": tool.title,
  114. "MWFButtonAction": "runCustomAction",
  115. "MWFButtonText": tool.text
  116. }).inject(node);
  117. if( tool.properties ){
  118. actionNode.set(tool.properties);
  119. }
  120. if (tool.actionScript){
  121. actionNode.store("script", tool.actionScript);
  122. }
  123. if (tool.sub){
  124. var subNode = node.getLast();
  125. this.setCustomToolbars(tool.sub, subNode);
  126. }
  127. }
  128. }
  129. }.bind(this));
  130. },
  131. getImagePath: function(img, iscustom){
  132. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  133. if( iscustom ){
  134. var style;
  135. if( this.json.customIconStyle ){
  136. style = this.json.customIconStyle;
  137. }else{
  138. style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  139. }
  140. return path+""+this.form.options.style+"/custom/"+ style + "/" +img;
  141. }else{
  142. return path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+img
  143. }
  144. },
  145. getImageOverPath: function(img_over, img, iscustom){
  146. var path = "../x_component_cms_FormDesigner/Module/Actionbar/";
  147. if( iscustom ){
  148. var style_over = this.json.customIconOverStyle || "white";
  149. return path+""+this.form.options.style+"/custom/" + style_over + "/"+ img;
  150. }else{
  151. return path+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+img_over;
  152. }
  153. },
  154. setToolbars: function(tools, node, readonly, noCondition){
  155. tools.each(function(tool){
  156. var flag = true;
  157. if (tool.control){
  158. flag = this.form.businessData.control[tool.control]
  159. }
  160. if (!noCondition) if (tool.condition){
  161. var hideFlag = this.form.Macro.exec(tool.condition, this);
  162. flag = flag && (!hideFlag);
  163. }
  164. //if (tool.id == "action_processWork"){
  165. // if (!this.form.businessData.task){
  166. // flag = false;
  167. // }
  168. //}
  169. if (readonly){
  170. if (!tool.read) flag = false;
  171. }else{
  172. if (!tool.edit) flag = false;
  173. }
  174. if (this.json.hideSetPopularDocumentTool && tool.id == "action_popular"){
  175. flag = false;
  176. }
  177. if (flag){
  178. var actionNode = new Element("div", {
  179. "id": tool.id,
  180. "MWFnodetype": tool.type,
  181. //"MWFButtonImage": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  182. //"MWFButtonImageOver": "../x_component_cms_FormDesigner/Module/Actionbar/"+(this.options.style||"default")+"/tools/"+ (this.json.style || "default") +"/"+tool.img_over,
  183. "MWFButtonImage": this.json.iconType==="font" ? "" : this.getImagePath(tool.img, tool.customImg),
  184. "MWFButtonIcon": tool.icon,
  185. "MWFButtonImageOver": this.getImageOverPath(tool.img_over, tool.img, tool.customImg),
  186. "title": tool.title,
  187. "MWFButtonAction": tool.action,
  188. "MWFButtonText": tool.text
  189. }).inject(node);
  190. if (tool.sub){
  191. var subNode = node.getLast();
  192. this.setToolbars(tool.sub, subNode);
  193. }
  194. }
  195. }.bind(this));
  196. },
  197. runCustomAction: function(bt){
  198. var script = bt.node.retrieve("script");
  199. this.form.Macro.exec(script, this);
  200. },
  201. saveDocument: function(){
  202. this.form.saveDocument();
  203. },
  204. saveDraftDocument: function(){
  205. this.form.saveDocument();
  206. },
  207. closeDocument: function(){
  208. this.form.closeDocument();
  209. },
  210. publishDocument: function(){
  211. this.form.publishDocument();
  212. },
  213. publishDocumentDelayed: function(){
  214. this.form.publishDocumentDelayed();
  215. },
  216. archiveDocument: function(){
  217. this.form.archiveDocument();
  218. },
  219. redraftDocument: function(){
  220. this.form.redraftDocument();
  221. },
  222. deleteDocument: function(){
  223. this.form.deleteDocument();
  224. },
  225. editDocument: function(){
  226. this.form.editDocument();
  227. },
  228. setPopularDocument: function(){
  229. this.form.setPopularDocument();
  230. },
  231. printDocument: function(){
  232. this.form.printDocument();
  233. },
  234. setTop: function(){
  235. this.form.setTop();
  236. },
  237. cancelTop: function(){
  238. this.form.cancelTop();
  239. },
  240. downloadAll: function(){
  241. this.form.downloadAll();
  242. },
  243. });