Actionbar.js 12 KB

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