Sidebar.js 14 KB

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