Add more field types to MUC config

Added support for fixed, jid-multi and list-multi types.
This commit is contained in:
Guillermo Bonvehí 2014-11-13 18:18:32 -03:00
parent 572b3e8d74
commit 69ccdc9a85
8 changed files with 53 additions and 13 deletions

View File

@ -2394,13 +2394,17 @@
$fields = $stanza.find('field'), $fields = $stanza.find('field'),
title = $stanza.find('title').text(), title = $stanza.find('title').text(),
instructions = $stanza.find('instructions').text(), instructions = $stanza.find('instructions').text(),
i, j, options=[], $field, $options; i, j, options=[], $field, $options,
values=[], $values, value;
var input_types = { var input_types = {
'text-private': 'password', 'text-private': 'password',
'text-single': 'textline', 'text-single': 'textline',
'fixed': 'label',
'boolean': 'checkbox', 'boolean': 'checkbox',
'hidden': 'hidden', 'hidden': 'hidden',
'list-single': 'dropdown' 'jid-multi': 'textarea',
'list-single': 'dropdown',
'list-multi': 'dropdown'
}; };
$form.find('span.spinner').remove(); $form.find('span.spinner').remove();
$form.append($('<legend>').text(title)); $form.append($('<legend>').text(title));
@ -2409,19 +2413,35 @@
} }
for (i=0; i<$fields.length; i++) { for (i=0; i<$fields.length; i++) {
$field = $($fields[i]); $field = $($fields[i]);
if ($field.attr('type') == 'list-single') { if ($field.attr('type') == 'list-single' || $field.attr('type') == 'list-multi') {
values = [];
$values = $field.children('value');
for (j=0; j<$values.length; j++) {
values.push($($values[j]).text());
}
options = []; options = [];
$options = $field.find('option'); $options = $field.children('option');
for (j=0; j<$options.length; j++) { for (j=0; j<$options.length; j++) {
value = $($options[j]).find('value').text();
options.push(converse.templates.select_option({ options.push(converse.templates.select_option({
value: $($options[j]).find('value').text(), value: value,
label: $($options[j]).attr('label') label: $($options[j]).attr('label'),
selected: (values.indexOf(value) >= 0)
})); }));
} }
$form.append(converse.templates.form_select({ $form.append(converse.templates.form_select({
name: $field.attr('var'), name: $field.attr('var'),
label: $field.attr('label'), label: $field.attr('label'),
options: options.join('') options: options.join(''),
multiple: ($field.attr('type') == 'list-multi')
}));
} else if ($field.attr('type') == 'fixed') {
$form.append($('<p>').text($field.find('value').text()));
} else if ($field.attr('type') == 'jid-multi') {
$form.append(converse.templates.form_textarea({
name: $field.attr('var'),
label: $field.attr('label') || '',
value: $field.find('value').text()
})); }));
} else if ($field.attr('type') == 'boolean') { } else if ($field.attr('type') == 'boolean') {
$form.append(converse.templates.form_checkbox({ $form.append(converse.templates.form_checkbox({
@ -2455,6 +2475,15 @@
var $input = $(this), value; var $input = $(this), value;
if ($input.is('[type=checkbox]')) { if ($input.is('[type=checkbox]')) {
value = $input.is(':checked') && 1 || 0; value = $input.is(':checked') && 1 || 0;
} else if ($input.is('textarea')) {
value = [];
var lines = $input.val().split('\n');
for( var vk=0; vk<lines.length; vk++) {
var val = $.trim(lines[vk]);
if (val == '')
continue;
value.push(val);
}
} else { } else {
value = $input.val(); value = $input.val();
} }

View File

@ -926,6 +926,9 @@ dl.add-converse-contact {
display: block; display: block;
clear: both; clear: both;
} }
#conversejs .chatroom-form label.label-ta {
height: auto;
}
#conversejs .chatroom-form label input, #conversejs .chatroom-form label input,
#conversejs .chatroom-form label select { #conversejs .chatroom-form label select {
float: right; float: right;

View File

@ -103,7 +103,8 @@ require.config({
"status_option": "src/templates/status_option", "status_option": "src/templates/status_option",
"toggle_chats": "src/templates/toggle_chats", "toggle_chats": "src/templates/toggle_chats",
"toolbar": "src/templates/toolbar", "toolbar": "src/templates/toolbar",
"trimmed_chat": "src/templates/trimmed_chat" "trimmed_chat": "src/templates/trimmed_chat",
"form_textarea": "src/templates/form_textarea"
}, },
map: { map: {

View File

@ -41,7 +41,8 @@ define("converse-templates", [
"tpl!status_option", "tpl!status_option",
"tpl!toggle_chats", "tpl!toggle_chats",
"tpl!toolbar", "tpl!toolbar",
"tpl!trimmed_chat" "tpl!trimmed_chat",
"tpl!form_textarea"
], function () { ], function () {
return { return {
action: arguments[0], action: arguments[0],
@ -86,6 +87,7 @@ define("converse-templates", [
status_option: arguments[39], status_option: arguments[39],
toggle_chats: arguments[40], toggle_chats: arguments[40],
toolbar: arguments[41], toolbar: arguments[41],
trimmed_chat: arguments[42] trimmed_chat: arguments[42],
form_textarea: arguments[43]
}; };
}); });

View File

@ -1 +1,5 @@
<field var="{{name}}"><value>{{value}}</value></field> <field var="{{name}}">{[ if (_.isArray(value)) { ]}
{[ _.each(value,function(arrayValue) { ]}<value>{{arrayValue}}</value>{[ }); ]}
{[ } else { ]}
<value>{{value}}</value>
{[ } ]}</field>

View File

@ -1 +1 @@
<label>{{label}}<select name="{{name}}">{{options}}</select></label> <label>{{label}}<select name="{{name}}" {[ if (multiple) { ]} multiple="multiple" {[ } ]}>{{options}}</select></label>

View File

@ -0,0 +1 @@
<label class="label-ta">{{label}}<textarea name="{{name}}">{{value}}</textarea></label>

View File

@ -1 +1 @@
<option value="{{value}}">{{label}}</option> <option value="{{value}}" {[ if (selected) { ]} selected="selected" {[ } ]} >{{label}}</option>