MailWidget.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MWF.xDesktop.requireApp("VsettanMail", "Actions.RestActions", null, false);
  2. MWF.xApplication.VsettanMail = MWF.xApplication.VsettanMail || {};
  3. MWF.xApplication.VsettanMail.MailWidget = new Class({
  4. Extends: MWF.xApplication.Common.Widget,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "title": MWF.xApplication.VsettanMail.LP.title,
  9. "appName": "VsettanMail",
  10. "name": "MailWidget",
  11. "position": {"right": 10, "bottom": 10},
  12. "width": "400",
  13. "height": "550"
  14. },
  15. loadContent: function(callback){
  16. this.ssoCount = 0;
  17. this.widget.node.setStyle("display", "none");
  18. //this.setTimeout();
  19. this.action = new MWF.xApplication.VsettanMail.Actions.RestActions();
  20. if (this.desktop.session.user.name!="xadmin") this.getUnreadCount();
  21. this.widget.close()
  22. },
  23. setTimeout: function(){
  24. window.setTimeout(function(){
  25. this.getUnreadCount();
  26. }.bind(this), 30000);
  27. },
  28. getUnreadCount: function(){
  29. this.checkUser(function(mail){
  30. this.getUnreadCountXml(mail);
  31. }.bind(this));
  32. },
  33. getUnreadCountXml: function(mail){
  34. var url = mail+"/iNotes/Proxy/?OpenDocument&Form=s_ReadViewEntries_JSONP&PresetFields=FolderName;($Inbox),UnreadCountInfo;1,callback;Request.JSONP.request_map.request_"+Request.JSONP.counter+"&Start=1&Count=0";
  35. //var url = "http://mail.vsettan.com.cn/land/xsso.nsf/(getUserMail)?openpage";
  36. MWF.getJSONP(url, {
  37. "onSuccess": function(json){
  38. if (json.unreadcount.toInt()>0) this.setFlagText(json.unreadcount);
  39. this.setTimeout();
  40. }.bind(this)
  41. });
  42. //try {
  43. // var xml = new COMMON.XML();
  44. // xml.get(url, function(xml){
  45. // var unreadcount = xml.queryNode("readviewentries/unreadinfo/unreadcount").text();
  46. // this.setFlagText(unreadcount);
  47. // this.setTimeout();
  48. // }.bind(this));
  49. //}catch(e){
  50. // var iframe = new Element("iframe", {"styles": {"display": "none"}}).inject(this.desktop.desktopNode);
  51. // iframe.set("src", url);
  52. // window.setTimeout(function(){
  53. // xml = new COMMON.XML(iframe.contentDocument)
  54. // var unreadcount = xml.queryNode("readviewentries/unreadinfo/unreadcount").text();
  55. // this.setFlagText(unreadcount);
  56. // this.setTimeout();
  57. // iframe.destroy();
  58. // }.bind(this), 1000);
  59. //}
  60. },
  61. checkUser: function(callback, nosso){
  62. var url = "http://"+layout.config.mail+"/land/xsso.nsf/(getUserMail)?openpage";
  63. MWF.getJSONP(url, {
  64. "onSuccess": function(json){
  65. if (json.name==this.desktop.session.user.unique){
  66. this.ssoCount = 0;
  67. if (callback) callback(json.mail);
  68. }else{
  69. if (!nosso){
  70. if (this.ssoCount<5){
  71. this.ssoMail(json.mail);
  72. this.ssoCount++;
  73. }
  74. }
  75. }
  76. }.bind(this)
  77. }, true);
  78. },
  79. ssoMail: function(){
  80. this.action.getPassword(function(json){
  81. var url = "http://"+layout.config.mail+"/names.nsf?login?login&username="+this.desktop.session.user.unique+"&password="+json.data.password+"&RedirectTo=/land/xsso.nsf/(callback)?openpage";
  82. var iframe = new Element("iframe", {"styles": {"display": "none"}}).inject(this.desktop.desktopNode);
  83. iframe.set("src", url);
  84. window.setTimeout(function(){
  85. this.setTimeout();
  86. iframe.destroy();
  87. this.checkUser(function(mail){
  88. this.getUnreadCountXml(mail);
  89. }.bind(this), true);
  90. }.bind(this), 2000);
  91. }.bind(this));
  92. },
  93. setFlagText: function(unreadcount){
  94. this.unreadcount = unreadcount;
  95. this.desktop.lnks.each(function(lnk){
  96. if (lnk.par=="VsettanMail"){
  97. if (!lnk.flagNode){
  98. var node = this.createFlagNode();
  99. node.inject(lnk.node);
  100. lnk.flagNode = node;
  101. var lnkSize = lnk.node.getSize();
  102. var top = lnkSize.y;
  103. node.setStyles({
  104. "top": "-"+top+"px"
  105. });
  106. }
  107. var txt = unreadcount;
  108. if (unreadcount.toInt()>99) txt = "99+";
  109. lnk.flagNode.set("text", txt);
  110. }
  111. }.bind(this));
  112. this.desktop.navi.navis.each(function(navi){
  113. var json = navi.retrieve("navi");
  114. if (json){
  115. if (json.action=="VsettanMail"){
  116. var flagNode = navi.retrieve("flagNode");
  117. if (!flagNode){
  118. var node = this.createFlagNode();
  119. node.inject(navi);
  120. navi.store("flagNode", node);
  121. flagNode = node;
  122. var lnkSize = navi.getSize();
  123. var top = lnkSize.y-5;
  124. flagNode.setStyles({
  125. "top": "-"+top+"px",
  126. "margin-right": "12px"
  127. });
  128. }
  129. var txt = unreadcount;
  130. if (unreadcount.toInt()>99) txt = "99+";
  131. flagNode.set("text", txt);
  132. }
  133. }
  134. }.bind(this));
  135. //if (this.desktop.top.loadMenuAction){
  136. // if (!this.desktop.top.flagCountNode){
  137. // var node = this.createFlagNode(this.css.flagNodeMenu);
  138. // this.desktop.top.flagCountNode = node;
  139. // node.inject(this.desktop.top.loadMenuAction);
  140. //
  141. // var actionSize = this.desktop.top.flagCountNode.getSize();
  142. // var top = actionSize.y-node.getSize().y;
  143. // node.setStyles({
  144. // "top": "-"+top+"px"
  145. // });
  146. // }
  147. // var txt = unreadcount;
  148. // if (unreadcount.toInt()>99) txt = "99+";
  149. // this.desktop.top.flagCountNode.set("text", txt);
  150. //}
  151. },
  152. createFlagNode:function(css){
  153. var node = new Element("div", {
  154. "styles": css || this.css.flagNode
  155. });
  156. return node;
  157. }
  158. });