Actionbar.js 15 KB

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