diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js index 3044d6e8..1759ee47 100644 --- a/plugins/kolab_files/kolab_files.js +++ b/plugins/kolab_files/kolab_files.js @@ -1,2344 +1,2644 @@ /** * Kolab files plugin * * @author Aleksander Machniak * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (C) 2011, Kolab Systems AG * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * * @licend The above is the entire license notice * for the JavaScript code in this file. */ window.rcmail && window.files_api && rcmail.addEventListener('init', function() { if (rcmail.task == 'mail') { // mail compose if (rcmail.env.action == 'compose') { var elem = $('#compose-attachments > div'), input = $('') .attr('tabindex', $('input', elem).attr('tabindex') || 0) .val(rcmail.gettext('kolab_files.fromcloud')) .click(function() { kolab_files_selector_dialog(); }) .appendTo(elem); if (rcmail.gui_objects.filelist) { rcmail.file_list = new rcube_list_widget(rcmail.gui_objects.filelist, { multiselect: true, keyboard: true, column_movable: false, dblclick_time: rcmail.dblclick_time }); rcmail.file_list.addEventListener('select', function(o) { kolab_files_list_select(o); }) .addEventListener('listupdate', function(e) { rcmail.triggerEvent('listupdate', e); }); rcmail.enable_command('files-sort', 'files-search', 'files-search-reset', true); rcmail.file_list.init(); kolab_files_list_coltypes(); } // register some commands to skip warning message on compose page $.merge(rcmail.env.compose_commands, ['files-list', 'files-sort', 'files-search', 'files-search-reset']); } // mail preview else if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') { var attachment_list = $('#attachment-list'); if ($('li', attachment_list).length) { var link = $('') .text(rcmail.gettext('kolab_files.saveall')) .click(function() { kolab_directory_selector_dialog(); }) .insertAfter(attachment_list); } rcmail.addEventListener('menu-open', kolab_files_attach_menu_open); rcmail.enable_command('folder-create', true); } // attachment preview else if (rcmail.env.action == 'get') { rcmail.enable_command('folder-create', true); } kolab_files_init(); } else if (rcmail.task == 'files') { if (rcmail.gui_objects.filelist) { rcmail.file_list = new rcube_list_widget(rcmail.gui_objects.filelist, { multiselect: true, draggable: true, keyboard: true, column_movable: rcmail.env.col_movable, dblclick_time: rcmail.dblclick_time }); rcmail.file_list.addEventListener('dblclick', function(o) { kolab_files_list_dblclick(o); }) .addEventListener('select', function(o) { kolab_files_list_select(o); }) .addEventListener('keypress', function(o) { kolab_files_list_keypress(o); }) .addEventListener('dragstart', function(e) { kolab_files_drag_start(e); }) .addEventListener('dragmove', function(e) { kolab_files_drag_move(e); }) .addEventListener('dragend', function(e) { kolab_files_drag_end(e); }) .addEventListener('column_replace', function(e) { kolab_files_set_coltypes(e); }) .addEventListener('listupdate', function(e) { rcmail.triggerEvent('listupdate', e); }); rcmail.enable_command('menu-open', 'menu-save', 'files-sort', 'files-search', 'files-search-reset', 'folder-create', true); rcmail.file_list.init(); kolab_files_list_coltypes(); kolab_files_drag_drop_init($(rcmail.gui_objects.filelist).parents('.droptarget')); } // "one file only" commands rcmail.env.file_commands = ['files-get']; // "one or more file" commands rcmail.env.file_commands_all = ['files-delete', 'files-move', 'files-copy']; kolab_files_init(); if (rcmail.env.action == 'open') { rcmail.enable_command('files-get', 'files-delete', rcmail.env.file); } else { file_api.folder_list(); file_api.browser_capabilities_check(); rcmail.enable_command('folder-mount', rcmail.env.external_sources); } } }); /**********************************************************/ /********* Shared functionality **********/ /**********************************************************/ // Initializes API object function kolab_files_init() { if (window.file_api) return; // Initialize application object (don't change var name!) file_api = $.extend(new files_api(), new kolab_files_ui()); file_api.set_env({ token: kolab_files_token(), url: rcmail.env.files_url, sort_col: 'name', sort_reverse: false, search_threads: rcmail.env.search_threads, resources_dir: rcmail.assets_path('program/resources'), + caps: rcmail.env.files_caps, supported_mimetypes: rcmail.env.file_mimetypes }); file_api.translations = rcmail.labels; }; // returns API authorization token function kolab_files_token() { // consider the token from parent window more reliable (fresher) than in framed window // it's because keep-alive is not requested in frames return window.parent && parent.rcmail && parent.rcmail.env.files_token ? parent.rcmail.env.files_token : rcmail.env.files_token; }; // folder selection dialog function kolab_directory_selector_dialog(id) { var dialog = $('#files-dialog'), input = $('#file-save-as-input'), form = $('#file-save-as'), list = $('#folderlistbox'), buttons = {}, label = 'saveto', win = window, fn; // attachment is specified if (id) { var attach = $('#attach' + id + '> a').first(), filename = attach.attr('title'); if (!filename) { attach = attach.clone(); $('.attachment-size', attach).remove(); filename = $.trim(attach.text()); } form.show(); dialog.addClass('saveas'); input.val(filename); } // attachment preview page else if (rcmail.env.action == 'get') { id = rcmail.env.part; form.show(); dialog.addClass('saveas'); input.val(rcmail.env.filename); } else { form.hide(); dialog.removeClass('saveas'); label = 'saveall'; } $('#foldercreatelink').attr('tabindex', 0); buttons[rcmail.gettext('kolab_files.save')] = function () { if (!file_api.env.folder) return; var lock = rcmail.set_busy(true, 'saving'), request = { act: 'save-file', source: rcmail.env.mailbox, uid: rcmail.env.uid, dest: file_api.env.folder }; if (id) { request.id = id; request.name = input.val(); } rcmail.http_post('plugin.kolab_files', request, lock); kolab_dialog_close(this); }; buttons[rcmail.gettext('kolab_files.cancel')] = function () { kolab_dialog_close(this); }; if (!rcmail.env.folders_loaded) { fn = function() { file_api.folder_list(); rcmail.env.folders_loaded = true; }; } // show dialog window kolab_dialog_show(dialog, { title: rcmail.gettext('kolab_files.' + label), buttons: buttons, button_classes: ['mainaction'], minWidth: 250, minHeight: 300, height: 400, width: 300 }, fn); // "enable" folder creation when dialog is displayed in parent window if (rcmail.is_framed() && !parent.rcmail.folder_create) { parent.rcmail.enable_command('folder-create', true); parent.rcmail.folder_create = function() { win.kolab_files_folder_create_dialog(); }; } }; // file selection dialog function kolab_files_selector_dialog() { var dialog = $('#files-compose-dialog'), buttons = {}; buttons[rcmail.gettext('kolab_files.attachsel')] = function () { var list = []; $('#filelist tr.selected').each(function() { list.push($(this).data('file')); }); kolab_dialog_close(this); if (list.length) { // display upload indicator and cancel button var content = '' + rcmail.get_label('kolab_files.attaching') + '', id = new Date().getTime(); rcmail.add2attachment_list(id, {name:'', html:content, classname:'uploading', complete:false}); // send request rcmail.http_post('plugin.kolab_files', { act: 'attach-file', files: list, id: rcmail.env.compose_id, uploadid: id }); } }; buttons[rcmail.gettext('kolab_files.cancel')] = function () { kolab_dialog_close(this); }; // show dialog window kolab_dialog_show(dialog, { title: rcmail.gettext('kolab_files.selectfiles'), buttons: buttons, button_classes: ['mainaction'], minWidth: 500, minHeight: 300, width: 700, height: 500 }, function() { rcmail.file_list.resize(); }); if (!rcmail.env.files_loaded) { file_api.folder_list(); rcmail.env.files_loaded = true; } else { rcmail.file_list.clear_selection(); } }; function kolab_files_attach_menu_open(p) { if (!p || !p.props || p.props.menu != 'attachmentmenu') return; var id = p.props.id; $('#attachmenusaveas').unbind('click').attr('onclick', '').click(function(e) { return kolab_directory_selector_dialog(id); }); }; // folder creation dialog function kolab_files_folder_create_dialog() { var dialog = $('#files-folder-create-dialog'), buttons = {}, select = $('select[name="parent"]', dialog).html(''), input = $('input[name="name"]', dialog).val(''); buttons[rcmail.gettext('kolab_files.create')] = function () { var folder = '', name = input.val(), parent = select.val(); if (!name) return; if (parent) folder = parent + file_api.env.directory_separator; folder += name; file_api.folder_create(folder); kolab_dialog_close(this); }; buttons[rcmail.gettext('kolab_files.cancel')] = function () { kolab_dialog_close(this); }; // show dialog window kolab_dialog_show(dialog, { title: rcmail.gettext('kolab_files.foldercreate'), buttons: buttons, button_classes: ['mainaction'] }); // Fix submitting form with Enter $('form', dialog).submit(kolab_dialog_submit_handler); // build parent selector select.append($('').text(rcmail.gettext('kolab_files.collection_' + n))) rows.push(row); }); - list.append(rows); + list.append(rows).appendTo(elem) + .on('click', 'a.subscription', function(e) { + return file_api.folder_list_subscription_button_click(this); + }); + + if (rcmail.folder_list) { + rcmail.folder_list.reset(); + this.search_results_widget = null; + } // init treelist widget rcmail.folder_list = new rcube_treelist_widget(list, { selectable: true, id_prefix: 'rcmli', parent_focus: true, searchbox: searchbox, id_encode: rcmail.html_identifier_encode, id_decode: rcmail.html_identifier_decode, check_droptarget: function(node) { return !node.virtual && node.id != file_api.env.folder && $.inArray('collection', node.classes) == -1; } }); rcmail.folder_list .addEventListener('collapse', function(node) { file_api.folder_collapsed(node); }) .addEventListener('expand', function(node) { file_api.folder_collapsed(node); }) .addEventListener('beforeselect', function(node) { return !rcmail.busy; }) - .addEventListener('select', function(node) { file_api.folder_select(node.id); }); + .addEventListener('search', function(search) { file_api.folder_search(search); }) + .addEventListener('select', function(node) { + if (file_api.search_results_widget) + file_api.search_results_widget.select(); + file_api.folder_select(node.id); + }); // select first folder? if (response.result.auth_errors) { } else if (this.env.folder) rcmail.folder_list.select(this.env.folder); else if (this.env.collection) rcmail.folder_list.select('folder-collection-' + this.env.collection); else if (first) rcmail.folder_list.select(first); // add tree icons // this.folder_list_tree(this.env.folders); // handle authentication errors on external sources this.folder_list_auth_errors(response.result); }; this.folder_select = function(folder) { if (rcmail.busy) return; var is_collection = folder.match(/^folder-collection-(.*)$/), collection = RegExp.$1 || null; if (is_collection) folder = null; // search-reset can re-select the same folder, skip if (this.env.folder == folder && this.env.collection == collection) return; this.env.folder = folder; this.env.collection = collection; rcmail.enable_command('files-list', true); rcmail.enable_command('files-folder-delete', 'folder-rename', 'files-upload', !is_collection); rcmail.command('files-list', is_collection ? {collection: collection} : {folder: folder}); this.quota(); }; this.folder_unselect = function() { rcmail.folder_list.select(); this.env.folder = null; this.env.collection = null; rcmail.enable_command('files-folder-delete', 'files-upload', false); }; this.folder_collapsed = function(node) { var prefname = 'kolab_files_collapsed_folders', old = rcmail.env[prefname], entry = '&' + urlencode(node.id) + '&'; if (node.collapsed) { rcmail.env[prefname] = rcmail.env[prefname] + entry; // select the folder if one of its childs is currently selected // don't select if it's virtual (#1488346) if (!node.virtual && this.env.folder && this.env.folder.startsWith(node.id + '/')) { rcmail.folder_list.select(node.id); } } else { rcmail.env[prefname] = rcmail.env[prefname].replace(entry, ''); } if (old !== rcmail.env[prefname] && (!rcmail.file_list || !rcmail.file_list.drag_active)) rcmail.command('save-pref', {name: prefname, value: rcmail.env[prefname]}); }; this.folder_list_row = function(i, folder, parent) { var toggle, sublist, collapsed, parent, parent_name, row = $('
  • '), id = 'rcmli' + rcmail.html_identifier_encode(i); - row.attr('id', id).append($('').text(folder.name)); + row.attr('id', id).append($('').text(folder.name)); if (folder.virtual) row.addClass('virtual'); + else if (folder.subscribed !== undefined) + row.append(this.folder_list_subscription_button(folder.subscribed)); folder.ref = row; if (folder.depth) { // find parent folder parent_name = i.replace(/\/[^/]+$/, ''); if (!parent) parent = $(this.env.folders[parent_name].ref); toggle = $('div.treetoggle', parent); sublist = $('> ul', parent); if (!toggle.length) { collapsed = rcmail.env.kolab_files_collapsed_folders.indexOf('&' + urlencode(parent_name) + '&') > -1; toggle = $('
    ').attr('class', 'treetoggle' + (collapsed ? ' collapsed' : ' expanded')) .html(' ').appendTo(parent); sublist = $('