Commit e07d71d1 authored by Steve Johnson's avatar Steve Johnson

extracted loginSettings.js

parent 246ea07d
......@@ -12,6 +12,8 @@
<!--link href="login.css" media="screen" rel="stylesheet" type="text/css"/-->
<script src="https://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="loginSettings.js"></script>
<!-- javascript - external -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
......@@ -71,130 +73,7 @@
margin-left: 10px;
}
</style>
<script>
var newBaseUrl = "";
var qparams = "";
// This is the url baked into the application that redirects to the selected location.
var routingUri = "/mse/remote/remote.html";
function initLogin() {
// Get query params from redirect uri.
var qp = queryParams();
var redirectUri = decodeURIComponent(qp.redirect_uri);
var qindex = redirectUri.indexOf('?');
if (qindex != -1) {
qparams = redirectUri.substring(qindex);
console.log("qstring: "+qparams);
}
window.addEventListener('keyup', function(event) {
if(event.keyCode == 13){
onSelect();
}
}, true);
//var baseurl = document.location.protocol + "//" + document.location.host;
//$('#hostLabel').text(baseurl);
onInputTextChange();
}
function onSelect() {
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Set new redirect
document.cookie = 'MSE_LoginRedirect='+newBaseUrl+';expires=Thu, 01 Jan 2016 00:00:01 GMT;path=/';
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function onCancel() {
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function onReset() {
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Clear redirect
document.cookie = 'MSE_LoginRedirect=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function enableOptions(enable) {
if ($('#selectButton')[0].enable == undefined || $('#selectButton')[0].enable != enable) {
$('#selectButton')[0].enable = enable;
if (enable) {
$('#selectButton').removeClass('ui-disabled');
}
else {
$('#selectButton').addClass('ui-disabled');
}
}
}
function newRemoteUrl() {
}
function onInputTextChange() {
var url = document.getElementById('url').value;
if (url == undefined || url == '' || url.charAt(0) != "/") {
enableOptions(false);
}
else {
if (url.slice(-1) != "/") {
url += "/";
}
newBaseUrl = url + "mse/remote/remote.html";
var request = new XMLHttpRequest();
request.open("HEAD", newBaseUrl, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
enableOptions(request.status == 200);
}
}
request.send(null);
}
}
function queryParams() {
var urlParams = {};
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
return urlParams;
}
</script>
</head>
<body onload="initLogin();" >
......
var newBaseUrl = "";
var qparams = "";
// This is the url baked into the application that redirects to the selected location.
var routingUri = "/mse/remote/remote.html";
function initLogin() {
// Get query params from redirect uri.
var qp = queryParams();
var redirectUri = decodeURIComponent(qp.redirect_uri);
var qindex = redirectUri.indexOf('?');
if (qindex != -1) {
qparams = redirectUri.substring(qindex);
console.log("qstring: "+qparams);
}
window.addEventListener('keyup', function(event) {
if(event.keyCode == 13){
onSelect();
}
}, true);
//var baseurl = document.location.protocol + "//" + document.location.host;
//$('#hostLabel').text(baseurl);
onInputTextChange();
}
function onSelect() {
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Set new redirect
document.cookie = 'MSE_LoginRedirect='+newBaseUrl+';expires=Thu, 01 Jan 2016 00:00:01 GMT;path=/';
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function onCancel() {
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function onReset() {
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Clear redirect
document.cookie = 'MSE_LoginRedirect=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Redirect to routing url (remote.html in this folder)
location.replace(routingUri+qparams);
}
function enableOptions(enable) {
if ($('#selectButton')[0].enable == undefined || $('#selectButton')[0].enable != enable) {
$('#selectButton')[0].enable = enable;
if (enable) {
$('#selectButton').removeClass('ui-disabled');
}
else {
$('#selectButton').addClass('ui-disabled');
}
}
}
function newRemoteUrl() {
}
function onInputTextChange() {
var url = document.getElementById('url').value;
console.log("url: "+url);
if (url == undefined || url == '' || url.charAt(0) != "/") {
enableOptions(false);
}
else {
if (url.slice(-1) != "/") {
url += "/";
}
newBaseUrl = url + "mse/remote/remote.html";
var request = new XMLHttpRequest();
request.open("HEAD", newBaseUrl, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
enableOptions(request.status == 200);
}
}
request.send(null);
}
}
function queryParams() {
var urlParams = {};
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
return urlParams;
}
......@@ -1169,9 +1169,12 @@ var Remote = (function () {
}
remote.loginSettings = function() {
console.log("loginSettings - location: "+redirectUri);
var redirectUri = location.href;
var encodedUri = encodeURIComponent(redirectUri);
window.location.replace(Url.loginSettings(encodedUri));
var settingsUri = Url.loginSettings(encodedUri);
console.log("loginSettings - location: "+redirectUri+" loginSettings: "+settingsUri);
window.location.replace(settingsUri);
}
return remote;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment