Skip to content

Commit

Permalink
Move Hm_MessagesStore to the core module, and move some remanants cod…
Browse files Browse the repository at this point in the history
…e previously handled by hm_list_path() and hm_page_name() to the new navigation module. There are still a few occurences to move
  • Loading branch information
mercihabam authored and josaphatim committed Oct 16, 2024
1 parent c0041b2 commit 477e6b1
Show file tree
Hide file tree
Showing 22 changed files with 503 additions and 460 deletions.
30 changes: 30 additions & 0 deletions modules/advanced_search/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function applyAdvancedSearchPageHandlers() {
globals.close_html = '<i class="bi bi-x-circle-fill cursor-pointer"></i>';

$('.settings_subtitle').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
$('.adv_folder_select').on("click", function() { adv_select_imap_folder(this); });
$('.new_time').on("click", function() { add_remove_times(this); });
$('.new_target').on("click", function() { add_remove_targets(this); });
$('.new_term').on("click", function() { add_remove_terms(this); });
$('.adv_expand_all').on("click", function() { adv_expand_sections(); });
$('.adv_collapse_all').on("click", function() { adv_collapse(); });
$('#adv_search').on("click", function() { process_advanced_search(); });
$('.toggle_link').on("click", function() { return Hm_Message_List.toggle_rows(); });
$('.adv_reset').on("click", function() { adv_reset_page(); });
$('.combined_sort').on("change", function() { Hm_Message_List.sort($(this).val()); });

apply_saved_search();
var data = Hm_Utils.get_from_local_storage('formatted_advanced_search_data');
if (data && data.length) {
adv_collapse();
Hm_Utils.tbody().html(data);
$('.adv_controls').show();
$('.core_msg_control').off('click');
$('.core_msg_control').on("click", function() { return Hm_Message_List.message_action($(this).data('action')); });
Hm_Message_List.set_checkbox_callback();
if (typeof check_select_for_imap !== 'undefined') {
check_select_for_imap();
}
}
Hm_Message_List.check_empty_list();
}
34 changes: 0 additions & 34 deletions modules/advanced_search/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,37 +514,3 @@ var adv_reset_page = function() {
Hm_Utils.save_to_local_storage('adv_search_params', '');
document.location.href = '?page=advanced_search';
};

$(function() {
if (hm_page_name() == 'advanced_search') {

globals.close_html = '<i class="bi bi-x-circle-fill cursor-pointer"></i>';

$('.settings_subtitle').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
$('.adv_folder_select').on("click", function() { adv_select_imap_folder(this); });
$('.new_time').on("click", function() { add_remove_times(this); });
$('.new_target').on("click", function() { add_remove_targets(this); });
$('.new_term').on("click", function() { add_remove_terms(this); });
$('.adv_expand_all').on("click", function() { adv_expand_sections(); });
$('.adv_collapse_all').on("click", function() { adv_collapse(); });
$('#adv_search').on("click", function() { process_advanced_search(); });
$('.toggle_link').on("click", function() { return Hm_Message_List.toggle_rows(); });
$('.adv_reset').on("click", function() { adv_reset_page(); });
$('.combined_sort').on("change", function() { Hm_Message_List.sort($(this).val()); });

apply_saved_search();
var data = Hm_Utils.get_from_local_storage('formatted_advanced_search_data');
if (data && data.length) {
adv_collapse();
Hm_Utils.tbody().html(data);
$('.adv_controls').show();
$('.core_msg_control').off('click');
$('.core_msg_control').on("click", function() { return Hm_Message_List.message_action($(this).data('action')); });
Hm_Message_List.set_checkbox_callback();
if (typeof check_select_for_imap !== 'undefined') {
check_select_for_imap();
}
}
Hm_Message_List.check_empty_list();
}
});
2 changes: 1 addition & 1 deletion modules/calendar/hm-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function output_event($day) {
$res .= '<div class="cal_event">'.
$this->output_event_details($event).
$this->output_mod->html_safe(date('H:i', $event['ts'])).
' <a class="cal_title cursor-pointer">'.$this->output_mod->html_safe($event['title']).
' <a class="cal_title cursor-pointer" href="#">'.$this->output_mod->html_safe($event['title']).
'</a></div>';
}
return $res;
Expand Down
15 changes: 15 additions & 0 deletions modules/calendar/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function applyCalendarPageHandlers() {
$('.event_delete').on("click", function() {
if (hm_delete_prompt()) {
$(this).parent().submit();
}
});
$('.cal_title').on("click", function(e) {
e.preventDefault();
$('.event_details').hide();
$('.event_details', $(this).parent()).show();
$('.event_details').on("click", function() {
$(this).hide();
});
});
}
17 changes: 0 additions & 17 deletions modules/calendar/site.js
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
'use strict';

$(function() {
if (hm_page_name() == 'calendar') {
$('.event_delete').on("click", function() {
if (hm_delete_prompt()) {
$(this).parent().submit();
}
});
$('.cal_title').on("click", function() {
$('.event_details').hide();
$('.event_details', $(this).parent()).show();
$('.event_details').on("click", function() {
$(this).hide();
});
});
}
});
33 changes: 33 additions & 0 deletions modules/contacts/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function applyContactsPageHandlers() {
$('.delete_contact').on("click", function() {
delete_contact($(this).data('id'), $(this).data('source'), $(this).data('type'));
return false;
});
$('.show_contact').on("click", function() {
$('#'+$(this).data('id')).toggle();
return false;
});
$('.reset_contact').on("click", function() {
Hm_Utils.redirect('?page=contacts');
});
$('.server_title').on("click", function() {
$(this).next().toggle();
});
$('#contact_phone').on("keyup", function() {
let contact_phone = $('#contact_phone').val();
const regex_number = new RegExp('^\\d+$');
const allowed_characters = ['+','-','(',')'];
for (let chain_counter = 0; chain_counter < contact_phone.length; chain_counter++) {
if(!(regex_number.test(contact_phone[chain_counter])) && !(allowed_characters.indexOf(contact_phone[chain_counter]) > -1)){
Hm_Notices.show([hm_trans("This phone number appears to contain invalid character (s).\nIf you are sure ignore this warning and continue!")]);
$(this).off();
}
}

});
$('.source_link').on("click", function () {
$('.list_actions').toggle(); $('#list_controls_menu').hide();
return false;
});
contact_import_pagination();
}
40 changes: 0 additions & 40 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,43 +263,3 @@ var check_cc_exist_in_contacts_list = function() {
}
return "";
};

if (hm_page_name() == 'contacts') {
$('.delete_contact').on("click", function() {
delete_contact($(this).data('id'), $(this).data('source'), $(this).data('type'));
return false;
});
$('.show_contact').on("click", function() {
$('#'+$(this).data('id')).toggle();
return false;
});
$('.reset_contact').on("click", function() {
Hm_Utils.redirect('?page=contacts');
});
$('.server_title').on("click", function() {
$(this).next().toggle();
});
$('#contact_phone').on("keyup", function() {
let contact_phone = $('#contact_phone').val();
const regex_number = new RegExp('^\\d+$');
const allowed_characters = ['+','-','(',')'];
for (let chain_counter = 0; chain_counter < contact_phone.length; chain_counter++) {
if(!(regex_number.test(contact_phone[chain_counter])) && !(allowed_characters.indexOf(contact_phone[chain_counter]) > -1)){
Hm_Notices.show([hm_trans("This phone number appears to contain invalid character (s).\nIf you are sure ignore this warning and continue!")]);
$(this).off();
}
}

});
$('.source_link').on("click", function () {
$('.list_actions').toggle(); $('#list_controls_menu').hide();
return false;
});
contact_import_pagination();
}
else if (hm_page_name() == 'compose') {
$('.compose_to').on('keyup', function(e) { autocomplete_contact(e, '.compose_to', '#to_contacts'); });
$('.compose_cc').on('keyup', function(e) { autocomplete_contact(e, '.compose_cc', '#cc_contacts'); });
$('.compose_bcc').on('keyup', function(e) { autocomplete_contact(e, '.compose_bcc', '#bcc_contacts'); });
$('.compose_to').focus();
}
File renamed without changes.
33 changes: 33 additions & 0 deletions modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function applyServersPageHandlers() {
$('.server_section').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
$('.edit_server_connection').on('click', imap_smtp_edit_action);
// NUX
expand_server_settings();
$('.nux_next_button').on("click", nux_service_select);
Expand All @@ -10,9 +11,41 @@ function applyServersPageHandlers() {
$('.nux_extra_fields_container').remove();
}
});

// Optional modules
if (window.feedServersPageHandler) feedServersPageHandler();
if (window.githubServersPageHandler) githubServersPageHandler();
}

function applySettingsPageHandlers() {
Hm_Utils.expand_core_settings();
$('.settings_subtitle').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
$('.reset_default_value_checkbox').on("click", reset_default_value_checkbox);
$('.reset_default_value_select').on("click", reset_default_value_select);
$('.reset_default_value_input').on("click", reset_default_value_input);
$('.reset_default_timezone').on("click", reset_default_timezone);

if (window.expand_feed_settings) expand_feed_settings();
}

function applySearchPageHandlers() {
Hm_Message_List.select_combined_view();
sortHandlerForMessageListAndSearchPage();
$('.search_reset').on("click", Hm_Utils.reset_search_form);
}

function applyHomePageHandlers() {
$('.pw_update').on("click", function() { update_password($(this).data('id')); });
}

function applyInfoPageHandlers() {
const timer = setTimeout(() => {
imap_status_update();
if (window.feed_status_update) feed_status_update();
if (window.github_repo_update) github_repo_update();
}, 100);

return () => {
clearTimeout(timer);
}
}
61 changes: 54 additions & 7 deletions modules/core/navigation/routes.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,69 @@
ROUTES = [
/*
NOTE: Handlers are registered as strings instead of functions because some modules might not be enabled, making their pages' handler functions unaccessible.
*/
const modulesRoutes = [
{
page: 'message_list',
handler: applyImapMessageListPageHandlers
handler: 'applyImapMessageListPageHandlers'
},
{
page: 'message',
handler: applyImapMessageContentPageHandlers
handler: 'applyImapMessageContentPageHandlers'
},
{
page: 'compose',
handler: applySmtpPageHandlers
handler: 'applyComposePageHandlers'
},
{
page: 'servers',
handler: applyServersPageHandlers
handler: 'applyServersPageHandlers'
},
{
page: 'settings',
handler: applySettingsPageHandlers
handler: 'applySettingsPageHandlers'
},
{
page: 'search',
handler: 'applySearchPageHandlers'
},
{
page: 'home',
handler: 'applyHomePageHandlers'
},
{
page: 'info',
handler: 'applyInfoPageHandlers'
},
{
page: 'calendar',
handler: 'applyCalendarPageHandlers'
},
{
page: 'advanced_search',
handler: 'applyAdvancedSearchPageHandlers'
},
{
page: 'contacts',
handler: 'applyContactsPageHandlers'
},
{
page: 'history',
handler: 'applyHistoryPageHandlers'
},
{
page: 'folders',
handler: 'applyFoldersPageHandlers'
},
{
page: 'folders_subscription',
handler: 'applyFoldersSubscriptionPageHandlers'
}
]
]

/*
Now let's validate and use handlers that are given.
*/
ROUTES = modulesRoutes.filter(route => typeof(window[route.handler]) === 'function').map(route => ({
...route,
handler: window[route.handler]
}))
Loading

0 comments on commit 477e6b1

Please sign in to comment.