Common.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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 ){
  166. //可以传入target 或者 targetCoordinates,两种选一
  167. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  168. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  169. if( options ){
  170. this.setOptions(options);
  171. }
  172. this.container = container;
  173. this.target = target;
  174. this.targetCoordinates = targetCoordinates;
  175. this.app = app;
  176. //if(app)this.lp = app.lp;
  177. this.lp = this.app.lp.common.tooltip;
  178. this.data = data;
  179. this.actions = this.app.restActions;
  180. this.path = "/x_component_TeamWork/$Common/";
  181. if(options.path) this.path = options.path;
  182. if( this.target ){
  183. this.setTargetEvents();
  184. }
  185. this.fireEvent("postInitialize",[this]);
  186. },
  187. _loadCustom : function( callback ){
  188. // new Element("div.aaa",{styles:{"background-color":"#ff0000",width:"500px","height":"800px",position:"absolute",
  189. // left:"100px",top:"200px"
  190. // }}).inject(this.container);
  191. if(callback)callback();
  192. },
  193. hide: function(){
  194. if( this.node ){
  195. this.node.setStyle("display","none");
  196. this.status = "hidden";
  197. if( this.maskNode ){
  198. this.maskNode.setStyle("display","none");
  199. }
  200. this.fireEvent("hide",[this]);
  201. }
  202. if( this.maskNode ){
  203. this.maskNode.destroy();
  204. }
  205. this.close();
  206. },
  207. // 增加的方法
  208. close: function(data){
  209. if( this.node ){
  210. this.node.setStyle("display","none");
  211. this.status = "hidden";
  212. if( this.maskNode ){
  213. this.maskNode.setStyle("display","none");
  214. }
  215. this.fireEvent("hide",[this]);
  216. //this.fireEvent("close",[data]);
  217. }
  218. if( this.maskNode ){
  219. this.maskNode.destroy();
  220. }
  221. this.fireEvent("close",[data]);
  222. this.destroy();
  223. },
  224. _getHtml : function(){
  225. // var data = this.data;
  226. // var titleStyle = "font-size:14px;color:#333";
  227. // var valueStyle = "font-size:14px;color:#666;padding-right:10px";
  228. // var html =
  229. // "<div style='font-size: 16px;color:#333;padding:10px 10px 10px 20px;'>ddddddddddddddd</div>"+
  230. // "<div style='height:1px;margin:0px 20px;border-bottom:1px solid #ccc;'></div>"+
  231. // "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' style='margin:13px 13px 13px 13px;'>" +
  232. // "<tr><td style='"+titleStyle+";' width='40'>开始:</td>" +
  233. // " <td style='"+valueStyle+"'></td></tr>" +
  234. // "<tr><td style='"+titleStyle+"'>结束:</td>" +
  235. // " <td style='"+valueStyle+ "'></td></tr>" +
  236. // "<tr><td style='"+titleStyle+"'></td>" +
  237. // " <td style='"+valueStyle+ "'></td></tr>" +
  238. // //( this.options.isHideAttachment ? "" :
  239. // //"<tr><td style='"+titleStyle+"'>"+this.lp.eventAttachment+":</td>" +
  240. // //" <td style='"+valueStyle+"' item='attachment'></td></tr>"+
  241. // //)+
  242. // "<tr><td style='"+titleStyle+"'></td>" +
  243. // " <td style='"+valueStyle+ "' item='seeMore'></td></tr>"+
  244. // "</table>";
  245. html = "";
  246. return html;
  247. },
  248. setTargetEvents : function(){
  249. if( this.options.event == "click" ){
  250. // if( this.options.isAutoShow ){
  251. // this.target.addEvents({
  252. // "click": function( ev ){
  253. // this.load();
  254. // ev.stopPropagation();
  255. // }.bind(this)
  256. // });
  257. // }
  258. }else{
  259. if( this.options.isAutoHide || this.options.isAutoShow ){
  260. this.target.addEvents({
  261. "mouseenter": function(){
  262. if( this.timer_hide ){
  263. clearTimeout(this.timer_hide);
  264. }
  265. }.bind(this)
  266. });
  267. }
  268. if( this.options.isAutoShow ){
  269. this.target.addEvents({
  270. "mouseenter": function(){
  271. if( this.status != "display" ){
  272. this.timer_show = setTimeout( this.load.bind(this),this.options.displayDelay );
  273. }
  274. }.bind(this)
  275. });
  276. }
  277. if( this.options.isAutoHide || this.options.isAutoShow ){
  278. this.target.addEvents({
  279. "mouseleave" : function(){
  280. if( this.timer_show ){
  281. clearTimeout(this.timer_show);
  282. }
  283. }.bind(this)
  284. });
  285. }
  286. if( this.options.isAutoHide ){
  287. this.target.addEvents({
  288. "mouseleave" : function(){
  289. if( this.status == "display" ){
  290. this.timer_hide = setTimeout( this.hide.bind(this),this.options.hiddenDelay );
  291. }
  292. }.bind(this)
  293. });
  294. }
  295. }
  296. },
  297. destroy: function(){
  298. //if( this.options.event == "click" && this.node ){
  299. // this.container.removeEvent("mousedown",this.hideFun );
  300. //}
  301. if( this.options.event == "click" && this.app && this.hideFun_resize ){
  302. this.app.removeEvent("resize",this.hideFun_resize );
  303. }
  304. if( this.node ){
  305. this.node.destroy();
  306. this.node = null;
  307. }
  308. this.fireEvent("destroy",[this]);
  309. MWF.release(this);
  310. },
  311. setCoondinates_y : function(){
  312. var targetCoondinates = this.target ? this.target.getCoordinates( this.container ) : this.targetCoordinates ;
  313. var node = this.node;
  314. if( this.resetHeight ){
  315. node.setStyles({
  316. overflow : "visible",
  317. height : "auto"
  318. });
  319. if(this.arrowNode)this.arrowNode.setStyle("display","");
  320. this.resetHeight = false;
  321. }
  322. var containerScroll = this.container.getScroll();
  323. var containerSize = this.container.getSize();
  324. var nodeSize = node.getSize();
  325. var top;
  326. var arrowX, arrowY;
  327. var offsetY = this.options.hasArrow ? 10 : 0;
  328. if( this.options.position.y == "top" ){
  329. top = targetCoondinates.top - nodeSize.y - offsetY;
  330. arrowY = "bottom";
  331. }else if( this.options.position.y == "bottom" ){
  332. top = targetCoondinates.bottom + offsetY;
  333. arrowY = "top";
  334. }else{
  335. var priorityOfAuto = this.options.priorityOfAuto;
  336. if( priorityOfAuto && priorityOfAuto.y ){
  337. for( var i=0; i<priorityOfAuto.y.length; i++ ){
  338. if( priorityOfAuto.y[i] == "top" ){
  339. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){
  340. top = targetCoondinates.top - nodeSize.y - offsetY;
  341. arrowY = "bottom";
  342. break;
  343. }
  344. }
  345. if( priorityOfAuto.y[i] == "bottom" ){
  346. if( containerSize.y + containerScroll.y - targetCoondinates.bottom > nodeSize.y ){
  347. top = targetCoondinates.bottom + offsetY;
  348. arrowY = "top";
  349. break;
  350. }
  351. }
  352. }
  353. }
  354. if( !top ){
  355. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom){
  356. top = targetCoondinates.top - nodeSize.y - offsetY;
  357. arrowY = "bottom";
  358. }else{
  359. top = targetCoondinates.bottom + offsetY;
  360. arrowY = "top";
  361. }
  362. }
  363. }
  364. var left;
  365. if( this.options.position.x == "center" ){
  366. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  367. arrowX = "center";
  368. }else if( this.options.position.x == "left" ){
  369. left = targetCoondinates.right - nodeSize.x;
  370. arrowX = "right";
  371. }else if( this.options.position.x == "right" ){
  372. left = targetCoondinates.left;
  373. arrowX = "left";
  374. }else{
  375. var priorityOfAuto = this.options.priorityOfAuto;
  376. if( priorityOfAuto && priorityOfAuto.x ){
  377. for( var i=0; i<priorityOfAuto.x.length; i++ ){
  378. if( priorityOfAuto.x[i] == "center" ){
  379. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  380. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  381. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  382. arrowX = "center";
  383. break;
  384. }
  385. }
  386. if( priorityOfAuto.x[i] == "left" ){
  387. if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){
  388. left = targetCoondinates.right - nodeSize.x;
  389. arrowX = "right";
  390. break;
  391. }
  392. }
  393. if( priorityOfAuto.x[i] == "right" ){
  394. if( containerSize.x + containerScroll.x - targetCoondinates.right > nodeSize.x ){
  395. left = targetCoondinates.left;
  396. arrowX = "left";
  397. break;
  398. }
  399. }
  400. }
  401. }
  402. if( !left ){
  403. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  404. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  405. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  406. arrowX = "center";
  407. } else if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right ){
  408. left = targetCoondinates.right - nodeSize.x;
  409. arrowX = "right";
  410. }else{
  411. left = targetCoondinates.left;
  412. arrowX = "left";
  413. }
  414. }
  415. }
  416. var arrowOffsetX = 0;
  417. if( this.options.isFitToContainer ){
  418. if( left < containerScroll.x ){
  419. arrowOffsetX = containerScroll.x - left;
  420. left = containerScroll.x;
  421. }else if( left + nodeSize.x > containerSize.x + containerScroll.x ){
  422. arrowOffsetX = containerSize.x + containerScroll.x - left - nodeSize.x;
  423. left = containerSize.x + containerScroll.x - nodeSize.x;
  424. }
  425. }
  426. if( this.options.overflow == "scroll" ){
  427. if( top < 0 ){
  428. node.setStyles({
  429. "overflow" : "auto",
  430. "height" : nodeSize.y + top - offsetY
  431. });
  432. this.resetHeight = true;
  433. top = 0
  434. }else if( top + nodeSize.y > containerSize.y + containerScroll.y ){
  435. node.setStyles({
  436. "overflow" : "auto",
  437. "height" : Math.abs( containerSize.y + containerScroll.y - top + offsetY )
  438. });
  439. top = top - offsetY;
  440. this.resetHeight = true;
  441. }
  442. }
  443. if( this.resetHeight ){
  444. if( this.arrowNode )this.arrowNode.setStyle("display","none");
  445. }else if( this.options.hasArrow && this.arrowNode ){
  446. if( arrowY == "top" ){
  447. this.arrowNode.setStyles( {
  448. "top" : "-8px",
  449. "bottom" : "auto",
  450. "background-position": "0px -18px"
  451. });
  452. }else{
  453. this.arrowNode.setStyles( {
  454. "top" : "auto",
  455. "bottom" : "-8px",
  456. "background-position": "0px -28px"
  457. });
  458. }
  459. var aw = this.arrowNode.getSize().x / 2 ;
  460. //var tw = targetCoondinates.width / 2 - aw;
  461. var w = Math.min( targetCoondinates.width , nodeSize.x )/ 2 - aw;
  462. var radiusDv = 0; //圆角和箭头偏移量的差值
  463. var radius = 0; //圆角值
  464. if( arrowX == "center" ) {
  465. this.arrowNode.setStyles({
  466. "left": (nodeSize.x/2 - aw - arrowOffsetX )+"px",
  467. "right": "auto"
  468. })
  469. }else if( arrowX == "left" ){
  470. radius = this.node.getStyle("border-"+arrowY+"-left-radius");
  471. radius = radius ? parseInt( radius ) : 0;
  472. if( radius > w ){
  473. radiusDv = radius - w;
  474. }
  475. this.arrowNode.setStyles({
  476. "left" : w + radiusDv - arrowOffsetX + "px",
  477. "right" : "auto"
  478. })
  479. }else{
  480. radius = this.node.getStyle("border-" + arrowY + "-right-radius");
  481. radius = radius ? parseInt(radius) : 0;
  482. if( radius > w ){
  483. radiusDv = radius - w;
  484. }
  485. this.arrowNode.setStyles({
  486. "left" : "auto",
  487. "right" : w + radiusDv + arrowOffsetX +"px"
  488. })
  489. }
  490. var l = left;
  491. if( radiusDv ){
  492. if( arrowX == "left" ){
  493. l = l - radiusDv;
  494. }else if( arrowX == "right" ){
  495. l = l + radiusDv;
  496. }
  497. }
  498. }
  499. node.setStyles({
  500. "left" : l || left,
  501. "top" : top+4
  502. });
  503. }
  504. });