Actionbar.js 12 KB

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