Sidebar.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. //MWF.require("MWF.widget.Tree", null, false);
  3. /** @class Sidebar 侧边操作条。
  4. * @o2cn 侧边操作条
  5. * @example
  6. * //可以在脚本中获取该组件
  7. * //方法1:
  8. * var sidebar = this.form.get("fieldId"); //获取侧边操作条
  9. * //方法2
  10. * var sidebar = this.target; //在侧边操作条和操作本身的事件脚本中获取
  11. * @extends MWF.xApplication.process.Xform.$Module
  12. * @o2category FormComponents
  13. * @o2range {Process}
  14. * @hideconstructor
  15. */
  16. MWF.xApplication.process.Xform.Sidebar = MWF.APPSidebar = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Sidebar# */
  18. {
  19. Extends: MWF.APP$Module,
  20. options: {
  21. /**
  22. * 组件加载前触发。当前组件的queryLoad事件还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取当前组件。
  23. * @event MWF.xApplication.process.Xform.Sidebar#queryLoad
  24. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  25. */
  26. /**
  27. * 组件加载时触发。
  28. * @event MWF.xApplication.process.Xform.Sidebar#load
  29. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  30. */
  31. /**
  32. * 组件加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
  33. * @event MWF.xApplication.process.Xform.Sidebar#postLoad
  34. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  35. */
  36. /**
  37. * 组件加载后事件。这个时候操作条已生成
  38. * @event MWF.xApplication.process.Xform.Sidebar#afterLoad
  39. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  40. */
  41. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  42. },
  43. _loadUserInterface: function(){
  44. this.node.setStyles(this.form.css.sidebar);
  45. this.node.setStyles({
  46. "min-width":"126px",
  47. "max-width":"240px",
  48. "width": "auto"
  49. });
  50. // this.node.setStyle("width", this.node.getSize().x+"px");
  51. this.toolbarNode = this.node.getFirst("div");
  52. this.toolbarNode.empty();
  53. if (this.form.businessData.task){
  54. MWF.require("MWF.widget.Toolbar", function(){
  55. var toolbars = [];
  56. //this.form.businessData.task.routeNameList.each(function(route, i){
  57. // if (!this.json.defaultTools) this.json.defaultTools = [];
  58. // var o= {
  59. // "type": "MWFToolBarButton",
  60. // "img": "submit.png",
  61. // "title": route,
  62. // "action": "processWork:"+route,
  63. // "text": route,
  64. // "id": "action_processWork",
  65. // "control": "allowProcessing",
  66. // "condition": "",
  67. // "read": false
  68. // };
  69. // toolbars.push(o);
  70. //}.bind(this));
  71. ( this.getRouteNameList() || [] ).each(function(route, i){
  72. if (!this.json.defaultTools) this.json.defaultTools = [];
  73. var o= {
  74. "type": "MWFToolBarButton",
  75. "img": "submit.png",
  76. "title": route.displayName,
  77. "action": "processWork:"+route.routeName,
  78. "text": route.displayName,
  79. "id": "action_processWork",
  80. "control": "allowProcessing",
  81. "condition": "",
  82. "read": false
  83. };
  84. toolbars.push(o);
  85. }.bind(this));
  86. this.json.defaultTools = toolbars.concat(this.json.defaultTools);
  87. //this.json.defaultTools.unshift(o);
  88. /**
  89. * @summary Toolbar组件,平台使用该组件生成操作条。
  90. * @member {o2.widget.Toolbar}
  91. * @example
  92. * //可以在脚本中获取该组件
  93. * var toolbarWidget = this.form.get("fieldId").toolbarWidget; //获取组件对象
  94. */
  95. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  96. "style": this.json.style,
  97. "onPostLoad" : function(){
  98. this.fireEvent("afterLoad");
  99. }.bind(this)
  100. }, this);
  101. //alert(this.readonly)
  102. if (this.json.hideSystemTools){
  103. if (this.json.tools.length){
  104. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  105. this.toolbarWidget.load();
  106. }else{
  107. this.toolbarNode.setStyle("display", "none");
  108. }
  109. }else{
  110. if (this.json.defaultTools.length || this.json.tools.length){
  111. if (this.json.defaultTools){
  112. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  113. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  114. this.toolbarWidget.load();
  115. }else{
  116. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  117. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  118. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  119. this.toolbarWidget.load();
  120. }.bind(this), false);
  121. }
  122. }else{
  123. this.toolbarNode.setStyle("display", "none");
  124. }
  125. }
  126. if (this.toolbarWidget.children.length){
  127. //this.form.app.addEvent("resize", this.loadPosition.bind(this));
  128. this.node.setStyle("display", "none");
  129. window.setTimeout(this.loadPosition.bind(this), 500);
  130. var _self = this;
  131. this.form.app.content.getFirst().addEvent("scroll", function(e){
  132. _self.loadPosition(this);
  133. });
  134. this.form.app.addEvent("resize", function(e){
  135. _self.loadPosition(this);
  136. });
  137. }else{
  138. this.toolbarNode.setStyle("display", "none");
  139. }
  140. }.bind(this));
  141. }else{
  142. this.node.setStyle("display", "none");
  143. }
  144. },
  145. loadPosition: function(){
  146. // this.node.setStyle("display", "block");
  147. // var parent = this.node.getParent();
  148. // while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  149. //
  150. // var top = this.json.styles.top;
  151. // this.sideNode = parent || this.form.node;
  152. //
  153. // var size = this.form.app.content.getSize();
  154. // var scroll = this.form.app.content.getScroll();
  155. // var sideSize = this.sideNode.getSize();
  156. //
  157. // var y = (scroll.y+size.y/2)-sideSize.y/2;
  158. // var x = 5;
  159. //
  160. // var position = "centerRight";
  161. // var edge = "centerLeft";
  162. // if (!parent){
  163. // edge = "centerRight";
  164. // x = 5;
  165. // }
  166. //
  167. // if (this.json.barPosition=="left"){
  168. // position = "centerLeft";
  169. // edge = "centerRight";
  170. // x = -5;
  171. // if (!parent){
  172. // edge = "centerLeft";
  173. // x = 5;
  174. // }
  175. // }
  176. //
  177. // this.node.position({
  178. // "relativeTo": this.sideNode,
  179. // "position": position,
  180. // "edge": edge,
  181. // "offset" : {"y": y, "x": x}
  182. // });
  183. // this.json.styles.top = top;
  184. // if (top) this.node.setStyle("top", top);
  185. this.node.setStyle("display", "block");
  186. var parent = this.node.getParent();
  187. while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  188. this.sideNode = parent || this.form.node;
  189. var size = this.form.app.content.getSize();
  190. //var scroll = this.form.designer.designNode.getScroll();
  191. var sideSize = this.sideNode.getSize();
  192. var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
  193. var nodeSize = this.node.getSize();
  194. if (sideSize.y>size.y){
  195. var center = (size.y/2-nodeSize.y/2);
  196. if (center<sidePosition.y){
  197. this.node.setStyle("top", ""+sidePosition.y+"px");
  198. }else if (center>(sidePosition.y+sideSize.y)){
  199. var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
  200. this.node.setStyle("top", ""+tmp+"px");
  201. }else{
  202. this.node.setStyle("top", ""+center+"px");
  203. }
  204. }else{
  205. var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
  206. if (top>size.y){
  207. if (sidePosition.y+nodeSize.y>size.y){
  208. this.node.setStyle("top", ""+sidePosition.y+"px");
  209. }else{
  210. var tmp = size.y-nodeSize.y;
  211. this.node.setStyle("top", ""+tmp+"px");
  212. }
  213. }else if(top<=0){
  214. if(sidePosition.y+sideSize.y<nodeSize.y){
  215. var tmp = sidePosition.y+sideSize.y-nodeSize.y;
  216. this.node.setStyle("top", ""+tmp+"px");
  217. }else{
  218. this.node.setStyle("top", "45px");
  219. }
  220. }else{
  221. this.node.setStyle("top", ""+top+"px");
  222. }
  223. }
  224. //var left = sideSize.x+sidePosition.x+5;
  225. var x = sidePosition.x+sideSize.x+nodeSize.x;
  226. var left;
  227. if( x > size.x ){
  228. left = size.x - nodeSize.x - 5;
  229. }else{
  230. left = sideSize.x+sidePosition.x+5;
  231. }
  232. this.node.setStyle("left", ""+left+"px");
  233. this.node.setStyle("position", "absolute");
  234. this.node.setStyles({"right": "auto", "bottom": "auto"});
  235. // this.json.styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
  236. //
  237. // var p = this.sideNode.getPosition();
  238. // var s = this.sideNode.getSize();
  239. // this.sidePosition = {"p": p, "s": s};
  240. },
  241. setCustomToolbars: function(tools, node){
  242. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  243. tools.each(function(tool){
  244. var flag = true;
  245. if (this.readonly){
  246. flag = tool.readShow;
  247. }else{
  248. flag = tool.editShow;
  249. }
  250. if (flag){
  251. flag = true;
  252. if (tool.control){
  253. flag = this.form.businessData.control[tool.control]
  254. }
  255. if (tool.condition){
  256. var hideFlag = this.form.Macro.exec(tool.condition, this);
  257. flag = !hideFlag;
  258. }
  259. if (flag){
  260. var actionNode = new Element("div", {
  261. "id": tool.id,
  262. "MWFnodetype": tool.type,
  263. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  264. "MWFButtonImage": path+(this.form.options.style||"default") +"/custom/"+tool.img,
  265. "title": tool.title,
  266. "MWFButtonAction": "runCustomAction",
  267. "MWFButtonText": tool.text
  268. }).inject(node);
  269. if (tool.actionScript){
  270. actionNode.store("script", tool.actionScript);
  271. }
  272. if (tool.sub){
  273. var subNode = node.getLast();
  274. this.setCustomToolbars(tool.sub, subNode);
  275. }
  276. }
  277. }
  278. }.bind(this));
  279. },
  280. setToolbars: function(tools, node, readonly, noCondition){
  281. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  282. tools.each(function(tool){
  283. var flag = true;
  284. if (tool.control){
  285. flag = this.form.businessData.control[tool.control]
  286. }
  287. if (!noCondition) if (tool.condition){
  288. var hideFlag = this.form.Macro.exec(tool.condition, this);
  289. flag = !hideFlag;
  290. }
  291. if (tool.id == "action_processWork"){
  292. if (!this.form.businessData.task){
  293. flag = false;
  294. }
  295. }
  296. if (readonly) if (!tool.read) flag = false;
  297. if (flag){
  298. var actionNode = new Element("div", {
  299. "id": tool.id,
  300. "MWFnodetype": tool.type,
  301. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  302. "MWFButtonImage": path+(this.form.options.style||"default") +"/tools/default/"+tool.img,
  303. "title": tool.title,
  304. "MWFButtonAction": tool.action,
  305. "MWFButtonText": tool.text
  306. }).inject(node);
  307. if (tool.sub){
  308. var subNode = node.getLast();
  309. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  310. }
  311. }
  312. }.bind(this));
  313. },
  314. getRouteNameList: function( routeList ){
  315. var _self = this;
  316. var list = [];
  317. if( !routeList )routeList = this.getRouteDataList();
  318. routeList.each(function(route, i){
  319. if( route.hiddenScriptText && this.form && this.form.Macro ){
  320. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  321. }
  322. var routeName = route.name;
  323. if( route.displayNameScriptText && this.form && this.form.Macro ){
  324. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  325. }
  326. list.push({
  327. "routeId" : route.id,
  328. "displayName" : routeName,
  329. "routeName" : route.name
  330. })
  331. }.bind(this));
  332. return list;
  333. },
  334. getRouteDataList : function(){
  335. if(this.routeDataList)return this.routeDataList;
  336. if (this.form && this.form.businessData && this.form.businessData.task && this.form.businessData.task.routeNameDisable){
  337. this.routeDataList = [{
  338. "id": o2.uuid(),
  339. "asyncSupported": false,
  340. "soleDirect": false,
  341. "name": "继续流转",
  342. "alias": "",
  343. "selectConfigList": []
  344. }];
  345. return this.routeDataList;
  346. }
  347. if( this.form && this.form.businessData && this.form.businessData.routeList ){
  348. this.form.businessData.routeList.sort( function(a, b){
  349. var aIdx = parseInt(a.orderNumber || "9999999");
  350. var bIdx = parseInt(b.orderNumber || "9999999");
  351. return aIdx - bIdx;
  352. }.bind(this));
  353. this.form.businessData.routeList.each( function(d){
  354. d.selectConfigList = JSON.parse(d.selectConfig || "[]");
  355. }.bind(this));
  356. this.routeDataList = this.form.businessData.routeList;
  357. }
  358. if( !this.routeDataList && this.form && this.form.businessData && this.form.businessData.task && this.form.businessData.task ){
  359. o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.form.businessData.task.routeList} , function( json ){
  360. json.data.sort(function(a, b){
  361. var aIdx = parseInt(a.orderNumber || "9999999");
  362. var bIdx = parseInt(b.orderNumber || "9999999");
  363. return aIdx - bIdx;
  364. }.bind(this));
  365. json.data.each( function(d){
  366. d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
  367. }.bind(this));
  368. this.routeDataList = json.data;
  369. }.bind(this), null, false );
  370. }
  371. return this.routeDataList;
  372. },
  373. isOpinionRequired: function( routeName ){
  374. var routeList = this.getRouteDataList();
  375. for( var i=0; i<routeList.length; i++ ){
  376. if( routeList[i].name === routeName ){
  377. return routeList[i].opinionRequired;
  378. }
  379. }
  380. },
  381. getRouteId: function( routeName ){
  382. var routeList = this.getRouteDataList();
  383. for( var i=0; i<routeList.length; i++ ){
  384. if( routeList[i].name === routeName ){
  385. return routeList[i].id;
  386. }
  387. }
  388. },
  389. getRouteData : function( routeId ){
  390. var routeList = this.getRouteDataList();
  391. for( var i=0; i<routeList.length; i++ ){
  392. if( routeList[i].id === routeId ){
  393. return routeList[i];
  394. }
  395. }
  396. },
  397. getOrgData: function (routeId) {
  398. var routeList = this.getRouteDataList();
  399. for (var i = 0; i < routeList.length; i++) {
  400. if (routeList[i].id === routeId) {
  401. return routeList[i].selectConfigList;
  402. }
  403. }
  404. },
  405. getVisableOrgData: function (routeId) {
  406. var selectConfigList = this.getOrgData(routeId);
  407. var list = [];
  408. (selectConfigList || []).each(function (config) {
  409. if (!this.isOrgHidden(config)) {
  410. list.push(config);
  411. }
  412. }.bind(this));
  413. return list;
  414. },
  415. isOrgHidden: function (d) {
  416. if (d.hiddenScript && d.hiddenScript.code) { //如果隐藏路由,返回
  417. var hidden = this.form.Macro.exec(d.hiddenScript.code, this);
  418. if (hidden && hidden.toString() === "true") return true;
  419. }
  420. return false;
  421. },
  422. runCustomAction: function(bt){
  423. var script = bt.node.retrieve("script");
  424. this.form.Macro.exec(script, this);
  425. },
  426. saveWork: function(){
  427. this.form.saveWork();
  428. },
  429. closeWork: function(){
  430. this.form.closeWork();
  431. },
  432. processWork: function(route){
  433. var opinion = this.form.getOpinion();
  434. if( !opinion.opinion && !opinion.medias.length && this.isOpinionRequired(route)){
  435. this.form.notice(MWF.xApplication.process.Work.LP.opinionRequired, "error");
  436. return false;
  437. }
  438. this.form.Macro.environment.form.currentRouteName = route;
  439. this.form.Macro.environment.form.opinion = opinion.opinion;
  440. this.form.Macro.environment.form.medias = opinion.medias;
  441. var routeId = this.getRouteId( route );
  442. var routeData = this.getRouteData( routeId );
  443. if (routeData.validationScriptText) {
  444. var validation = this.form.Macro.exec(routeData.validationScriptText, this);
  445. if (!validation || validation.toString() !== "true") {
  446. validation = typeOf(validation) === "string" ? validation : MWF.xApplication.process.Work.LP.routeValidFailure;
  447. this.form.notice(validation, "error");
  448. return false;
  449. }
  450. }
  451. if (!this.form.formCustomValidation()){
  452. this.form.app.content.unmask();
  453. // if (callback) callback();
  454. return false;
  455. }
  456. if( this.getVisableOrgData( routeId ).length > 0 ){
  457. this.form.processWork( routeId );
  458. }else{
  459. this.form.submitWork(route, opinion.opinion, opinion.medias)
  460. }
  461. // var opinionField = this.json.opinion || "opinion";
  462. // var data = this.form.getData();
  463. // var opinion = data[opinionField];
  464. // data[opinionField] = "";
  465. // this.form.submitWork(route, opinion, null, null, data);
  466. },
  467. resetWork: function(){
  468. this.form.resetWork();
  469. },
  470. retractWork: function(e, ev){
  471. this.form.retractWork(e, ev);
  472. },
  473. rerouteWork: function(e, ev){
  474. this.form.rerouteWork(e, ev);
  475. },
  476. deleteWork: function(){
  477. this.form.deleteWork();
  478. },
  479. printWork: function(){
  480. this.form.printWork();
  481. }
  482. });