diff --git a/js/app.js b/js/app.js index 4d815f07..d61a9328 100644 --- a/js/app.js +++ b/js/app.js @@ -93,6 +93,21 @@ app = Sammy('#main', function (sam) { }); }, + isInstalled: function() { + domain = window.location.hostname; + $.ajax({ + dataType: "json", + url: 'https://'+ domain +'/yunohost/api/installed', + timeout: 3000 + }) + .success(function(data) { + return data.installed; + }) + .fail(function() { + return false; + }); + }, + // API call api: function(uri, callback, method, data) { c = this; @@ -109,6 +124,10 @@ app = Sammy('#main', function (sam) { // If not connected, WebSocket connection will raise an error, but we do not want to interrupt API request ws.onerror = ws.onopen; + ws.onclose = function() { + store.clear('flash'); + } + ws.onopen = function(evt) { method = typeof method !== 'undefined' ? method : 'GET'; data = typeof data !== 'undefined' ? data : {}; @@ -125,19 +144,15 @@ app = Sammy('#main', function (sam) { installing = true; }, 1500); - $('#popup-title').text(y18n.t('installing')); - $('#popup-body').html('

'+y18n.t('installation_complete_wait', [data.domain])+'

'); - $('#popup-body').append('
'); - $('#popup').modal('show'); } else { loaded = false; - if ($('div.loader').length == 0) { + } + if ($('div.loader').length == 0) { setInterval(function () { if (!loaded && $('div.loader').length == 0) { $('#main').append('
'); } }, 500); - } } jQuery.ajax({ url: 'https://'+ store.get('url') + uri, @@ -208,28 +223,17 @@ app = Sammy('#main', function (sam) { } else { if (uri == '/postinstall') { if (installing) { - if (args.domain.match(/\.nohost\.me$/) || args.domain.match(/\.noho\.st$/)) { - $('#popup-title').text(y18n.t('installed')); - $('#popup-body p').text(y18n.t('installation_complete_dns')); - interval = 180000; - } else { - interval = 5000; - } setInterval(function () { if (window.location.hostname === args.domain) { - $('#popup-title').text(y18n.t('installation_complete')); - $('#popup-body').html( - '

'+ y18n.t('installation_complete_desc', ['https://'+ args.domain +'/yunohost/admin', args.domain +'/yunohost/admin']) +'

' - + '
' - + '

'+ y18n.t('installation_complete_help_dns') +'

'); + window.open('https://'+ args.domain +'/yunohost/admin'); } else { - $('#popup').modal('hide'); - c.flash('success', y18n.t('installation_complete')); - c.redirect('#/login'); + if (!c.isInstalled()) { + c.flash('success', y18n.t('installation_complete')); + c.redirect('#/login'); + } } - }, interval); + }, 5000); } else { - $('#popup').modal('hide'); c.flash('fail', y18n.t('error_occured')); } } else { @@ -243,7 +247,8 @@ app = Sammy('#main', function (sam) { }, // Render view (cross-browser) - view: function (view, data) { + view: function (view, data, callback) { + callback = typeof callback !== 'undefined' ? callback : function() {}; rendered = this.render('views/'+ view +'.ms', data); enableSlide = true; // Change to false to disable animation @@ -262,6 +267,7 @@ app = Sammy('#main', function (sam) { store.set('slide', 'to'); } }); + callback(); }); } @@ -290,7 +296,7 @@ app = Sammy('#main', function (sam) { leSwap(); } } else { - rendered.swap(); + rendered.swap(callback); } } }); @@ -315,7 +321,7 @@ app = Sammy('#main', function (sam) { }); }); - sam.before({except: {path: ['#/logout', '#/login', '#/postinstall']}}, function (req) { + sam.before({except: {path: ['#/logout', '#/login', '#/postinstall', '#/postinstall/domain', '#/postinstall/password']}}, function (req) { // Store path for further redirections store.set('path-1', store.get('path')); store.set('path', req.path); @@ -358,26 +364,12 @@ app = Sammy('#main', function (sam) { }); sam.get('#/login', function (c) { + $('#masthead').show(); $('.logout-button').hide(); store.set('path-1', '#/login'); - - // Check if te client is hosted on a yunohost node - domain = window.location.hostname - $.ajax({ - dataType: "json", - url: 'https://'+ domain +'/yunohost/api/installed', - timeout: 3000 - }) - .success(function(data) { - if (!data.installed) { - c.redirect('#/postinstall'); - } else { - c.view('login', { 'domain': domain }); - } - }) - .fail(function() { - c.view('login'); - }); + if (!c.isInstalled()) { + c.redirect('#/postinstall'); + } }); sam.post('#/login', function (c) { @@ -416,34 +408,69 @@ app = Sammy('#main', function (sam) { }); sam.get('#/postinstall', function(c) { - c.view('postinstall', {'ddomains': ['.nohost.me', '.noho.st']}); + $('#masthead').hide(); + c.view('postinstall/postinstall_1'); + }); + + sam.get('#/postinstall/domain', function(c) { + $('#masthead').hide(); + c.view('postinstall/postinstall_2', {'ddomains': ['.nohost.me', '.noho.st']}, function() { + $('#domain, #ddomain').keyup(function(event){ + if(event.keyCode == 13){ + $('a.savedomain').click(); + } + }); + $('a.savedomain').on('click', function(e) { + if ($('#domain').val() === '') { + if ($('#ddomain').val() === '') { + e.preventDefault(); + store.clear('slide'); + c.flash('fail', y18n.t('error_select_domain')); + } else { + domain = $('#ddomain').val() + $('select[name="ddomain-ext"]').val(); + } + } else { + domain = $('#domain').val(); + } + store.set('maindomain', domain); + }); + }); + + }); + + sam.get('#/postinstall/password', function(c) { + $('#masthead').hide(); + $('#flash .alert').remove(); + if (!store.get('maindomain')) { + store.clear('slide'); + c.redirect('#/postinstall/domain'); + } else { + c.view('postinstall/postinstall_3', { 'domain': store.get('maindomain') }); + } }); sam.post('#/postinstall', function (c) { if (c.params['password'] == '' || c.params['confirmation'] == '') { - c.flash('fail', y18n.t('password_empty')) + c.flash('fail', y18n.t('password_empty')); } else if (c.params['password'] == c.params['confirmation']) { - if (c.params['domain'] == '') { - if (c.params['ddomain'] == '') { - c.flash('fail', y18n.t('error_select_domain')); - store.clear('slide'); - c.redirect('#/postinstall'); - } else { - params = { 'domain': c.params['ddomain'] + c.params['ddomain-ext'] } - } + if (c.params['domain'] === '') { + c.flash('fail', y18n.t('error_select_domain')); + store.clear('slide'); + c.redirect('#/postinstall/domain'); } else { params = { 'domain': c.params['domain'] } } - params['password'] = c.params['password'] + if (confirm(y18n.t('confirm_postinstall', [c.params['domain']]))) { + params['password'] = c.params['password'] - store.set('url', window.location.hostname +'/yunohost/api'); - store.set('user', 'admin'); - store.set('password', btoa('yunohost')); - c.api('/postinstall', function(data) { // http://api.yunohost.org/#!/tools/tools_postinstall_post_0 - c.redirect('#/'); - }, 'POST', params); + store.set('url', window.location.hostname +'/yunohost/api'); + store.set('user', 'admin'); + c.api('/postinstall', function(data) { // http://api.yunohost.org/#!/tools/tools_postinstall_post_0 + c.redirect('#/login'); + }, 'POST', params); + } } else { c.flash('fail', y18n.t('passwords_dont_match')); } diff --git a/locales/en.json b/locales/en.json index d2f6e317..52407f55 100644 --- a/locales/en.json +++ b/locales/en.json @@ -65,7 +65,15 @@ "confirm_service_action" : "Are you sure you want to %s %s ?", "confirm_update_type" : "Are you sure you want update every %s %s ?", - "postinstall_intro" : "A last step is necessary to fulfill the installation: You have to link your YunoHost instance to a domain name, and set a new administrator password.", + "postinstall_intro_1" : "Congratulations! YunoHost has been successfully installed.", + "postinstall_intro_2" : "Two more configuration steps are required to activate the services of your server.", + "postinstall_intro_3" : "You can obtain more information by visiting the appropriate documentation page", + "begin" : "Begin", + "postinstall_domain" : "This is the first domain name linked to your YunoHost server, but also the one which will be used by your server's users to access the authentication portal. It will thus be visible by everyone, choose it carefully.", + "previous": "Previous", + "next": "Next", + "postinstall_password" : "This password will be used to manage everything on your server. Take the time to choose it wisely.", + "confirm_postinstall" : "You are about to launch the postinstallation process on the domain %s. It may take a few minutes, *do not interrupt the operation*.", "application" : "Application", "applications" : "Applications", diff --git a/locales/fr.json b/locales/fr.json index c4f12e80..14eac9c1 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -65,7 +65,13 @@ "confirm_service_action" : "Êtes-vous sur de vouloir %s %s ?", "confirm_update_type" : "Êtes-vous sur de vouloir mettre à jour tous les %s ?", - "postinstall_intro" : "A last step is necessary to fulfill the installation: You have to link your YunoHost instance to a domain name, and set a new administrator password.", + "postinstall_intro_1" : "Congratulations! YunoHost has been successfully installed.", + "postinstall_intro_2" : "Two more configuration steps are required to activate the services of your server.", + "postinstall_intro_3" : "You can obtain more information by visiting the appropriate documentation page", + "begin" : "Begin", + "postinstall_domain" : "This is the first domain name linked to your YunoHost server, but also the one which will be used by your server's users to access the authentication portal. It will thus be visible by everyone, choose it carefully.", + "postinstall_password" : "This password will be used to manage everything on your server. Take the time to choose it wisely.", + "confirm_postinstall" : "You are about to launch the postinstallation process on the domain %s. It may take a few minutes, *do not interrupt the operation*.", "application" : "Application", "applications" : "Applications", @@ -106,7 +112,7 @@ "domain_add" : "Ajouter un domaine", "domain_add_panel_with_domain" : "J'ai déjà un nom de domaine …", "domain_add_panel_without_domain" : "Je n'ai pas de nom de domaine …", - "domain_add_dns_doc" : "… et j'ai configurer mes DNS correctement.", + "domain_add_dns_doc" : "… et j'ai configué mes DNS correctement.", "domain_add_dyndns_doc" : "… et je souhaite un service de DNS dynamique.", "domain_default" : "Domaine par défaut", "domain_default_desc" : "Les utilisateurs se connecteront au domaine par défaut.",