Skip to content

Commit

Permalink
Ensure text has been converted before clearing textarea information
Browse files Browse the repository at this point in the history
Otherwise a network/server error can cause the existing compose data
to be lost.
  • Loading branch information
slusarz committed Mar 14, 2014
1 parent 1b9ba57 commit e4b656d
Showing 1 changed file with 52 additions and 47 deletions.
99 changes: 52 additions & 47 deletions imp/js/compose-dimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,70 +401,33 @@ var DimpCompose = {
return this.toggleHtmlEditor.bind(this, noupdate).delay(0.1);
}

if (ImpComposeBase.editor_on) {
this.RTELoading('show');
this.RTELoading('show');

if (ImpComposeBase.editor_on) {
action = 'html2Text',
params.set('body', {
changed: Number(this.msgHash() != this.hash_msgOrig),
text: this.rte.getData()
});

this.rte.destroy(true);
delete this.rte;

if ($('signature') && (this.sigHash() != this.hash_sigOrig)) {
sigChanged = true;
params.set('sig', {
changed: 1,
text: ImpComposeBase.rte.getData()
});
}
} else {
this.RTELoading('show');

} else if (!noupdate) {
action = 'text2Html';

if (!noupdate) {
tmp = $F('composeMessage');
if (!tmp.blank()) {
params.set('body', {
changed: Number(this.msgHash() != this.hash_msgOrig),
text: tmp
});
}
}

if (Object.isUndefined(this.rte_loaded)) {
CKEDITOR.on('instanceReady', function(evt) {
this.RTELoading('hide');
this.rte.focus();
this.rte_loaded = true;
this.resizeMsgArea();

new CKEDITOR.dom.document(
evt.editor.getThemeSpace('contents').$.down('IFRAME').contentWindow.document)
.on('keydown', function(evt) {
this.keydownHandler(Event.extend(evt.data.$), true);
}.bind(this));
}.bind(this));
CKEDITOR.on('instanceDestroyed', function(evt) {
this.RTELoading('hide');
this.rte_loaded = false;
}.bind(this));
tmp = $F('composeMessage');
if (!tmp.blank()) {
params.set('body', {
changed: Number(this.msgHash() != this.hash_msgOrig),
text: tmp
});
}

this.rte = CKEDITOR.replace('composeMessage', Object.clone(IMP.ckeditor_config));
this.rte.on('getData', function(evt) {
var elt = new Element('SPAN').insert(evt.data.dataValue),
elts = elt.select('IMG[dropatc_id]');
if (elts.size()) {
elts.invoke('writeAttribute', 'dropatc_id', null);
elts.invoke('writeAttribute', 'src', null);
evt.data.dataValue = elt.innerHTML;
}
}.bind(this));

if ($('signature')) {
tmp = $F('signature');
if (!tmp.blank() && (this.sigHash() != this.hash_sigOrig)) {
Expand All @@ -482,8 +445,10 @@ var DimpCompose = {
data: Object.toJSON(params)
}), {
ajaxopts: { asynchronous: false },
callback: this.setMessageText.bind(this, action == 'text2Html')
callback: this.setMessageText.bind(this, !ImpComposeBase.editor_on)
});
} else {
this.rteInit(!ImpComposeBase.editor_on);
}

ImpComposeBase.editor_on = !ImpComposeBase.editor_on;
Expand Down Expand Up @@ -569,6 +534,8 @@ var DimpCompose = {
);
}

this.rteInit(rte);

if (this.rte_loaded && rte) {
this.rte.setData(r.text.body);
} else if (!this.rte_loaded && !rte) {
Expand All @@ -585,6 +552,44 @@ var DimpCompose = {
this.resizeMsgArea();
},

rteInit: function(rte)
{
if (rte && !this.rte) {
if (Object.isUndefined(this.rte_loaded)) {
CKEDITOR.on('instanceReady', function(evt) {
this.RTELoading('hide');
this.rte.focus();
this.rte_loaded = true;
this.resizeMsgArea();

new CKEDITOR.dom.document(
evt.editor.getThemeSpace('contents').$.down('IFRAME').contentWindow.document)
.on('keydown', function(evt) {
this.keydownHandler(Event.extend(evt.data.$), true);
}.bind(this));
}.bind(this));
CKEDITOR.on('instanceDestroyed', function(evt) {
this.RTELoading('hide');
this.rte_loaded = false;
}.bind(this));
}

this.rte = CKEDITOR.replace('composeMessage', Object.clone(IMP.ckeditor_config));
this.rte.on('getData', function(evt) {
var elt = new Element('SPAN').insert(evt.data.dataValue),
elts = elt.select('IMG[dropatc_id]');
if (elts.size()) {
elts.invoke('writeAttribute', 'dropatc_id', null);
elts.invoke('writeAttribute', 'src', null);
evt.data.dataValue = elt.innerHTML;
}
}.bind(this));
} else if (!rte && this.rte) {
this.rte.destroy(true);
delete this.rte;
}
},

// ob = addr, body, format, identity, opts, subject, type
// ob.opts = auto, focus, fwd_list, noupdate, priority, readreceipt,
// reply_lang, reply_recip, reply_list_id, show_editor
Expand Down

0 comments on commit e4b656d

Please sign in to comment.