Merge pull request #279 from gbonvehi/support-muc-config
Add more field types to MUC config
This commit is contained in:
commit
0a57bb8a4b
43
converse.js
43
converse.js
@ -2396,13 +2396,17 @@
|
||||
$fields = $stanza.find('field'),
|
||||
title = $stanza.find('title').text(),
|
||||
instructions = $stanza.find('instructions').text(),
|
||||
i, j, options=[], $field, $options;
|
||||
i, j, options=[], $field, $options,
|
||||
values=[], $values, value;
|
||||
var input_types = {
|
||||
'text-private': 'password',
|
||||
'text-single': 'textline',
|
||||
'fixed': 'label',
|
||||
'boolean': 'checkbox',
|
||||
'hidden': 'hidden',
|
||||
'list-single': 'dropdown'
|
||||
'jid-multi': 'textarea',
|
||||
'list-single': 'dropdown',
|
||||
'list-multi': 'dropdown'
|
||||
};
|
||||
$form.find('span.spinner').remove();
|
||||
$form.append($('<legend>').text(title));
|
||||
@ -2411,19 +2415,35 @@
|
||||
}
|
||||
for (i=0; i<$fields.length; 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 = $field.find('option');
|
||||
$options = $field.children('option');
|
||||
for (j=0; j<$options.length; j++) {
|
||||
value = $($options[j]).find('value').text();
|
||||
options.push(converse.templates.select_option({
|
||||
value: $($options[j]).find('value').text(),
|
||||
label: $($options[j]).attr('label')
|
||||
value: value,
|
||||
label: $($options[j]).attr('label'),
|
||||
selected: (values.indexOf(value) >= 0)
|
||||
}));
|
||||
}
|
||||
$form.append(converse.templates.form_select({
|
||||
name: $field.attr('var'),
|
||||
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') {
|
||||
$form.append(converse.templates.form_checkbox({
|
||||
@ -2457,6 +2477,15 @@
|
||||
var $input = $(this), value;
|
||||
if ($input.is('[type=checkbox]')) {
|
||||
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 {
|
||||
value = $input.val();
|
||||
}
|
||||
|
@ -926,6 +926,9 @@ dl.add-converse-contact {
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
#conversejs .chatroom-form label.label-ta {
|
||||
height: auto;
|
||||
}
|
||||
#conversejs .chatroom-form label input,
|
||||
#conversejs .chatroom-form label select {
|
||||
float: right;
|
||||
|
3
main.js
3
main.js
@ -103,7 +103,8 @@ require.config({
|
||||
"status_option": "src/templates/status_option",
|
||||
"toggle_chats": "src/templates/toggle_chats",
|
||||
"toolbar": "src/templates/toolbar",
|
||||
"trimmed_chat": "src/templates/trimmed_chat"
|
||||
"trimmed_chat": "src/templates/trimmed_chat",
|
||||
"form_textarea": "src/templates/form_textarea"
|
||||
},
|
||||
|
||||
map: {
|
||||
|
@ -41,7 +41,8 @@ define("converse-templates", [
|
||||
"tpl!status_option",
|
||||
"tpl!toggle_chats",
|
||||
"tpl!toolbar",
|
||||
"tpl!trimmed_chat"
|
||||
"tpl!trimmed_chat",
|
||||
"tpl!form_textarea"
|
||||
], function () {
|
||||
return {
|
||||
action: arguments[0],
|
||||
@ -86,6 +87,7 @@ define("converse-templates", [
|
||||
status_option: arguments[39],
|
||||
toggle_chats: arguments[40],
|
||||
toolbar: arguments[41],
|
||||
trimmed_chat: arguments[42]
|
||||
trimmed_chat: arguments[42],
|
||||
form_textarea: arguments[43]
|
||||
};
|
||||
});
|
||||
|
@ -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>
|
||||
|
@ -1 +1 @@
|
||||
<label>{{label}}<select name="{{name}}">{{options}}</select></label>
|
||||
<label>{{label}}<select name="{{name}}" {[ if (multiple) { ]} multiple="multiple" {[ } ]}>{{options}}</select></label>
|
||||
|
1
src/templates/form_textarea.html
Normal file
1
src/templates/form_textarea.html
Normal file
@ -0,0 +1 @@
|
||||
<label class="label-ta">{{label}}<textarea name="{{name}}">{{value}}</textarea></label>
|
@ -1 +1 @@
|
||||
<option value="{{value}}">{{label}}</option>
|
||||
<option value="{{value}}" {[ if (selected) { ]} selected="selected" {[ } ]} >{{label}}</option>
|
||||
|
Loading…
Reference in New Issue
Block a user