mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Handle input type from manifest (user, domain, app, password).
This commit is contained in:
parent
3cd27e01c8
commit
8c5b1e4603
4 changed files with 45 additions and 23 deletions
64
js/app.js
64
js/app.js
|
@ -299,6 +299,16 @@ app = Sammy('#main', function (sam) {
|
||||||
req.params.users = data.users;
|
req.params.users = data.users;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
sam.before(/apps\/install\//, function (req){
|
||||||
|
// Preload apps list.
|
||||||
|
req.params.apps = [];
|
||||||
|
req.api('/apps', function(data) {
|
||||||
|
// Only installed apps
|
||||||
|
$.each(data['apps'], function(k, v) {
|
||||||
|
if (v['installed']) req.params.apps.push(v);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
sam.before({except: {path: ['#/logout', '#/login', '#/postinstall', '#/postinstall/domain', '#/postinstall/password']}}, function (req) {
|
sam.before({except: {path: ['#/logout', '#/login', '#/postinstall', '#/postinstall/domain', '#/postinstall/password']}}, function (req) {
|
||||||
// Store path for further redirections
|
// Store path for further redirections
|
||||||
|
@ -841,7 +851,7 @@ app = Sammy('#main', function (sam) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Helper function that build app installation form
|
// Helper function that build app installation form
|
||||||
sam.helper('appInstallForm', function(appId, manifest, users, domains) {
|
sam.helper('appInstallForm', function(appId, manifest, params) {
|
||||||
data = {
|
data = {
|
||||||
id: appId,
|
id: appId,
|
||||||
manifest: manifest
|
manifest: manifest
|
||||||
|
@ -849,11 +859,13 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
if (typeof data.manifest.arguments.install !== 'undefined') {
|
if (typeof data.manifest.arguments.install !== 'undefined') {
|
||||||
$.each(data.manifest.arguments.install, function(k, v) {
|
$.each(data.manifest.arguments.install, function(k, v) {
|
||||||
// Default values
|
|
||||||
data.manifest.arguments.install[k].type = 'text';
|
|
||||||
data.manifest.arguments.install[k].required = 'required';
|
|
||||||
|
|
||||||
// Radio button
|
// Default values
|
||||||
|
data.manifest.arguments.install[k].type = (typeof v.type !== 'undefined') ? v.type : 'string';
|
||||||
|
data.manifest.arguments.install[k].inputType = 'text';
|
||||||
|
data.manifest.arguments.install[k].required = (typeof v.optional !== 'undefined' && v.optional == "true") ? '' : 'required';
|
||||||
|
|
||||||
|
// Input with choices becomes select list
|
||||||
if (typeof data.manifest.arguments.install[k].choices !== 'undefined') {
|
if (typeof data.manifest.arguments.install[k].choices !== 'undefined') {
|
||||||
// Update choices values with key and checked data
|
// Update choices values with key and checked data
|
||||||
$.each(data.manifest.arguments.install[k].choices, function(ck, cv){
|
$.each(data.manifest.arguments.install[k].choices, function(ck, cv){
|
||||||
|
@ -867,9 +879,9 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
// Special case for domain input.
|
// Special case for domain input.
|
||||||
// Display a list of available domains
|
// Display a list of available domains
|
||||||
if (v.name == 'domain') {
|
if (v.name == 'domain' || data.manifest.arguments.install[k].type == 'domain') {
|
||||||
data.manifest.arguments.install[k].choices = [];
|
data.manifest.arguments.install[k].choices = [];
|
||||||
$.each(domains, function(key, domain){
|
$.each(params.domains, function(key, domain){
|
||||||
data.manifest.arguments.install[k].choices.push({
|
data.manifest.arguments.install[k].choices.push({
|
||||||
value: domain,
|
value: domain,
|
||||||
label: domain,
|
label: domain,
|
||||||
|
@ -879,11 +891,11 @@ app = Sammy('#main', function (sam) {
|
||||||
data.manifest.arguments.install[k].help = "<a href='#/domains'>"+y18n.t('manage_domains')+"</a>";
|
data.manifest.arguments.install[k].help = "<a href='#/domains'>"+y18n.t('manage_domains')+"</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for admin input.
|
// Special case for admin / user input.
|
||||||
// Display a list of available users
|
// Display a list of available users
|
||||||
if (v.name == 'admin') {
|
if (v.name == 'admin' || data.manifest.arguments.install[k].type == 'user') {
|
||||||
data.manifest.arguments.install[k].choices = [];
|
data.manifest.arguments.install[k].choices = [];
|
||||||
$.each(users, function(key, user){
|
$.each(params.users, function(key, user){
|
||||||
data.manifest.arguments.install[k].choices.push({
|
data.manifest.arguments.install[k].choices.push({
|
||||||
value: user.username,
|
value: user.username,
|
||||||
label: user.fullname+' ('+user.mail+')',
|
label: user.fullname+' ('+user.mail+')',
|
||||||
|
@ -893,17 +905,27 @@ app = Sammy('#main', function (sam) {
|
||||||
data.manifest.arguments.install[k].help = "<a href='#/users'>"+y18n.t('manage_users')+"</a>";
|
data.manifest.arguments.install[k].help = "<a href='#/users'>"+y18n.t('manage_users')+"</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for password input.
|
// 'app' type input display a list of available apps
|
||||||
if (v.name == 'password') {
|
if (data.manifest.arguments.install[k].type == 'app') {
|
||||||
data.manifest.arguments.install[k].type = 'password';
|
data.manifest.arguments.install[k].choices = [];
|
||||||
|
$.each(params.apps, function(key, app){
|
||||||
|
data.manifest.arguments.install[k].choices.push({
|
||||||
|
value: app.id,
|
||||||
|
label: app.name,
|
||||||
|
selected: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
data.manifest.arguments.install[k].help = "<a href='#/apps'>"+y18n.t('manage_apps')+"</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional field
|
// 'password' type input.
|
||||||
if (typeof v.optional !== 'undefined' && v.optional == "true") {
|
if (v.name == 'password' || data.manifest.arguments.install[k].type == 'password') {
|
||||||
data.manifest.arguments.install[k].required = '';
|
// Change html input type
|
||||||
|
data.manifest.arguments.install[k].inputType = 'password';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multilingual description
|
|
||||||
|
// Multilingual label
|
||||||
data.manifest.arguments.install[k].label = (typeof data.manifest.arguments.install[k].ask[y18n.locale] !== 'undefined') ?
|
data.manifest.arguments.install[k].label = (typeof data.manifest.arguments.install[k].ask[y18n.locale] !== 'undefined') ?
|
||||||
data.manifest.arguments.install[k].ask[y18n.locale] :
|
data.manifest.arguments.install[k].ask[y18n.locale] :
|
||||||
data.manifest.arguments.install[k].ask['en']
|
data.manifest.arguments.install[k].ask['en']
|
||||||
|
@ -917,7 +939,7 @@ app = Sammy('#main', function (sam) {
|
||||||
data.manifest.description['en']
|
data.manifest.description['en']
|
||||||
;
|
;
|
||||||
|
|
||||||
// Multi Instance settings
|
// Multi Instance settings boolean to text
|
||||||
data.manifest.multi_instance = (data.manifest.multi_instance == 'true') ? y18n.t('yes') : y18n.t('no');
|
data.manifest.multi_instance = (data.manifest.multi_instance == 'true') ? y18n.t('yes') : y18n.t('no');
|
||||||
|
|
||||||
// View app install form
|
// View app install form
|
||||||
|
@ -932,8 +954,7 @@ app = Sammy('#main', function (sam) {
|
||||||
c.appInstallForm(
|
c.appInstallForm(
|
||||||
c.params['app'],
|
c.params['app'],
|
||||||
data[c.params['app']].manifest,
|
data[c.params['app']].manifest,
|
||||||
c.params.users,
|
c.params
|
||||||
c.params.domains
|
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -986,8 +1007,7 @@ app = Sammy('#main', function (sam) {
|
||||||
c.appInstallForm(
|
c.appInstallForm(
|
||||||
params.app,
|
params.app,
|
||||||
manifest,
|
manifest,
|
||||||
c.params.users,
|
c.params
|
||||||
c.params.domains
|
|
||||||
);
|
);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -113,6 +113,7 @@
|
||||||
"multi_instance" : "Multi instance",
|
"multi_instance" : "Multi instance",
|
||||||
"manage_domains" : "Manage domains",
|
"manage_domains" : "Manage domains",
|
||||||
"manage_users" : "Manage users",
|
"manage_users" : "Manage users",
|
||||||
|
"manage_apps" : "Manage apps",
|
||||||
"install_time" : "Install time",
|
"install_time" : "Install time",
|
||||||
"custom_app_install" : "Install custom app",
|
"custom_app_install" : "Install custom app",
|
||||||
"custom_app_url_only_github" : "Currently only from GitHub",
|
"custom_app_url_only_github" : "Currently only from GitHub",
|
||||||
|
|
|
@ -112,6 +112,7 @@
|
||||||
"multi_instance" : "Multi instance",
|
"multi_instance" : "Multi instance",
|
||||||
"manage_domains" : "Gérer les domaines",
|
"manage_domains" : "Gérer les domaines",
|
||||||
"manage_users" : "Gérer les utilisateurs",
|
"manage_users" : "Gérer les utilisateurs",
|
||||||
|
"manage_apps" : "Gérer les applications",
|
||||||
"install_time" : "Date d'installation",
|
"install_time" : "Date d'installation",
|
||||||
"custom_app_install" : "Installer une application personnalisée",
|
"custom_app_install" : "Installer une application personnalisée",
|
||||||
"custom_app_url_only_github" : "Uniquement depuis GitHub",
|
"custom_app_url_only_github" : "Uniquement depuis GitHub",
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
{{#choices}}<option value="{{value}}" {{#if selected}}selected{{/if}}>{{label}}</option>{{/choices}}
|
{{#choices}}<option value="{{value}}" {{#if selected}}selected{{/if}}>{{label}}</option>{{/choices}}
|
||||||
</select>
|
</select>
|
||||||
{{else}}
|
{{else}}
|
||||||
<input type="{{type}}" id="{{name}}" name="{{name}}" class="form-control" value="{{default}}" placeholder="{{example}}" {{required}}>
|
<input type="{{inputType}}" id="{{name}}" name="{{name}}" class="form-control" value="{{default}}" placeholder="{{example}}" {{required}}>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if help}}
|
{{#if help}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue