Actionbar.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. /** @class Actionbar 操作条组件。
  5. * @example
  6. * //可以在脚本中获取该组件
  7. * //方法1:
  8. * var actionbar = this.form.get("name"); //获取操作条
  9. * //方法2
  10. * var actionbar = this.target; //在操作条和操作本身的事件脚本中获取
  11. * @extends MWF.xApplication.process.Xform.$Module
  12. * @category FormComponents
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.Actionbar = MWF.APPActionbar = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Actionbar# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 组件加载前触发。
  22. * @event MWF.xApplication.process.Xform.Actionbar#queryLoad
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. /**
  26. * 组件加载时触发。
  27. * @event MWF.xApplication.process.Xform.Actionbar#load
  28. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  29. */
  30. /**
  31. * 组件加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
  32. * @event MWF.xApplication.process.Xform.Actionbar#postLoad
  33. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  34. */
  35. /**
  36. * 组件加载后事件。这个时候操作条已生成
  37. * @event MWF.xApplication.process.Xform.Actionbar#afterLoad
  38. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  39. */
  40. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  41. },
  42. /**
  43. * @summary 重新加载操作条.
  44. * @example
  45. * this.form.get("name").reload(); //显示操作条
  46. */
  47. reload : function(){
  48. this._loadUserInterface();
  49. },
  50. _loadUserInterface: function(){
  51. // if (this.form.json.mode == "Mobile"){
  52. // this.node.empty();
  53. // }else if (COMMON.Browser.Platform.isMobile){
  54. // this.node.empty();
  55. // }else{
  56. this.toolbarNode = this.node.getFirst("div");
  57. if(!this.toolbarNode)return;
  58. this.toolbarNode.empty();
  59. MWF.require("MWF.widget.Toolbar", function(){
  60. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  61. "style": this.json.style,
  62. "onPostLoad" : function(){
  63. this.fireEvent("afterLoad");
  64. }.bind(this)
  65. }, this);
  66. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  67. //alert(this.readonly)
  68. if( this.json.multiTools ){ //自定义操作和系统操作混合的情况,用 system : true 来区分系统和自定义
  69. var addReadActionFlag = !this.json.hideSystemTools && !this.json.hideReadedAction; //是否需要增加已阅
  70. this.json.multiTools.each( function (tool) {
  71. if( tool.system ){
  72. if( !this.json.hideSystemTools ){
  73. if( tool.id === "action_readed" )addReadActionFlag = false;
  74. this.setToolbars([tool], this.toolbarNode, this.readonly);
  75. }
  76. }else{
  77. this.setCustomToolbars([tool], this.toolbarNode);
  78. }
  79. }.bind(this));
  80. if( addReadActionFlag ){
  81. var addActions = [
  82. {
  83. "type": "MWFToolBarButton",
  84. "img": "read.png",
  85. "title": "标记为已阅",
  86. "action": "readedWork",
  87. "text": "已阅",
  88. "id": "action_readed",
  89. "control": "allowReadProcessing",
  90. "condition": "",
  91. "read": true
  92. }
  93. ];
  94. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  95. }
  96. this.toolbarWidget.load();
  97. }else{
  98. if (this.json.hideSystemTools){
  99. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  100. this.toolbarWidget.load();
  101. }else{
  102. if (this.json.defaultTools){
  103. var addActions = [
  104. {
  105. "type": "MWFToolBarButton",
  106. "img": "read.png",
  107. "title": "标记为已阅",
  108. "action": "readedWork",
  109. "text": "已阅",
  110. "id": "action_readed",
  111. "control": "allowReadProcessing",
  112. "condition": "",
  113. "read": true
  114. }
  115. ];
  116. //this.form.businessData.control.allowReflow =
  117. //this.json.defaultTools.push(o);
  118. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  119. if( !this.json.hideReadedAction ){
  120. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  121. }
  122. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  123. this.toolbarWidget.load();
  124. }else{
  125. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  126. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  127. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  128. this.toolbarWidget.load();
  129. }.bind(this), null);
  130. }
  131. }
  132. }
  133. }.bind(this));
  134. // }
  135. },
  136. setCustomToolbars: function(tools, node){
  137. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  138. var iconPath = "";
  139. if( this.json.customIconStyle ){
  140. iconPath = this.json.customIconStyle+"/";
  141. }
  142. tools.each(function(tool){
  143. var flag = true;
  144. if (this.readonly){
  145. flag = tool.readShow;
  146. }else{
  147. flag = tool.editShow;
  148. }
  149. if (flag){
  150. flag = true;
  151. if (tool.control){
  152. flag = this.form.businessData.control[tool.control]
  153. }
  154. if (tool.condition){
  155. var hideFlag = this.form.Macro.exec(tool.condition, this);
  156. flag = !hideFlag;
  157. }
  158. if (flag){
  159. var actionNode = new Element("div", {
  160. "id": tool.id,
  161. "MWFnodetype": tool.type,
  162. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  163. "title": tool.title,
  164. "MWFButtonAction": "runCustomAction",
  165. "MWFButtonText": tool.text
  166. }).inject(node);
  167. if( this.json.customIconOverStyle ){
  168. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  169. }
  170. if( tool.properties ){
  171. actionNode.set(tool.properties);
  172. }
  173. if (tool.actionScript){
  174. actionNode.store("script", tool.actionScript);
  175. }
  176. if (tool.sub){
  177. var subNode = node.getLast();
  178. this.setCustomToolbars(tool.sub, subNode);
  179. }
  180. }
  181. }
  182. }.bind(this));
  183. },
  184. setToolbarItem: function(tool, node, readonly, noCondition){
  185. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  186. var flag = true;
  187. if (tool.control){
  188. flag = this.form.businessData.control[tool.control]
  189. }
  190. if (!noCondition) if (tool.condition){
  191. var hideFlag = this.form.Macro.exec(tool.condition, this);
  192. flag = flag && (!hideFlag);
  193. }
  194. // if (tool.id == "action_processWork"){
  195. // if (!this.form.businessData.task){
  196. // flag = false;
  197. // }
  198. // }
  199. if (tool.id == "action_downloadAll" || tool.id == "action_print"){
  200. if (!this.form.businessData.work.startTime){
  201. flag = false;
  202. }
  203. }
  204. if (tool.id == "action_delete"){
  205. if (!this.form.businessData.work || !this.form.businessData.work.id){
  206. flag = false;
  207. }
  208. }
  209. if (tool.id == "action_rollback") tool.read = true;
  210. if (readonly) if (!tool.read) flag = false;
  211. if (flag){
  212. var actionNode = new Element("div", {
  213. "id": tool.id,
  214. "MWFnodetype": tool.type,
  215. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  216. "MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  217. "title": tool.title,
  218. "MWFButtonAction": tool.action,
  219. "MWFButtonText": tool.text
  220. }).inject(node);
  221. if( this.json.iconOverStyle ){
  222. actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  223. }
  224. if( tool.properties ){
  225. actionNode.set(tool.properties);
  226. }
  227. if (tool.sub){
  228. var subNode = node.getLast();
  229. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  230. }
  231. }
  232. },
  233. /**
  234. * @summary 根据操作id获取操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  235. * @param {String} id - 必选,操作id.
  236. * @return {o2.widget.ToolbarButton} 操作
  237. * @example
  238. * var actionbar = this.form.get("name"); //获取操作条
  239. * var item = actionbar.getItem( "action_delete" ); //获取删除操作
  240. * item.node.hide(); //隐藏删除操作的节点
  241. * item.node.click(); //触发操作的click事件
  242. */
  243. getItem : function( id ){
  244. if( this.toolbarWidget && id ){
  245. return this.toolbarWidget.items[id]
  246. }
  247. },
  248. /**
  249. * @summary 获取所有操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  250. * @return {Array} 操作数组
  251. * @example
  252. * var actionbar = this.form.get("name"); //获取操作条
  253. * var itemList = actionbar.getAllItem(); //获取操作数组
  254. * itemList[1].node.hide(); //隐藏第一个操作
  255. */
  256. getAllItem : function(){
  257. return this.toolbarWidget ? this.toolbarWidget.childrenButton : [];
  258. },
  259. setToolbars: function(tools, node, readonly, noCondition){
  260. tools.each(function(tool){
  261. this.setToolbarItem(tool, node, readonly, noCondition);
  262. }.bind(this));
  263. },
  264. runCustomAction: function(bt){
  265. var script = bt.node.retrieve("script");
  266. this.form.Macro.exec(script, this);
  267. },
  268. saveWork: function(){
  269. this.form.saveWork();
  270. },
  271. closeWork: function(){
  272. this.form.closeWork();
  273. },
  274. processWork: function(){
  275. this.form.processWork();
  276. },
  277. resetWork: function(){
  278. this.form.resetWork();
  279. },
  280. retractWork: function(e, ev){
  281. this.form.retractWork(e, ev);
  282. },
  283. rerouteWork: function(e, ev){
  284. this.form.rerouteWork(e, ev);
  285. },
  286. deleteWork: function(){
  287. this.form.deleteWork();
  288. },
  289. printWork: function(){
  290. this.form.printWork();
  291. },
  292. readedWork: function(b,e){
  293. this.form.readedWork(e);
  294. },
  295. addSplit: function(e){
  296. this.form.addSplit(e);
  297. },
  298. rollback: function(e){
  299. this.form.rollback(e);
  300. },
  301. downloadAll: function(e){
  302. this.form.downloadAll(e);
  303. },
  304. pressWork: function(e){
  305. this.form.pressWork(e);
  306. }
  307. });