define(['html!templates/switchNetwork', 'css!styles/switchNetwork' ], function(tpcLayout) { var modValue = { type: null }; var status = { initialized: false }; function init(type) { if (!status.initialized) { $(tpcLayout).appendTo('body'); bindEvents(); subscribe(); status.initialized = true; } modValue.type = type; setLayout(); }; function setLayout() { if (modValue.type == 1) { var html = "输入离线账户切换至离线"; } else { var html = "输入在线账户切换至在线"; } $("#switchNetworkContent h3").html(html); //$("#userNameNetwork").val(ONEMAP.D.user.name); $("#switchNetworkContent").show(); if(map23DData.display.map2D){ $('#switchNetworkContent').removeClass('class3d'); }else if(map23DData.display.map3D){ $('#switchNetworkContent').addClass('class3d'); } } function mergeConfig() { if (modValue.type == 1) { $.each(map23DConfigIntranet, function(i, t) { map23DConfig[i] = t }) $.each(onemapUrlConfigIntranet, function(i, t) { onemapUrlConfig[i] = t }) } else { $.each(map23DConfigNetwork, function(i, t) { map23DConfig[i] = t }) $.each(onemapUrlConfigNetwork, function(i, t) { onemapUrlConfig[i] = t }) } } function getCMSTicket() { if ($("#userPWNetwork").val() == "") { alert("密码不能为空"); return false } $.ajax({ type: "post", dataTpe: "json", url: onemapUrlConfig.oauthServiceUrl + "/v1.0/user/gcms/auth", data: { "password": $("#userPWNetwork").val(), "email": $("#userNameNetwork").val() } }) .done(function(data) { if (data.code == 0) { $.ajax({ type: "get", dataType: 'json', url: onemapUrlConfig.userDataUrl + '/v1.0/user/current_user', success: function(data) { _.merge(ONEMAP.D.user, data.data); if (modValue.type == 1) { ONEMAP.C.publisher.publish('network', 'seitchNetwork'); } else { ONEMAP.C.publisher.publish('intranet', 'seitchNetwork'); } $("#switchNetworkContent").hide(); }, error: function() { alert("无效的用户"); } }); } else { alert(data.message) } }) .fail(function() { alert("无效的用户"); }); } function bindEvents() { $("#switchNetworkContent .sure").bind('click', function() { mergeConfig(); getCMSTicket(); }) $("#switchNetworkContent .close").bind('click', function() { $("#switchNetworkContent").hide(); }) } function change23D(options){ if(options == '2d'){ $('#switchNetworkContent').removeClass('class3d'); }else{ $('#switchNetworkContent').addClass('class3d'); } } /** * 注册监听 * @type {Function} */ function subscribe() { ONEMAP.C.publisher.subscribe(change23D, 'change23D'); }; return ONEMAP.M.switchNetwork = { init: init } })