From ea2bdd41b82802d843852b0e4783f4d1c713b8e4 Mon Sep 17 00:00:00 2001 From: thardev Date: Sat, 25 Feb 2017 04:30:20 +0100 Subject: [PATCH] events file login/logout event and check connected home --- src/gulpfile.js | 1 + src/js/yunohost/controllers/home.js | 3 ++- src/js/yunohost/events.js | 19 +++++++++++++++++++ src/js/yunohost/main.js | 8 +++++--- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/js/yunohost/events.js diff --git a/src/gulpfile.js b/src/gulpfile.js index 608a8748..c81a5cf5 100644 --- a/src/gulpfile.js +++ b/src/gulpfile.js @@ -50,6 +50,7 @@ gulp.task('js', function() { 'js/yunohost/main.js', 'js/yunohost/helpers.js', 'js/yunohost/filters.js', + 'js/yunohost/events.js', 'js/yunohost/controllers/*.js', ]) .pipe(gulpif(isProduction, uglify())) diff --git a/src/js/yunohost/controllers/home.js b/src/js/yunohost/controllers/home.js index 08df552c..8f9c78c0 100644 --- a/src/js/yunohost/controllers/home.js +++ b/src/js/yunohost/controllers/home.js @@ -143,7 +143,7 @@ }; c.api('/login', function(data) { store.set('connected', true); - + c.trigger('login'); $('#masthead .logout-btn').fadeIn(); c.flash('success', y18n.t('logged_in')); if (store.get('path')) { @@ -160,6 +160,7 @@ store.clear('url'); store.clear('connected'); store.set('path', '#/'); + c.trigger('logout'); c.flash('success', y18n.t('logged_out')); c.redirect('#/login'); }, 'GET', {}, false); diff --git a/src/js/yunohost/events.js b/src/js/yunohost/events.js new file mode 100644 index 00000000..7a845d22 --- /dev/null +++ b/src/js/yunohost/events.js @@ -0,0 +1,19 @@ +(function() { + // Get application context + var app = Sammy.apps['#main']; + var store = app.store; + + /** + * Events + * + */ + app.bind('login', function(e, data) { + this.api('/version', function(versions) { + $('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost])); + }); + }); + + app.bind('logout', function(e, data) { + $('#yunohost-version').empty(); + }); +})(); diff --git a/src/js/yunohost/main.js b/src/js/yunohost/main.js index 735f326f..8882d9a6 100644 --- a/src/js/yunohost/main.js +++ b/src/js/yunohost/main.js @@ -71,9 +71,11 @@ sam.store.set('url', window.location.hostname + '/yunohost/api'); // Get YunoHost version - this.api('/version', function(versions) { - $('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost])); - }); + if (sam.store.get('connected')) { + this.api('/version', function(versions) { + $('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost])); + }); + } // Flash messages var flashMessage = $('#flashMessage');