mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 06:30:59 +01:00
* File selector: implement Overwrite and Rename possibilities for saving an existing email message or attachment
This commit is contained in:
parent
07272a9174
commit
4619d55045
@ -1236,42 +1236,68 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend(
|
||||
// define a mini app object for vfs select UI
|
||||
app.vfsSelectUI = new app.classes.vfsSelectUI;
|
||||
|
||||
this.dialog = et2_createWidget("dialog",
|
||||
// callback for dialog
|
||||
this.submit_callback = function(submit_button_id, submit_value, savemode)
|
||||
{
|
||||
callback: function(_button_id, _value)
|
||||
{
|
||||
if ((_button_id == 'submit' || (extra_buttons_action && extra_buttons_action[_button_id])) && _value)
|
||||
if ((submit_button_id == 'submit' || (extra_buttons_action && extra_buttons_action[submit_button_id])) && submit_value)
|
||||
{
|
||||
var files = [];
|
||||
switch(_data.content.mode)
|
||||
{
|
||||
case 'open-multiple':
|
||||
if (_value.dir && _value.dir.selected)
|
||||
if (submit_value.dir && submit_value.dir.selected)
|
||||
{
|
||||
for(var key in Object.keys(_value.dir.selected))
|
||||
for(var key in Object.keys(submit_value.dir.selected))
|
||||
{
|
||||
if (_value.dir.selected[key] != "")
|
||||
if (submit_value.dir.selected[key] != "")
|
||||
{
|
||||
files.push(_value.path+'/'+_value.dir.selected[key]);
|
||||
files.push(submit_value.path+'/'+submit_value.dir.selected[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'select-dir':
|
||||
files = _value.path;
|
||||
files = submit_value.path;
|
||||
break;
|
||||
default:
|
||||
if (self.options.method === 'download') _value.path = _data.content.download_baseUrl;
|
||||
files = _value.path+'/'+_value.name;
|
||||
if (self.options.method === 'download') submit_value.path = _data.content.download_baseUrl;
|
||||
files = submit_value.path+'/'+submit_value.name;
|
||||
if (self.options.method !== 'download' && !savemode)
|
||||
{
|
||||
for(var p in _data.content.dir)
|
||||
{
|
||||
if (_data.content.dir[p]['name'] == submit_value.name)
|
||||
{
|
||||
var saveModeDialogButtons = [
|
||||
{text: self.egw().lang("Yes"), id: "overwrite", class: "ui-priority-primary", "default": true, image: 'check'},
|
||||
{text: self.egw().lang("Rename"), id:"rename", image: 'edit'},
|
||||
{text: self.egw().lang("Cancel"), id:"cancel"}
|
||||
];
|
||||
return et2_dialog.show_prompt(function(_button_id, _value) {
|
||||
switch (_button_id)
|
||||
{
|
||||
case "overwrite":
|
||||
return self.submit_callback(submit_button_id, submit_value, 'overwrite');
|
||||
case "rename":
|
||||
submit_value.name = _value;
|
||||
return self.submit_callback(submit_button_id, submit_value, 'rename');
|
||||
}
|
||||
},
|
||||
self.egw().lang('Do you want to overwrite existing file %1 in directory %2?', submit_value.name, submit_value.path),
|
||||
self.egw().lang('File %1 already exists', submit_value.name),
|
||||
submit_value.name, saveModeDialogButtons);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
self._setRecentPaths(_value.path);
|
||||
self._setRecentPaths(submit_value.path);
|
||||
self.value = files;
|
||||
if (self.options.method && self.options.method !== 'download')
|
||||
{
|
||||
egw(window).json(
|
||||
self.options.method,
|
||||
[self.options.method_id, files, _button_id],
|
||||
[self.options.method_id, files, submit_button_id, savemode],
|
||||
function(){
|
||||
jQuery(self.node).change();
|
||||
}
|
||||
@ -1284,7 +1310,11 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend(
|
||||
delete app.vfsSelectUI;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.dialog = et2_createWidget("dialog",
|
||||
{
|
||||
callback: this.submit_callback,
|
||||
title: this.options.dialog_title,
|
||||
buttons: buttons,
|
||||
minWidth: 500,
|
||||
|
@ -2813,18 +2813,22 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
* action => string
|
||||
* )
|
||||
* @param string $path path to save the emails
|
||||
* @param string $submit_button_id dialog button id of triggered submit
|
||||
* @param string $savemode save mode: 'overwrite' or 'rename'
|
||||
*/
|
||||
function ajax_vfsSave ($params,$path)
|
||||
function ajax_vfsSave ($params, $path, $submit_button_id, $savemode)
|
||||
{
|
||||
unset($submit_button_id); // not used here
|
||||
|
||||
$response = Api\Json\Response::get();
|
||||
|
||||
switch ($params['action'])
|
||||
{
|
||||
case 'message':
|
||||
$result = $this->vfsSaveMessages($params['ids'], $path);
|
||||
$result = $this->vfsSaveMessages($params['ids'], $path, $savemode);
|
||||
break;
|
||||
case 'attachment':
|
||||
$result = $this->vfsSaveAttachments($params['ids'], $path);
|
||||
$result = $this->vfsSaveAttachments($params['ids'], $path, $savemode);
|
||||
break;
|
||||
}
|
||||
$response->call('app.mail.vfsSaveCallback', $result);
|
||||
@ -2835,6 +2839,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
*
|
||||
* @param string|array $ids use splitRowID, to separate values
|
||||
* @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array)
|
||||
* @param string $savemode save mode: 'overwrite' or 'rename'
|
||||
*
|
||||
* @return array returns an array including message and success result
|
||||
* array (
|
||||
@ -2842,7 +2847,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
* 'success' => BOOLEAN
|
||||
* )
|
||||
*/
|
||||
function vfsSaveMessages($ids,$path)
|
||||
function vfsSaveMessages($ids,$path, $savemode)
|
||||
{
|
||||
// add mail translation
|
||||
Api\Translation::add_app('mail');
|
||||
@ -2884,6 +2889,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
$file = $dir . '/' . mail_bo::clean_subject_for_filename(str_replace($dir.'/', '', $path));
|
||||
}
|
||||
|
||||
if ($savemode != 'overwrite')
|
||||
{
|
||||
// Check if file already exists, then try to assign a none existance filename
|
||||
$counter = 1;
|
||||
$tmp_file = $file;
|
||||
@ -2895,6 +2902,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
$counter++;
|
||||
}
|
||||
$file = $tmp_file;
|
||||
}
|
||||
|
||||
if (!($fp = Vfs::fopen($file,'wb')) || !fwrite($fp,$message))
|
||||
{
|
||||
@ -2927,6 +2935,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
*
|
||||
* @param string|array $ids '::' delimited mailbox::uid::part-id::is_winmail::name (::name for multiple id's)
|
||||
* @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array)
|
||||
* @param string $savemode save mode: 'overwrite' or 'rename'
|
||||
*
|
||||
* @return array returns an array including message and success result
|
||||
* array (
|
||||
@ -2934,7 +2943,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
* 'success' => BOOLEAN
|
||||
* )
|
||||
*/
|
||||
function vfsSaveAttachments($ids,$path)
|
||||
function vfsSaveAttachments($ids,$path, $savemode)
|
||||
{
|
||||
$res = array (
|
||||
'msg' => lang('Attachment has been saved successfully.'),
|
||||
@ -3032,6 +3041,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
|
||||
$file = $dir. '/' . ($filename ? $filename : mail_bo::clean_subject_for_filename($attachment['filename']));
|
||||
|
||||
if ($savemode != 'overwrite')
|
||||
{
|
||||
$counter = 1;
|
||||
$tmp_file = $file;
|
||||
while (Vfs::file_exists($tmp_file))
|
||||
@ -3042,6 +3053,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
||||
$counter++;
|
||||
}
|
||||
$file = $tmp_file;
|
||||
}
|
||||
|
||||
if (!($fp = Vfs::fopen($file,'wb')) ||
|
||||
!fwrite($fp,$attachment['attachment']))
|
||||
|
Loading…
Reference in New Issue
Block a user