Sidebar.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.require("MWF.widget.Tree", null, false);
  3. /** @class Sidebar 侧边操作条。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var sidebar = this.form.get("fieldId"); //获取侧边操作条
  8. * //方法2
  9. * var sidebar = this.target; //在侧边操作条和操作本身的事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @category FormComponents
  12. * @hideconstructor
  13. */
  14. MWF.xApplication.process.Xform.Sidebar = MWF.APPSidebar = new Class(
  15. /** @lends MWF.xApplication.process.Xform.Sidebar# */
  16. {
  17. Extends: MWF.APP$Module,
  18. _loadUserInterface: function(){
  19. this.node.setStyles(this.form.css.sidebar);
  20. this.toolbarNode = this.node.getFirst("div");
  21. this.toolbarNode.empty();
  22. if (this.form.businessData.task){
  23. MWF.require("MWF.widget.Toolbar", function(){
  24. var toolbars = [];
  25. //this.form.businessData.task.routeNameList.each(function(route, i){
  26. // if (!this.json.defaultTools) this.json.defaultTools = [];
  27. // var o= {
  28. // "type": "MWFToolBarButton",
  29. // "img": "submit.png",
  30. // "title": route,
  31. // "action": "processWork:"+route,
  32. // "text": route,
  33. // "id": "action_processWork",
  34. // "control": "allowProcessing",
  35. // "condition": "",
  36. // "read": false
  37. // };
  38. // toolbars.push(o);
  39. //}.bind(this));
  40. ( this.getRouteNameList() || [] ).each(function(route, i){
  41. if (!this.json.defaultTools) this.json.defaultTools = [];
  42. var o= {
  43. "type": "MWFToolBarButton",
  44. "img": "submit.png",
  45. "title": route.displayName,
  46. "action": "processWork:"+route.routeName,
  47. "text": route.displayName,
  48. "id": "action_processWork",
  49. "control": "allowProcessing",
  50. "condition": "",
  51. "read": false
  52. };
  53. toolbars.push(o);
  54. }.bind(this));
  55. this.json.defaultTools = toolbars.concat(this.json.defaultTools);
  56. //this.json.defaultTools.unshift(o);
  57. /**
  58. * @summary Toolbar组件,平台使用该组件生成操作条。
  59. * @member {o2.widget.Toolbar}
  60. * @example
  61. * //可以在脚本中获取该组件
  62. * var toolbarWidget = this.form.get("fieldId").toolbarWidget; //获取组件对象
  63. */
  64. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  65. //alert(this.readonly)
  66. if (this.json.hideSystemTools){
  67. if (this.json.tools.length){
  68. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  69. this.toolbarWidget.load();
  70. }else{
  71. this.toolbarNode.setStyle("display", "none");
  72. }
  73. }else{
  74. if (this.json.defaultTools.length || this.json.tools.length){
  75. if (this.json.defaultTools){
  76. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  77. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  78. this.toolbarWidget.load();
  79. }else{
  80. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  81. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  82. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  83. this.toolbarWidget.load();
  84. }.bind(this), false);
  85. }
  86. }else{
  87. this.toolbarNode.setStyle("display", "none");
  88. }
  89. }
  90. if (this.toolbarWidget.children.length){
  91. //this.form.app.addEvent("resize", this.loadPosition.bind(this));
  92. this.node.setStyle("display", "none");
  93. window.setTimeout(this.loadPosition.bind(this), 500);
  94. var _self = this;
  95. this.form.app.content.getFirst().addEvent("scroll", function(e){
  96. _self.loadPosition(this);
  97. });
  98. this.form.app.addEvent("resize", function(e){
  99. _self.loadPosition(this);
  100. });
  101. }else{
  102. this.toolbarNode.setStyle("display", "none");
  103. }
  104. }.bind(this));
  105. }
  106. },
  107. loadPosition: function(){
  108. // this.node.setStyle("display", "block");
  109. // var parent = this.node.getParent();
  110. // while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  111. //
  112. // var top = this.json.styles.top;
  113. // this.sideNode = parent || this.form.node;
  114. //
  115. // var size = this.form.app.content.getSize();
  116. // var scroll = this.form.app.content.getScroll();
  117. // var sideSize = this.sideNode.getSize();
  118. //
  119. // var y = (scroll.y+size.y/2)-sideSize.y/2;
  120. // var x = 5;
  121. //
  122. // var position = "centerRight";
  123. // var edge = "centerLeft";
  124. // if (!parent){
  125. // edge = "centerRight";
  126. // x = 5;
  127. // }
  128. //
  129. // if (this.json.barPosition=="left"){
  130. // position = "centerLeft";
  131. // edge = "centerRight";
  132. // x = -5;
  133. // if (!parent){
  134. // edge = "centerLeft";
  135. // x = 5;
  136. // }
  137. // }
  138. //
  139. // this.node.position({
  140. // "relativeTo": this.sideNode,
  141. // "position": position,
  142. // "edge": edge,
  143. // "offset" : {"y": y, "x": x}
  144. // });
  145. // this.json.styles.top = top;
  146. // if (top) this.node.setStyle("top", top);
  147. this.node.setStyle("display", "block");
  148. var parent = this.node.getParent();
  149. while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  150. this.sideNode = parent || this.form.node;
  151. var size = this.form.app.content.getSize();
  152. //var scroll = this.form.designer.designNode.getScroll();
  153. var sideSize = this.sideNode.getSize();
  154. var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
  155. var nodeSize = this.node.getSize();
  156. if (sideSize.y>size.y){
  157. var center = (size.y/2-nodeSize.y/2);
  158. if (center<sidePosition.y){
  159. this.node.setStyle("top", ""+sidePosition.y+"px");
  160. }else if (center>(sidePosition.y+sideSize.y)){
  161. var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
  162. this.node.setStyle("top", ""+tmp+"px");
  163. }else{
  164. this.node.setStyle("top", ""+center+"px");
  165. }
  166. }else{
  167. var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
  168. if (top>size.y){
  169. if (sidePosition.y+nodeSize.y>size.y){
  170. this.node.setStyle("top", ""+sidePosition.y+"px");
  171. }else{
  172. var tmp = size.y-nodeSize.y;
  173. this.node.setStyle("top", ""+tmp+"px");
  174. }
  175. }else if(top<=0){
  176. if(sidePosition.y+sideSize.y<nodeSize.y){
  177. var tmp = sidePosition.y+sideSize.y-nodeSize.y;
  178. this.node.setStyle("top", ""+tmp+"px");
  179. }else{
  180. this.node.setStyle("top", "45px");
  181. }
  182. }else{
  183. this.node.setStyle("top", ""+top+"px");
  184. }
  185. }
  186. var left = sideSize.x+sidePosition.x+5;
  187. this.node.setStyle("left", ""+left+"px");
  188. this.node.setStyle("position", "absolute");
  189. this.node.setStyles({"right": "auto", "bottom": "auto"});
  190. // this.json.styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
  191. //
  192. // var p = this.sideNode.getPosition();
  193. // var s = this.sideNode.getSize();
  194. // this.sidePosition = {"p": p, "s": s};
  195. },
  196. setCustomToolbars: function(tools, node){
  197. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  198. tools.each(function(tool){
  199. var flag = true;
  200. if (this.readonly){
  201. flag = tool.readShow;
  202. }else{
  203. flag = tool.editShow;
  204. }
  205. if (flag){
  206. flag = true;
  207. if (tool.control){
  208. flag = this.form.businessData.control[tool.control]
  209. }
  210. if (tool.condition){
  211. var hideFlag = this.form.Macro.exec(tool.condition, this);
  212. flag = !hideFlag;
  213. }
  214. if (flag){
  215. var actionNode = new Element("div", {
  216. "id": tool.id,
  217. "MWFnodetype": tool.type,
  218. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  219. "MWFButtonImage": path+(this.form.options.style||"default") +"/custom/"+tool.img,
  220. "title": tool.title,
  221. "MWFButtonAction": "runCustomAction",
  222. "MWFButtonText": tool.text
  223. }).inject(node);
  224. if (tool.actionScript){
  225. actionNode.store("script", tool.actionScript);
  226. }
  227. if (tool.sub){
  228. var subNode = node.getLast();
  229. this.setCustomToolbars(tool.sub, subNode);
  230. }
  231. }
  232. }
  233. }.bind(this));
  234. },
  235. setToolbars: function(tools, node, readonly, noCondition){
  236. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  237. tools.each(function(tool){
  238. var flag = true;
  239. if (tool.control){
  240. flag = this.form.businessData.control[tool.control]
  241. }
  242. if (!noCondition) if (tool.condition){
  243. var hideFlag = this.form.Macro.exec(tool.condition, this);
  244. flag = !hideFlag;
  245. }
  246. if (tool.id == "action_processWork"){
  247. if (!this.form.businessData.task){
  248. flag = false;
  249. }
  250. }
  251. if (readonly) if (!tool.read) flag = false;
  252. if (flag){
  253. var actionNode = new Element("div", {
  254. "id": tool.id,
  255. "MWFnodetype": tool.type,
  256. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  257. "MWFButtonImage": path+(this.form.options.style||"default") +"/tools/default/"+tool.img,
  258. "title": tool.title,
  259. "MWFButtonAction": tool.action,
  260. "MWFButtonText": tool.text
  261. }).inject(node);
  262. if (tool.sub){
  263. var subNode = node.getLast();
  264. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  265. }
  266. }
  267. }.bind(this));
  268. },
  269. getRouteNameList: function( routeList ){
  270. var _self = this;
  271. var list = [];
  272. if( !routeList )routeList = this.getRouteDataList();
  273. routeList.each(function(route, i){
  274. if( route.hiddenScriptText && this.form && this.form.Macro ){
  275. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  276. }
  277. var routeName = route.name;
  278. if( route.displayNameScriptText && this.form && this.form.Macro ){
  279. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  280. }
  281. list.push({
  282. "routeId" : route.id,
  283. "displayName" : routeName,
  284. "routeName" : route.name
  285. })
  286. }.bind(this));
  287. return list;
  288. },
  289. getRouteDataList : function(){
  290. if( !this.routeDataList ){
  291. o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.form.businessData.task.routeList} , function( json ){
  292. json.data.each( function(d){
  293. d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
  294. }.bind(this));
  295. this.routeDataList = json.data;
  296. }.bind(this), null, false );
  297. }
  298. return this.routeDataList;
  299. },
  300. getRouteData : function( routeId ){
  301. var routeList = this.getRouteDataList();
  302. for( var i=0; i<routeList.length; i++ ){
  303. if( routeList[i].id === routeId ){
  304. return routeList[i];
  305. }
  306. }
  307. },
  308. runCustomAction: function(bt){
  309. var script = bt.node.retrieve("script");
  310. this.form.Macro.exec(script, this);
  311. },
  312. saveWork: function(){
  313. this.form.saveWork();
  314. },
  315. closeWork: function(){
  316. this.form.closeWork();
  317. },
  318. processWork: function(route){
  319. opinion = this.form.getOpinion();
  320. if (!this.form.formCustomValidation()){
  321. this.form.app.content.unmask();
  322. // if (callback) callback();
  323. return false;
  324. }
  325. this.form.submitWork(route, opinion.opinion, opinion.medias)
  326. // var opinionField = this.json.opinion || "opinion";
  327. // var data = this.form.getData();
  328. // var opinion = data[opinionField];
  329. // data[opinionField] = "";
  330. // this.form.submitWork(route, opinion, null, null, data);
  331. },
  332. resetWork: function(){
  333. this.form.resetWork();
  334. },
  335. retractWork: function(e, ev){
  336. this.form.retractWork(e, ev);
  337. },
  338. rerouteWork: function(e, ev){
  339. this.form.rerouteWork(e, ev);
  340. },
  341. deleteWork: function(){
  342. this.form.deleteWork();
  343. },
  344. printWork: function(){
  345. this.form.printWork();
  346. }
  347. });