Support Download/Upload Link tabs in seafile sharing dialog

This commit is contained in:
Aleksander Machniak 2018-10-16 11:25:23 +02:00
parent 94014f845f
commit 8a10209bd4
3 changed files with 112 additions and 35 deletions

View file

@ -1327,7 +1327,10 @@ function kolab_files_progress_str(param)
function kolab_files_share_form_init() function kolab_files_share_form_init()
{ {
$('fieldset > table', rcmail.gui_objects.shareform).each(function() { $('fieldset > table', rcmail.gui_objects.shareform).each(function() {
var mode = $(this).data('mode'); var cnt = 0,
mode = $(this).data('mode'),
single = $(this).data('single');
$('tbody > tr', this).each(function(i, row) { $('tbody > tr', this).each(function(i, row) {
if (!i) { if (!i) {
$('button.submit', row).on('click', function() { file_api.sharing_submit(rcmail.env.folder, row, mode); }); $('button.submit', row).on('click', function() { file_api.sharing_submit(rcmail.env.folder, row, mode); });
@ -1368,10 +1371,15 @@ function kolab_files_share_form_init()
}); });
} }
else { else {
cnt++;
$('button.delete', row).on('click', function() { file_api.sharing_delete(rcmail.env.folder, row, mode); }); $('button.delete', row).on('click', function() { file_api.sharing_delete(rcmail.env.folder, row, mode); });
$('select,input[type=text]', row).on('change', function() { file_api.sharing_update(rcmail.env.folder, row, mode); }); $('select,input[type=text]', row).on('change', function() { file_api.sharing_update(rcmail.env.folder, row, mode); });
} }
}); });
if (single && cnt) {
$('tbody > tr:first', this).find('button.submit, input, select').prop('disabled', true);
}
}); });
}; };
@ -2106,8 +2114,8 @@ function kolab_files_ui()
var root = folder.split(this.env.directory_separator)[0], var root = folder.split(this.env.directory_separator)[0],
caps = this.env.caps; caps = this.env.caps;
if (root != folder && this.env.caps.MOUNTPOINTS && this.env.caps.MOUNTPOINTS[root]) if (this.env.caps.MOUNTPOINTS && this.env.caps.MOUNTPOINTS[root])
caps = this.env.caps.MOUNTPOINTS[root]; caps = root != folder ? this.env.caps.MOUNTPOINTS[root] : {};
return !!caps.ACL; return !!caps.ACL;
}; };
@ -2749,6 +2757,9 @@ function kolab_files_ui()
{ {
var post = this.sharing_data(row, {action: 'submit', folder: folder, mode: mode}); var post = this.sharing_data(row, {action: 'submit', folder: folder, mode: mode});
if (post === false)
return;
this.sharing_submit_post = post; this.sharing_submit_post = post;
this.sharing_submit_row = row; this.sharing_submit_row = row;
this.req = this.set_busy(true, 'kolab_files.updatingfolder' + mode); this.req = this.set_busy(true, 'kolab_files.updatingfolder' + mode);
@ -2764,32 +2775,38 @@ function kolab_files_ui()
$(this.sharing_submit_row).find('input[type=text]').val(''); $(this.sharing_submit_row).find('input[type=text]').val('');
var hidden = [], var hidden = [],
post = $.extend({}, this.sharing_submit_post, response.data || {}), post = $.extend({}, this.sharing_submit_post, response.result || {}),
form_info = rcmail.env.form_info[post.mode], form_info = rcmail.env.form_info[post.mode],
table = $(this.sharing_submit_row).closest('table'),
row = $('<tr>'), row = $('<tr>'),
btn = $('<button type="button" class="btn btn-secondary delete">') btn = $('<button type="button" class="btn btn-secondary btn-danger delete">')
.text(rcmail.gettext('delete')) .text(rcmail.gettext('delete'))
.on('click', function() { file_api.sharing_delete(post.folder, $(this).closest('tr'), post.mode); }); .on('click', function() { file_api.sharing_delete(post.folder, $(this).closest('tr'), post.mode); });
$.each(form_info.form || [], function(i, v) { if (form_info.list_column) {
var content, opts = []; row.append($('<td>').append($('<span class="name">').text(post[form_info.list_column])));
}
else {
$.each(form_info.form || [], function(i, v) {
var content, opts = [];
if (v.type == 'select') { if (v.type == 'select') {
content = $('<select>').attr('name', i) content = $('<select>').attr('name', i)
.on('change', function() { file_api.sharing_update(post.folder, $(this).closest('tr'), post.mode); }); .on('change', function() { file_api.sharing_update(post.folder, $(this).closest('tr'), post.mode); });
$.each(v.options, function(i, v) { $.each(v.options, function(i, v) {
opts.push($('<option>').attr('value', i).text(v)); opts.push($('<option>').attr('value', i).text(v));
}); });
content.append(opts).val(post[i]); content.append(opts).val(post[i]);
} }
else { else {
content = $('<span class="name">').text(post[i]); content = $('<span class="name">').text(post[i]);
hidden.push($('<input>').attr({type: 'hidden', name: i, value: post[i] || ''})); hidden.push($('<input>').attr({type: 'hidden', name: i, value: post[i] || ''}));
} }
row.append($('<td>').append(content)); row.append($('<td>').append(content));
}); });
}
$.each(form_info.extra_fields || [], function(i, v) { $.each(form_info.extra_fields || [], function(i, v) {
hidden.push($('<input>').attr({type: 'hidden', name: i, value: post[i] || ''})); hidden.push($('<input>').attr({type: 'hidden', name: i, value: post[i] || ''}));
@ -2798,6 +2815,12 @@ function kolab_files_ui()
row.append($('<td>').append(btn).append(hidden)); row.append($('<td>').append(btn).append(hidden));
$(this.sharing_submit_row).parent().append(row); $(this.sharing_submit_row).parent().append(row);
if (table.data('single')) {
$('tbody > tr:first', table).find('button,input,select').prop('disabled', true);
}
$('tbody > tr:first', table).find('input[type=text],input[type=password]').val('');
}; };
this.sharing_update = function(folder, row, mode) this.sharing_update = function(folder, row, mode)
@ -2830,16 +2853,27 @@ function kolab_files_ui()
if (!this.response(response)) if (!this.response(response))
return; return;
var table = $(this.sharing_delete_row).closest('table');
if (table.data('single')) {
$('tbody > tr:first', table).find('button,input,select').prop('disabled', false);
}
$(this.sharing_delete_row).remove(); $(this.sharing_delete_row).remove();
}; };
this.sharing_data = function(row, data) this.sharing_data = function(row, data)
{ {
var error;
$('select,input', row).each(function() { $('select,input', row).each(function() {
if (this.type == 'password' && this.value != $('input[name=' + this.name + 'confirm]', row).val())
error = rcmail.display_message('kolab_files.passwordconflict', 'error');
data[this.name] = $(this).val(); data[this.name] = $(this).val();
}); });
return data; return error ? false : data;
}; };
// quota request // quota request

View file

@ -379,53 +379,90 @@ class kolab_files_engine
$out = ''; $out = '';
foreach ($info['form'] as $mode => $tab) { foreach ($info['form'] as $mode => $tab) {
$table = new html_table(array('cols' => count($tab['form']) + 1, 'data-mode' => $mode)); $table = new html_table(array(
'cols' => ($tab['list_column'] ? 1 : count($tab['form'])) + 1,
'data-mode' => $mode,
'data-single' => $tab['single'] ? 1 : 0,
));
$submit = new html_button(array('class' => 'btn btn-secondary submit')); $submit = new html_button(array('class' => 'btn btn-secondary submit'));
$delete = new html_button(array('class' => 'btn btn-secondary delete')); $delete = new html_button(array('class' => 'btn btn-secondary btn-danger delete'));
$fields = array(); $fields = array();
// Table header // Table header
foreach ($tab['form'] as $field) { if (!empty($tab['list_column'])) {
$table->add_header(null, rcube::Q($field['title'])); $table->add_header(null, rcube::Q($tab['list_column_label']));
}
else {
foreach ($tab['form'] as $field) {
$table->add_header(null, rcube::Q($field['title']));
}
} }
$table->add_header(null, ''); $table->add_header(null, '');
// Submit form // Submit form
$record = '';
foreach ($tab['form'] as $index => $field) { foreach ($tab['form'] as $index => $field) {
$add = '';
if ($field['type'] == 'select') { if ($field['type'] == 'select') {
$ff = new html_select(array('name' => $index)); $ff = new html_select(array('name' => $index));
foreach ($field['options'] as $opt_idx => $opt) { foreach ($field['options'] as $opt_idx => $opt) {
$ff->add($opt, $opt_idx); $ff->add($opt, $opt_idx);
} }
} }
else if ($field['type'] == 'password') {
$ff = new html_passwordfield(array(
'name' => $index,
'placeholder' => $this->rc->gettext('password'),
));
$add = new html_passwordfield(array(
'name' => $index . 'confirm',
'placeholder' => $this->plugin->gettext('confirmpassword'),
));
$add = $add->show();
}
else { else {
$ff = new html_inputfield(array( $ff = new html_inputfield(array(
'name' => $index, 'name' => $index,
'data-autocomplete' => $field['autocomplete'], 'data-autocomplete' => $field['autocomplete'],
'placeholder' => $field['placeholder'],
)); ));
} }
$table->add(null, $ff->show()); if (!empty($tab['list_column'])) {
$record .= $ff->show() . $add;
}
else {
$table->add(null, $ff->show() . $add);
}
$fields[$index] = $ff; $fields[$index] = $ff;
} }
if (!empty($tab['list_column'])) {
$table->add('form', $record);
}
$hidden = ''; $hidden = '';
foreach ((array) $tab['extra_fields'] as $key => $default) { foreach ((array) $tab['extra_fields'] as $key => $default) {
$h = new html_hiddenfield(array('name' => $key, 'value' => $default)); $h = new html_hiddenfield(array('name' => $key, 'value' => $default));
$hidden .= $h->show(); $hidden .= $h->show();
} }
$table->add(null, $hidden . $submit->show(rcube::Q($this->plugin->gettext('submit')))); $table->add(null, $hidden . $submit->show(rcube::Q($tab['label'] ?: $this->plugin->gettext('submit'))));
// Existing entries // Existing entries
foreach ((array) $info['rights'] as $entry) { foreach ((array) $info['rights'] as $entry) {
if ($entry['mode'] == $mode) { if ($entry['mode'] == $mode) {
foreach ($tab['form'] as $index => $field) { if (!empty($tab['list_column'])) {
if ($fields[$index] instanceof html_select) { $table->add(null, html::span('name', rcube::Q($entry[$tab['list_column']])));
$table->add(null, $fields[$index]->show($entry[$index])); }
} else {
else if ($fields[$index] instanceof html_inputfield) { foreach ($tab['form'] as $index => $field) {
$table->add(null, html::span('name', rcube::Q($entry[$index]))); if ($fields[$index] instanceof html_select) {
$table->add(null, $fields[$index]->show($entry[$index]));
}
else if ($fields[$index] instanceof html_inputfield) {
$table->add(null, html::span('name', rcube::Q($entry[$index])));
}
} }
} }
@ -441,13 +478,15 @@ class kolab_files_engine
} }
} }
$this->rc->output->add_label('kolab_files.updatingfolder' . $mode);
$out .= html::tag('fieldset', $mode, html::tag('legend', null, rcube::Q($tab['title'])) . $table->show()) . "\n"; $out .= html::tag('fieldset', $mode, html::tag('legend', null, rcube::Q($tab['title'])) . $table->show()) . "\n";
} }
$this->rc->output->set_env('folder', $folder); $this->rc->output->set_env('folder', $folder);
$this->rc->output->set_env('form_info', $info['form']); $this->rc->output->set_env('form_info', $info['form']);
$this->rc->output->add_gui_object('shareform', $attrib['id']); $this->rc->output->add_gui_object('shareform', $attrib['id']);
$this->rc->output->add_label('kolab_files.submit', 'delete', 'kolab_files.updatingfoldershares'); $this->rc->output->add_label('kolab_files.submit', 'kolab_files.passwordconflict', 'delete');
return html::div($attrib, $out); return html::div($attrib, $out);
} }

View file

@ -59,6 +59,8 @@ $labels['documenttitle'] = 'Title:';
$labels['close'] = 'Close'; $labels['close'] = 'Close';
$labels['docedit'] = 'Document editing'; $labels['docedit'] = 'Document editing';
$labels['submit'] = 'Submit'; $labels['submit'] = 'Submit';
$labels['confirmpassword'] = 'Confirm password';
$labels['passwordconflict'] = 'Passwords do not match';
$labels['collection_audio'] = 'Audio'; $labels['collection_audio'] = 'Audio';
$labels['collection_video'] = 'Video'; $labels['collection_video'] = 'Video';
@ -93,6 +95,8 @@ $labels['filemovenotice'] = 'File(s) moved successfully.';
$labels['filecopynotice'] = 'File(s) copied successfully.'; $labels['filecopynotice'] = 'File(s) copied successfully.';
$labels['uploadsizeerror'] = 'Maximum file size ($size) exceeded!'; $labels['uploadsizeerror'] = 'Maximum file size ($size) exceeded!';
$labels['updatingfoldershares'] = 'Updating folder permissions...'; $labels['updatingfoldershares'] = 'Updating folder permissions...';
$labels['updatingfolderupload-link'] = 'Updating upload link...';
$labels['updatingfolderdownload-link'] = 'Updating download link...';
$labels['listpermanent'] = 'List permanently'; $labels['listpermanent'] = 'List permanently';
$labels['additionalfolders'] = 'Additional folders'; $labels['additionalfolders'] = 'Additional folders';