switchNetwork.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. define(['html!templates/switchNetwork',
  2. 'css!styles/switchNetwork'
  3. ],
  4. function(tpcLayout) {
  5. var modValue = {
  6. type: null
  7. };
  8. var status = {
  9. initialized: false
  10. };
  11. function init(type) {
  12. if (!status.initialized) {
  13. $(tpcLayout).appendTo('body');
  14. bindEvents();
  15. subscribe();
  16. status.initialized = true;
  17. }
  18. modValue.type = type;
  19. setLayout();
  20. };
  21. function setLayout() {
  22. if (modValue.type == 1) {
  23. var html = "输入离线账户切换至离线";
  24. } else {
  25. var html = "输入在线账户切换至在线";
  26. }
  27. $("#switchNetworkContent h3").html(html);
  28. //$("#userNameNetwork").val(ONEMAP.D.user.name);
  29. $("#switchNetworkContent").show();
  30. if(map23DData.display.map2D){
  31. $('#switchNetworkContent').removeClass('class3d');
  32. }else if(map23DData.display.map3D){
  33. $('#switchNetworkContent').addClass('class3d');
  34. }
  35. }
  36. function mergeConfig() {
  37. if (modValue.type == 1) {
  38. $.each(map23DConfigIntranet, function(i, t) {
  39. map23DConfig[i] = t
  40. })
  41. $.each(onemapUrlConfigIntranet, function(i, t) {
  42. onemapUrlConfig[i] = t
  43. })
  44. } else {
  45. $.each(map23DConfigNetwork, function(i, t) {
  46. map23DConfig[i] = t
  47. })
  48. $.each(onemapUrlConfigNetwork, function(i, t) {
  49. onemapUrlConfig[i] = t
  50. })
  51. }
  52. }
  53. function getCMSTicket() {
  54. if ($("#userPWNetwork").val() == "") {
  55. alert("密码不能为空");
  56. return false
  57. }
  58. $.ajax({
  59. type: "post",
  60. dataTpe: "json",
  61. url: onemapUrlConfig.oauthServiceUrl + "/v1.0/user/gcms/auth",
  62. data: {
  63. "password": $("#userPWNetwork").val(),
  64. "email": $("#userNameNetwork").val()
  65. }
  66. })
  67. .done(function(data) {
  68. if (data.code == 0) {
  69. $.ajax({
  70. type: "get",
  71. dataType: 'json',
  72. url: onemapUrlConfig.userDataUrl + '/v1.0/user/current_user',
  73. success: function(data) {
  74. _.merge(ONEMAP.D.user, data.data);
  75. if (modValue.type == 1) {
  76. ONEMAP.C.publisher.publish('network', 'seitchNetwork');
  77. } else {
  78. ONEMAP.C.publisher.publish('intranet', 'seitchNetwork');
  79. }
  80. $("#switchNetworkContent").hide();
  81. },
  82. error: function() {
  83. alert("无效的用户");
  84. }
  85. });
  86. } else {
  87. alert(data.message)
  88. }
  89. })
  90. .fail(function() {
  91. alert("无效的用户");
  92. });
  93. }
  94. function bindEvents() {
  95. $("#switchNetworkContent .sure").bind('click', function() {
  96. mergeConfig();
  97. getCMSTicket();
  98. })
  99. $("#switchNetworkContent .close").bind('click', function() {
  100. $("#switchNetworkContent").hide();
  101. })
  102. }
  103. function change23D(options){
  104. if(options == '2d'){
  105. $('#switchNetworkContent').removeClass('class3d');
  106. }else{
  107. $('#switchNetworkContent').addClass('class3d');
  108. }
  109. }
  110. /**
  111. * 注册监听
  112. * @type {Function}
  113. */
  114. function subscribe() {
  115. ONEMAP.C.publisher.subscribe(change23D, 'change23D');
  116. };
  117. return ONEMAP.M.switchNetwork = {
  118. init: init
  119. }
  120. })