Actionbar.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. /**
  61. * @summary Toolbar组件,平台使用该组件生成操作条。
  62. * @member {o2.widget.Toolbar}
  63. * @example
  64. * //可以在脚本中获取该组件
  65. * var toolbarWidget = this.form.get("fieldId").toolbarWidget; //获取组件对象
  66. */
  67. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  68. "style": this.json.style,
  69. "onPostLoad" : function(){
  70. this.fireEvent("afterLoad");
  71. }.bind(this)
  72. }, this);
  73. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  74. //alert(this.readonly)
  75. if( this.json.multiTools ){ //自定义操作和系统操作混合的情况,用 system : true 来区分系统和自定义
  76. var addReadActionFlag = !this.json.hideSystemTools && !this.json.hideReadedAction; //是否需要增加已阅
  77. this.json.multiTools.each( function (tool) {
  78. if( tool.system ){
  79. if( !this.json.hideSystemTools ){
  80. if( tool.id === "action_readed" )addReadActionFlag = false;
  81. this.setToolbars([tool], this.toolbarNode, this.readonly);
  82. }
  83. }else{
  84. this.setCustomToolbars([tool], this.toolbarNode);
  85. }
  86. }.bind(this));
  87. if( addReadActionFlag ){
  88. var addActions = [
  89. {
  90. "type": "MWFToolBarButton",
  91. "img": "read.png",
  92. "title": "标记为已阅",
  93. "action": "readedWork",
  94. "text": "已阅",
  95. "id": "action_readed",
  96. "control": "allowReadProcessing",
  97. "condition": "",
  98. "read": true
  99. }
  100. ];
  101. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  102. }
  103. this.toolbarWidget.load();
  104. }else{
  105. if (this.json.hideSystemTools){
  106. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  107. this.toolbarWidget.load();
  108. }else{
  109. if (this.json.defaultTools){
  110. var addActions = [
  111. {
  112. "type": "MWFToolBarButton",
  113. "img": "read.png",
  114. "title": "标记为已阅",
  115. "action": "readedWork",
  116. "text": "已阅",
  117. "id": "action_readed",
  118. "control": "allowReadProcessing",
  119. "condition": "",
  120. "read": true
  121. }
  122. ];
  123. //this.form.businessData.control.allowReflow =
  124. //this.json.defaultTools.push(o);
  125. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  126. if( !this.json.hideReadedAction ){
  127. this.setToolbars(addActions, this.toolbarNode, this.readonly);
  128. }
  129. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  130. this.toolbarWidget.load();
  131. }else{
  132. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  133. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  134. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  135. this.toolbarWidget.load();
  136. }.bind(this), null);
  137. }
  138. }
  139. }
  140. }.bind(this));
  141. // }
  142. },
  143. setCustomToolbars: function(tools, node){
  144. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  145. var iconPath = "";
  146. if( this.json.customIconStyle ){
  147. iconPath = this.json.customIconStyle+"/";
  148. }
  149. tools.each(function(tool){
  150. var flag = true;
  151. if (this.readonly){
  152. flag = tool.readShow;
  153. }else{
  154. flag = tool.editShow;
  155. }
  156. if (flag){
  157. flag = true;
  158. if (tool.control){
  159. flag = this.form.businessData.control[tool.control]
  160. }
  161. if (tool.condition){
  162. var hideFlag = this.form.Macro.exec(tool.condition, this);
  163. flag = !hideFlag;
  164. }
  165. if (flag){
  166. var actionNode = new Element("div", {
  167. "id": tool.id,
  168. "MWFnodetype": tool.type,
  169. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  170. "title": tool.title,
  171. "MWFButtonAction": "runCustomAction",
  172. "MWFButtonText": tool.text
  173. }).inject(node);
  174. if( this.json.customIconOverStyle ){
  175. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  176. }
  177. if( tool.properties ){
  178. actionNode.set(tool.properties);
  179. }
  180. if (tool.actionScript){
  181. actionNode.store("script", tool.actionScript);
  182. }
  183. if (tool.sub){
  184. var subNode = node.getLast();
  185. this.setCustomToolbars(tool.sub, subNode);
  186. }
  187. }
  188. }
  189. }.bind(this));
  190. },
  191. setToolbarItem: function(tool, node, readonly, noCondition){
  192. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  193. var flag = true;
  194. if (tool.control){
  195. flag = this.form.businessData.control[tool.control]
  196. }
  197. if (!noCondition) if (tool.condition){
  198. var hideFlag = this.form.Macro.exec(tool.condition, this);
  199. flag = flag && (!hideFlag);
  200. }
  201. // if (tool.id == "action_processWork"){
  202. // if (!this.form.businessData.task){
  203. // flag = false;
  204. // }
  205. // }
  206. if (tool.id == "action_downloadAll" || tool.id == "action_print"){
  207. if (!this.form.businessData.work.startTime){
  208. flag = false;
  209. }
  210. }
  211. if (tool.id == "action_delete"){
  212. if (!this.form.businessData.work || !this.form.businessData.work.id){
  213. flag = false;
  214. }
  215. }
  216. if (tool.id == "action_rollback") tool.read = true;
  217. if (readonly) if (!tool.read) flag = false;
  218. if (flag){
  219. var actionNode = new Element("div", {
  220. "id": tool.id,
  221. "MWFnodetype": tool.type,
  222. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  223. "MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  224. "title": tool.title,
  225. "MWFButtonAction": tool.action,
  226. "MWFButtonText": tool.text
  227. }).inject(node);
  228. if( this.json.iconOverStyle ){
  229. actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  230. }
  231. if( tool.properties ){
  232. actionNode.set(tool.properties);
  233. }
  234. if (tool.sub){
  235. var subNode = node.getLast();
  236. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  237. }
  238. }
  239. },
  240. /**
  241. * @summary 根据操作id获取操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  242. * @param {String} id - 必选,操作id.
  243. * @return {o2.widget.ToolbarButton} 操作
  244. * @example
  245. * var actionbar = this.form.get("name"); //获取操作条
  246. * var item = actionbar.getItem( "action_delete" ); //获取删除操作
  247. * item.node.hide(); //隐藏删除操作的节点
  248. * item.node.click(); //触发操作的click事件
  249. */
  250. getItem : function( id ){
  251. if( this.toolbarWidget && id ){
  252. return this.toolbarWidget.items[id]
  253. }
  254. },
  255. /**
  256. * @summary 获取所有操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  257. * @return {Array} 操作数组
  258. * @example
  259. * var actionbar = this.form.get("name"); //获取操作条
  260. * var itemList = actionbar.getAllItem(); //获取操作数组
  261. * itemList[1].node.hide(); //隐藏第一个操作
  262. */
  263. getAllItem : function(){
  264. return this.toolbarWidget ? this.toolbarWidget.childrenButton : [];
  265. },
  266. setToolbars: function(tools, node, readonly, noCondition){
  267. tools.each(function(tool){
  268. this.setToolbarItem(tool, node, readonly, noCondition);
  269. }.bind(this));
  270. },
  271. runCustomAction: function(bt){
  272. var script = bt.node.retrieve("script");
  273. this.form.Macro.exec(script, this);
  274. },
  275. saveWork: function(){
  276. this.form.saveWork();
  277. },
  278. closeWork: function(){
  279. this.form.closeWork();
  280. },
  281. processWork: function(){
  282. this.form.processWork();
  283. },
  284. resetWork: function(){
  285. this.form.resetWork();
  286. },
  287. retractWork: function(e, ev){
  288. this.form.retractWork(e, ev);
  289. },
  290. rerouteWork: function(e, ev){
  291. this.form.rerouteWork(e, ev);
  292. },
  293. deleteWork: function(){
  294. this.form.deleteWork();
  295. },
  296. printWork: function(){
  297. this.form.printWork();
  298. },
  299. readedWork: function(b,e){
  300. this.form.readedWork(e);
  301. },
  302. addSplit: function(e){
  303. this.form.addSplit(e);
  304. },
  305. rollback: function(e){
  306. this.form.rollback(e);
  307. },
  308. downloadAll: function(e){
  309. this.form.downloadAll(e);
  310. },
  311. pressWork: function(e){
  312. this.form.pressWork(e);
  313. }
  314. });