From 2199e5ec5f81ddbfe5eaa0ae17443dc2864783f9 Mon Sep 17 00:00:00 2001 From: Jefferson Stachelski Date: Wed, 28 Oct 2015 17:19:54 -0200 Subject: Issue #493 - Fixed some bug and did some refactors Fixed the nagivation mode when used click to edit recipients and also refactored the code to split the responsability --- web-ui/app/js/mail_view/ui/recipients/recipient.js | 16 +++++++------- .../app/js/mail_view/ui/recipients/recipients.js | 25 ++++++++++++++++++++-- .../mail_view/ui/recipients/recipients_iterator.js | 4 ---- 3 files changed, 31 insertions(+), 14 deletions(-) (limited to 'web-ui/app/js/mail_view') diff --git a/web-ui/app/js/mail_view/ui/recipients/recipient.js b/web-ui/app/js/mail_view/ui/recipients/recipient.js index 2985a9ab..66577f51 100644 --- a/web-ui/app/js/mail_view/ui/recipients/recipient.js +++ b/web-ui/app/js/mail_view/ui/recipients/recipient.js @@ -89,18 +89,18 @@ define( }.bind(this)); }; - this.editRecipient = function(evt) { - var mailAddr = this.$node.find('input[type=hidden]').val(); - // TODO: refactor the code bellow - $('#recipients-to-area').find('input.tt-input').val(mailAddr); - $('#recipients-to-area').find('input.tt-input').focus(); - this.destroy(); - // TODO: fix the bug when edit recipient and click out of the input + this.getMailAddress = function() { + return this.$node.find('input[type=hidden]').val(); }; + this.triggerEditRecipient = function(event, element) { + this.trigger(this.$node.closest('.recipients-area'), events.ui.recipients.clickToEdit, this); + } + this.after('initialize', function () { this.recipientDelActions(); - this.on('click', this.editRecipient); + this.on('click', this.triggerEditRecipient); + if (this.attr.invalidAddress){ this.sinalizeInvalid(); } else { diff --git a/web-ui/app/js/mail_view/ui/recipients/recipients.js b/web-ui/app/js/mail_view/ui/recipients/recipients.js index 7072c09e..3dfd6661 100644 --- a/web-ui/app/js/mail_view/ui/recipients/recipients.js +++ b/web-ui/app/js/mail_view/ui/recipients/recipients.js @@ -46,11 +46,31 @@ define( this.addressesUpdated(); } - function editCurrentRecipient() { - this.attr.iterator.editCurrent(); + function editCurrentRecipient(event, recipient) { + var mailAddr = this.attr.iterator.current().getMailAddress(); + this.attr.iterator.deleteCurrent(); + this.attr.input.$node.val(mailAddr).focus(); + this.unselectAllRecipients(); this.addressesUpdated(); } + this.clickToEditRecipient = function(event, recipient) { + this.attr.iterator = null; + var mailAddr = recipient.getMailAddress(); + + var position = recipient.$node.closest('.recipients-area').find('.fixed-recipient').index(recipient.$node); + this.attr.recipients.splice(position, 1); + recipient.destroy(); + + this.addressesUpdated(); + this.unselectAllRecipients(); + this.attr.input.$node.val(mailAddr).focus(); + }; + + this.unselectAllRecipients = function() { + this.$node.find('.recipient-value.selected').removeClass('selected'); + } + var SPECIAL_KEYS_ACTIONS = { 8: deleteCurrentRecipient, 46: deleteCurrentRecipient, @@ -156,6 +176,7 @@ define( this.on(events.ui.recipients.selectLast, this.selectLastRecipient); this.on(events.ui.recipients.entered, this.recipientEntered); this.on(events.ui.recipients.enteredInvalid, this.invalidRecipientEntered); + this.on(events.ui.recipients.clickToEdit, this.clickToEditRecipient); this.on(document, events.ui.recipients.doCompleteInput, this.doCompleteRecipients); diff --git a/web-ui/app/js/mail_view/ui/recipients/recipients_iterator.js b/web-ui/app/js/mail_view/ui/recipients/recipients_iterator.js index 35741bb7..6c52c52e 100644 --- a/web-ui/app/js/mail_view/ui/recipients/recipients_iterator.js +++ b/web-ui/app/js/mail_view/ui/recipients/recipients_iterator.js @@ -54,10 +54,6 @@ define(['helpers/iterator'], function (Iterator) { this.input.focus(); } }; - - this.editCurrent = function() { - this.iterator.removeCurrent().editRecipient(); - }; } }); -- cgit v1.2.3