Actionbar.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  182. "title": tool.title,
  183. "MWFButtonAction": "runCustomAction",
  184. "MWFButtonText": tool.text
  185. }).inject(node);
  186. if( this.json.customIconOverStyle ){
  187. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  188. }
  189. if( tool.properties ){
  190. actionNode.set(tool.properties);
  191. }
  192. if (tool.actionScript){
  193. actionNode.store("script", tool.actionScript);
  194. }
  195. if (tool.sub){
  196. var subNode = node.getLast();
  197. this.setCustomToolbars(tool.sub, subNode);
  198. }
  199. }
  200. }
  201. }.bind(this));
  202. },
  203. getImagePath: function(img, iscustom){
  204. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  205. if( iscustom ){
  206. var iconPath = this.json.customIconStyle ? (this.json.customIconStyle+ "/") : "";
  207. return path+""+this.form.options.style+"/custom/"+iconPath+img;
  208. }else{
  209. return path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+img;
  210. }
  211. },
  212. getImageOverPath: function(img, iscustom){
  213. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  214. if( iscustom && this.json.customIconOverStyle ){
  215. return path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +img
  216. }else{
  217. return path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+img;
  218. }
  219. },
  220. setToolbarItem: function(tool, node, readonly, noCondition){
  221. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  222. var flag = true;
  223. if (tool.control){
  224. flag = this.form.businessData.control[tool.control]
  225. }
  226. if (!noCondition) if (tool.condition){
  227. var hideFlag = this.form.Macro.exec(tool.condition, this);
  228. flag = flag && (!hideFlag);
  229. }
  230. if (tool.id == "action_downloadAll" || tool.id == "action_print"){
  231. if (!this.form.businessData.work.startTime){
  232. flag = false;
  233. }
  234. }
  235. if (tool.id == "action_delete"){
  236. if (!this.form.businessData.work || !this.form.businessData.work.id){
  237. flag = false;
  238. }
  239. }
  240. if (tool.id == "action_rollback") tool.read = true;
  241. if (readonly) if (!tool.read) flag = false;
  242. if (flag){
  243. var actionNode = new Element("div", {
  244. "id": tool.id,
  245. "MWFnodetype": tool.type,
  246. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  247. "MWFButtonImage": this.getImagePath(tool.img, tool.customImg),
  248. "title": tool.title,
  249. "MWFButtonAction": tool.action,
  250. "MWFButtonText": tool.text,
  251. "MWFHide": (tool.id === "action_goBack") ? 'true' : ''
  252. }).inject(node);
  253. if( this.json.iconOverStyle ){
  254. actionNode.set("MWFButtonImageOver" , this.getImageOverPath(tool.img, tool.customImg) );
  255. }
  256. if( tool.properties ){
  257. actionNode.set(tool.properties);
  258. }
  259. if (tool.sub){
  260. var subNode = node.getLast();
  261. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  262. }
  263. }
  264. },
  265. /**
  266. * @summary 根据操作id获取操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  267. * @param {String} id - 必选,操作id.
  268. * @return {o2.widget.ToolbarButton} 操作
  269. * @example
  270. * var actionbar = this.form.get("name"); //获取操作条
  271. * var item = actionbar.getItem( "action_delete" ); //获取删除操作
  272. * item.node.hide(); //隐藏删除操作的节点
  273. * item.node.click(); //触发操作的click事件
  274. */
  275. getItem : function( id ){
  276. if( this.toolbarWidget && id ){
  277. return this.toolbarWidget.items[id]
  278. }
  279. },
  280. /**
  281. * @summary 获取所有操作,该方法在操作条的afterLoad事件中有效,操作的操作脚本有效。
  282. * @return {Array} 操作数组
  283. * @example
  284. * var actionbar = this.form.get("name"); //获取操作条
  285. * var itemList = actionbar.getAllItem(); //获取操作数组
  286. * itemList[1].node.hide(); //隐藏第一个操作
  287. */
  288. getAllItem : function(){
  289. return this.toolbarWidget ? this.toolbarWidget.childrenButton : [];
  290. },
  291. setToolbars: function(tools, node, readonly, noCondition){
  292. tools.each(function(tool){
  293. this.setToolbarItem(tool, node, readonly, noCondition);
  294. }.bind(this));
  295. },
  296. runCustomAction: function(bt){
  297. var script = bt.node.retrieve("script");
  298. this.form.Macro.exec(script, this);
  299. },
  300. saveWork: function(){
  301. debugger;
  302. this.form.saveWork();
  303. },
  304. closeWork: function(){
  305. this.form.closeWork();
  306. },
  307. flowWork: function(){
  308. this.form.flowWork();
  309. },
  310. processWork: function(){
  311. this.form.processWork();
  312. },
  313. resetWork: function(){
  314. this.form.resetWork();
  315. },
  316. addTask: function(){
  317. this.form.addTask();
  318. },
  319. retractWork: function(e, ev){
  320. this.form.retractWork(e, ev);
  321. },
  322. rerouteWork: function(e, ev){
  323. this.form.rerouteWork(e, ev);
  324. },
  325. deleteWork: function(){
  326. this.form.deleteWork();
  327. },
  328. printWork: function(){
  329. this.form.printWork();
  330. },
  331. readedWork: function(b,e){
  332. this.form.readedWork(e);
  333. },
  334. addSplit: function(e){
  335. this.form.addSplit(e);
  336. },
  337. rollback: function(e){
  338. this.form.rollback(e);
  339. },
  340. downloadAll: function(e){
  341. this.form.downloadAll(e);
  342. },
  343. monitor: function(e){
  344. this.form.monitor(e);
  345. },
  346. pressWork: function(e){
  347. this.form.pressWork(e);
  348. },
  349. pauseTask: function(e){
  350. var p = this.form.pauseTask(e);
  351. if (p){
  352. p.then(function(){
  353. e.setText(MWF.xApplication.process.Xform.LP.resume);
  354. e.options.action = "resumeTask";
  355. var img = e.picNode.getElement("img");
  356. var src = img.get("src");
  357. src = src.substr(0, src.lastIndexOf("/"));
  358. src = src+"/resume.png";
  359. img.set("src", src);
  360. }.bind(this), function(){});
  361. }
  362. },
  363. resumeTask: function(e){
  364. var p = this.form.resumeTask(e);
  365. if (p){
  366. p.then(function(){
  367. e.setText( MWF.xApplication.process.Xform.LP.pause);
  368. e.options.action = "pauseTask";
  369. var img = e.picNode.getElement("img");
  370. var src = img.get("src");
  371. src = src.substr(0, src.lastIndexOf("/"));
  372. src = src+"/pause.png";
  373. img.set("src", src);
  374. }.bind(this), function(){});
  375. }
  376. },
  377. goBack: function(e){
  378. this.form.goBack(e);
  379. },
  380. terminate: function(e, ev){
  381. this.form.terminateWork(e, ev);
  382. }
  383. });