Actionbar.js 12 KB

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