Actionbar.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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; //是否需要增加已阅
  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. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  81. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  82. this.toolbarWidget.load();
  83. }else{
  84. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  85. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  86. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  87. this.toolbarWidget.load();
  88. }.bind(this), null);
  89. }
  90. }
  91. }
  92. }.bind(this));
  93. // }
  94. },
  95. setCustomToolbars: function(tools, node){
  96. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  97. var iconPath = "";
  98. if( this.json.customIconStyle ){
  99. iconPath = this.json.customIconStyle+"/";
  100. }
  101. tools.each(function(tool){
  102. var flag = true;
  103. if (this.readonly){
  104. flag = tool.readShow;
  105. }else{
  106. flag = tool.editShow;
  107. }
  108. if (flag){
  109. flag = true;
  110. if (tool.control){
  111. flag = this.form.businessData.control[tool.control]
  112. }
  113. if (tool.condition){
  114. var hideFlag = this.form.Macro.exec(tool.condition, this);
  115. flag = !hideFlag;
  116. }
  117. if (flag){
  118. var actionNode = new Element("div", {
  119. "id": tool.id,
  120. "MWFnodetype": tool.type,
  121. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  122. "title": tool.title,
  123. "MWFButtonAction": "runCustomAction",
  124. "MWFButtonText": tool.text
  125. }).inject(node);
  126. if( this.json.customIconOverStyle ){
  127. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  128. }
  129. if( tool.properties ){
  130. actionNode.set(tool.properties);
  131. }
  132. if (tool.actionScript){
  133. actionNode.store("script", tool.actionScript);
  134. }
  135. if (tool.sub){
  136. var subNode = node.getLast();
  137. this.setCustomToolbars(tool.sub, subNode);
  138. }
  139. }
  140. }
  141. }.bind(this));
  142. },
  143. setToolbarItem: function(tool, node, readonly, noCondition){
  144. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  145. var flag = true;
  146. if (tool.control){
  147. flag = this.form.businessData.control[tool.control]
  148. }
  149. if (!noCondition) if (tool.condition){
  150. var hideFlag = this.form.Macro.exec(tool.condition, this);
  151. flag = flag && (!hideFlag);
  152. }
  153. // if (tool.id == "action_processWork"){
  154. // if (!this.form.businessData.task){
  155. // flag = false;
  156. // }
  157. // }
  158. if (tool.id == "action_downloadAll" || tool.id == "action_print"){
  159. if (!this.form.businessData.work.startTime){
  160. flag = false;
  161. }
  162. }
  163. if (tool.id == "action_delete"){
  164. if (!this.form.businessData.work || !this.form.businessData.work.id){
  165. flag = false;
  166. }
  167. }
  168. if (tool.id == "action_rollback") tool.read = true;
  169. if (readonly) if (!tool.read) flag = false;
  170. if (flag){
  171. var actionNode = new Element("div", {
  172. "id": tool.id,
  173. "MWFnodetype": tool.type,
  174. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  175. "MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  176. "title": tool.title,
  177. "MWFButtonAction": tool.action,
  178. "MWFButtonText": tool.text
  179. }).inject(node);
  180. if( this.json.iconOverStyle ){
  181. actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  182. }
  183. if( tool.properties ){
  184. actionNode.set(tool.properties);
  185. }
  186. if (tool.sub){
  187. var subNode = node.getLast();
  188. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  189. }
  190. }
  191. },
  192. setToolbars: function(tools, node, readonly, noCondition){
  193. tools.each(function(tool){
  194. this.setToolbarItem(tool, node, readonly, noCondition);
  195. }.bind(this));
  196. },
  197. runCustomAction: function(bt){
  198. var script = bt.node.retrieve("script");
  199. this.form.Macro.exec(script, this);
  200. },
  201. saveWork: function(){
  202. this.form.saveWork();
  203. },
  204. closeWork: function(){
  205. this.form.closeWork();
  206. },
  207. processWork: function(){
  208. this.form.processWork();
  209. },
  210. resetWork: function(){
  211. this.form.resetWork();
  212. },
  213. retractWork: function(e, ev){
  214. this.form.retractWork(e, ev);
  215. },
  216. rerouteWork: function(e, ev){
  217. this.form.rerouteWork(e, ev);
  218. },
  219. deleteWork: function(){
  220. this.form.deleteWork();
  221. },
  222. printWork: function(){
  223. this.form.printWork();
  224. },
  225. readedWork: function(b,e){
  226. this.form.readedWork(e);
  227. },
  228. addSplit: function(e){
  229. this.form.addSplit(e);
  230. },
  231. rollback: function(e){
  232. this.form.rollback(e);
  233. },
  234. downloadAll: function(e){
  235. this.form.downloadAll(e);
  236. },
  237. pressWork: function(e){
  238. this.form.pressWork(e);
  239. }
  240. });