mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
Modify flashing behaviour
This commit is contained in:
parent
6d2755e236
commit
47295a966d
1 changed files with 17 additions and 17 deletions
34
js/app.js
34
js/app.js
|
@ -38,6 +38,7 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
// API connection helper
|
// API connection helper
|
||||||
api: function (uri, callback, method, data) {
|
api: function (uri, callback, method, data) {
|
||||||
|
c = this;
|
||||||
method = typeof method !== 'undefined' ? method : 'GET';
|
method = typeof method !== 'undefined' ? method : 'GET';
|
||||||
data = typeof data !== 'undefined' ? data : {};
|
data = typeof data !== 'undefined' ? data : {};
|
||||||
auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password')));
|
auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password')));
|
||||||
|
@ -52,16 +53,22 @@ app = Sammy('#main', function (sam) {
|
||||||
req.setRequestHeader('Authorization', auth);
|
req.setRequestHeader('Authorization', auth);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.success(function(data) {
|
||||||
|
data = typeof data !== 'undefined' ? data : {};
|
||||||
|
if (typeof data.win !== 'undefined') {
|
||||||
|
$.each(data.win, function(k, v) {
|
||||||
|
c.flash('success', v);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
callback(data);
|
||||||
|
})
|
||||||
|
.fail(function(xhr) {
|
||||||
|
c.flash('fail', xhr.responseJSON.error);
|
||||||
|
c.redirect(store.get('path-1'));
|
||||||
|
store.clear('slide');
|
||||||
|
})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
result = data;
|
|
||||||
})
|
|
||||||
.fail(function() {
|
|
||||||
req.redirect('#/login');
|
|
||||||
result = false;
|
|
||||||
})
|
|
||||||
.always(function() {
|
|
||||||
callback(result);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -118,6 +125,7 @@ app = Sammy('#main', function (sam) {
|
||||||
sam.before({except: {path: '#/login'}}, function (req) {
|
sam.before({except: {path: '#/login'}}, function (req) {
|
||||||
|
|
||||||
// Store path for further redirections
|
// Store path for further redirections
|
||||||
|
store.set('path-1', store.get('path'));
|
||||||
store.set('path', req.path);
|
store.set('path', req.path);
|
||||||
|
|
||||||
// Redirect to login page if no credentials stored
|
// Redirect to login page if no credentials stored
|
||||||
|
@ -160,12 +168,7 @@ app = Sammy('#main', function (sam) {
|
||||||
store.set('user', 'admin');
|
store.set('user', 'admin');
|
||||||
store.set('password', btoa(c.params['password']));
|
store.set('password', btoa(c.params['password']));
|
||||||
c.api('/users', function(data) {
|
c.api('/users', function(data) {
|
||||||
if (data.error) {
|
$('#disconnect-button').fadeIn();
|
||||||
c.flash('fail', 'Error: '+ data.error);
|
|
||||||
} else {
|
|
||||||
$('#disconnect-button').fadeIn();
|
|
||||||
c.flash('success', 'Connected :)');
|
|
||||||
}
|
|
||||||
if (store.get('path')) {
|
if (store.get('path')) {
|
||||||
c.redirect(store.get('path'));
|
c.redirect(store.get('path'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,7 +193,6 @@ app = Sammy('#main', function (sam) {
|
||||||
if (c.params['password'] == c.params['confirmation']) {
|
if (c.params['password'] == c.params['confirmation']) {
|
||||||
c.params['mail'] = c.params['email'] + '@' + c.params['domain'];
|
c.params['mail'] = c.params['email'] + '@' + c.params['domain'];
|
||||||
c.api('/users', function(data) {
|
c.api('/users', function(data) {
|
||||||
c.flash('success', 'User successfully created');
|
|
||||||
c.redirect('#/users');
|
c.redirect('#/users');
|
||||||
}, 'POST', c.params.toHash());
|
}, 'POST', c.params.toHash());
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,7 +225,6 @@ app = Sammy('#main', function (sam) {
|
||||||
c.redirect('#/users/'+ c.params['user'] + '/edit');
|
c.redirect('#/users/'+ c.params['user'] + '/edit');
|
||||||
} else {
|
} else {
|
||||||
c.api('/users/'+ c.params['user'], function(data) {
|
c.api('/users/'+ c.params['user'], function(data) {
|
||||||
c.flash('success', 'User successfully updated');
|
|
||||||
c.redirect('#/users/'+ c.params['user']);
|
c.redirect('#/users/'+ c.params['user']);
|
||||||
}, 'PUT', params);
|
}, 'PUT', params);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +233,6 @@ app = Sammy('#main', function (sam) {
|
||||||
sam.get('#/users/:user/delete', function (c) {
|
sam.get('#/users/:user/delete', function (c) {
|
||||||
if (confirm('Are you sure you want to delete '+ c.params['user'] +' ?')) {
|
if (confirm('Are you sure you want to delete '+ c.params['user'] +' ?')) {
|
||||||
c.api('/users/'+ c.params['user'], function(data) {
|
c.api('/users/'+ c.params['user'], function(data) {
|
||||||
c.flash('success', 'User successfully deleted');
|
|
||||||
c.redirect('#/users');
|
c.redirect('#/users');
|
||||||
}, 'DELETE');
|
}, 'DELETE');
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue