events file login/logout event and check connected home

This commit is contained in:
thardev 2017-02-25 04:30:20 +01:00
parent d9f4904cc6
commit ea2bdd41b8
4 changed files with 27 additions and 4 deletions

View file

@ -50,6 +50,7 @@ gulp.task('js', function() {
'js/yunohost/main.js', 'js/yunohost/main.js',
'js/yunohost/helpers.js', 'js/yunohost/helpers.js',
'js/yunohost/filters.js', 'js/yunohost/filters.js',
'js/yunohost/events.js',
'js/yunohost/controllers/*.js', 'js/yunohost/controllers/*.js',
]) ])
.pipe(gulpif(isProduction, uglify())) .pipe(gulpif(isProduction, uglify()))

View file

@ -143,7 +143,7 @@
}; };
c.api('/login', function(data) { c.api('/login', function(data) {
store.set('connected', true); store.set('connected', true);
c.trigger('login');
$('#masthead .logout-btn').fadeIn(); $('#masthead .logout-btn').fadeIn();
c.flash('success', y18n.t('logged_in')); c.flash('success', y18n.t('logged_in'));
if (store.get('path')) { if (store.get('path')) {
@ -160,6 +160,7 @@
store.clear('url'); store.clear('url');
store.clear('connected'); store.clear('connected');
store.set('path', '#/'); store.set('path', '#/');
c.trigger('logout');
c.flash('success', y18n.t('logged_out')); c.flash('success', y18n.t('logged_out'));
c.redirect('#/login'); c.redirect('#/login');
}, 'GET', {}, false); }, 'GET', {}, false);

19
src/js/yunohost/events.js Normal file
View file

@ -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();
});
})();

View file

@ -71,9 +71,11 @@
sam.store.set('url', window.location.hostname + '/yunohost/api'); sam.store.set('url', window.location.hostname + '/yunohost/api');
// Get YunoHost version // Get YunoHost version
this.api('/version', function(versions) { if (sam.store.get('connected')) {
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost])); this.api('/version', function(versions) {
}); $('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost]));
});
}
// Flash messages // Flash messages
var flashMessage = $('#flashMessage'); var flashMessage = $('#flashMessage');