Improve readability of api() calls

This commit is contained in:
Alexandre Aubin 2019-10-14 00:05:27 +02:00
parent 35099d0dbc
commit 9c7ed43a24
15 changed files with 162 additions and 170 deletions

View file

@ -10,7 +10,7 @@
// List installed apps
app.get('#/apps', function (c) {
c.api('/apps?installed', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
c.api('GET', '/apps?installed', {}, function(data) {
var apps = data['apps'];
c.arraySortById(apps);
c.view('app/app_list', {apps: apps});
@ -109,8 +109,8 @@
// List available apps
app.get('#/apps/install', function (c) {
c.api('/apps', function (data) { // http://api.yunohost.org/#!/app/app_list_get_8
c.api('/apps?raw', function (dataraw) { // http://api.yunohost.org/#!/app/app_list_get_8
c.api('GET', '/apps', {}, function (data) {
c.api('GET', '/apps?raw', {}, function (dataraw) {
var apps = []
$.each(data['apps'], function(k, v) {
app = dataraw[v['id']];
@ -201,7 +201,7 @@
// Get app information
app.get('#/apps/:app', function (c) {
c.api('/apps/'+c.params['app']+'?raw', function(data) { // http://api.yunohost.org/#!/app/app_info_get_9
c.api('GET', '/apps/'+c.params['app']+'?raw', {}, function(data) {
// Presentation
data.settings.allowed_users = (data.settings.allowed_users) ? data.settings.allowed_users.replace(',', ', ')+"." : y18n.t('everyone_has_access');
@ -221,14 +221,14 @@
// Get app debug page
app.get('#/apps/:app/debug', function (c) {
c.api('/apps/'+c.params['app']+'/debug', function(data) {
c.api('GET', '/apps/'+c.params['app']+'/debug', {}, function(data) {
c.view('app/app_debug', data);
});
});
// Get app actions list
app.get('#/apps/:app/actions', function (c) {
c.api('/apps/'+c.params['app']+'/actions', function(data) {
c.api('GET', '/apps/'+c.params['app']+'/actions', {}, function(data) {
$.each(data.actions, function(_, action) {
formatYunoHostStyleArguments(action.arguments, c.params);
@ -264,14 +264,14 @@
'args': c.serialize(c.params.toHash())
}
c.api('/apps/'+app_id+'/actions/'+action_id, function() { // http://api.yunohost.org/#!/app/app_install_post_2
c.api('PUT', '/apps/'+app_id+'/actions/'+action_id, params, function() {
c.redirect('#/apps/'+app_id+'/actions');
}, 'PUT', params);
});
});
// Get app config panel
app.get('#/apps/:app/config-panel', function (c) {
c.api('/apps/'+c.params['app']+'/config-panel', function(data) {
c.api('GET', '/apps/'+c.params['app']+'/config-panel', {}, function(data) {
$.each(data.config_panel.panel, function(_, panel) {
$.each(panel.sections, function(_, section) {
formatYunoHostStyleArguments(section.options, c.params);
@ -297,9 +297,9 @@
'args': c.serialize(c.params.toHash())
}
c.api('/apps/'+app_id+'/config', function() { // http://api.yunohost.org/#!/app/app_install_post_2
c.api('POST', '/apps/'+app_id+'/config', params, function() {
c.redirect('#/apps/'+app_id+'/config-panel');
}, 'POST', params);
});
})
// Special case for custom app installation.
@ -477,7 +477,7 @@
// App installation form
app.get('#/apps/install/:app', function (c) {
c.api('/apps?raw', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
c.api('GET', '/apps?raw', {}, function(data) {
var app_name = c.params["app"];
var app_infos = data[app_name];
if (app_infos['state'] === "validated")
@ -543,9 +543,9 @@
delete params['args'];
}
c.api('/apps', function() { // http://api.yunohost.org/#!/app/app_install_post_2
c.api('POST', '/apps', params, function() {
c.redirect('#/apps');
}, 'POST', params);
});
}
else {
c.flash('warning', y18n.t('app_install_cancel'));
@ -608,9 +608,9 @@
y18n.t('applications'),
y18n.t('confirm_uninstall', [c.params['app']]),
function() {
c.api('/apps/'+ c.params['app'], function() { // http://api.yunohost.org/#!/app/app_remove_delete_4
c.api('DELETE', '/apps/'+ c.params['app'], {}, function() { // http://api.yunohost.org/#!/app/app_remove_delete_4
c.redirect('#/apps');
}, 'DELETE');
});
},
function() {
store.clear('slide');
@ -621,8 +621,8 @@
// Manage app access
app.get('#/apps/:app/access', function (c) {
c.api('/apps/'+c.params['app']+'?raw', function(data) { // http://api.yunohost.org/#!/app/app_info_get_9
c.api('/users', function(dataUsers) {
c.api('GET', '/apps/'+c.params['app']+'?raw', {}, function(data) {
c.api('GET', '/users', {}, function(dataUsers) {
// allowed_users as array
if (typeof data.settings.allowed_users !== 'undefined') {
@ -674,10 +674,10 @@
apps: c.params['app'],
users: []
};
c.api('/access?'+c.serialize(params), function(data) { // http://api.yunohost.org/#!/app/app_removeaccess_delete_12
c.api('DELETE', '/access?'+c.serialize(params), params, function(data) {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']+ '/access');
}, 'DELETE', params);
});
},
function() {
store.clear('slide');
@ -696,10 +696,10 @@
apps: c.params['app'],
users: c.params['user']
};
c.api('/access?'+c.serialize(params), function(data) { // http://api.yunohost.org/#!/app/app_removeaccess_delete_12
c.api('DELETE', '/access?'+c.serialize(params), params, function(data) {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']+ '/access');
}, 'DELETE', params); // passing 'params' here is useless because jQuery doesn't handle ajax datas for DELETE requests. Passing parameters through uri.
});
},
function() {
store.clear('slide');
@ -718,10 +718,10 @@
apps: c.params['app'],
users: null
};
c.api('/access', function() { // http://api.yunohost.org/#!/app/app_addaccess_put_13
c.api('PUT', '/access', params, function() {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app'] +'/access');
}, 'PUT', params);
});
},
function() {
store.clear('slide');
@ -736,10 +736,10 @@
users: c.params['user'],
apps: c.params['app']
};
c.api('/access', function() { // http://api.yunohost.org/#!/app/app_addaccess_put_13
c.api('PUT', '/access', params, function() {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app'] +'/access');
}, 'PUT', params);
});
});
// Clear access (reset)
@ -751,10 +751,10 @@
var params = {
apps: c.params['app']
};
c.api('/access', function() { //
c.api('POST', '/access', params, function() {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app'] +'/access');
}, 'POST', params);
});
},
function() {
store.clear('slide');
@ -769,10 +769,10 @@
y18n.t('applications'),
y18n.t('confirm_app_default'),
function() {
c.api('/apps/'+ c.params['app'] +'/default', function() { //
c.api('PUT', '/apps/'+c.params['app']+'/default', {}, function() {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']);
}, 'PUT');
});
},
function() {
store.clear('slide');
@ -783,28 +783,28 @@
// Get app change label page
app.get('#/apps/:app/changelabel', function (c) {
c.api('/apps/'+c.params['app']+'?raw', function(app_data) {
data = {
c.api('GET', '/apps/'+c.params['app']+'?raw', {}, function(app_data) {
data = {
id: c.params['app'],
label: app_data.settings.label,
};
c.view('app/app_changelabel', data);
};
c.view('app/app_changelabel', data);
});
});
// Change app label
app.post('#/apps/:app/changelabel', function (c) {
params = {'new_label': c.params['label']};
c.api('/apps/' + c.params['app'] + '/label', function(data) { // Call changelabel API
c.api('PUT', '/apps/' + c.params['app'] + '/label', params, function(data) { // Call changelabel API
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']);
}, 'PUT', params);
});
});
// Get app change URL page
app.get('#/apps/:app/changeurl', function (c) {
c.api('/apps/'+c.params['app']+'?raw', function(app_data) {
c.api('/domains', function(domain_data) { // http://api.yunohost.org/#!/domain/domain_list_get_2
c.api('GET', '/apps/'+c.params['app']+'?raw', {}, function(app_data) {
c.api('GET', '/domains', {}, function(domain_data) { // http://api.yunohost.org/#!/domain/domain_list_get_2
// Display a list of available domains
var domains = [];
@ -836,10 +836,10 @@
y18n.t('confirm_app_change_url', [c.params['app']]),
function() {
params = {'domain': c.params['domain'], 'path': c.params['path']};
c.api('/apps/' + c.params['app'] + '/changeurl', function(data) { // Call changeurl API
c.api('PUT', '/apps/' + c.params['app'] + '/changeurl', params, function(data) { // Call changeurl API
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']);
}, 'PUT', params);
});
},
function() {
store.clear('slide');

View file

@ -50,10 +50,10 @@
id:c.params['storage'],
name:y18n.t('local_archives')
};
c.api('/hooks/backup', function(hooks) {
c.api('GET', '/hooks/backup', {}, function(hooks) {
data['hooks'] = c.groupHooks(hooks['hooks']);
data['apps'] = {};
c.api('/apps?with_backup', function(apps_list) {
c.api('GET', '/apps?with_backup', {}, function(apps_list) {
data['apps'] = apps_list.apps;
c.view('backup/backup_create', data, c.selectAllOrNone);
});
@ -63,10 +63,10 @@
app.post('#/backup/:storage', function (c) {
var params = c.ungroupHooks(c.params['system_parts'],c.params['apps']);
c.api('/backup', function() {
c.api('POST', '/backup', params, function() {
store.clear('slide');
c.redirect('#/backup/'+ c.params['storage']);
}, 'POST', params);
});
});
// Restore a backup
@ -77,10 +77,10 @@
$.proxy(function(c){
var params = c.ungroupHooks(c.params['system_parts'],c.params['apps']);
params['force'] = '';
c.api('/backup/restore/'+c.params['archive'], function(data) {
c.api('POST', '/backup/restore/'+c.params['archive'], params, function(data) {
store.clear('slide');
c.redirect('#/backup/'+ c.params['storage']+'/'+c.params['archive']);
}, 'POST', params);
});
}, this, c),
function(){
store.clear('slide');
@ -95,9 +95,9 @@
y18n.t('backup'),
y18n.t('confirm_delete', [c.params['archive']]),
function(){
c.api('/backup/archives/'+c.params['archive'], function(data) {
c.api('DELETE', '/backup/archives/'+c.params['archive'], {}, function(data) {
c.redirect('#/backup/'+ c.params['storage']);
}, 'DELETE');
});
},
function(){
store.clear('slide');
@ -108,9 +108,9 @@
// Download a backup
app.get('#/backup/:storage/:archive/download', function (c) {
c.api('/backup/'+c.params['archive']+'/download', function(data) {
c.api('GET', '/backup/'+c.params['archive']+'/download', {}, function(data) {
c.redirect('#/backup/'+ c.params['storage']+'/'+c.params['archive']);
}, 'GET');
});
});
// Copy a backup
@ -127,7 +127,7 @@
// Get archive info
app.get('#/backup/:storage/:archive', function (c) {
c.api('/backup/archives/'+c.params['archive']+'?with_details', function(data) {
c.api('GET', '/backup/archives/'+c.params['archive']+'?with_details', {}, function(data) {
data.storage = {
id: c.params['storage'],
name: y18n.t('local_archives')
@ -143,7 +143,7 @@
// Archive list
app.get('#/backup/:storage', function (c) {
c.api('/backup/archives?with_info', function(data) {
c.api('GET', '/backup/archives?with_info', {}, function(data) {
data.storage = {
id: 'local',
name: y18n.t('local_archives')

View file

@ -10,8 +10,8 @@
// List existing domains
app.get('#/domains', function (c) {
c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_list_get_2
c.api('/domains/main', function(data2) {
c.api('GET', '/domains', {}, function(data) {
c.api('PUT', '/domains/main', {}, function(data2) {
var domains = [];
$.each(data.domains, function(k, domain) {
domains.push({
@ -29,7 +29,7 @@
domains: domains,
main_domain_form: main_domain_form
});
}, 'PUT');
});
});
});
@ -77,15 +77,15 @@
params.domain = c.params['domain'];
}
c.api('/domains?'+endurl, function(data) { // http://api.yunohost.org/#!/domain/domain_add_post_1
c.api('POST', '/domains?'+endurl, params, function(data) {
c.redirect('#/domains');
}, 'POST', params);
});
});
// Get existing domain info
app.get('#/domains/:domain', function (c) {
c.api('/domains/main', function(dataMain) {
c.api('/apps?installed', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
c.api('PUT', '/domains/main', {}, function(dataMain) {
c.api('GET', '/apps?installed', {}, function(data) {
// FIXME - This dirty trick (along with the previous API call
// for apps installed) should be removed once letsencrypt_ynh
@ -107,12 +107,12 @@
};
c.view('domain/domain_info', domain);
});
}, 'PUT');
});
});
// Domain DNS
app.get('#/domains/:domain/dns', function (c) {
c.api('/domains/' + c.params['domain'] + '/dns', function(data) {
c.api('GET', '/domains/' + c.params['domain'] + '/dns', {}, function(data) {
var domain = {
name: c.params['domain'],
dns: data
@ -123,7 +123,7 @@
// Domain certificate
app.get('#/domains/:domain/cert-management', function (c) {
c.api('/domains/cert-status/' + c.params['domain'] + '?full', function(data) {
c.api('GET', '/domains/cert-status/' + c.params['domain'] + '?full', {}, function(data) {
var s = data["certificates"][c.params['domain']];
var status_ = {
@ -209,10 +209,10 @@
y18n.t('certificate'),
y18n.t('confirm_cert_install_LE', [c.params['domain']]),
function(){
c.api('/domains/cert-install/' + c.params['domain'], function(data) {
c.api('POST', '/domains/cert-install/' + c.params['domain'], {}, function(data) {
store.clear('slide');
c.redirect('#/domains/'+c.params['domain']+'/cert-management');
}, 'POST');
});
},
function(){
store.clear('slide');
@ -227,10 +227,10 @@
y18n.t('certificate'),
y18n.t('confirm_cert_regen_selfsigned', [c.params['domain']]),
function(){
c.api('/domains/cert-install/' + c.params['domain'] + "?self_signed", function(data) {
c.api('POST', '/domains/cert-install/' + c.params['domain'] + "?self_signed", {}, function(data) {
store.clear('slide');
c.redirect('#/domains/'+c.params['domain']+'/cert-management');
}, 'POST');
});
},
function(){
store.clear('slide');
@ -245,10 +245,10 @@
y18n.t('certificate'),
y18n.t('confirm_cert_manual_renew_LE', [c.params['domain']]),
function(){
c.api('/domains/cert-renew/' + c.params['domain'] + "?force", function(data) {
c.api('POST', '/domains/cert-renew/' + c.params['domain'] + "?force", {}, function(data) {
store.clear('slide');
c.redirect('#/domains/'+c.params['domain']+'/cert-management');
}, 'POST');
});
},
function(){
store.clear('slide');
@ -263,10 +263,10 @@
y18n.t('certificate'),
y18n.t('confirm_cert_revert_to_selfsigned', [c.params['domain']]),
function(){
c.api('/domains/cert-install/' + c.params['domain'] + "?self_signed&force", function(data) {
c.api('POST', '/domains/cert-install/' + c.params['domain'] + "?self_signed&force", {}, function(data) {
store.clear('slide');
c.redirect('#/domains/'+c.params['domain']+'/cert-management');
}, 'POST');
});
},
function(){
store.clear('slide');
@ -282,10 +282,10 @@
y18n.t('domains'),
y18n.t('confirm_delete', [c.params['domain']]),
function(){
c.api('/domains/'+ c.params['domain'], function(data) { // http://api.yunohost.org/#!/domain/domain_remove_delete_3
c.api('DELETE', '/domains/'+ c.params['domain'], {}, function(data) {
store.clear('slide');
c.redirect('#/domains');
}, 'DELETE');
});
},
function(){
store.clear('slide');
@ -308,10 +308,10 @@
var params = {
new_domain: c.params['domain']
};
c.api('/domains/main', function(data) { // http://api.yunohost.org/#!/tools/tools_maindomain_put_1
c.api('PUT', '/domains/main', params, function(data) {
store.clear('slide');
c.redirect('#/domains');
}, 'PUT', params);
});
// Wait 15s and refresh the page
var refreshDomain = window.setTimeout(function(){

View file

@ -10,7 +10,7 @@
// Firewall status
app.get('#/tools/firewall', function (c) {
c.api('/firewall?raw', function(data) {
c.api('GET', '/firewall?raw', {}, function(data) {
var firewall = {
ports: {},
upnp: false
@ -44,10 +44,10 @@
var params = {
action : c.params['action']
};
c.api('/firewall/upnp', function(data) {
c.api('GET', '/firewall/upnp', params, function(data) {
store.clear('slide');
c.redirect('#/tools/firewall');
}, 'GET', params);
});
},
function(){
store.clear('slide');
@ -115,10 +115,10 @@
port : port,
protocol : protocol
};
c.api('/firewall/port?'+endurl, function(data) {
c.api(method, '/firewall/port?'+endurl, params, function(data) {
store.clear('slide');
c.redirect('#/tools/firewall');
}, method, params);
});
}
else {
store.clear('slide');
@ -169,4 +169,4 @@
);
});
})();
})();

View file

@ -80,7 +80,7 @@
var params = {
password: c.params['password']
};
c.api('/login', function(data) {
c.api('POST', '/login', params, function(data) {
store.set('connected', true);
c.trigger('login');
$('#masthead .logout-btn').fadeIn();
@ -90,19 +90,19 @@
} else {
c.redirect('#/');
}
}, 'POST', params, false);
}, undefined, false);
});
app.get('#/logout', function (c) {
c.api('/logout', function (data) {
c.api('GET', '/logout', {}, function (data) {
store.clear('url');
store.clear('connected');
store.set('path', '#/');
c.trigger('logout');
c.flash('success', y18n.t('logged_out'));
c.redirect('#/login');
}, 'GET', {}, false);
}, undefined, false);
});
})();

View file

@ -13,29 +13,28 @@
var monitorData = {};
// Why this method ?
c.api('/services/glances', function(data) { // ?
c.api('GET', '/services/glances', {}, function(data) {
monitorData.status = true;
if (data.status == 'running') {
c.api('/monitor/system', function(data) {
c.api('GET', '/monitor/system', {}, function(data) {
monitorData.system = data;
c.api('/monitor/disk', function(data) {
c.api('GET', '/monitor/disk', {}, function(data) {
monitorData.disk = data;
c.api('/monitor/network', function(data) {
c.api('GET', '/monitor/network', {}, function(data) {
monitorData.network = data;
// Remove useless interface
delete monitorData.network.usage.lo;
// Get YunoHost versions too
c.api('/diagnosis', function(diagnosis) {
c.api('GET', '/diagnosis', {}, function(diagnosis) {
monitorData.versions = diagnosis.packages;
c.view('tools/tools_monitoring', monitorData);
});
});
});
});
}
@ -43,8 +42,7 @@
monitorData.status = false;
c.view('tools/tools_monitoring', monitorData);
}
}, 'GET');
});
});
})();

View file

@ -92,9 +92,9 @@
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.api('POST', '/postinstall', params, function(data) {
c.redirect('#/login');
}, 'POST', params);
});
},
function(){
}

View file

@ -10,7 +10,7 @@
// All services status
app.get('#/services', function (c) {
c.api('/services', function(data) { // ?
c.api('GET', '/services', {}, function(data) {
var data2 = {
services: []
};
@ -45,7 +45,7 @@
// Status & actions for a service
app.get('#/services/:service', function (c) {
c.api('/services/'+ c.params['service'], function(data) { // ?
c.api('GET', '/services/'+ c.params['service'], {}, function(data) { // ?
var data2 = {
service: data
};
@ -66,7 +66,7 @@
}
store.clear('slide');
c.view('service/service_info', data2);
}, 'GET');
});
});
// Service log
@ -74,14 +74,14 @@
var params = {
number: 50
};
c.api('/services/'+ c.params['service'] +'/log', function(data) { // ?
c.api('GET', '/services/'+ c.params['service'] +'/log', params, function(data) { // ?
data2 = { 'logs': [], 'name': c.params['service'] };
$.each(data, function(k, v) {
data2.logs.push({filename: k, filecontent: v.join('\n')});
});
c.view('service/service_log', data2);
}, 'GET', params);
});
});
// Enable/Disable & Start/Stop service
@ -116,10 +116,10 @@
}
if (method && endurl) {
c.api('/services/'+ endurl, function(data) {
c.api(method, '/services/'+ endurl, {}, function(data) {
store.clear('slide');
c.redirect('#/services/'+ c.params['service']);
}, method);
});
}
else {
store.clear('slide');

View file

@ -33,24 +33,24 @@
store.clear('slide');
c.redirect('#/tools/adminpw');
} else {
c.api('/login', function(data) {
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('/adminpw', function(data) { // http://api.yunohost.org/#!/tools/tools_adminpw_put_3
c.api('PUT', '/adminpw', params, function(data) {
c.redirect('#/logout');
}, 'PUT', params);
}, 'POST', { 'password': params['old_password'] }, false);
});
}, undefined, false);
}
});
// System update & upgrade
app.get('#/update', function (c) {
c.api('/update', function(data) {
c.api('PUT', '/update', {}, function(data) {
c.view('update/update', data);
}, 'PUT');
});
});
// Upgrade apps or packages
@ -60,12 +60,10 @@
// confirm_update_apps and confirm_update_packages
y18n.t('confirm_update_' + c.params['type'].toLowerCase()),
function(){
c.api('/upgrade?'+c.params["type"],
function(data) {
c.api('PUT', '/upgrade?'+c.params["type"], {}, function(data) {
store.clear('slide');
c.redirect('#/tools/logs');
},
'PUT');
});
},
function(){
store.clear('slide');
@ -80,12 +78,10 @@
y18n.t('tools'),
y18n.t('confirm_update_specific_app', [c.params['app']]),
function(){
c.api('/upgrade/apps?app='+c.params['app'].toLowerCase(),
function(data) {
store.clear('slide');
c.redirect('#/tools/logs');
},
'PUT');
c.api('PUT', '/upgrade/apps?app='+c.params['app'].toLowerCase(), {}, function(data) {
store.clear('slide');
c.redirect('#/tools/logs');
});
},
function(){
store.clear('slide');
@ -96,7 +92,7 @@
// Display journals list
app.get('#/tools/logs', function (c) {
c.api("/logs?limit=25&with_details", function(categories) {
c.api('GET', "/logs?limit=25&with_details", {}, function(categories) {
data = [];
category_icons = {
'operation': 'wrench',
@ -139,7 +135,7 @@
var number = (c.params["number"])?c.params["number"]:50;
params += "&number=" + number;
c.api("/logs/display" + params, function(log) {
c.api('GET', "/logs/display" + params, {}, function(log) {
if ('metadata' in log) {
if (!'env' in log.metadata && 'args' in log.metadata) {
log.metadata.env = log.metadata.args
@ -222,10 +218,10 @@
// confirm_reboot_action_reboot or confirm_reboot_action_shutdown
y18n.t('confirm_reboot_action_' + action),
function(){
c.api('/'+action+'?force', function(data) {
c.api('PUT', '/'+action+'?force', {}, function(data) {
// This code is not executed due to 502 response (reboot or shutdown)
c.redirect('#/logout');
}, 'PUT', {}, false, function (xhr) {
}, function (xhr) {
c.flash('success', y18n.t('tools_' + action + '_done'))
// Disconnect from the webadmin
store.clear('url');
@ -249,7 +245,7 @@
// Force scrollTop on page load
$('html, body').scrollTop(0);
store.clear('slide');
});
}, false);
},
function(){
@ -271,7 +267,7 @@
var private = (c.params.splat[0] == 'private');
var endurl = (private) ? '?private' : '';
c.api('/diagnosis'+endurl, function(diagnosis) {
c.api('GET', '/diagnosis'+endurl, {}, function(diagnosis) {
c.view('tools/tools_diagnosis', {
'diagnosis' : JSON.stringify(diagnosis, undefined, 4),
'raw' : diagnosis,
@ -282,8 +278,8 @@
// Reboot or shutdown button
app.get('#/tools/migrations', function (c) {
c.api('/migrations?pending', function(pending_migrations) {
c.api('/migrations?done', function(done_migrations) {
c.api('GET', '/migrations?pending', {}, function(pending_migrations) {
c.api('GET', '/migrations?done', {}, function(done_migrations) {
pending_migrations = pending_migrations.migrations;
done_migrations = done_migrations.migrations;
@ -331,19 +327,17 @@
// /tools/migrations/run page "directly" somehow ...
if (withAcceptDisclaimerFlag)
{
c.api('/migrations/migrate?accept_disclaimer',
function (data) {
store.clear('slide');
c.redirect('#/tools/migrations');
}, 'POST')
c.api('POST', '/migrations/migrate?accept_disclaimer', {}, function (data) {
store.clear('slide');
c.redirect('#/tools/migrations');
})
}
else
{
c.api('/migrations/migrate',
function (data) {
store.clear('slide');
c.redirect('#/tools/migrations');
}, 'POST')
c.api('POST', '/migrations/migrate', {}, function (data) {
store.clear('slide');
c.redirect('#/tools/migrations');
})
}
});
@ -352,10 +346,10 @@
y18n.t('migrations'),
y18n.t('confirm_migrations_skip'),
function(){
c.api('/migrations/migrate?skip&targets=' + c.params['migration_id'], function(data) {
c.api('POST', '/migrations/migrate?skip&targets=' + c.params['migration_id'], {}, function(data) {
store.clear('slide');
c.redirect('#/tools/migrations');
}, 'POST');
});
},
function(){
store.clear('slide');
@ -366,7 +360,7 @@
// List available apps lists
app.get('#/tools/appslists', function (c) {
c.api('/appslists', function(data) {
c.api('GET', '/appslists', {}, function(data) {
list = [];
$.each(data, function(listname, listinfo) {
list.push({
@ -379,7 +373,7 @@
c.view('tools/tools_appslists_list', {
appslists: list
});
}, 'GET');
});
});
// Add a new apps list
@ -389,15 +383,15 @@
'url' : c.params['appslist_url']
}
c.api('/appslists', function(data) {
c.api('PUT', '/appslists', list, function(data) {
store.clear('slide');
c.redirect('#/tools/appslists/' + list.name);
}, 'PUT', list);
});
});
// Show appslist info and operations
app.get('#/tools/appslists/:appslist', function (c) {
c.api('/appslists', function(data) {
c.api('GET', '/appslists', {}, function(data) {
if (typeof data[c.params['appslist']] !== 'undefined') {
list = {
'name' : c.params['appslist'],
@ -412,22 +406,22 @@
store.clear('slide');
c.redirect('#/tools/appslists');
}
}, 'GET');
});
});
// Refresh available apps list
app.get('#/tools/appslists/refresh', function (c) {
c.api('/appslists', function(data) {
c.api('PUT', '/appslists', {}, function(data) {
// c.redirect(store.get('path'));
c.redirect('#/apps/install');
}, 'PUT');
});
});
// Refresh specific apps list
app.get('#/tools/appslists/:appslist/refresh', function (c) {
c.api('/appslists', function(data) {
c.api('PUT', '/appslists', {'name' : c.params['appslist']}, function(data) {
c.redirect('#/tools/appslists');
}, 'PUT', {'name' : c.params['appslist']});
});
});
// Remove apps list
@ -436,9 +430,9 @@
y18n.t('appslist'),
y18n.t('appslists_confirm_remove', [c.params['app']]),
function() {
c.api('/appslists', function() {
c.api('DELETE', '/appslists', {'name' : c.params['appslist']}, function() {
c.redirect('#/tools/appslists');
}, 'DELETE', {'name' : c.params['appslist']});
});
},
function() {
store.clear('slide');

View file

@ -12,14 +12,14 @@
// List existing users
app.get('#/users', function (c) {
c.api('/users', function(data) { // http://api.yunohost.org/#!/user/user_list_get_3
c.api('GET', '/users', {}, function(data) {
c.view('user/user_list', data);
});
});
// Create user form
app.get('#/users/create', function (c) {
c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_list_get_2
c.api('GET', '/domains', {}, function(data) {
// Password min length
data.password_min_length = PASSWORD_MIN_LENGTH;
@ -52,9 +52,9 @@
// Compute email field
c.params['mail'] = c.params['email'] + c.params['domain'];
c.api('/users', function(data) { // http://api.yunohost.org/#!/user/user_create_post_2
c.api('POST', '/users', c.params.toHash(), function(data) {
c.redirect('#/users');
}, 'POST', c.params.toHash());
});
}
} else {
c.flash('fail', y18n.t('passwords_dont_match'));
@ -65,15 +65,15 @@
// Show user information
app.get('#/users/:user', function (c) {
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0
c.api('GET', '/users/'+ c.params['user'], {}, function(data) {
c.view('user/user_info', data);
});
});
// Edit user form
app.get('#/users/:user/edit', function (c) {
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0
c.api('/domains', function(dataDomains) { // http://api.yunohost.org/#!/domain/domain_list_get_2
c.api('GET', '/users/'+ c.params['user'], {}, function(data) {
c.api('GET', '/domains', {}, function(dataDomains) {
// Password min length
data.password_min_length = PASSWORD_MIN_LENGTH;
@ -124,7 +124,7 @@
// Update user information
app.put('#/users/:user', function (c) {
// Get full user object
c.api('/users/'+ c.params['user'], function(user) {
c.api('GET', '/users/'+ c.params['user'], {}, function(user) {
// Force unit or disable quota
if (c.params['mailbox_quota']) {
c.params['mailbox_quota'] += "M";
@ -175,9 +175,9 @@
}
else {
params['change_password'] = params['password'];
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1
c.api('PUT', '/users/'+ c.params['user'], params, function(data) {
c.redirect('#/users/'+ c.params['user']);
}, 'PUT', params);
});
}
} else {
c.flash('fail', y18n.t('passwords_dont_match'));
@ -186,9 +186,9 @@
}
}
else {
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1
c.api('PUT', '/users/'+ c.params['user'], params, function(data) {
c.redirect('#/users/'+ c.params['user']);
}, 'PUT', params);
});
}
}
}, 'GET');
@ -209,9 +209,9 @@
y18n.t('users'),
confirmModalContent,
function(){
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_delete_delete_4
c.api('DELETE', '/users/'+ c.params['user'], params, function(data) {
c.redirect('#/users');
}, 'DELETE', params);
});
},
function(){
store.clear('slide');

View file

@ -8,7 +8,7 @@
*
*/
app.bind('login', function(e, data) {
c.api('/users', function(data) {
c.api('GET', '/users', {}, function(data) {
// Warn admin if no users are created.
if (typeof data.users !== 'undefined' && data.users.length === 0) {
c.flash('warning', y18n.t('warning_first_user'));
@ -69,7 +69,7 @@
c.flash('fail', y18n.t('error_retrieve_feed', [securityFeed]));
});
c.api("/diagnosis", function(data) {
c.api("GET", "/diagnosis", {}, function(data) {
versions = data.packages;
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
if (data.security["CVE-2017-5754"].vulnerable) {

View file

@ -12,7 +12,7 @@
function prefetchDomains(req) {
// Preload domains list.
req.params.domains = [];
req.api('/domains', function(data) {
req.api('GET', '/domains', {}, function(data) {
req.params.domains = data.domains;
});
}
@ -20,7 +20,7 @@
function prefetchUsers(req){
// Preload users lists.
req.params.users = [];
req.api('/users', function(data) {
req.api('GET', '/users', {}, function(data) {
req.params.users = data.users;
});
}

View file

@ -85,7 +85,7 @@
},
// API call
api: function(uri, callback, method, data, websocket, callbackOnFailure) {
api: function(method, uri, data, callback, callbackOnFailure, websocket) {
c = this;
method = typeof method !== 'undefined' ? method : 'GET';

View file

@ -150,7 +150,7 @@
sam.store.set('url', window.location.hostname + '/yunohost/api');
if (sam.store.get('connected')) {
this.api('/diagnosis', function(diagnosis) {
this.api('GET', '/diagnosis', {}, function(diagnosis) {
versions = diagnosis.packages;
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
});

View file

@ -10,7 +10,7 @@
</div>
<div class="actions-group">
<a href="javascript:void(null);" onclick="c.api('/logs/display?path={{#if log.name}}{{ log.name }}{{else}}{{ log.log_path }}{{/if}}&share', function(data) { $('div.loader').remove(); window.open(data.url, '_blank'); });" class="btn btn-success">
<a href="javascript:void(null);" onclick="c.api('GET', '/logs/display?path={{#if log.name}}{{ log.name }}{{else}}{{ log.log_path }}{{/if}}&share', {}, function(data) { $('div.loader').remove(); window.open(data.url, '_blank'); });" class="btn btn-success">
<span class="fa-cloud-upload"></span> {{t 'logs_share_with_yunopaste'}}
</a>
</div>