Actionbar.js 17 KB

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