[enh] Allow empty install arg. Handle password type arg. Force select instead of radios.

This commit is contained in:
opi 2014-09-03 13:57:31 +02:00
parent 54217acac1
commit 7fb9a1f1ac
2 changed files with 54 additions and 32 deletions

View file

@ -796,7 +796,9 @@ app = Sammy('#main', function (sam) {
// Loop through installation arguments
if (typeof appData.manifest.arguments.install !== 'undefined') {
$.each(appData.manifest.arguments.install, function(k, v) {
appData.manifest.arguments.install[k].allowedValues = [];
// Default values
appData.manifest.arguments.install[k].type = 'text';
appData.manifest.arguments.install[k].required = 'required';
// Radio button
if (typeof appData.manifest.arguments.install[k].choices !== 'undefined') {
@ -804,8 +806,8 @@ app = Sammy('#main', function (sam) {
$.each(appData.manifest.arguments.install[k].choices, function(ck, cv){
appData.manifest.arguments.install[k].choices[ck] = {
value: cv,
key: ck,
checked: (cv == appData.manifest.arguments.install[k].default) ? true : false,
label: cv,
selected: (cv == appData.manifest.arguments.install[k].default) ? true : false,
};
});
}
@ -813,27 +815,41 @@ app = Sammy('#main', function (sam) {
// Special case for domain input.
// Display a list of available domains
if (v.name == 'domain') {
appData.manifest.arguments.install[k].choices = [];
$.each(c.params.domains, function(key, domain){
appData.manifest.arguments.install[k].allowedValues.push({
appData.manifest.arguments.install[k].choices.push({
value: domain,
label: domain,
selected: false,
});
})
});
appData.manifest.arguments.install[k].help = "<a href='#/domains'>"+y18n.t('manage_domains')+"</a>";
}
// Special case for admin input.
// Display a list of available users
if (v.name == 'admin') {
appData.manifest.arguments.install[k].choices = [];
$.each(c.params.users, function(key, user){
appData.manifest.arguments.install[k].allowedValues.push({
appData.manifest.arguments.install[k].choices.push({
value: user.username,
label: user.fullname+' ('+user.mail+')'
label: user.fullname+' ('+user.mail+')',
selected: false,
});
})
});
appData.manifest.arguments.install[k].help = "<a href='#/users'>"+y18n.t('manage_users')+"</a>";
}
// Special case for password input.
if (v.name == 'password') {
appData.manifest.arguments.install[k].type = 'password';
}
// Optional field
if (typeof v.optional !== 'undefined' && v.optional == "true") {
appData.manifest.arguments.install[k].required = '';
}
// Multilingual description
appData.manifest.arguments.install[k].label = (typeof appData.manifest.arguments.install[k].ask[y18n.locale] !== 'undefined') ?
appData.manifest.arguments.install[k].ask[y18n.locale] :
@ -896,7 +912,9 @@ app = Sammy('#main', function (sam) {
if (typeof appData.manifest.arguments.install !== 'undefined') {
$.each(appData.manifest.arguments.install, function(k, v) {
appData.manifest.arguments.install[k].allowedValues = [];
// Default values
appData.manifest.arguments.install[k].type = 'text';
appData.manifest.arguments.install[k].required = 'required';
// Radio button
if (typeof appData.manifest.arguments.install[k].choices !== 'undefined') {
@ -904,8 +922,8 @@ app = Sammy('#main', function (sam) {
$.each(appData.manifest.arguments.install[k].choices, function(ck, cv){
appData.manifest.arguments.install[k].choices[ck] = {
value: cv,
key: ck,
checked: (cv == appData.manifest.arguments.install[k].default) ? true : false,
label: cv,
selected: (cv == appData.manifest.arguments.install[k].default) ? true : false,
};
});
}
@ -913,27 +931,41 @@ app = Sammy('#main', function (sam) {
// Special case for domain input.
// Display a list of available domains
if (v.name == 'domain') {
appData.manifest.arguments.install[k].choices = [];
$.each(c.params.domains, function(key, domain){
appData.manifest.arguments.install[k].allowedValues.push({
appData.manifest.arguments.install[k].choices.push({
value: domain,
label: domain,
selected: false
});
})
});
appData.manifest.arguments.install[k].help = "<a href='#/domains'>"+y18n.t('manage_domains')+"</a>";
}
// Special case for admin input.
// Display a list of available users
if (v.name == 'admin') {
appData.manifest.arguments.install[k].choices = [];
$.each(c.params.users, function(key, user){
appData.manifest.arguments.install[k].allowedValues.push({
appData.manifest.arguments.install[k].choices.push({
value: user.username,
label: user.fullname+' ('+user.mail+')'
label: user.fullname+' ('+user.mail+')',
selected: false
});
})
});
appData.manifest.arguments.install[k].help = "<a href='#/users'>"+y18n.t('manage_users')+"</a>";
}
// Special case for password input.
if (v.name == 'password') {
appData.manifest.arguments.install[k].type = 'password';
}
// Optional field
if (typeof v.optional !== 'undefined' && v.optional == "true") {
appData.manifest.arguments.install[k].required = '';
}
// Multilingual description
appData.manifest.arguments.install[k].label = (typeof appData.manifest.arguments.install[k].ask[y18n.locale] !== 'undefined') ?
appData.manifest.arguments.install[k].ask[y18n.locale] :

View file

@ -37,27 +37,17 @@
<input type="text" id="label" name="label" class="form-control" value="{{manifest.name}}" required>
</div>
</div>
{{#manifest.arguments.install}}
{{#manifest.arguments.install}}
<div class="form-group">
<label for="{{name}}" class="col-sm-12">{{label}}</label>
<div class="col-sm-12">
{{#if allowedValues}}
<select id="{{name}}" name="{{name}}" required placeholder="{{example}}" class="form-control" {{#if multipleValues}}multiple{{/if}}>
<option value="" default disabled selected>{{example}}</option>
{{#allowedValues}}<option value="{{value}}">{{label}}</option>{{/allowedValues}}
{{#if choices}}
<select id="{{name}}" name="{{name}}" required class="form-control">
{{#choices}}<option value="{{value}}" {{#if selected}}selected{{/if}}>{{label}}</option>{{/choices}}
</select>
{{else}}
{{#if choices}}
{{#each choices}}
<div class="radio">
<label for="{{../name}}-{{key}}">
<input type="radio" id="{{../name}}-{{key}}" name="{{../name}}" value="{{value}}" {{#if checked}}checked{{/if}} required> {{value}}
</label>
</div>
{{/each}}
{{else}}
<input type="text" id="{{name}}" name="{{name}}" class="form-control" value="{{default}}" placeholder="{{example}}" required>
{{/if}}
<input type="{{type}}" id="{{name}}" name="{{name}}" class="form-control" value="{{default}}" placeholder="{{example}}" {{required}}>
{{/if}}
{{#if help}}