Skip to content

Commit

Permalink
Added Mailpile.Composer.Model and QuotedReply and Setup logics
Browse files Browse the repository at this point in the history
  • Loading branch information
bnvk committed Oct 22, 2014
1 parent 3569bb4 commit c4c9971
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions static/default/html/jsapi/compose/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Composer - Body */

// This is rough, and isn't being fully used yet
Mailpile.Composer.Model = {
to: [], // Something like { fn: '', address: '', secure: false}
cc: [],
bcc: [],
subject: '',
body: '',
quoted_reply: '',
attachements: [],
datetime: 0,
crypto: {
encrypt: false,
sign: false,
type: 'openpgp',
email_key: false,
}
};


Mailpile.Composer.Body.Setup = function(mid) {

// Add Autosize
$('#compose-text-' + mid).autosize();

// Is Ephemeral (means .compose-text has quoted_reply)
if (/\breply-all\b/g.test(mid)) {

// Add Quoted to Model
Mailpile.Composer.Drafts[mid].quoted_reply = $('#compose-text-' + mid).val();

// If Quoted Reply disabled, remove from field
if ($('#compose-quoted-reply-' + mid).parent().data('quoted_reply') === 'disabled') {
$('#compose-text-' + mid).val('').trigger('autosize.resize');
}
// Not disabled, add to model
else {
Mailpile.Composer.Drafts[mid].body = $('#compose-text-' + mid).val();
}
}
// Is Draft add to model
else {
Mailpile.Composer.Drafts[mid].body = $('#compose-text-' + mid).val();
}
};


Mailpile.Composer.Body.QuotedReply = function(mid, state) {

$checkbox = $('#compose-quoted-reply-' + mid);

if ($checkbox.is(':checked')) {
$checkbox.val('yes');
}
else {
$checkbox.val('no');

// Check Quoted Setting State
if (state === 'unset' && Mailpile.Composer.Drafts[mid].quoted_reply) {
Mailpile.Composer.Body.QuotedReplySetup();
$('#compose-text-' + mid).val('').trigger('autosize.resize');
}
// Empty body & .compose-text as it's just a quoted reply
else if (Mailpile.Composer.Drafts[mid].body === Mailpile.Composer.Drafts[mid].quoted_reply) {
Mailpile.Composer.Drafts[mid].body = '';
$('#compose-text-' + mid).val('').trigger('autosize.resize');
}
// Replace composer with quoted reply
else if (Mailpile.Composer.Drafts[mid].quoted_reply) {
Mailpile.Composer.Drafts[mid].body = Mailpile.Composer.Drafts[mid].quoted_reply;
$('#compose-text-' + mid).val(Mailpile.Composer.Drafts[mid].quoted_reply).trigger('autosize.resize');
}
}
};


Mailpile.Composer.Body.QuotedReplySetup = function() {
var modal_template = _.template($('#modal-compose-quoted-reply').html());
$('#modal-full').html(modal_template());
$('#modal-full').modal(Mailpile.UI.ModalOptions);
};

0 comments on commit c4c9971

Please sign in to comment.