Skip to content

Commit

Permalink
Final move of the remnants of the code previously handled by hm_list_…
Browse files Browse the repository at this point in the history
…path(), hm_msg_uid(), and hm_page_name() to the new navigation module
  • Loading branch information
mercihabam authored and josaphatim committed Oct 16, 2024
1 parent 477e6b1 commit 8f73017
Show file tree
Hide file tree
Showing 27 changed files with 1,584 additions and 912 deletions.
4 changes: 2 additions & 2 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ var add_contact_from_popup = function(event) {
{'name': 'contact_source', 'value': source}],
function (res) {
$("#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()}`);
sessionStorage.removeItem(`${window.location.pathname}imap_4_${getListPathParam()}`);
sessionStorage.removeItem(`${window.location.pathname}${getMessageUidParam()}_${getListPathParam()}`);
}
);
}
Expand Down
9 changes: 8 additions & 1 deletion modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function applyServersPageHandlers() {
// Optional modules
if (window.feedServersPageHandler) feedServersPageHandler();
if (window.githubServersPageHandler) githubServersPageHandler();
if (window.nasaServersPageHandler) nasaServersPageHandler();
if (window.smtpServersPageHandler) smtpServersPageHandler();
if (window.wpServersPageHandler) wpServersPageHandler();
}

function applySettingsPageHandlers() {
Expand All @@ -26,12 +29,16 @@ function applySettingsPageHandlers() {
$('.reset_default_timezone').on("click", reset_default_timezone);

if (window.expand_feed_settings) expand_feed_settings();
if (window.smtpSettingsPageHandler) smtpSettingsPageHandler();
}

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

if (window.inlineMessageMessageListAndSearchPageHandler) inlineMessageMessageListAndSearchPageHandler(routeParams);
if (window.savedSearchesSearchPageHandler) savedSearchesSearchPageHandler();
}

function applyHomePageHandlers() {
Expand Down
20 changes: 20 additions & 0 deletions modules/core/navigation/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
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: 'hello_world',
handler: 'applyHelloWorldPageHandlers'
},
{
page: 'message_list',
handler: 'applyImapMessageListPageHandlers'
Expand Down Expand Up @@ -57,6 +61,22 @@ const modulesRoutes = [
{
page: 'folders_subscription',
handler: 'applyFoldersSubscriptionPageHandlers'
},
{
page: 'pgp',
handler: 'applyPgpPageHandlers'
},
{
page: 'profiles',
handler: 'applyProfilesPageHandler'
},
{
page: 'block_list',
handler: 'applyBlockListPageHandlers'
},
{
page: 'sieve_filters',
handler: 'applySieveFiltersPageHandler'
}
]

Expand Down
8 changes: 6 additions & 2 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ protected function output() {
}
$core = false;
$mods = $this->get('router_module_list');
// Load navigation utilities used by subsequent modules' handlers
if (in_array('core', $mods)) {
$res .= '<script type="text/javascript" src="modules/core/navigation/utils.js"></script>';
}
foreach (glob(APP_PATH.'modules'.DIRECTORY_SEPARATOR.'**', GLOB_ONLYDIR | GLOB_MARK) as $name) {
$rel_name = str_replace(APP_PATH, '', $name);
$mod = str_replace(array('modules', DIRECTORY_SEPARATOR), '', $rel_name);
Expand All @@ -574,11 +578,11 @@ protected function output() {
if ($core) {
$res = '<script type="text/javascript" src="'.WEB_ROOT.sprintf("%ssite.js", $core).'"></script>'.$res;
/* Load navigation js modules
* utils.js, routes.js, navigation.js
* routes.js, navigation.js
* They have to be loaded after each module's js files, because routes.js depend on the handlers defined in the modules.
* Therefore, navigation.js is also loaded after routes.js, because the routes should be loaded beforehand to be able to navigate.
*/
foreach (['utils', 'routes', 'navigation'] as $js) {
foreach (['routes', 'navigation'] as $js) {
$res .= '<script type="text/javascript" src="'.WEB_ROOT.sprintf("%snavigation/%s.js", $core, $js).'"></script>';
}
}
Expand Down
30 changes: 15 additions & 15 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ function Message_List() {
});
}
// apply JS pagination only on aggregate folders; imap ones already have the messages sorted
if (hm_list_path().substring(0, 5) != 'imap_' && element) {
if (getListPathParam().substring(0, 5) != 'imap_' && element) {
$(row, msg_rows).insertBefore(element);
}
else {
Expand Down Expand Up @@ -752,10 +752,10 @@ function Message_List() {

this.update_after_action = function(action_type, selected) {
var remove = false;
if (action_type == 'read' && hm_list_path() == 'unread') {
if (action_type == 'read' && getListPathParam() == 'unread') {
remove = true;
}
if (action_type == 'unflag' && hm_list_path() == 'flagged') {
if (action_type == 'unflag' && getListPathParam() == 'flagged') {
remove = true;
}
else if (action_type == 'delete' || action_type == 'archive') {
Expand All @@ -777,9 +777,9 @@ function Message_List() {
};

this.save_updated_list = function() {
if (this.page_caches.hasOwnProperty(hm_list_path())) {
this.set_message_list_state(this.page_caches[hm_list_path()]);
Hm_Utils.save_to_local_storage('sort_'+hm_list_path(), this.sort_fld);
if (this.page_caches.hasOwnProperty(getListPathParam())) {
this.set_message_list_state(this.page_caches[getListPathParam()]);
Hm_Utils.save_to_local_storage('sort_'+getListPathParam(), this.sort_fld);
}
};

Expand Down Expand Up @@ -852,8 +852,8 @@ function Message_List() {
};

this.select_combined_view = function() {
if (self.page_caches.hasOwnProperty(hm_list_path())) {
self.setup_combined_view(self.page_caches[hm_list_path()]);
if (self.page_caches.hasOwnProperty(getListPathParam())) {
self.setup_combined_view(self.page_caches[getListPathParam()]);
}
else {
if (getPageNameParam() == 'search') {
Expand All @@ -863,7 +863,7 @@ function Message_List() {
self.setup_combined_view(false);
}
}
var sort_type = Hm_Utils.get_from_local_storage('sort_'+hm_list_path());
var sort_type = Hm_Utils.get_from_local_storage('sort_'+getListPathParam());
if (sort_type != null) {
this.sort_fld = sort_type;
$('.combined_sort').val(sort_type);
Expand Down Expand Up @@ -916,23 +916,23 @@ function Message_List() {
var count = 0;
var rows = Hm_Utils.rows();
var tbody = Hm_Utils.tbody();
if (hm_list_path() == 'unread') {
if (getListPathParam() == 'unread') {
count = rows.length;
document.title = count+' '+hm_trans('Unread');
}
else if (hm_list_path() == 'flagged') {
else if (getListPathParam() == 'flagged') {
count = rows.length;
document.title = count+' '+hm_trans('Flagged');
}
else if (hm_list_path() == 'combined_inbox') {
else if (getListPathParam() == 'combined_inbox') {
count = $('tr .unseen', tbody).length;
document.title = count+' '+hm_trans('Unread in Everything');
}
else if (hm_list_path() == 'email') {
else if (getListPathParam() == 'email') {
count = $('tr .unseen', tbody).length;
document.title = count+' '+hm_trans('Unread in Email');
}
else if (hm_list_path() == 'feeds') {
else if (getListPathParam() == 'feeds') {
count = $('tr .unseen', tbody).length;
document.title = count+' '+hm_trans('Unread in Feeds');
}
Expand Down Expand Up @@ -2184,7 +2184,7 @@ if(tableBody && !hm_mobile()) {
(res) =>{
for (const index in res.move_count) {
$('.'+Hm_Utils.clean_selector(res.move_count[index])).remove();
select_imap_folder(hm_list_path());
select_imap_folder(getListPathParam());
}
}
);
Expand Down
10 changes: 5 additions & 5 deletions modules/feeds/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ var display_feeds_combined_inbox = function(res) {

var feed_item_view = function(uid, list_path, callback) {
if (!uid) {
uid = hm_msg_uid();
uid = getMessageUidParam();
}
if (!list_path) {
list_path = hm_list_path();
list_path = getListPathParam();
}
$('.msg_text_inner').html('');
Hm_Ajax.request(
Expand All @@ -139,13 +139,13 @@ var display_feed_item_content = function(res) {
if (!res.feed_msg_headers) {
return;
}
var msg_uid = hm_msg_uid();
var msg_uid = getMessageUidParam();
$('.msg_text').html('');
$('.msg_text').append(res.feed_msg_headers);
$('.msg_text').append(res.feed_msg_text);
set_message_content();
document.title = $('.header_subject th').text();
var path = hm_list_path();
var path = getListPathParam();
if (hm_list_parent() == 'feeds') {
Hm_Message_List.prev_next_links('formatted_feed_data', path+'_'+msg_uid);
}
Expand All @@ -170,7 +170,7 @@ var display_feed_item_content = function(res) {
};

var load_feed_list = function(id) {
var cached = Hm_Utils.get_from_local_storage(hm_list_path());
var cached = Hm_Utils.get_from_local_storage(getListPathParam());
if (cached) {
$('.message_table tbody').html(cached);
}
Expand Down
18 changes: 9 additions & 9 deletions modules/github/site.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var load_github_data = function(id) {
if (hm_list_path() == 'github_all') {
if (getListPathParam() == 'github_all') {
Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_github_data'}, {'name': 'github_repo', 'value': id}], display_github_data, [], false, cache_github_all);
}
else {
if (hm_list_path().substr(0, 6) == 'github') {
var cached = Hm_Utils.get_from_local_storage(hm_list_path());
if (getListPathParam().substr(0, 6) == 'github') {
var cached = Hm_Utils.get_from_local_storage(getListPathParam());
if (cached) {
$('.message_table tbody').html(cached);
}
Expand All @@ -27,7 +27,7 @@ var display_github_data_background = function(res) {
};

var display_github_data = function(res) {
var path = hm_list_path();
var path = getListPathParam();
Hm_Message_List.update([res.github_server_id], res.formatted_message_list, 'github');
if (path != 'github_all') {
var data = Hm_Message_List.filter_list();
Expand All @@ -37,17 +37,17 @@ var display_github_data = function(res) {
};

var cache_github_all = function() {
if (hm_list_path() == 'github_all') {
if (getListPathParam() == 'github_all') {
Hm_Message_List.set_message_list_state('formatted_github_all')
}
};

var github_item_view = function(list_path, uid, callback) {
if (!list_path) {
list_path = hm_list_path();
list_path = getListPathParam();
}
if (!uid) {
uid = hm_msg_uid();
uid = getMessageUidParam();
}
$('.msg_text_inner').html('');
Hm_Ajax.request(
Expand All @@ -64,15 +64,15 @@ var github_item_view = function(list_path, uid, callback) {

var display_github_item_content = function(res) {
$('.msg_text').html(res.github_msg_text);
var uid = hm_msg_uid();
var uid = getMessageUidParam();
if (hm_list_parent() == 'unread') {
Hm_Message_List.prev_next_links('formatted_unread_data', uid);
}
else if (hm_list_parent() == 'github_all') {
Hm_Message_List.prev_next_links('formatted_github_all', uid);
}
else {
Hm_Message_List.prev_next_links(hm_list_path(), uid);
Hm_Message_List.prev_next_links(getListPathParam(), uid);
}
if (Hm_Message_List.track_read_messages(uid)) {
if (hm_list_parent() == 'unread') {
Expand Down
8 changes: 8 additions & 0 deletions modules/hello_world/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* If we are on the "hello_world" page, activate the click handler
*/
function applyHelloWorldPageHandlers() {
$('.hw_ajax_link').on("click", function() {
hello_world_ajax_update();
});
}
14 changes: 2 additions & 12 deletions modules/hello_world/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/**
* This JS sets up an AJAX request and assigns it to a link on the hello_world page.
* You have access to cash.js functions when this code is loaded, so use the standard
* way to delay actions until page onload if you need to. Built in data sources like
* hm_page_name() are defined before this is run so they are also available. When the
* way to delay actions until page onload if you need to. When the
* site build process is run this code will be combined with JS from other module sets,
* and optionally minified based on the config/app.php file settings.
*/
Expand All @@ -24,13 +23,4 @@ var hello_world_ajax_update = function() {
*/
var update_hello_world_display = function(res) {
alert(res.hello_world_ajax_result);
};

/**
* If we are on the "hello_world" page, activate the click handler
*/
if (hm_page_name() == 'hello_world') {
$('.hw_ajax_link').on("click", function() {
hello_world_ajax_update();
});
}
};
4 changes: 4 additions & 0 deletions modules/imap/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function applyImapMessageListPageHandlers(routeParams) {
imap_setup_tags();

if (window.githubMessageListPageHandler) githubMessageListPageHandler(routeParams);
if (window.inlineMessageMessageListAndSearchPageHandler) inlineMessageMessageListAndSearchPageHandler(routeParams);
if (window.wpMessageListPageHandler) wpMessageListPageHandler(routeParams);

return async function() {
const refreshIntervalId = await refreshInterval;
Expand All @@ -21,4 +23,6 @@ function applyImapMessageContentPageHandlers(routeParams) {

if (window.feedMessageContentPageHandler) feedMessageContentPageHandler(routeParams);
if (window.githubMessageContentPageHandler) githubMessageContentPageHandler(routeParams);
if (window.pgpMessageContentPageHandler) pgpMessageContentPageHandler();
if (window.wpMessageContentPageHandler) wpMessageContentPageHandler(routeParams);
}
Loading

0 comments on commit 8f73017

Please sign in to comment.