Elastic: Support more compact contact frame (info and form)

... plus some CS fixes
pull/6040/head
Aleksander Machniak 7 years ago
parent fe542437a8
commit 5031028d48

@ -890,7 +890,6 @@ rcube_webmail.prototype.managesieve_tip_register = function(tips)
tip = framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer;
for (n in tips) {
console.log(tips[n]);
$('#'+tips[n][0])
.data('tip-class', tips[n][1])
.data('tip-msg', tips[n][2])

@ -6498,20 +6498,21 @@ function rcube_webmail()
if (!elem)
elem = $('.ff_' + col);
if (label)
if (label && !$('label[for="ff_' + col + '"]').length)
elem.placeholder(label);
};
this.insert_edit_field = function(col, section, menu)
{
// just make pre-defined input field visible
var elem = $('#ff_'+col);
var elem = $('#ff_' + col);
if (elem.length) {
$('label[for="ff_' + col + '"]').parent().show();
elem.show().focus();
$(menu).children('option[value="'+col+'"]').prop('disabled', true);
$(menu).children('option[value="' + col + '"]').prop('disabled', true);
}
else {
var lastelem = $('.ff_'+col),
var lastelem = $('.ff_' + col),
appendcontainer = $('#contactsection'+section+' .contactcontroller'+col);
if (!appendcontainer.length) {
@ -6524,25 +6525,31 @@ function rcube_webmail()
sect.prepend(appendcontainer);
}
if (appendcontainer.length && appendcontainer.get(0).nodeName == 'FIELDSET') {
var input, colprop = this.env.coltypes[col],
if (appendcontainer.get(0).nodeName == 'FIELDSET') {
var label, input,
colprop = this.env.coltypes[col],
name_suffix = colprop.limit != 1 ? '[]' : '',
compact = $(menu).data('compact') ? true : false,
input_id = 'ff_' + col + (colprop.count || 0),
row = $('<div>').addClass('row'),
cell = $('<div>').addClass('contactfieldcontent data'),
label = $('<div>').addClass('contactfieldlabel label');
if (colprop.subtypes_select)
label.html(colprop.subtypes_select);
row = $('<div>').addClass('row input-group'),
cell = $('<div>').addClass('contactfieldcontent ' + colprop.type);
// Field label
if (colprop.subtypes_select) {
label = $(colprop.subtypes_select);
if (!compact)
label = $('<div>').addClass('contactfieldlabel label').append(label);
else
label.addClass('input-group-addon');
}
else
label.html('<label for="' + input_id + '">' + colprop.label + '</label>');
var name_suffix = colprop.limit != 1 ? '[]' : '';
label = $('<label>').addClass('contactfieldlabel label input-group-addon').attr('for', input_id).text(colprop.label);
// Field input
if (colprop.type == 'text' || colprop.type == 'date') {
input = $('<input>')
.addClass('ff_'+col)
.attr({type: 'text', name: '_'+col+name_suffix, size: colprop.size, id: input_id})
.appendTo(cell);
.addClass('form-control ff_' + col)
.attr({type: 'text', name: '_'+col+name_suffix, size: colprop.size, id: input_id});
this.init_edit_field(col, input);
@ -6551,17 +6558,19 @@ function rcube_webmail()
}
else if (colprop.type == 'textarea') {
input = $('<textarea>')
.addClass('ff_'+col)
.attr({ name: '_'+col+name_suffix, cols:colprop.size, rows:colprop.rows, id: input_id })
.appendTo(cell);
.addClass('form-control ff_' + col)
.attr({ name: '_' + col + name_suffix, cols: colprop.size, rows: colprop.rows, id: input_id });
this.init_edit_field(col, input);
}
else if (colprop.type == 'composite') {
var i, childcol, cp, first, templ, cols = [], suffices = [];
var i, childcol, cp, first, templ, cols = [], suffices = [], content = cell;
if (compact)
content = $('<div class="content input-group-addon">');
// read template for composite field order
if ((templ = this.env[col+'_template'])) {
if (templ = this.env[col + '_template']) {
for (i=0; i < templ.length; i++) {
cols.push(templ[i][1]);
suffices.push(templ[i][2]);
@ -6576,42 +6585,61 @@ function rcube_webmail()
childcol = cols[i];
cp = colprop.childs[childcol];
input = $('<input>')
.addClass('ff_'+childcol)
.attr({ type: 'text', name: '_'+childcol+name_suffix, size: cp.size })
.appendTo(cell);
cell.append(suffices[i] || " ");
.addClass('form-control ff_' + childcol)
.attr({ type: 'text', name: '_' + childcol + name_suffix, size: cp.size })
.appendTo(content);
if (!compact)
content.append(suffices[i] || " ");
this.init_edit_field(childcol, input);
if (!first) first = input;
}
input = first; // set focus to the first of this composite fields
if (compact)
input = content;
else
input = first; // set focus to the first of this composite fields
}
else if (colprop.type == 'select') {
input = $('<select>')
.addClass('ff_'+col)
.attr({ 'name': '_'+col+name_suffix, id: input_id })
.appendTo(cell);
.addClass('form-control ff_' + col)
.attr({ name: '_' + col + name_suffix, id: input_id });
var options = input.attr('options');
options[options.length] = new Option('---', '');
if (colprop.options)
$.each(colprop.options, function(i, val){ options[options.length] = new Option(val, i); });
$.each(colprop.options, function(i, val) { options[options.length] = new Option(val, i); });
}
if (input) {
var delbutton = $('<a href="#del"></a>')
.addClass('contactfieldbutton deletebutton')
.addClass('contactfieldbutton deletebutton input-group-addon icon delete')
.attr({title: this.get_label('delete'), rel: col})
.html(this.env.delbutton)
.click(function(){ ref.delete_edit_field(this); return false })
.appendTo(cell);
.click(function() { ref.delete_edit_field(this); return false; });
row.append(label);
row.append(label).append(cell).appendTo(appendcontainer.show());
input.first().focus();
if (!compact) {
if (colprop.type != 'composite')
cell.append(input);
row.append(cell.append(delbutton));
}
else
row.append(input).append(delbutton);
row.appendTo(appendcontainer.show());
if (input.is('div'))
input.find('input:first').focus();
else
input.first().focus();
// disable option if limit reached
if (!colprop.count) colprop.count = 0;
if (++colprop.count == colprop.limit && colprop.limit)
$(menu).children('option[value="'+col+'"]').prop('disabled', true);
$(menu).children('option[value="' + col + '"]').prop('disabled', true);
}
}
}
@ -6626,7 +6654,7 @@ function rcube_webmail()
// just clear input but don't hide the last field
if (--colprop.count <= 0 && colprop.visible)
$(elem).parent().children('input').val('').blur();
$(elem).parent().find('input').val('').blur();
else {
$(elem).parents('div.row').remove();
// hide entire fieldset if no more rows

@ -538,9 +538,17 @@ function rcmail_contact_form($form, $record, $attrib = null)
$record = $plugin['record'];
$head_fields = $plugin['head_fields'];
$edit_mode = $RCMAIL->action != 'show' && $RCMAIL->action != 'print';
$del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete'))) : $RCMAIL->gettext('delete');
$compact = rcube_utils::get_boolean($attrib['compact-form']);
$use_labels = rcube_utils::get_boolean($attrib['use-labels']);
$out = '';
if ($attrib['deleteicon']) {
$del_button = html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete')));
}
else {
$del_button = html::span('inner', $RCMAIL->gettext('delete'));
}
unset($attrib['deleteicon']);
// get default coltypes
@ -566,7 +574,7 @@ function rcmail_contact_form($form, $record, $attrib = null)
continue;
}
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section));
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section, 'data-compact' => $compact ? "true" : null));
$select_add->add($RCMAIL->gettext('addfield'), '');
// render head section with name fields (not a regular list of rows)
@ -579,11 +587,14 @@ function rcmail_contact_form($form, $record, $attrib = null)
}
foreach ($head_fields as $blockname => $colnames) {
$fields = '';
$fields = '';
$block_attr = array('class' => $blockname . (count($colnames) == 1 ? ' row' : ''));
foreach ($colnames as $col) {
// skip cols unknown to the backend
if (!$coltypes[$col])
if (!$coltypes[$col]) {
continue;
}
// skip cols not listed in the form definition
if (is_array($fieldset['content']) && !in_array($col, array_keys($fieldset['content']))) {
@ -591,28 +602,50 @@ function rcmail_contact_form($form, $record, $attrib = null)
}
// only string values are expected here
if (is_array($record[$col]))
if (is_array($record[$col])) {
$record[$col] = join(' ', $record[$col]);
}
if (!$edit_mode) {
if (!empty($record[$col]))
$fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . " ";
if (!empty($record[$col])) {
$fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . ' ';
}
}
else {
$colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];
$colprop['id'] = 'ff_'.$col;
$colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];
$colprop['id'] = 'ff_' . $col;
$visible = true;
if (empty($record[$col]) && !$colprop['visible']) {
$colprop['style'] = 'display:none';
$visible = false;
$colprop['style'] = $use_labels ? null : 'display:none';
$select_add->add($colprop['label'], $col);
}
$fields .= rcube_output::get_edit_field($col, $record[$col], $colprop, $colprop['type']);
$input = rcube_output::get_edit_field($col, $record[$col], $colprop, $colprop['type']);
if ($use_labels) {
$_content = html::label($colprop['id'], rcube::Q($colprop['label'])) . html::div(null, $input);
if (count($colnames) > 1) {
$fields .= html::div(array('class' => 'row', 'style' => $visible ? null : 'display:none'), $_content);
}
else {
$fields .= $_content;
$block_attr['style'] = $visible ? null : 'display:none';
}
}
else {
$fields .= $input;
}
}
}
$content .= html::div($blockname, $fields);
$content .= html::div($block_attr, $fields);
}
if ($edit_mode)
if ($edit_mode) {
$content .= html::p('addfield', $select_add->show(null));
}
$out .= html::tag('fieldset', $attrib, (!empty($fieldset['name']) ? html::tag('legend', null, rcube::Q($fieldset['name'])) : '') . $content) ."\n";
continue;
@ -702,11 +735,11 @@ function rcmail_contact_form($form, $record, $attrib = null)
if ($edit_mode) {
if ($colprop['subtypes'] || $colprop['limit'] != 1) $cp['array'] = true;
$composite['{'.$childcol.'}'] = rcube_output::get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " ";
$composite['{'.$childcol.'}'] = rcube_output::get_edit_field($childcol, $childvalue, $cp, $cp['type']) . ' ';
}
else {
$childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : rcube::Q($childvalue);
$composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . " ";
$composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . ' ';
}
$j++;
}
@ -714,58 +747,86 @@ function rcmail_contact_form($form, $record, $attrib = null)
$coltypes[$field] += (array)$colprop;
$coltypes[$field]['count']++;
$val = preg_replace('/\{\w+\}/', '', strtr($template, $composite));
if ($compact) {
$val = html::div('content', str_replace('<br/>', '', $val));
}
}
else if ($edit_mode) {
// call callback to render/format value
if ($colprop['render_func'])
if ($colprop['render_func']) {
$val = call_user_func($colprop['render_func'], $val, $col);
}
$coltypes[$field] = (array)$colprop + $coltypes[$field];
if ($colprop['subtypes'] || $colprop['limit'] != 1)
if ($colprop['subtypes'] || $colprop['limit'] != 1) {
$colprop['array'] = true;
}
// load jquery UI datepicker for date fields
if ($colprop['type'] == 'date') {
$colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
if (!$colprop['render_func'])
if (!$colprop['render_func']) {
$val = rcmail_format_date_col($val);
}
}
$val = rcube_output::get_edit_field($col, $val, $colprop, $colprop['type']);
$coltypes[$field]['count']++;
}
else if ($colprop['render_func'])
else if ($colprop['render_func']) {
$val = call_user_func($colprop['render_func'], $val, $col);
else if (is_array($colprop['options']) && isset($colprop['options'][$val]))
}
else if (is_array($colprop['options']) && isset($colprop['options'][$val])) {
$val = $colprop['options'][$val];
else
}
else {
$val = rcube::Q($val);
}
// use subtype as label
if ($colprop['subtypes'])
if ($colprop['subtypes']) {
$label = rcmail_get_type_label($subtype);
}
$_del_btn = html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => $RCMAIL->gettext('delete'), 'rel' => $col), $del_button);
// add delete button/link
if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1))
$val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => $RCMAIL->gettext('delete'), 'rel' => $col), $del_button);
if (!$compact && $edit_mode && !($colprop['visible'] && $colprop['limit'] == 1)) {
$val .= $_del_btn;
}
// display row with label
if ($label) {
if ($RCMAIL->action == 'print') {
$_label = rcube::Q($colprop['label'] . ($label != $colprop['label'] ? ' (' . $label . ')' : ''));
if (!$compact) {
$_label = html::div('contactfieldlabel label', $_label);
}
}
else if ($select_subtype) {
$_label = $select_subtype->show($subtype);
if (!$compact) {
$_label = html::div('contactfieldlabel label', $_label);
}
}
else {
$_label = html::label(array('class' => 'contactfieldlabel label', 'for' => $colprop['id']), rcube::Q($label));
}
if (!$compact) {
$val = html::div('contactfieldcontent ' . $colprop['type'], $val);
}
else {
$_label = $select_subtype ? $select_subtype->show($subtype) : html::label($colprop['id'], rcube::Q($label));
$val .= $_del_btn;
}
$rows .= html::div('row',
html::div('contactfieldlabel label', $_label) .
html::div('contactfieldcontent '.$colprop['type'], $val));
$rows .= html::div('row', $_label . $val);
}
// row without label
else {
$rows .= html::div('row', html::div('contactfield', $val));
$rows .= html::div('row', $compact ? $val : html::div('contactfield', $val));
}
}
@ -787,12 +848,14 @@ function rcmail_contact_form($form, $record, $attrib = null)
}
}
if (!$content && (!$edit_mode || !$select_add->_count))
if (!$content && (!$edit_mode || !$select_add->_count)) {
continue;
}
// also render add-field selector
if ($edit_mode)
if ($edit_mode) {
$content .= html::p('addfield', $select_add->show(null, array('style' => $select_add->_count ? null : 'display:none')));
}
$content = html::div(array('id' => 'contactsection' . $section), $content);
}
@ -800,8 +863,10 @@ function rcmail_contact_form($form, $record, $attrib = null)
$content = $fieldset['content'];
}
if ($content)
$out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $content) ."\n";
if ($content) {
$out .= html::tag('fieldset', array('class' => $attrib['fieldset-class']),
html::tag('legend', null, rcube::Q($fieldset['name'])) . $content) . "\n";
}
}
if ($edit_mode) {

@ -141,7 +141,7 @@ function rcmail_contact_details($attrib)
);
}
return rcmail_contact_form($form, $record);
return rcmail_contact_form($form, $record, $attrib);
}

Loading…
Cancel
Save