Skip to content

Commit

Permalink
Ref: clean session storage on save contact
Browse files Browse the repository at this point in the history
  • Loading branch information
henochit committed Oct 17, 2023
1 parent e9de4fa commit 6140ef5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
20 changes: 16 additions & 4 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,31 @@ var add_contact_from_message_view = function() {
}
};

var add_contact_from_popup = function() {
var add_contact_from_popup = function(event) {
event.stopPropagation()
var source = 'local:local';
var contact = $('#contact_info').text().replace('>','').replace('<','');


if (contact) {
var emailRegex = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
var email = contact.match(emailRegex)[0];
var name = contact.replace(emailRegex, "");

var saveContactContent = `<div><table>
<tr><td><strong>Name :</strong></td><td>${name}</td></tr>
<tr><td><strong>Email :</strong></td><td>${email}</td></tr>
<tr><td><strong>Source :</strong></td><td>Local</td></tr>
</table></div>`

Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_add_contact'},
{'name': 'contact_value', 'value': contact},
{'name': 'contact_source', 'value': source}],
function (res) {
$(".popup .show").removeClass('show');
remove_message_content();
window.location.reload();
$("#contact_popup_body").html(saveContactContent);
sessionStorage.removeItem(`${window.location.pathname}imap_4_${hm_list_path()}`);
sessionStorage.removeItem(`${window.location.pathname}${hm_msg_uid()}_${hm_list_path()}`);
}
);
}
Expand Down
12 changes: 7 additions & 5 deletions modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ protected function output() {
$txt .= '<tr class="header_'.$fld.'"><th>'.$this->trans($name).'
</th>
<td>
<div class="popup" onclick="imap_show_add_contact_popup(event)">
<div class="popup" onclick="imap_show_add_contact_popup(event)">
<span id="contact_info">' . $this->html_safe($value) . '
</span>
<img alt="" class="icon_arrow_up" src="'.Hm_Image_Sources::$arrow_drop_up.'" width="20" height="20" />
<img alt="" class="icon_arrow_down" src="'.Hm_Image_Sources::$arrow_drop_down.'" width="20" height="20" />
<div class="popup-container" id="contact_popup">
<div class="popup-container_header">
<a onclick="imap_show_add_contact_popup()">x</a>
</div>';
</div>
<div id="contact_popup_body">';

if($contact_exists){
$txt .= '<div>
Expand Down Expand Up @@ -267,12 +268,13 @@ protected function output() {
</div>';
} else {
$txt .= '<div class="popup-container_footer">
<button onclick="return add_contact_from_popup()" class="add_contact_btn" type="button" value="">'.$this->trans('Add local contacts').'
<button onclick="return add_contact_from_popup(event)" class="add_contact_btn" type="button" value="">'.$this->trans('Add local contacts').'
</button>
</div>';
}

$txt .= ' </div>
$txt .= ' </div>
</div>
</div>
</td>
</tr>';
Expand Down Expand Up @@ -362,7 +364,7 @@ protected function output() {
$txt .= ' | <a class="delete_link hlink" id="delete_message" href="#">'.$this->trans('Delete').'</a>';
$txt .= ' | <a class="hlink" id="copy_message" href="#">'.$this->trans('Copy').'</a>';
$txt .= ' | <a class="hlink" id="move_message" href="#">'.$this->trans('Move').'</a>';
$txt .= ' | <a class="archive_link hlink" id="archive_message" href="#">'.$this->trans('Archive').'</a>';
$txt .= ' | <a class="archive_link hlink" id="archive_message" href="#">'.$this->trans('Archive').'</a>';
$txt .= ' | ' . snooze_dropdown($this, isset($headers['X-Snoozed']));

if ($this->get('sieve_filters_enabled')) {
Expand Down
24 changes: 21 additions & 3 deletions modules/imap/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@


/* Toggle this class - hide and show the popup */
.show > .popup-container {
.show.popup-container {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}

.show > .icon_arrow_up {
.show.icon_arrow_up {
display: block;
}

.show > .icon_arrow_down {
.show.icon_arrow_down {
display: none;
}

Expand All @@ -198,3 +198,21 @@
from {opacity: 0;}
to {opacity:1 ;}
}

@keyframes fadeOut {
0% { opacity: 1; }
100% { opacity: 0; }
}

.fade {
animation-duration: 0.5s;
animation-fill-mode: forwards;
}

.fade-out {
animation-name: fadeOut;
}

.fade-in {
animation-name: fadeIn;
}
20 changes: 12 additions & 8 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ var imap_message_list_content = function(id, folder, hook, batch_callback) {
}

Hm_Message_List.update(ids, res.formatted_message_list, 'imap');

$('.page_links').html(res.page_links);
cache_imap_page();
},
Expand Down Expand Up @@ -793,7 +793,7 @@ var imap_prefetch_message_content = function(uid, server_id, folder) {
var imap_prefetch_msgs = function() {
var detail;
var key;

$(Hm_Utils.get_from_local_storage('formatted_unread_data')).each(function() {
if ($(this).attr('class').match(/^imap/)) {
detail = Hm_Utils.parse_folder_path($(this).attr('class'), 'imap');
Expand Down Expand Up @@ -902,7 +902,7 @@ var imap_move_copy = function(e, action, context) {
folders.show();
$('.imap_folder_link', folders).addClass('imap_move_folder_link').removeClass('imap_folder_link');
if (action == 'move') {
label = $('.move_to_string1').val();
label = $('.move_to_string1').val();
}
else {
label = $('.move_to_string2').val();
Expand Down Expand Up @@ -1131,7 +1131,7 @@ var imap_setup_snooze = function() {
});
}

var imap_unsnooze_messages = function() {
var imap_unsnooze_messages = function() {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_imap_unsnooze'}],
function() {},
Expand Down Expand Up @@ -1186,7 +1186,7 @@ $(function() {
else if (hm_page_name() === 'info') {
setTimeout(imap_status_update, 100);
}

if (hm_page_name() === 'message_list' || hm_page_name() === 'message') {
imap_setup_snooze();
}
Expand Down Expand Up @@ -1263,7 +1263,11 @@ var imap_archive_message = function(state, supplied_uid, supplied_detail) {

var imap_show_add_contact_popup = function() {
var popup = document.getElementById("contact_popup");
if(!popup.classList.contains("show")) {
popup.classList.toggle("show");
}
popup.classList.toggle("show");
};

var imap_hide_add_contact_popup = function(event) {
event.stopPropagation()
var popup = document.getElementById("contact_popup");
popup.classList.toggle("show");
};

0 comments on commit 6140ef5

Please sign in to comment.