mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +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
|
// define a mini app object for vfs select UI
|
||||||
app.vfsSelectUI = new app.classes.vfsSelectUI;
|
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 ((submit_button_id == 'submit' || (extra_buttons_action && extra_buttons_action[submit_button_id])) && submit_value)
|
||||||
{
|
|
||||||
if ((_button_id == 'submit' || (extra_buttons_action && extra_buttons_action[_button_id])) && _value)
|
|
||||||
{
|
{
|
||||||
var files = [];
|
var files = [];
|
||||||
switch(_data.content.mode)
|
switch(_data.content.mode)
|
||||||
{
|
{
|
||||||
case 'open-multiple':
|
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;
|
break;
|
||||||
case 'select-dir':
|
case 'select-dir':
|
||||||
files = _value.path;
|
files = submit_value.path;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (self.options.method === 'download') _value.path = _data.content.download_baseUrl;
|
if (self.options.method === 'download') submit_value.path = _data.content.download_baseUrl;
|
||||||
files = _value.path+'/'+_value.name;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
self._setRecentPaths(_value.path);
|
self._setRecentPaths(submit_value.path);
|
||||||
self.value = files;
|
self.value = files;
|
||||||
if (self.options.method && self.options.method !== 'download')
|
if (self.options.method && self.options.method !== 'download')
|
||||||
{
|
{
|
||||||
egw(window).json(
|
egw(window).json(
|
||||||
self.options.method,
|
self.options.method,
|
||||||
[self.options.method_id, files, _button_id],
|
[self.options.method_id, files, submit_button_id, savemode],
|
||||||
function(){
|
function(){
|
||||||
jQuery(self.node).change();
|
jQuery(self.node).change();
|
||||||
}
|
}
|
||||||
@ -1284,7 +1310,11 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend(
|
|||||||
delete app.vfsSelectUI;
|
delete app.vfsSelectUI;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
this.dialog = et2_createWidget("dialog",
|
||||||
|
{
|
||||||
|
callback: this.submit_callback,
|
||||||
title: this.options.dialog_title,
|
title: this.options.dialog_title,
|
||||||
buttons: buttons,
|
buttons: buttons,
|
||||||
minWidth: 500,
|
minWidth: 500,
|
||||||
|
@ -2813,18 +2813,22 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
* action => string
|
* action => string
|
||||||
* )
|
* )
|
||||||
* @param string $path path to save the emails
|
* @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();
|
$response = Api\Json\Response::get();
|
||||||
|
|
||||||
switch ($params['action'])
|
switch ($params['action'])
|
||||||
{
|
{
|
||||||
case 'message':
|
case 'message':
|
||||||
$result = $this->vfsSaveMessages($params['ids'], $path);
|
$result = $this->vfsSaveMessages($params['ids'], $path, $savemode);
|
||||||
break;
|
break;
|
||||||
case 'attachment':
|
case 'attachment':
|
||||||
$result = $this->vfsSaveAttachments($params['ids'], $path);
|
$result = $this->vfsSaveAttachments($params['ids'], $path, $savemode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$response->call('app.mail.vfsSaveCallback', $result);
|
$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|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 $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
|
* @return array returns an array including message and success result
|
||||||
* array (
|
* array (
|
||||||
@ -2842,7 +2847,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
* 'success' => BOOLEAN
|
* 'success' => BOOLEAN
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
function vfsSaveMessages($ids,$path)
|
function vfsSaveMessages($ids,$path, $savemode)
|
||||||
{
|
{
|
||||||
// add mail translation
|
// add mail translation
|
||||||
Api\Translation::add_app('mail');
|
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));
|
$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
|
// Check if file already exists, then try to assign a none existance filename
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
$tmp_file = $file;
|
$tmp_file = $file;
|
||||||
@ -2895,6 +2902,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
$file = $tmp_file;
|
$file = $tmp_file;
|
||||||
|
}
|
||||||
|
|
||||||
if (!($fp = Vfs::fopen($file,'wb')) || !fwrite($fp,$message))
|
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|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 $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
|
* @return array returns an array including message and success result
|
||||||
* array (
|
* array (
|
||||||
@ -2934,7 +2943,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
* 'success' => BOOLEAN
|
* 'success' => BOOLEAN
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
function vfsSaveAttachments($ids,$path)
|
function vfsSaveAttachments($ids,$path, $savemode)
|
||||||
{
|
{
|
||||||
$res = array (
|
$res = array (
|
||||||
'msg' => lang('Attachment has been saved successfully.'),
|
'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']));
|
$file = $dir. '/' . ($filename ? $filename : mail_bo::clean_subject_for_filename($attachment['filename']));
|
||||||
|
|
||||||
|
if ($savemode != 'overwrite')
|
||||||
|
{
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
$tmp_file = $file;
|
$tmp_file = $file;
|
||||||
while (Vfs::file_exists($tmp_file))
|
while (Vfs::file_exists($tmp_file))
|
||||||
@ -3042,6 +3053,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
$file = $tmp_file;
|
$file = $tmp_file;
|
||||||
|
}
|
||||||
|
|
||||||
if (!($fp = Vfs::fopen($file,'wb')) ||
|
if (!($fp = Vfs::fopen($file,'wb')) ||
|
||||||
!fwrite($fp,$attachment['attachment']))
|
!fwrite($fp,$attachment['attachment']))
|
||||||
|
Loading…
Reference in New Issue
Block a user