app.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. $.ajaxSetup({
  2. cache: true
  3. });
  4. Array.indexOf = function (arr, elt) {
  5. for (var i = 0; i < arr.length; i++) {
  6. if (arr[i] === elt) {
  7. return i;
  8. }
  9. }
  10. return -1;
  11. };
  12. var holly = {
  13. session: {
  14. logined: false,
  15. extenType: 'sip',
  16. user: null,
  17. account: null
  18. },
  19. setCookie: function (name, value, days) {
  20. var cookieTime = days * 24 * 60 * 60 * 1000;
  21. var d = new Date();
  22. d.setTime(d.getTime() + cookieTime);
  23. var cookieExpires = "; expires=" + d.toGMTString();
  24. document.cookie = name + "=" + escape(value) + cookieExpires + "; path=/";
  25. },
  26. app: {
  27. init: function () {
  28. $("#softphoneBarKick").on("click", function () {
  29. if (holly.session.logined) {
  30. holly.phone._phone_exit(true);
  31. }
  32. });
  33. $("#softphoneBarPick").on("click", function () {
  34. if (!holly.session.logined) {
  35. holly.phone._phone_relogin(false);
  36. }
  37. });
  38. $("#softphone-bar .state_dropdown").click(function () {
  39. $("#softphone_otherstate").fadeToggle('fast');
  40. });
  41. $('body').click(function (e) {
  42. if ($("#softphone_otherstate").css("display") === "block" && e.target.id !== "softphone_dropdown" && e.target.id != "softphone_dropdown_caret") {
  43. $("#softphone_otherstate").fadeOut('fast');
  44. }
  45. });
  46. },
  47. loginSuccessCallback: function () {
  48. if (hollyglobal.loginSuccessCallback && typeof hollyglobal.loginSuccessCallback == 'function') {
  49. hollyglobal.loginSuccessCallback();
  50. }
  51. },
  52. loginFailureCallback: function (mess) {
  53. if (hollyglobal.loginFailureCallback && typeof hollyglobal.loginFailureCallback == 'function') {
  54. hollyglobal.loginFailureCallback(mess);
  55. } else {
  56. alert(mess);
  57. }
  58. },
  59. loginMonitor: function () {
  60. holly.app._initMonitorPhone();
  61. },
  62. _initMonitorPhone: function () {
  63. var currentPbxId = hollyglobal.sipConfigId, pbx, nickName, proxyUrl, pbxId;
  64. var config = {
  65. monitor: true
  66. };
  67. for (var i = 0; i < hollyglobal.pbxs.length; i++) {
  68. pbx = hollyglobal.pbxs[i];
  69. nickName = pbx.NickName;
  70. proxyUrl = pbx.proxyUrl;
  71. pbxId = pbx.PBX;
  72. pbx = {
  73. sipConfigId: pbxId,
  74. pbxNick: nickName,
  75. proxyUrl: proxyUrl,
  76. sessionId: "",
  77. isWaitingPbxEvent: false,
  78. isMonitorLogOff: false
  79. };
  80. if (pbxId !== currentPbxId) {
  81. if (!config.monitor) {
  82. continue;
  83. }
  84. // pbx.monitor = false;
  85. } else {//找到账户相应的PBX,存储到phone_pbx,做为监控数据的基础数据
  86. config.proxy_url = proxyUrl;
  87. config.extenType = hollyglobal.loginExtenType;
  88. config.password = hollyglobal.loginPassword;
  89. config.user = hollyglobal.loginUser;
  90. config.busyType = hollyglobal.loginBusyType;
  91. config.pbxNick = nickName;
  92. config.curPbx = pbxId;
  93. }
  94. holly.phone.phone_pbxs[pbxId] = pbx;
  95. }
  96. var phoneJson = {
  97. Command: "Action",
  98. Action: "Login",
  99. ActionID: "Login" + Math.random(),
  100. PBX: config.curPbx,
  101. Account: hollyglobal.accountId,
  102. Password: hollyglobal.monitorPassword,
  103. UserID: hollyglobal.monitorUserID,
  104. MonitorUser: true
  105. };
  106. phoneJson.isMonitorPage = true;
  107. holly.phone.phone_register(config, phoneJson);
  108. },
  109. _initSoftbarPhone: function () {
  110. holly.app.init();
  111. var actionName = "Login",
  112. phoneJson = {
  113. Command: "Action",
  114. Action: actionName,
  115. ActionID: actionName + Math.random(),
  116. Monitor: true,
  117. ExtenType: hollyglobal.loginExtenType,
  118. Password: hollyglobal.loginPassword,
  119. BusyType: hollyglobal.loginBusyType,
  120. User: hollyglobal.loginUser
  121. },
  122. config = {
  123. proxy_url: hollyglobal.loginProxyUrl,
  124. user: hollyglobal.loginUser
  125. };
  126. holly.phone.phone_register(config, phoneJson);
  127. }
  128. }
  129. };