From 69ccdc9a85b33feae402475855600236c26a19c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Bonveh=C3=AD?= Date: Thu, 13 Nov 2014 18:18:32 -0300 Subject: [PATCH] Add more field types to MUC config Added support for fixed, jid-multi and list-multi types. --- converse.js | 43 ++++++++++++++++++++++++++------ css/converse.css | 3 +++ main.js | 3 ++- src/templates.js | 6 +++-- src/templates/field.html | 6 ++++- src/templates/form_select.html | 2 +- src/templates/form_textarea.html | 1 + src/templates/select_option.html | 2 +- 8 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/templates/form_textarea.html diff --git a/converse.js b/converse.js index d23c69fdc..27b41d2e7 100644 --- a/converse.js +++ b/converse.js @@ -2394,13 +2394,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($('').text(title)); @@ -2409,19 +2413,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($('

').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({ @@ -2455,6 +2475,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{{value}} +{[ if (_.isArray(value)) { ]} + {[ _.each(value,function(arrayValue) { ]}{{arrayValue}}{[ }); ]} +{[ } else { ]} + {{value}} +{[ } ]} diff --git a/src/templates/form_select.html b/src/templates/form_select.html index a62cd6224..f0d0fa32d 100644 --- a/src/templates/form_select.html +++ b/src/templates/form_select.html @@ -1 +1 @@ - + diff --git a/src/templates/form_textarea.html b/src/templates/form_textarea.html new file mode 100644 index 000000000..762a9e7fa --- /dev/null +++ b/src/templates/form_textarea.html @@ -0,0 +1 @@ + diff --git a/src/templates/select_option.html b/src/templates/select_option.html index 08eba6abe..abc2c273b 100644 --- a/src/templates/select_option.html +++ b/src/templates/select_option.html @@ -1 +1 @@ - +