Actionbar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.require("MWF.widget.Tree", null, false);
  3. //MWF.require("MWF.widget.Toolbar", null, false);
  4. MWF.xApplication.process.Xform.Actionbar = MWF.APPActionbar = new Class({
  5. Extends: MWF.APP$Module,
  6. options: {
  7. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  8. },
  9. reload : function(){
  10. this._loadUserInterface();
  11. },
  12. _loadUserInterface: function(){
  13. // if (this.form.json.mode == "Mobile"){
  14. // this.node.empty();
  15. // }else if (COMMON.Browser.Platform.isMobile){
  16. // this.node.empty();
  17. // }else{
  18. this.toolbarNode = this.node.getFirst("div");
  19. this.toolbarNode.empty();
  20. MWF.require("MWF.widget.Toolbar", function(){
  21. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  22. "style": this.json.style,
  23. "onPostLoad" : function(){
  24. this.fireEvent("afterLoad");
  25. }.bind(this)
  26. }, this);
  27. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  28. //alert(this.readonly)
  29. if( this.json.multiTools ){ //自定义操作和系统操作混合的情况,用 system : true 来区分系统和自定义
  30. var addReadActionFlag = !this.json.hideSystemTools && !this.json.hideReadedAction; //是否需要增加已阅
  31. this.json.multiTools.each( function (tool) {
  32. if( tool.system ){
  33. if( !this.json.hideSystemTools ){
  34. if( tool.id === "action_readed" )addReadActionFlag = false;
  35. this.setToolbars([tool], this.toolbarNode, this.readonly);
  36. }
  37. }else{
  38. this.setCustomToolbars([tool], this.toolbarNode);
  39. }
  40. }.bind(this));
  41. if( addReadActionFlag ){
  42. var addActions = [
  43. {
  44. "type": "MWFToolBarButton",
  45. "img": "read.png",
  46. "title": "标记为已阅",
  47. "action": "readedWork",
  48. "text": "已阅",
  49. "id": "action_readed",
  50. "control": "allowReadProcessing",
  51. "condition": "",
  52. "read": true
  53. }
  54. ];
  55. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  56. }
  57. this.toolbarWidget.load();
  58. }else{
  59. if (this.json.hideSystemTools){
  60. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  61. this.toolbarWidget.load();
  62. }else{
  63. if (this.json.defaultTools){
  64. var addActions = [
  65. {
  66. "type": "MWFToolBarButton",
  67. "img": "read.png",
  68. "title": "标记为已阅",
  69. "action": "readedWork",
  70. "text": "已阅",
  71. "id": "action_readed",
  72. "control": "allowReadProcessing",
  73. "condition": "",
  74. "read": true
  75. }
  76. ];
  77. //this.form.businessData.control.allowReflow =
  78. //this.json.defaultTools.push(o);
  79. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  80. if( !this.json.hideReadedAction ){
  81. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  82. }
  83. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  84. this.toolbarWidget.load();
  85. }else{
  86. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  87. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  88. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  89. this.toolbarWidget.load();
  90. }.bind(this), null);
  91. }
  92. }
  93. }
  94. }.bind(this));
  95. // }
  96. },
  97. setCustomToolbars: function(tools, node){
  98. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  99. var iconPath = "";
  100. if( this.json.customIconStyle ){
  101. iconPath = this.json.customIconStyle+"/";
  102. }
  103. tools.each(function(tool){
  104. var flag = true;
  105. if (this.readonly){
  106. flag = tool.readShow;
  107. }else{
  108. flag = tool.editShow;
  109. }
  110. if (flag){
  111. flag = true;
  112. if (tool.control){
  113. flag = this.form.businessData.control[tool.control]
  114. }
  115. if (tool.condition){
  116. var hideFlag = this.form.Macro.exec(tool.condition, this);
  117. flag = !hideFlag;
  118. }
  119. if (flag){
  120. var actionNode = new Element("div", {
  121. "id": tool.id,
  122. "MWFnodetype": tool.type,
  123. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  124. "title": tool.title,
  125. "MWFButtonAction": "runCustomAction",
  126. "MWFButtonText": tool.text
  127. }).inject(node);
  128. if( this.json.customIconOverStyle ){
  129. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  130. }
  131. if( tool.properties ){
  132. actionNode.set(tool.properties);
  133. }
  134. if (tool.actionScript){
  135. actionNode.store("script", tool.actionScript);
  136. }
  137. if (tool.sub){
  138. var subNode = node.getLast();
  139. this.setCustomToolbars(tool.sub, subNode);
  140. }
  141. }
  142. }
  143. }.bind(this));
  144. },
  145. setToolbarItem: function(tool, node, readonly, noCondition){
  146. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  147. var flag = true;
  148. if (tool.control){
  149. flag = this.form.businessData.control[tool.control]
  150. }
  151. if (!noCondition) if (tool.condition){
  152. var hideFlag = this.form.Macro.exec(tool.condition, this);
  153. flag = flag && (!hideFlag);
  154. }
  155. // if (tool.id == "action_processWork"){
  156. // if (!this.form.businessData.task){
  157. // flag = false;
  158. // }
  159. // }
  160. if (tool.id == "action_downloadAll" || tool.id == "action_print"){
  161. if (!this.form.businessData.work.startTime){
  162. flag = false;
  163. }
  164. }
  165. if (tool.id == "action_delete"){
  166. if (!this.form.businessData.work || !this.form.businessData.work.id){
  167. flag = false;
  168. }
  169. }
  170. if (tool.id == "action_rollback") tool.read = true;
  171. if (readonly) if (!tool.read) flag = false;
  172. if (flag){
  173. var actionNode = new Element("div", {
  174. "id": tool.id,
  175. "MWFnodetype": tool.type,
  176. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  177. "MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  178. "title": tool.title,
  179. "MWFButtonAction": tool.action,
  180. "MWFButtonText": tool.text
  181. }).inject(node);
  182. if( this.json.iconOverStyle ){
  183. actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  184. }
  185. if( tool.properties ){
  186. actionNode.set(tool.properties);
  187. }
  188. if (tool.sub){
  189. var subNode = node.getLast();
  190. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  191. }
  192. }
  193. },
  194. setToolbars: function(tools, node, readonly, noCondition){
  195. tools.each(function(tool){
  196. this.setToolbarItem(tool, node, readonly, noCondition);
  197. }.bind(this));
  198. },
  199. runCustomAction: function(bt){
  200. var script = bt.node.retrieve("script");
  201. this.form.Macro.exec(script, this);
  202. },
  203. saveWork: function(){
  204. this.form.saveWork();
  205. },
  206. closeWork: function(){
  207. this.form.closeWork();
  208. },
  209. processWork: function(){
  210. this.form.processWork();
  211. },
  212. resetWork: function(){
  213. this.form.resetWork();
  214. },
  215. retractWork: function(e, ev){
  216. this.form.retractWork(e, ev);
  217. },
  218. rerouteWork: function(e, ev){
  219. this.form.rerouteWork(e, ev);
  220. },
  221. deleteWork: function(){
  222. this.form.deleteWork();
  223. },
  224. printWork: function(){
  225. this.form.printWork();
  226. },
  227. readedWork: function(b,e){
  228. this.form.readedWork(e);
  229. },
  230. addSplit: function(e){
  231. this.form.addSplit(e);
  232. },
  233. rollback: function(e){
  234. this.form.rollback(e);
  235. },
  236. downloadAll: function(e){
  237. this.form.downloadAll(e);
  238. },
  239. pressWork: function(e){
  240. this.form.pressWork(e);
  241. }
  242. });