Common.js 21 KB

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