Sidebar.js 14 KB

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