Common.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. MWF.xApplication.TeamWork.Common = MWF.xApplication.TeamWork.Common || {};
  2. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xApplication.TeamWork.Common.Popup = new Class({
  5. Extends: MPopupForm,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "width": 500,
  10. "height": 450,
  11. "top": null,
  12. "left": null,
  13. "bottom" : null,
  14. "right" : null,
  15. "minWidth" : 300,
  16. "minHeight" : 220,
  17. "isLimitSize": true,
  18. "ifFade": false,
  19. "hasTop": false,
  20. "hasTopIcon" : false,
  21. "hasTopContent" : false,
  22. "hasIcon": false,
  23. "hasBottom": false,
  24. "hasMask" : true,
  25. "closeByClickMask" : true,
  26. "hasScroll" : true,
  27. "scrollType" : "",
  28. "title": "",
  29. "draggable": false,
  30. "resizeable" : false,
  31. "maxAction" : false,
  32. "closeAction": false,
  33. "relativeToApp" : true,
  34. "sizeRelateTo" : "app", //desktop
  35. "resultSeparator" : ","
  36. },
  37. initialize: function (explorer, data, options, para) {
  38. this.setOptions(options);
  39. this.explorer = explorer;
  40. if( para ){
  41. if( this.options.relativeToApp ){
  42. this.app = para.app || this.explorer.app;
  43. this.container = para.container || this.app.content;
  44. this.lp = para.lp || this.explorer.lp || this.app.lp;
  45. this.css = para.css || this.explorer.css || this.app.css;
  46. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions || this.app.rootActions;
  47. }else{
  48. this.container = para.container;
  49. this.lp = para.lp || this.explorer.lp;
  50. this.css = para.css || this.explorer.css;
  51. this.actions = para.actions || this.explorer.actions;
  52. }
  53. }else{
  54. if( this.options.relativeToApp ){
  55. this.app = this.explorer.app;
  56. this.container = this.app.content;
  57. this.lp = this.explorer.lp || this.app.lp;
  58. this.css = this.explorer.css || this.app.css;
  59. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  60. }else{
  61. this.container = window.document.body;
  62. this.lp = this.explorer.lp;
  63. this.css = this.explorer.css;
  64. this.actions = this.explorer.actions;
  65. }
  66. }
  67. this.rootActions = this.app.rootActions;
  68. this.data = data || {};
  69. this.cssPath = "/x_component_TeamWork/$Common/"+this.options.style+"/css.wcss";
  70. this.load();
  71. if(this.css && this.css.popup)this.css = this.css.popup; //使用common 样式和传进来的样式
  72. //if(para.css) this.css = Object.merge( this.css, para.css );
  73. },
  74. close: function (data) {
  75. this.fireEvent("queryClose");
  76. this._close();
  77. //if( this.form ){
  78. // this.form.destroy();
  79. //}
  80. if(this.setFormNodeSizeFun && this.app && this.app.removeEvent ){
  81. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  82. }
  83. if( this.formMaskNode )this.formMaskNode.destroy();
  84. if( this.formAreaNode )this.formAreaNode.destroy();
  85. this.fireEvent("postClose",data);
  86. delete this;
  87. },
  88. // open: function (e) {
  89. // this.fireEvent("queryOpen");
  90. // this.isNew = false;
  91. // this.isEdited = false;
  92. // this._open();
  93. // this.fireEvent("postOpen");
  94. // }
  95. });
  96. MWF.xApplication.TeamWork.Common.Tips = new Class({
  97. Extends: MTooltips,
  98. options : {
  99. style:"default",
  100. axis: "x", //箭头在x轴还是y轴上展现
  101. position : { //node 固定的位置
  102. x : "auto", //x轴上left center right, auto 系统自动计算
  103. y : "auto" //y 轴上top middle bottom, auto 系统自动计算
  104. },
  105. priorityOfAuto :{
  106. x : [ "center", "right", "left" ], //当position x 为 auto 时候的优先级
  107. y : [ "middle", "bottom", "top" ] //当position y 为 auto 时候的优先级
  108. },
  109. isFitToContainer : true, //当position x 不为 auto, y 不为 auto 的时候,自动设置偏移量,使tooltip不超过容器的可见范围
  110. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  111. hiddenDelay : 100, //ms , 有target 且 事件类型为 mouseenter 时有效
  112. displayDelay : 1000, //ms , 有target 且事件类型为 mouseenter 时有效
  113. hasArrow : false,
  114. isAutoShow : true,
  115. isAutoHide : true,
  116. hasCloseAction : false,
  117. overflow : "hidden" //弹出框高宽超过container的时候怎么处理,hidden 表示超过的隐藏,scroll 表示超过的时候显示滚动条
  118. },
  119. initialize : function( container, target, app, data, options, targetCoordinates ){
  120. //可以传入target 或者 targetCoordinates,两种选一
  121. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  122. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  123. if( options ){
  124. this.setOptions(options);
  125. }
  126. this.container = container;
  127. this.target = target;
  128. this.targetCoordinates = targetCoordinates;
  129. this.app = app;
  130. if(app)this.lp = app.lp;
  131. this.data = data;
  132. this.path = "/x_component_TeamWork/$Common/";
  133. if( this.target ){
  134. this.setTargetEvents();
  135. }
  136. this.fireEvent("postInitialize",[this]);
  137. },
  138. hide: function(){
  139. if( this.node ){
  140. this.node.setStyle("display","none");
  141. this.status = "hidden";
  142. if( this.maskNode ){
  143. this.maskNode.setStyle("display","none");
  144. }
  145. this.fireEvent("hide",[this]);
  146. //this.node.destroy();
  147. }
  148. if( this.maskNode ){
  149. this.maskNode.destroy();
  150. }
  151. //this.close();
  152. },
  153. _getHtml : function(){
  154. var html = this.data["_html"]||"";
  155. return html;
  156. }
  157. });
  158. MWF.xApplication.TeamWork.Common.ToolTips = new Class({
  159. Extends: MTooltips,
  160. options : {
  161. // displayDelay : 300,
  162. style:"default",
  163. hasArrow:false,
  164. event:"click"
  165. },
  166. initialize : function( container, target, app, data, options, targetCoordinates, explorer ){
  167. //可以传入target 或者 targetCoordinates,两种选一
  168. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  169. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  170. if( options ){
  171. this.setOptions(options);
  172. }
  173. if(explorer) this.explorer = explorer;
  174. this.container = container;
  175. this.target = target;
  176. this.targetCoordinates = targetCoordinates;
  177. this.app = app;
  178. //if(app)this.lp = app.lp;
  179. this.lp = this.app.lp.common.tooltip;
  180. this.data = data;
  181. this.actions = this.app.rootActions;
  182. this.rootActions = this.app.rootActions;
  183. this.path = "/x_component_TeamWork/$Common/";
  184. if(options.path) this.path = options.path;
  185. if( this.target ){
  186. this.setTargetEvents();
  187. }
  188. this.fireEvent("postInitialize",[this]);
  189. },
  190. load: function(){
  191. this.fireEvent("queryLoad",[this]);
  192. this.create();
  193. this.fireEvent("postLoad",[this]);
  194. },
  195. _loadCustom : function( callback ){
  196. // new Element("div.aaa",{styles:{"background-color":"#ff0000",width:"500px","height":"800px",position:"absolute",
  197. // left:"100px",top:"200px"
  198. // }}).inject(this.container);
  199. if(callback)callback();
  200. },
  201. hide: function(){
  202. if( this.node ){
  203. this.node.setStyle("display","none");
  204. this.status = "hidden";
  205. if( this.maskNode ){
  206. this.maskNode.setStyle("display","none");
  207. }
  208. this.fireEvent("hide",[this]);
  209. }
  210. if( this.maskNode ){
  211. this.maskNode.destroy();
  212. }
  213. this.close();
  214. },
  215. // 增加的方法
  216. close: function(data){
  217. if( this.node ){
  218. this.node.setStyle("display","none");
  219. this.status = "hidden";
  220. if( this.maskNode ){
  221. this.maskNode.setStyle("display","none");
  222. }
  223. this.fireEvent("hide",[this]);
  224. //this.fireEvent("close",[data]);
  225. }
  226. if( this.maskNode ){
  227. this.maskNode.destroy();
  228. }
  229. this.fireEvent("close",[data]);
  230. this.destroy();
  231. },
  232. _getHtml : function(){
  233. // var data = this.data;
  234. // var titleStyle = "font-size:14px;color:#333";
  235. // var valueStyle = "font-size:14px;color:#666;padding-right:10px";
  236. // var html =
  237. // "<div style='font-size: 16px;color:#333;padding:10px 10px 10px 20px;'>ddddddddddddddd</div>"+
  238. // "<div style='height:1px;margin:0px 20px;border-bottom:1px solid #ccc;'></div>"+
  239. // "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' style='margin:13px 13px 13px 13px;'>" +
  240. // "<tr><td style='"+titleStyle+";' width='40'>开始:</td>" +
  241. // " <td style='"+valueStyle+"'></td></tr>" +
  242. // "<tr><td style='"+titleStyle+"'>结束:</td>" +
  243. // " <td style='"+valueStyle+ "'></td></tr>" +
  244. // "<tr><td style='"+titleStyle+"'></td>" +
  245. // " <td style='"+valueStyle+ "'></td></tr>" +
  246. // //( this.options.isHideAttachment ? "" :
  247. // //"<tr><td style='"+titleStyle+"'>"+this.lp.eventAttachment+":</td>" +
  248. // //" <td style='"+valueStyle+"' item='attachment'></td></tr>"+
  249. // //)+
  250. // "<tr><td style='"+titleStyle+"'></td>" +
  251. // " <td style='"+valueStyle+ "' item='seeMore'></td></tr>"+
  252. // "</table>";
  253. html = "";
  254. return html;
  255. },
  256. setTargetEvents : function(){
  257. if( this.options.event == "click" ){
  258. // if( this.options.isAutoShow ){
  259. // this.target.addEvents({
  260. // "click": function( ev ){
  261. // this.load();
  262. // ev.stopPropagation();
  263. // }.bind(this)
  264. // });
  265. // }
  266. }else{
  267. if( this.options.isAutoHide || this.options.isAutoShow ){
  268. this.target.addEvents({
  269. "mouseenter": function(){
  270. if( this.timer_hide ){
  271. clearTimeout(this.timer_hide);
  272. }
  273. }.bind(this)
  274. });
  275. }
  276. if( this.options.isAutoShow ){
  277. this.target.addEvents({
  278. "mouseenter": function(){
  279. if( this.status != "display" ){
  280. this.timer_show = setTimeout( this.load.bind(this),this.options.displayDelay );
  281. }
  282. }.bind(this)
  283. });
  284. }
  285. if( this.options.isAutoHide || this.options.isAutoShow ){
  286. this.target.addEvents({
  287. "mouseleave" : function(){
  288. if( this.timer_show ){
  289. clearTimeout(this.timer_show);
  290. }
  291. }.bind(this)
  292. });
  293. }
  294. if( this.options.isAutoHide ){
  295. this.target.addEvents({
  296. "mouseleave" : function(){
  297. if( this.status == "display" ){
  298. this.timer_hide = setTimeout( this.hide.bind(this),this.options.hiddenDelay );
  299. }
  300. }.bind(this)
  301. });
  302. }
  303. }
  304. },
  305. destroy: function(){
  306. //if( this.options.event == "click" && this.node ){
  307. // this.container.removeEvent("mousedown",this.hideFun );
  308. //}
  309. if( this.options.event == "click" && this.app && this.hideFun_resize ){
  310. this.app.removeEvent("resize",this.hideFun_resize );
  311. }
  312. if( this.node ){
  313. this.node.destroy();
  314. this.node = null;
  315. }
  316. this.fireEvent("destroy",[this]);
  317. MWF.release(this);
  318. },
  319. setCoondinates_y : function(){
  320. var targetCoondinates = this.target ? this.target.getCoordinates( this.container ) : this.targetCoordinates ;
  321. var node = this.node;
  322. if( this.resetHeight ){
  323. node.setStyles({
  324. overflow : "visible",
  325. height : "auto"
  326. });
  327. if(this.arrowNode)this.arrowNode.setStyle("display","");
  328. this.resetHeight = false;
  329. }
  330. var containerScroll = this.container.getScroll();
  331. var containerSize = this.container.getSize();
  332. var nodeSize = node.getSize();
  333. var top;
  334. var arrowX, arrowY;
  335. var offsetY = this.options.hasArrow ? 10 : 0;
  336. if( this.options.position.y == "top" ){
  337. top = targetCoondinates.top - nodeSize.y - offsetY;
  338. arrowY = "bottom";
  339. }else if( this.options.position.y == "bottom" ){
  340. top = targetCoondinates.bottom + offsetY;
  341. arrowY = "top";
  342. }else{
  343. var priorityOfAuto = this.options.priorityOfAuto;
  344. if( priorityOfAuto && priorityOfAuto.y ){
  345. for( var i=0; i<priorityOfAuto.y.length; i++ ){
  346. if( priorityOfAuto.y[i] == "top" ){
  347. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){
  348. top = targetCoondinates.top - nodeSize.y - offsetY;
  349. arrowY = "bottom";
  350. break;
  351. }
  352. }
  353. if( priorityOfAuto.y[i] == "bottom" ){
  354. if( containerSize.y + containerScroll.y - targetCoondinates.bottom > nodeSize.y ){
  355. top = targetCoondinates.bottom + offsetY;
  356. arrowY = "top";
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. if( !top ){
  363. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom){
  364. top = targetCoondinates.top - nodeSize.y - offsetY;
  365. arrowY = "bottom";
  366. }else{
  367. top = targetCoondinates.bottom + offsetY;
  368. arrowY = "top";
  369. }
  370. }
  371. }
  372. var left;
  373. if( this.options.position.x == "center" ){
  374. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  375. arrowX = "center";
  376. }else if( this.options.position.x == "left" ){
  377. left = targetCoondinates.right - nodeSize.x;
  378. arrowX = "right";
  379. }else if( this.options.position.x == "right" ){
  380. left = targetCoondinates.left;
  381. arrowX = "left";
  382. }else{
  383. var priorityOfAuto = this.options.priorityOfAuto;
  384. if( priorityOfAuto && priorityOfAuto.x ){
  385. for( var i=0; i<priorityOfAuto.x.length; i++ ){
  386. if( priorityOfAuto.x[i] == "center" ){
  387. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  388. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  389. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  390. arrowX = "center";
  391. break;
  392. }
  393. }
  394. if( priorityOfAuto.x[i] == "left" ){
  395. if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){
  396. left = targetCoondinates.right - nodeSize.x;
  397. arrowX = "right";
  398. break;
  399. }
  400. }
  401. if( priorityOfAuto.x[i] == "right" ){
  402. if( containerSize.x + containerScroll.x - targetCoondinates.right > nodeSize.x ){
  403. left = targetCoondinates.left;
  404. arrowX = "left";
  405. break;
  406. }
  407. }
  408. }
  409. }
  410. if( !left ){
  411. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  412. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  413. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  414. arrowX = "center";
  415. } else if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right ){
  416. left = targetCoondinates.right - nodeSize.x;
  417. arrowX = "right";
  418. }else{
  419. left = targetCoondinates.left;
  420. arrowX = "left";
  421. }
  422. }
  423. }
  424. var arrowOffsetX = 0;
  425. if( this.options.isFitToContainer ){
  426. if( left < containerScroll.x ){
  427. arrowOffsetX = containerScroll.x - left;
  428. left = containerScroll.x;
  429. }else if( left + nodeSize.x > containerSize.x + containerScroll.x ){
  430. arrowOffsetX = containerSize.x + containerScroll.x - left - nodeSize.x;
  431. left = containerSize.x + containerScroll.x - nodeSize.x;
  432. }
  433. }
  434. if( this.options.overflow == "scroll" ){
  435. if( top < 0 ){
  436. node.setStyles({
  437. "overflow" : "auto",
  438. "height" : nodeSize.y + top - offsetY
  439. });
  440. this.resetHeight = true;
  441. top = 0
  442. }else if( top + nodeSize.y > containerSize.y + containerScroll.y ){
  443. node.setStyles({
  444. "overflow" : "auto",
  445. "height" : Math.abs( containerSize.y + containerScroll.y - top + offsetY )
  446. });
  447. top = top - offsetY;
  448. this.resetHeight = true;
  449. }
  450. }
  451. if( this.resetHeight ){
  452. if( this.arrowNode )this.arrowNode.setStyle("display","none");
  453. }else if( this.options.hasArrow && this.arrowNode ){
  454. if( arrowY == "top" ){
  455. this.arrowNode.setStyles( {
  456. "top" : "-8px",
  457. "bottom" : "auto",
  458. "background-position": "0px -18px"
  459. });
  460. }else{
  461. this.arrowNode.setStyles( {
  462. "top" : "auto",
  463. "bottom" : "-8px",
  464. "background-position": "0px -28px"
  465. });
  466. }
  467. var aw = this.arrowNode.getSize().x / 2 ;
  468. //var tw = targetCoondinates.width / 2 - aw;
  469. var w = Math.min( targetCoondinates.width , nodeSize.x )/ 2 - aw;
  470. var radiusDv = 0; //圆角和箭头偏移量的差值
  471. var radius = 0; //圆角值
  472. if( arrowX == "center" ) {
  473. this.arrowNode.setStyles({
  474. "left": (nodeSize.x/2 - aw - arrowOffsetX )+"px",
  475. "right": "auto"
  476. })
  477. }else if( arrowX == "left" ){
  478. radius = this.node.getStyle("border-"+arrowY+"-left-radius");
  479. radius = radius ? parseInt( radius ) : 0;
  480. if( radius > w ){
  481. radiusDv = radius - w;
  482. }
  483. this.arrowNode.setStyles({
  484. "left" : w + radiusDv - arrowOffsetX + "px",
  485. "right" : "auto"
  486. })
  487. }else{
  488. radius = this.node.getStyle("border-" + arrowY + "-right-radius");
  489. radius = radius ? parseInt(radius) : 0;
  490. if( radius > w ){
  491. radiusDv = radius - w;
  492. }
  493. this.arrowNode.setStyles({
  494. "left" : "auto",
  495. "right" : w + radiusDv + arrowOffsetX +"px"
  496. })
  497. }
  498. var l = left;
  499. if( radiusDv ){
  500. if( arrowX == "left" ){
  501. l = l - radiusDv;
  502. }else if( arrowX == "right" ){
  503. l = l + radiusDv;
  504. }
  505. }
  506. }
  507. node.setStyles({
  508. "left" : l || left,
  509. "top" : top+4
  510. });
  511. }
  512. });