Skip to content

Commit

Permalink
[cmd:edit] error handling of function getContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Aug 5, 2018
1 parent ef68e27 commit 6e0a787
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
36 changes: 27 additions & 9 deletions js/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ elFinder.prototype.commands.edit = function() {
},
save = function() {
var encord = selEncoding? selEncoding.val():void(0),
saveDfd = $.Deferred().fail(function() {
saveDfd = $.Deferred().fail(function(err) {
dialogNode.show().find('button.elfinder-btncnt-0,button.elfinder-btncnt-1').hide();
}),
conf, res;
Expand All @@ -136,12 +136,20 @@ elFinder.prototype.commands.edit = function() {
if (res.promise) {
res.done(function(data) {
dfrd.notifyWith(ta, [encord, ta.data('hash'), old, saveDfd]);
}).fail(function(err) {
saveDfd.reject(err);
});
} else {
dfrd.notifyWith(ta, [encord, ta.data('hash'), old, saveDfd]);
}
return saveDfd;
},
saveon = function() {
if (!loaded()) { return; }
save().fail(function(err) {
err && fm.error(err);
});
},
cancel = function() {
ta.elfinderdialog('close');
},
Expand All @@ -151,17 +159,20 @@ elFinder.prototype.commands.edit = function() {
_loaded = false;
dialogNode.show();
cancel();
}).fail(function() {
}).fail(function(err) {
dialogNode.show();
err && fm.error(err);
});
dialogNode.hide();
},
saveAs = function() {
if (!loaded()) { return; }
var prevOld = old,
phash = fm.file(file.phash)? file.phash : fm.cwd().hash,
fail = function() {
dialogs.addClass(clsEditing).fadeIn();
fail = function(err) {
dialogs.addClass(clsEditing).fadeIn(function() {
err && fm.error(err);
});
old = prevOld;
fm.disable();
},
Expand Down Expand Up @@ -232,10 +243,13 @@ elFinder.prototype.commands.edit = function() {
hideCnt: true
});
}, 100);
res.done(function(d) {
res.always(function() {
tm && clearTimeout(tm);
fm.notify({ type : 'chkcontent', cnt: -1 });
}).done(function(d) {
dfd.resolve(old !== d);
}).fail(function(err) {
dfd.resolve(err || true);
});
} else {
dfd.resolve(old !== res);
Expand Down Expand Up @@ -283,10 +297,14 @@ elFinder.prototype.commands.edit = function() {
}
};
changed().done(function(change) {
var msgs = ['confirmNotSave'];
if (change) {
if (typeof change === 'string') {
msgs.unshift(change);
}
fm.confirm({
title : self.title,
text : 'confirmNotSave',
text : msgs,
accept : accept,
cancel : {
label : 'btnClose',
Expand Down Expand Up @@ -392,7 +410,7 @@ elFinder.prototype.commands.edit = function() {
focus : typeof editor.focus == 'function' ? editor.focus : function() {},
resize : typeof editor.resize == 'function' ? editor.resize : function() {},
instance : null,
doSave : save,
doSave : saveon,
doCancel : cancel,
doClose : savecl,
file : file,
Expand Down Expand Up @@ -450,7 +468,7 @@ elFinder.prototype.commands.edit = function() {
}
if (code == 'S'.charCodeAt(0)) {
e.preventDefault();
save();
saveon();
}
}

Expand Down Expand Up @@ -514,7 +532,7 @@ elFinder.prototype.commands.edit = function() {
}

if (!editor || !editor.info || !editor.info.preventGet) {
opts.buttons[fm.i18n('btnSave')] = save;
opts.buttons[fm.i18n('btnSave')] = saveon;
opts.buttons[fm.i18n('btnSaveClose')] = savecl;
opts.buttons[fm.i18n('btnSaveAs')] = saveAs;
opts.buttons[fm.i18n('btnCancel')] = cancel;
Expand Down
22 changes: 19 additions & 3 deletions js/extras/editors.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,26 @@
this.receive = function(e) {
var ev = e.originalEvent;
if (ev.origin === orig && ev.source === wnd) {
fm.log(phase);
fm.log(ev);
if (ev.data === 'done') {
if (phase === 0) {
dfdIni.resolve();
} else if (phase === 1) {
phase = 2;
ifm.trigger('contentsloaded');
} else {
if (dfdGet && dfdGet.state() === 'pending') {
dfdGet.reject('errDataEmpty');
}
}
} else {
if (dfdGet && dfdGet.state() === 'pending' && typeof ev.data === 'object') {
dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(ev.data));
if (dfdGet && dfdGet.state() === 'pending') {
if (typeof ev.data === 'object') {
dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(ev.data));
} else {
dfdGet.reject('errDataEmpty');
}
}
}
}
Expand All @@ -745,7 +755,13 @@
liveMsg = this.editor.liveMsg = new confObj.liveMsg(ifm, spnr, file);
$(window).on('message.' + fm.namespace, liveMsg.receive);
liveMsg.load().done(function() {
ifm.attr('src', orig + '/');
var d = JSON.stringify({
files : [],
environment : {
lang: fm.lang.replace(/_/g, '-')
}
});
ifm.attr('src', orig + '/#' + encodeURI(d));
});
},
load : function(base) {
Expand Down

0 comments on commit 6e0a787

Please sign in to comment.