diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js index 81a618f8..a1e02c04 100644 --- a/plugins/kolab_files/kolab_files.js +++ b/plugins/kolab_files/kolab_files.js @@ -1,2276 +1,2329 @@ /** * 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.row_init = function(o){ kolab_files_init_file_row(o); }; - rcmail.file_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); }); - rcmail.file_list.addEventListener('click', function(o){ p.msglist_click(o); }); - rcmail.file_list.addEventListener('keypress', function(o){ p.msglist_keypress(o); }); - rcmail.file_list.addEventListener('dragstart', function(o){ p.drag_start(o); }); - rcmail.file_list.addEventListener('dragmove', function(e){ p.drag_move(e); }); -*/ + 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'), 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 = 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 () { 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: 350, 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 }); 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))) - list.append(row); + rows.push(row); }); + list.append(rows); + + // init treelist widget + rcmail.folder_list = new rcube_treelist_widget(list, { + selectable: true, + id_prefix: 'rcmli', + parent_focus: true, + 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); }); + // select first folder? if (this.env.folder) - this.folder_select(this.env.folder); + rcmail.folder_list.select(this.env.folder); else if (this.env.collection) - this.folder_select(this.env.collection, true); + rcmail.folder_list.select('folder-collection-' + this.env.collection); else if (first) - this.folder_select(first); + rcmail.folder_list.select(first); // add tree icons - this.folder_list_tree(this.env.folders); +// 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, is_collection) + this.folder_select = function(folder) { if (rcmail.busy) return; - var list = $('#files-folder-list > ul'); - - // try parent window if the list element does not exist - // i.e. called from dialog in parent window - if (!list.length && window.parent && parent.rcmail) { - list = $('#files-folder-list > ul', window.parent.document.body); - } - - $('li.selected', list).removeClass('selected'); + var is_collection = folder.match(/^folder-collection-/); rcmail.enable_command('files-list', true); + rcmail.enable_command('files-folder-delete', 'folder-rename', 'files-upload', !is_collection); if (is_collection) { - var found = $('#folder-collection-' + folder, list).addClass('selected'); - - rcmail.enable_command('files-folder-delete', 'folder-rename', 'files-upload', false); this.env.folder = null; - rcmail.command('files-list', {collection: folder}); + rcmail.command('files-list', {collection: folder.replace(/^folder-collection-/, '')}); } else { - var found = $('#' + this.env.folders[folder].id, list).addClass('selected'); - - rcmail.enable_command('files-folder-delete', 'folder-rename', 'files-upload', true); this.env.folder = folder; this.env.collection = null; rcmail.command('files-list', {folder: folder}); } this.quota(); }; this.folder_unselect = function() { - var list = $('#files-folder-list > ul'); - $('li.selected', list).removeClass('selected'); - rcmail.enable_command('files-folder-delete', 'files-upload', false); + rcmail.folder_list.select(); this.env.folder = null; this.env.collection = null; + rcmail.enable_command('files-folder-delete', 'files-upload', false); }; - this.folder_list_row = function(i, folder) + this.folder_collapsed = function(node) { - var row = $('
  • '); + var prefname = 'kolab_files_collapsed_folders', + old = rcmail.env[prefname], + entry = '&' + urlencode(node.id) + '&'; - row.attr('id', folder.id).data('folder', i) - .append($('').text(folder.name)); + if (node.collapsed) { + rcmail.env[prefname] = rcmail.env[prefname] + entry; - if (folder.depth) { - $('span.branch', row).width(15 * folder.depth); - row.addClass('child'); + // 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)); + if (folder.virtual) row.addClass('virtual'); - else - row.attr('tabindex', 0) - .keypress(function(e) { if (e.which == 13 || e.which == 32) file_api.folder_select(i); }) - .click(function() { file_api.folder_select(i); }) - .mouseenter(function() { - if (rcmail.file_list && rcmail.file_list.drag_active && !$(this).hasClass('selected')) - $(this).addClass('droptarget'); - }) - .mouseleave(function() { - if (rcmail.file_list && rcmail.file_list.drag_active) - $(this).removeClass('droptarget'); - }); - return row; + 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 = $('
      ').attr({role: 'group'}).appendTo(parent); + if (collapsed) + sublist.hide(); + } + + sublist.append(row); + } + else { + return row; + } }; // folder create request this.folder_create = function(folder) { this.req = this.set_busy(true, 'kolab_files.foldercreating'); this.request('folder_create', {folder: folder}, 'folder_create_response'); }; // folder create response handler this.folder_create_response = function(response) { if (!this.response(response)) return; this.display_message('kolab_files.foldercreatenotice', 'confirmation'); // refresh folders list this.folder_list(); }; // folder rename request this.folder_rename = function(folder, new_name) { if (folder == new_name) return; this.env.folder_rename = new_name; this.req = this.set_busy(true, 'kolab_files.folderupdating'); this.request('folder_move', {folder: folder, 'new': new_name}, 'folder_rename_response'); }; // folder create response handler this.folder_rename_response = function(response) { if (!this.response(response)) return; this.display_message('kolab_files.folderupdatenotice', 'confirmation'); // refresh folders and files list this.env.folder = this.env.folder_rename; this.folder_list(); }; // folder mount (external storage) request this.folder_mount = function(data) { this.req = this.set_busy(true, 'kolab_files.foldermounting'); this.request('folder_create', data, 'folder_mount_response'); }; // folder create response handler this.folder_mount_response = function(response) { if (!this.response(response)) return; this.display_message('kolab_files.foldermountnotice', 'confirmation'); // refresh folders list this.folder_list(); }; // folder delete request this.folder_delete = function(folder) { this.req = this.set_busy(true, 'kolab_files.folderdeleting'); this.request('folder_delete', {folder: folder}, 'folder_delete_response'); }; // folder delete response handler this.folder_delete_response = function(response) { if (!this.response(response)) return; this.env.folder = null; rcmail.enable_command('files-folder-delete', 'folder-rename', 'files-list', false); this.display_message('kolab_files.folderdeletenotice', 'confirmation'); // refresh folders list this.folder_list(); this.quota(); }; // quota request this.quota = function() { if (rcmail.env.files_quota) this.request('quota', {folder: this.env.folder}, 'quota_response'); }; // quota response handler this.quota_response = function(response) { if (!this.response(response)) return; rcmail.files_set_quota(response.result); }; this.file_list = function(params) { if (!rcmail.gui_objects.filelist) return; if (!params) params = {}; // reset all pending list requests for (i in this.requests) { this.requests[i].abort(); rcmail.hide_message(i); delete this.requests[i]; } if (params.all_folders) { params.collection = null; params.folder = null; this.folder_unselect(); } if (params.collection == undefined) params.collection = this.env.collection; if (params.folder == undefined) params.folder = this.env.folder; if (params.sort == undefined) params.sort = this.env.sort_col; if (params.reverse == undefined) params.reverse = this.env.sort_reverse; if (params.search == undefined) params.search = this.env.search; this.env.folder = params.folder; this.env.collection = params.collection; this.env.sort_col = params.sort; this.env.sort_reverse = params.reverse; rcmail.enable_command(rcmail.env.file_commands, false); rcmail.enable_command(rcmail.env.file_commands_all, false); // empty the list this.env.file_list = []; rcmail.file_list.clear(true); // request if (params.collection || params.all_folders) this.file_list_loop(params); else if (this.env.folder) { params.req_id = this.set_busy(true, 'loading'); this.requests[params.req_id] = this.request('file_list', params, 'file_list_response'); } }; // file list response handler this.file_list_response = function(response) { if (response.req_id) rcmail.hide_message(response.req_id); if (!this.response(response)) return; var i = 0, list = [], table = $('#filelist'); $.each(response.result, function(key, data) { var row = file_api.file_list_row(key, data, ++i); rcmail.file_list.insert_row(row); data.row = row; data.filename = key; list.push(data); }); this.env.file_list = list; rcmail.file_list.resize(); }; // call file_list request for every folder (used for search and virt. collections) this.file_list_loop = function(params) { var i, folders = [], limit = Math.max(this.env.search_threads || 1, 1); if (params.collection) { if (!params.search) params.search = {}; params.search['class'] = params.collection; delete params['collection']; } delete params['all_folders']; $.each(this.env.folders, function(i, f) { if (!f.virtual) folders.push(i); }); this.env.folders_loop = folders; this.env.folders_loop_params = params; this.env.folders_loop_lock = false; for (i=0; i'); this.env.sort_col = col; this.env.sort_reverse = reverse; if (!list || !list.length) return; // sort the list list.sort(function (a, b) { return file_api.sort_compare(a, b); }); // add rows to the new body for (n=0, len=list.length; n' + '' + escapeHTML(data.name) + ''; else if (c == 'mtime') col = '' + data.mtime + ''; else if (c == 'size') col = '' + this.file_size(data.size) + ''; else if (c == 'options') col = ''; else col = ''; row += col; } row = $('') .html(row) .attr({id: 'rcmrow' + index, 'data-file': file, 'data-type': data.type}); $('td.options > span', row).click(function(e) { kolab_files_file_edit_dialog(file); }); // collection (or search) lists files from all folders // display file name with full path as title if (!this.env.folder) $('td.name span', row).attr('title', file); return row.get(0); }; this.file_search = function(value, all_folders) { if (value) { this.env.search = {name: value}; rcmail.command('files-list', {search: this.env.search, all_folders: all_folders}); } else this.search_reset(); }; this.file_search_reset = function() { if (this.env.search) { this.env.search = null; rcmail.command('files-list'); } }; this.file_get = function(file, params) { if (!params) params = {}; params.token = this.env.token; params.file = file; rcmail.redirect(this.env.url + this.url('file_get', params)); }; // file(s) delete request this.file_delete = function(files) { this.req = this.set_busy(true, 'kolab_files.filedeleting'); this.request('file_delete', {file: files}, 'file_delete_response'); }; // file(s) delete response handler this.file_delete_response = function(response) { if (!this.response(response)) return; var rco, dir, self = this; this.display_message('kolab_files.filedeletenotice', 'confirmation'); if (rcmail.env.file) { rco = rcmail.opener(); dir = this.file_path(rcmail.env.file); // check if opener window contains files list, if not we can just close current window if (rco && rco.file_list && (opener.file_api.env.folder == dir || !opener.file_api.env.folder)) self = opener.file_api; else window.close(); } // @TODO: consider list modification "in-place" instead of full reload self.file_list(); self.quota(); if (rcmail.env.file) window.close(); }; // file(s) move request this.file_move = function(files, folder) { if (!files || !files.length || !folder) return; var count = 0, list = {}; $.each(files, function(i, v) { var name = folder + file_api.env.directory_separator + file_api.file_name(v); if (name != v) { list[v] = name; count++; } }); if (!count) return; this.req = this.set_busy(true, 'kolab_files.filemoving'); this.request('file_move', {file: list}, 'file_move_response'); }; // file(s) move response handler this.file_move_response = function(response) { if (!this.response(response)) return; if (response.result && response.result.already_exist && response.result.already_exist.length) this.file_move_ask_user(response.result.already_exist, true); else { this.display_message('kolab_files.filemovenotice', 'confirmation'); this.file_list(); } }; // file(s) copy request this.file_copy = function(files, folder) { if (!files || !files.length || !folder) return; var count = 0, list = {}; $.each(files, function(i, v) { var name = folder + file_api.env.directory_separator + file_api.file_name(v); if (name != v) { list[v] = name; count++; } }); if (!count) return; this.req = this.set_busy(true, 'kolab_files.filecopying'); this.request('file_copy', {file: list}, 'file_copy_response'); }; // file(s) copy response handler this.file_copy_response = function(response) { if (!this.response(response)) return; if (response.result && response.result.already_exist && response.result.already_exist.length) this.file_move_ask_user(response.result.already_exist); else { this.display_message('kolab_files.filecopynotice', 'confirmation'); this.quota(); } }; // when file move/copy operation returns file-exists error // this displays a dialog where user can decide to skip // or overwrite destination file(s) this.file_move_ask_user = function(list, move) { var file = list[0], buttons = {}, text = rcmail.gettext('kolab_files.filemoveconfirm').replace('$file', file.dst) dialog = $('
      '); buttons[rcmail.gettext('kolab_files.fileoverwrite')] = function() { var file = list.shift(), f = {}, action = move ? 'file_move' : 'file_copy'; f[file.src] = file.dst; file_api.file_move_ask_list = list; file_api.file_move_ask_mode = move; dialog.dialog('destroy').remove(); file_api.req = file_api.set_busy(true, move ? 'kolab_files.filemoving' : 'kolab_files.filecopying'); file_api.request(action, {file: f, overwrite: 1}, 'file_move_ask_user_response'); }; if (list.length > 1) buttons[rcmail.gettext('kolab_files.fileoverwriteall')] = function() { var f = {}, action = move ? 'file_move' : 'file_copy'; $.each(list, function() { f[this.src] = this.dst; }); dialog.dialog('destroy').remove(); file_api.req = file_api.set_busy(true, move ? 'kolab_files.filemoving' : 'kolab_files.filecopying'); file_api.request(action, {file: f, overwrite: 1}, action + '_response'); }; var skip_func = function() { list.shift(); dialog.dialog('destroy').remove(); if (list.length) file_api.file_move_ask_user(list, move); else if (move) file_api.file_list(); }; buttons[rcmail.gettext('kolab_files.fileskip')] = skip_func; if (list.length > 1) buttons[rcmail.gettext('kolab_files.fileskipall')] = function() { dialog.dialog('destroy').remove(); if (move) file_api.file_list(); }; // open jquery UI dialog kolab_dialog_show(dialog.html(text), { close: skip_func, buttons: buttons, minWidth: 400, width: 400 }); }; // file move (with overwrite) response handler this.file_move_ask_user_response = function(response) { var move = this.file_move_ask_mode, list = this.file_move_ask_list; this.response(response); if (list && list.length) this.file_move_ask_user(list, mode); else { this.display_message('kolab_files.file' + (move ? 'move' : 'copy') + 'notice', 'confirmation'); if (move) this.file_list(); } }; // file(s) rename request this.file_rename = function(oldfile, newfile) { this.req = this.set_busy(true, 'kolab_files.fileupdating'); this.request('file_move', {file: oldfile, 'new': newfile}, 'file_rename_response'); }; // file(s) move response handler this.file_rename_response = function(response) { if (!this.response(response)) return; // @TODO: we could update metadata instead this.file_list(); }; // file upload request this.file_upload = function(form) { var form = $(form), field = $('input[type=file]', form).get(0), files = field.files ? field.files.length : field.value ? 1 : 0; if (!files || !this.file_upload_size_check(field.files)) return; // submit form and read server response this.file_upload_form(form, 'file_upload', function(event) { var doc, response; try { doc = this.contentDocument ? this.contentDocument : this.contentWindow.document; response = doc.body.innerHTML; // response may be wrapped in
       tag
               if (response.slice(0, 5).toLowerCase() == '
      ' && response.slice(-6).toLowerCase() == '
      ') { response = doc.body.firstChild.firstChild.nodeValue; } response = eval('(' + response + ')'); } catch (err) { response = {status: 'ERROR'}; } file_api.file_upload_progress_stop(event.data.ts); // refresh the list on upload success file_api.file_upload_response(response); }); }; // refresh the list on upload success this.file_upload_response = function(response) { if (this.response_parse(response)) { this.file_list(); this.quota(); } }; // check upload max size this.file_upload_size_check = function(files) { var i, size = 0, maxsize = rcmail.env.files_max_upload; if (maxsize && files) { for (i=0; i < files.length; i++) size += files[i].size || files[i].fileSize; if (size > maxsize) { alert(rcmail.get_label('kolab_files.uploadsizeerror').replace('$size', kolab_files_file_size(maxsize))); return false; } } return true; }; // post the given form to a hidden iframe this.file_upload_form = function(form, action, onload) { var ts = new Date().getTime(), frame_name = 'fileupload' + ts; // upload progress support if (rcmail.env.files_progress_name) { var fname = rcmail.env.files_progress_name, field = $('input[name='+fname+']', form); if (!field.length) { field = $('').attr({type: 'hidden', name: fname}); field.prependTo(form); } field.val(ts); this.file_upload_progress(ts, true); } rcmail.display_progress({name: ts}); // have to do it this way for IE // otherwise the form will be posted to a new window if (document.all) { var html = ''; document.body.insertAdjacentHTML('BeforeEnd', html); } // for standards-compliant browsers else $('