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;
|
||||
});
|
||||
});
|
||||
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) {
|
||||
// Store path for further redirections
|
||||
|
@ -841,7 +851,7 @@ app = Sammy('#main', function (sam) {
|
|||
});
|
||||
|
||||
// Helper function that build app installation form
|
||||
sam.helper('appInstallForm', function(appId, manifest, users, domains) {
|
||||
sam.helper('appInstallForm', function(appId, manifest, params) {
|
||||
data = {
|
||||
id: appId,
|
||||
manifest: manifest
|
||||
|
@ -849,11 +859,13 @@ app = Sammy('#main', function (sam) {
|
|||
|
||||
if (typeof data.manifest.arguments.install !== 'undefined') {
|
||||
$.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') {
|
||||
// Update choices values with key and checked data
|
||||
$.each(data.manifest.arguments.install[k].choices, function(ck, cv){
|
||||
|
@ -867,9 +879,9 @@ app = Sammy('#main', function (sam) {
|
|||
|
||||
// Special case for domain input.
|
||||
// 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 = [];
|
||||
$.each(domains, function(key, domain){
|
||||
$.each(params.domains, function(key, domain){
|
||||
data.manifest.arguments.install[k].choices.push({
|
||||
value: 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>";
|
||||
}
|
||||
|
||||
// Special case for admin input.
|
||||
// Special case for admin / user input.
|
||||
// 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 = [];
|
||||
$.each(users, function(key, user){
|
||||
$.each(params.users, function(key, user){
|
||||
data.manifest.arguments.install[k].choices.push({
|
||||
value: user.username,
|
||||
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>";
|
||||
}
|
||||
|
||||
// Special case for password input.
|
||||
if (v.name == 'password') {
|
||||
data.manifest.arguments.install[k].type = 'password';
|
||||
// 'app' type input display a list of available apps
|
||||
if (data.manifest.arguments.install[k].type == 'app') {
|
||||
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
|
||||
if (typeof v.optional !== 'undefined' && v.optional == "true") {
|
||||
data.manifest.arguments.install[k].required = '';
|
||||
// 'password' type input.
|
||||
if (v.name == 'password' || data.manifest.arguments.install[k].type == 'password') {
|
||||
// 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].ask[y18n.locale] :
|
||||
data.manifest.arguments.install[k].ask['en']
|
||||
|
@ -917,7 +939,7 @@ app = Sammy('#main', function (sam) {
|
|||
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');
|
||||
|
||||
// View app install form
|
||||
|
@ -932,8 +954,7 @@ app = Sammy('#main', function (sam) {
|
|||
c.appInstallForm(
|
||||
c.params['app'],
|
||||
data[c.params['app']].manifest,
|
||||
c.params.users,
|
||||
c.params.domains
|
||||
c.params
|
||||
);
|
||||
|
||||
});
|
||||
|
@ -986,8 +1007,7 @@ app = Sammy('#main', function (sam) {
|
|||
c.appInstallForm(
|
||||
params.app,
|
||||
manifest,
|
||||
c.params.users,
|
||||
c.params.domains
|
||||
c.params
|
||||
);
|
||||
|
||||
})
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
"multi_instance" : "Multi instance",
|
||||
"manage_domains" : "Manage domains",
|
||||
"manage_users" : "Manage users",
|
||||
"manage_apps" : "Manage apps",
|
||||
"install_time" : "Install time",
|
||||
"custom_app_install" : "Install custom app",
|
||||
"custom_app_url_only_github" : "Currently only from GitHub",
|
||||
|
|
|
@ -112,6 +112,7 @@
|
|||
"multi_instance" : "Multi instance",
|
||||
"manage_domains" : "Gérer les domaines",
|
||||
"manage_users" : "Gérer les utilisateurs",
|
||||
"manage_apps" : "Gérer les applications",
|
||||
"install_time" : "Date d'installation",
|
||||
"custom_app_install" : "Installer une application personnalisée",
|
||||
"custom_app_url_only_github" : "Uniquement depuis GitHub",
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
{{#choices}}<option value="{{value}}" {{#if selected}}selected{{/if}}>{{label}}</option>{{/choices}}
|
||||
</select>
|
||||
{{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 help}}
|
||||
|
|
Loading…
Add table
Reference in a new issue