Add per-attachment "Save as" dialog, css improvements
This commit is contained in:
parent
f5cc6d2618
commit
e73a2200e1
6 changed files with 103 additions and 19 deletions
|
@ -44,6 +44,8 @@ window.rcmail && rcmail.addEventListener('init', function() {
|
|||
.click(function() { kolab_directory_selector_dialog(); })
|
||||
.appendTo(attachment_list);
|
||||
}
|
||||
|
||||
rcmail.addEventListener('menu-open', kolab_files_attach_menu_open);
|
||||
}
|
||||
|
||||
kolab_files_init();
|
||||
|
@ -118,18 +120,40 @@ function kolab_files_token()
|
|||
/********* Plugin functionality in other tasks **********/
|
||||
/**********************************************************/
|
||||
|
||||
function kolab_directory_selector_dialog()
|
||||
function kolab_directory_selector_dialog(id)
|
||||
{
|
||||
var dialog = $('#files-dialog'), buttons = {};
|
||||
var dialog = $('#files-dialog'), buttons = {},
|
||||
input = $('#file-save-as-input'),
|
||||
form = $('#file-save-as'),
|
||||
list = $('#folderlistbox');
|
||||
|
||||
// attachment is specified
|
||||
if (id) {
|
||||
var attach = $('#attach'+id), filename = attach.attr('title') || attach.text();
|
||||
form.show();
|
||||
dialog.addClass('saveas');
|
||||
input.val(filename);
|
||||
}
|
||||
else {
|
||||
form.hide();
|
||||
dialog.removeClass('saveas');
|
||||
}
|
||||
|
||||
buttons[rcmail.gettext('kolab_files.save')] = function () {
|
||||
var lock = rcmail.set_busy(true, 'saving');
|
||||
rcmail.http_post('plugin.kolab_files', {
|
||||
act: 'saveall',
|
||||
source: rcmail.env.mailbox,
|
||||
uid: rcmail.env.uid,
|
||||
dest: file_api.env.folder
|
||||
}, lock);
|
||||
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);
|
||||
$('#files-dialog').dialog('destroy').hide();
|
||||
};
|
||||
buttons[rcmail.gettext('kolab_files.cancel')] = function () {
|
||||
|
@ -141,7 +165,7 @@ function kolab_directory_selector_dialog()
|
|||
modal: true,
|
||||
resizable: !bw.ie6,
|
||||
closeOnEscape: (!bw.ie6 && !bw.ie7), // disable for performance reasons
|
||||
title: rcmail.gettext('kolab_files.saveall'),
|
||||
title: rcmail.gettext('kolab_files.' + (id ? 'saveto' : 'saveall')),
|
||||
// close: function() { rcmail.dialog_close(); },
|
||||
buttons: buttons,
|
||||
minWidth: 250,
|
||||
|
@ -177,7 +201,7 @@ function kolab_files_selector_dialog()
|
|||
|
||||
// send request
|
||||
rcmail.http_post('plugin.kolab_files', {
|
||||
act: 'attach',
|
||||
act: 'attach-file',
|
||||
folder: file_api.env.folder,
|
||||
files: list,
|
||||
id: rcmail.env.compose_id,
|
||||
|
@ -211,6 +235,17 @@ function kolab_files_selector_dialog()
|
|||
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);
|
||||
});
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
/********** Main functionality **********/
|
||||
|
|
|
@ -53,6 +53,19 @@ class kolab_files_engine
|
|||
}
|
||||
else if ($this->rc->action == 'show' || $this->rc->action == 'preview') {
|
||||
$template = 'message_plugin';
|
||||
|
||||
// add "Save as" button into attachment menu
|
||||
$this->plugin->add_button(array(
|
||||
'id' => 'attachmenusaveas',
|
||||
'name' => 'attachmenusaveas',
|
||||
'type' => 'link',
|
||||
'wrapper' => 'li',
|
||||
'onclick' => 'return false',
|
||||
'class' => 'icon active saveas',
|
||||
'classact' => 'icon active saveas',
|
||||
'innerclass' => 'icon active saveas',
|
||||
'label' => 'kolab_files.saveto',
|
||||
), 'attachmentmenu');
|
||||
}
|
||||
}
|
||||
else if ($this->rc->task == 'files') {
|
||||
|
@ -495,11 +508,13 @@ class kolab_files_engine
|
|||
/**
|
||||
* Handler for "save all attachments into cloud" action
|
||||
*/
|
||||
protected function action_saveall()
|
||||
protected function action_save_file()
|
||||
{
|
||||
$source = rcube_utils::get_input_value('source', rcube_utils::INPUT_POST);
|
||||
$uid = rcube_utils::get_input_value('uid', rcube_utils::INPUT_POST);
|
||||
$dest = rcube_utils::get_input_value('dest', rcube_utils::INPUT_POST);
|
||||
$id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST);
|
||||
$name = rcube_utils::get_input_value('name', rcube_utils::INPUT_POST);
|
||||
|
||||
$temp_dir = unslashify($this->rc->config->get('temp_dir'));
|
||||
$storage = $this->rc->get_storage();
|
||||
|
@ -508,18 +523,25 @@ class kolab_files_engine
|
|||
$url = $request->getUrl();
|
||||
$files = array();
|
||||
$errors = array();
|
||||
$attachments = array();
|
||||
|
||||
$request->setMethod(HTTP_Request2::METHOD_POST);
|
||||
$request->setHeader('X-Session-Token', $this->get_api_token());
|
||||
$url->setQueryVariables(array('method' => 'file_create', 'folder' => $dest));
|
||||
$request->setUrl($url);
|
||||
|
||||
foreach ($message->attachments as $attach_prop) {
|
||||
if (empty($id) || $id == $attach_prop->mime_id) {
|
||||
$filename = strlen($name) ? $name : rcmail_attachment_name($attach_prop, true);
|
||||
$attachments[$filename] = $attach_prop;
|
||||
}
|
||||
}
|
||||
|
||||
// @TODO: handle error
|
||||
// @TODO: implement file upload using file URI instead of body upload
|
||||
|
||||
foreach ($message->attachments as $attach_prop) {
|
||||
$filename = rcmail_attachment_name($attach_prop, true);
|
||||
$path = tempnam($temp_dir, 'rcmAttmnt');
|
||||
foreach ($attachments as $attach_name => $attach_prop) {
|
||||
$path = tempnam($temp_dir, 'rcmAttmnt');
|
||||
|
||||
// save attachment to file
|
||||
if ($fp = fopen($path, 'w+')) {
|
||||
|
@ -539,13 +561,13 @@ class kolab_files_engine
|
|||
// send request to the API
|
||||
try {
|
||||
$request->setBody('');
|
||||
$request->addUpload('file[]', $path, $filename, $attach_prop->mimetype);
|
||||
$request->addUpload('file[]', $path, $attach_name, $attach_prop->mimetype);
|
||||
$response = $request->send();
|
||||
$status = $response->getStatus();
|
||||
$body = @json_decode($response->getBody(), true);
|
||||
|
||||
if ($status == 200 && $body['status'] == 'OK') {
|
||||
$files[] = $filename;
|
||||
$files[] = $attach_name;
|
||||
}
|
||||
else {
|
||||
throw new Exception($body['reason']);
|
||||
|
@ -583,7 +605,7 @@ class kolab_files_engine
|
|||
/**
|
||||
* Handler for "add attachments from the cloud" action
|
||||
*/
|
||||
protected function action_attach()
|
||||
protected function action_attach_file()
|
||||
{
|
||||
$folder = rcube_utils::get_input_value('folder', rcube_utils::INPUT_POST);
|
||||
$files = rcube_utils::get_input_value('files', rcube_utils::INPUT_POST);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
$labels['files'] = 'Files';
|
||||
$labels['saveall'] = 'Save all to cloud...';
|
||||
$labels['saveto'] = 'Save to cloud...';
|
||||
$labels['saveas'] = 'Save as:';
|
||||
$labels['save'] = 'Save';
|
||||
$labels['cancel'] = 'Cancel';
|
||||
$labels['fromcloud'] = 'From cloud...';
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.7 KiB |
|
@ -192,14 +192,18 @@
|
|||
}
|
||||
|
||||
#files-dialog #folderlistbox {
|
||||
bottom: 5px;
|
||||
top: 5px;
|
||||
bottom: 5px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: auto;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#files-dialog.saveas #folderlistbox {
|
||||
top: 50px;
|
||||
}
|
||||
|
||||
#files-compose-dialog #filelistcontainer {
|
||||
position: absolute;
|
||||
top: 45px;
|
||||
|
@ -226,6 +230,10 @@
|
|||
width: 15px;
|
||||
}
|
||||
|
||||
#files-compose-dialog .searchbox input {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#files-compose-dialog #quicksearchbar {
|
||||
top: 10px;
|
||||
right: 5px;
|
||||
|
@ -240,3 +248,16 @@ a.filesaveall {
|
|||
margin-top: .5em;
|
||||
padding: 3px 5px 4px 5px;
|
||||
}
|
||||
|
||||
#file-save-as {
|
||||
height: 25px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#file-save-as input {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
ul.toolbarmenu li span.saveas {
|
||||
background: url(images/buttons.png) -5px -180px no-repeat;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<div id="files-dialog" class="uidialog">
|
||||
<div id="file-save-as">
|
||||
<label for="file-save-as-input"><roundcube:label name="kolab_files.saveas" /></label>
|
||||
<input id="file-save-as-input" type="text" value="">
|
||||
</div>
|
||||
<div id="folderlistbox" class="uibox listbox">
|
||||
<div id="files-folder-list" class="scroller withfooter"></div>
|
||||
<div id="folderlist-footer" class="boxfooter">
|
||||
|
|
Loading…
Add table
Reference in a new issue