Skip to content

Commit

Permalink
[cmd:edit] to be able to "Save as" when save failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Sep 1, 2017
1 parent 18ca4d1 commit da747c4
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions js/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ elFinder.prototype.commands.edit = function() {
save = function() {
var encord = selEncoding? selEncoding.val():void(0),
conf;
ta.one('_savefail', function() {
ta.off('_savedone');
dialogNode.show().find('button.elfinder-btncnt-0,button.elfinder-btncnt-1').hide();
}).one('_savedone', function() {
ta.off('_savefail');
});
if (ta.editor) {
ta.editor.save(ta[0], ta.editor.instance);
conf = ta.editor.confObj;
Expand All @@ -90,12 +96,18 @@ elFinder.prototype.commands.edit = function() {
ta.elfinderdialog('close');
},
savecl = function() {
ta.one('_savedone', function() {
dialogNode.show();
cancel();
});
save();
cancel();
dialogNode.hide();
},
saveAs = function() {
var prevOld = old,
phash = fm.file(file.phash)? file.phash : fm.cwd().hash,
fail = function() {
dialogs.fadeIn();
old = prevOld;
fm.disable();
ta.addClass(clsEditing);
Expand All @@ -105,7 +117,7 @@ elFinder.prototype.commands.edit = function() {
self.prefix = file.name.replace(/ \d+(\.[^.]+)?$/, '$1');
self.requestCmd = 'mkfile';
self.nextAction = { cmd: 'edit', msg: 'cmdedit' };
self.data = {target : file.phash};
self.data = {target : phash};
$.proxy(fm.res('mixin', 'make'), self)()
.done(function(data) {
if (data.added && data.added.length) {
Expand All @@ -116,14 +128,14 @@ elFinder.prototype.commands.edit = function() {
} else {
fail();
}
dialogs.fadeIn();
})
.fail(fail)
.always(function() {
delete self.mime;
delete self.prefix;
delete self.nextAction;
delete self.data;
dialogs.fadeIn();
});
fm.trigger('unselectfiles', { files: [ file.hash ] });
},
Expand All @@ -133,8 +145,8 @@ elFinder.prototype.commands.edit = function() {
ta.removeClass(clsEditing);
fm.enable();

if (fm.searchStatus.state < 2 && file.phash !== fm.cwd().hash) {
reqOpen = fm.exec('open', [file.phash], {thash: file.phash});
if (fm.searchStatus.state < 2 && phash !== fm.cwd().hash) {
reqOpen = fm.exec('open', [phash], {thash: phash});
}

$.when([reqOpen]).done(function() {
Expand Down Expand Up @@ -464,6 +476,7 @@ elFinder.prototype.commands.edit = function() {
},
notify : {type : 'save', cnt : 1},
syncOnFail : true,
preventFail : true,
navigate : {
target : 'changed',
toast : {
Expand All @@ -473,12 +486,14 @@ elFinder.prototype.commands.edit = function() {
})
.fail(function(error) {
dfrd.reject(error);
ta.trigger('_savefail');
})
.done(function(data) {
setTimeout(function(){
ta.focus();
ta.editor && ta.editor.focus(ta[0], ta.editor.instance);
}, 50);
ta.trigger('_savedone');
});
})
.fail(function(error) {
Expand Down

0 comments on commit da747c4

Please sign in to comment.