Actionbar.js 10 KB

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