[enh] Clean use of store.set(url). Get url value ASAP.

This commit is contained in:
opi 2016-05-23 15:29:58 +02:00
parent 04cd9dfbf5
commit ce6b5c9940
3 changed files with 28 additions and 24 deletions

View file

@ -91,9 +91,10 @@
c.checkInstall(function(isInstalled) { c.checkInstall(function(isInstalled) {
if (isInstalled) { if (isInstalled) {
domain = window.location.hostname; // Remove loader
$('div.loader').remove(); $('div.loader').remove();
c.view('login', { 'domain': domain }); // Pass domain to hide form field
c.view('login', { 'domain': window.location.hostname });
} else if (typeof isInstalled === 'undefined') { } else if (typeof isInstalled === 'undefined') {
if (app.isInstalledTry > 0) { if (app.isInstalledTry > 0) {
app.isInstalledTry--; app.isInstalledTry--;
@ -134,6 +135,7 @@
*/ */
app.post('#/login', function (c) { app.post('#/login', function (c) {
// Store url from params, it could have change form 'run' state
store.set('url', c.params['domain'] +'/yunohost/api'); store.set('url', c.params['domain'] +'/yunohost/api');
params = { params = {

View file

@ -43,10 +43,9 @@
}, },
checkInstall: function(callback) { checkInstall: function(callback) {
domain = window.location.hostname;
$.ajax({ $.ajax({
dataType: "json", dataType: "json",
url: 'https://'+ domain +'/yunohost/api/installed', url: 'https://'+ store.get('url') +'/installed',
timeout: 3000 timeout: 3000
}) })
.success(function(data) { .success(function(data) {
@ -82,7 +81,7 @@
} }
jQuery.ajax({ jQuery.ajax({
url: 'https://'+ store.get('url') + uri, url: 'https://' + store.get('url') + uri,
type: method, type: method,
crossdomain: true, crossdomain: true,
data: data, data: data,

View file

@ -3,25 +3,6 @@
var app = Sammy('#main', function (sam) { var app = Sammy('#main', function (sam) {
/**
* Application bootstrap
*
*/
sam.bind('run', function () {
// Flash messages
var flashMessage = $('#flashMessage');
$('#toggle-btn', flashMessage).click(function(e) {
flashMessage.toggleClass('open');
});
$('#clear-btn', flashMessage).click(function(e) {
flashMessage.removeClass('open').find('.messages').html('');
$('#slider').removeClass('with-flashMessage');
});
});
/** /**
* Sammy Configuration * Sammy Configuration
* *
@ -80,6 +61,28 @@
sam.isInstalledTry = 3; sam.isInstalledTry = 3;
/**
* Application bootstrap
*
*/
sam.bind('run', function () {
// Store url
sam.store.set('url', window.location.hostname + '/yunohost/api');
// Flash messages
var flashMessage = $('#flashMessage');
$('#toggle-btn', flashMessage).click(function(e) {
flashMessage.toggleClass('open');
});
$('#clear-btn', flashMessage).click(function(e) {
flashMessage.removeClass('open').find('.messages').html('');
$('#slider').removeClass('with-flashMessage');
});
});
/** /**
* Errors * Errors
*/ */