if rename of file fails, the rename is undone in the view - #fix 2820
Changes: * OC.dialog -> OC.Notification * Added test * Fixed OC.Notification.show() issue for queued items * Highlight failed item and show notification
This commit is contained in:
parent
ab411d2700
commit
e0547a25ab
4 changed files with 40 additions and 9 deletions
|
@ -208,13 +208,44 @@ var FileList={
|
||||||
if (FileList.checkName(name, newname, false)) {
|
if (FileList.checkName(name, newname, false)) {
|
||||||
newname = name;
|
newname = name;
|
||||||
} else {
|
} else {
|
||||||
$.get(OC.filePath('files','ajax','rename.php'), { dir : $('#dir').val(), newname: newname, file: name },function(result) {
|
// save background image, because it's replaced by a spinner while async request
|
||||||
if (!result || result.status == 'error') {
|
var oldBackgroundImage = td.css('background-image');
|
||||||
OC.dialogs.alert(result.data.message, 'Error moving file');
|
// mark as loading
|
||||||
|
td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
||||||
|
$.ajax({
|
||||||
|
url: OC.filePath('files','ajax','rename.php'),
|
||||||
|
data: {
|
||||||
|
dir : $('#dir').val(),
|
||||||
|
newname: newname,
|
||||||
|
file: name
|
||||||
|
},
|
||||||
|
success: function(result) {
|
||||||
|
if (!result || result.status === 'error') {
|
||||||
|
OC.Notification.show(result.data.message);
|
||||||
newname = name;
|
newname = name;
|
||||||
|
// revert changes
|
||||||
|
tr.attr('data-file', newname);
|
||||||
|
var path = td.children('a.name').attr('href');
|
||||||
|
td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname)));
|
||||||
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
|
var basename=newname.substr(0,newname.lastIndexOf('.'));
|
||||||
|
} else {
|
||||||
|
var basename=newname;
|
||||||
|
}
|
||||||
|
td.find('a.name span.nametext').text(basename);
|
||||||
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
|
if (td.find('a.name span.extension').length === 0 ) {
|
||||||
|
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
||||||
|
}
|
||||||
|
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
||||||
|
}
|
||||||
|
tr.find('.fileactions').effect('highlight', {}, 5000);
|
||||||
|
tr.effect('highlight', {}, 5000);
|
||||||
|
}
|
||||||
|
// remove loading mark and recover old image
|
||||||
|
td.css('background-image', oldBackgroundImage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tr.data('renaming',false);
|
tr.data('renaming',false);
|
||||||
|
|
|
@ -70,7 +70,7 @@ class App {
|
||||||
} else {
|
} else {
|
||||||
// rename failed
|
// rename failed
|
||||||
$result['data'] = array(
|
$result['data'] = array(
|
||||||
'message' => $this->l10n->t('Unable to rename file')
|
'message' => $this->l10n->t('%s could not be renamed', array($oldname))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$result = $this->files->rename($dir, $oldname, $newname);
|
$result = $this->files->rename($dir, $oldname, $newname);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'data' => array('message' => 'Unable to rename file')
|
'data' => array('message' => '%s could not be renamed')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
|
@ -349,10 +349,10 @@ OC.Notification={
|
||||||
},
|
},
|
||||||
show: function(text) {
|
show: function(text) {
|
||||||
if(($('#notification').filter('span.undo').length == 1) || OC.Notification.isHidden()){
|
if(($('#notification').filter('span.undo').length == 1) || OC.Notification.isHidden()){
|
||||||
$('#notification').html(text);
|
$('#notification').text(text);
|
||||||
$('#notification').fadeIn().css("display","inline");
|
$('#notification').fadeIn().css("display","inline");
|
||||||
}else{
|
}else{
|
||||||
OC.Notification.queuedNotifications.push($(text).html());
|
OC.Notification.queuedNotifications.push($('<div/>').text(text).html());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isHidden: function() {
|
isHidden: function() {
|
||||||
|
|
Loading…
Reference in a new issue