Introduce a refresh() function to simplify code / make it more semantic

This commit is contained in:
Alexandre Aubin 2019-10-18 22:48:59 +02:00
parent 1ba6fa9b1a
commit 8f2c959cdd
6 changed files with 56 additions and 84 deletions

View file

@ -223,11 +223,7 @@
c.confirm(
y18n.t('applications'),
y18n.t('confirm_app_default'),
function() {
c.api('PUT', '/apps/'+app+'/default', {}, function() {
c.redirect_to('#/apps/'+ app, {slide:false});
});
}
function() { c.api('PUT', '/apps/'+app+'/default', {}, function() { c.refresh() }); }
);
});
@ -584,7 +580,7 @@
}
else {
c.flash('warning', y18n.t('app_install_cancel'));
c.redirect_to('#/apps/install', {slide: false});
c.refresh();
}
});
@ -624,7 +620,7 @@
})
.fail(function(xhr) {
c.flash('fail', y18n.t('app_install_custom_no_manifest'));
c.redirect_to('#/apps/install', {slide:false});
c.refresh();
});
}
);

View file

@ -100,21 +100,9 @@
y18n.t('domains'),
y18n.t('confirm_change_maindomain'),
function() {
var params = {
new_domain: c.params['domain']
};
c.api('PUT', '/domains/main', params, function(data) {
c.redirect_to('#/domains');
});
// WTF ... why is this hack needed v_v
// Wait 15s and refresh the page
var refreshDomain = window.setTimeout(function(){
c.redirect_to('#/domains');
}, 15000);
c.api('PUT', '/domains/main', {new_domain: domain}, function() { c.refresh() });
}
);
)
});
// Configure delete button
@ -257,11 +245,8 @@
c.confirm(
y18n.t('certificate'),
y18n.t(confirm_key, [domain]),
function(){
c.api('POST', api_url, {}, function(data) {
c.redirect_to('#/domains/'+domain+'/cert-management', {slide:false});
});
});
function(){ c.api('POST', api_url, {}, function() { c.refresh() }); }
);
});
});
});

View file

@ -54,11 +54,7 @@
y18n.t('firewall'),
// confirm_upnp_enable and confirm_upnp_disable
y18n.t('confirm_upnp_' + action),
function(){
c.api('GET', '/firewall/upnp', {action: action}, function(data) {
c.redirect_to('#/tools/firewall');
});
}
function(){ c.api('GET', '/firewall/upnp', {action: action}, function() { c.refresh() }); }
);
});
});
@ -90,7 +86,7 @@
if (port != parseInt(port) || port < 0 || port > 65535) {
c.flash('fail', y18n.t('unknown_argument', [port]));
c.redirect_to('#/tools/firewall', {slide: false});
c.refresh();
}
switch (connection) {
@ -122,29 +118,25 @@
break;
default:
c.flash('fail', y18n.t('unknown_action', [action]));
c.redirect_to('#/tools/firewall', {slide: false});
c.refresh();
}
if (method !== null && protocol !== null && port !== null) {
// port:
// protocol:
// - UDP
// - TCP
// - Both
// --ipv4-only:
// --ipv6-only:
// --no-upnp:
var params = {
port : port,
protocol : protocol
};
c.api(method, '/firewall/port?'+endurl, params, function(data) {
c.redirect_to('#/tools/firewall');
});
}
else {
c.redirect_to('#/tools/firewall');
}
// port:
// protocol:
// - UDP
// - TCP
// - Both
// --ipv4-only:
// --ipv6-only:
// --no-upnp:
var params = {
port : port,
protocol : protocol
};
c.api(method, '/firewall/port?'+endurl, params, function() { c.refresh() });
return;
});

View file

@ -94,17 +94,11 @@
break;
default:
c.flash('fail', y18n.t('unknown_action', [action]));
c.redirect_to('#/services/'+ service, {slide: false});
c.refresh();
return;
}
if (method && endurl) {
c.api(method, '/services/'+ endurl, {}, function(data) {
c.redirect_to('#/services/'+ service, {slide: false});
});
}
else {
c.redirect_to('#/services/'+ service, {slide: false});
}
c.api(method, '/services/'+ endurl, {}, function() { c.refresh(); });
});
});
});

View file

@ -26,22 +26,25 @@
});
if ($.isEmptyObject(params)) {
c.flash('fail', y18n.t('error_modify_something'));
c.redirect_to('#/tools/adminpw', {slide: false});
} else if (params['new_password'] !== params['confirm_new_password']) {
c.flash('fail', y18n.t('passwords_dont_match'));
c.redirect_to('#/tools/adminpw', {slide: false});
} else {
c.api('POST', '/login', { 'password': params['old_password'] }, function(data) {
// Remove useless variable
delete params['old_password'];
delete params['confirm_new_password'];
// Update password and redirect to the home
c.api('PUT', '/adminpw', params, function(data) {
c.redirect_to('#/logout');
});
}, undefined, false);
c.refresh();
return;
}
if (params['new_password'] !== params['confirm_new_password']) {
c.flash('fail', y18n.t('passwords_dont_match'));
c.refresh();
return;
}
c.api('POST', '/login', { 'password': params['old_password'] }, function(data) {
// Remove useless variable
delete params['old_password'];
delete params['confirm_new_password'];
// Update password and redirect to the home
c.api('PUT', '/adminpw', params, function(data) {
c.redirect_to('#/logout');
});
}, undefined, false);
});
// System update & upgrade
@ -298,14 +301,12 @@
{
// FIXME / TODO i18n
c.flash('fail', "Some of these migrations require you to acknowledge a disclaimer before running them.");
c.redirect_to('#/tools/migrations', {slide: false});
c.refresh();
return;
}
};
c.api('POST', '/migrations/migrate?accept_disclaimer', {}, function (data) {
c.redirect_to('#/tools/migrations', {slide: false});
});
c.api('POST', '/migrations/migrate?accept_disclaimer', {}, function() { c.refresh(); });
});
// Configure buttons 'Skip'
@ -315,9 +316,7 @@
y18n.t('migrations'),
y18n.t('confirm_migrations_skip'),
function(){
c.api('POST', '/migrations/migrate?skip&targets=' + migration_id, {}, function(data) {
c.redirect_to('#/tools/migrations', {slide: false});
});
c.api('POST', '/migrations/migrate?skip&targets=' + migration_id, {}, function() { c.refresh() });
}
);
});

View file

@ -588,7 +588,13 @@
c.app.last_location = c.path;
c.app.setLocation(destination);
c.app.trigger('location-changed');
},
refresh: function() {
c = this;
c.redirect_to(c.path, {slide: false});
}
});
})();