Skip to content

Commit 80a8161

Browse files
Improve Filter opening
1 parent bd4a294 commit 80a8161

File tree

3 files changed

+118
-117
lines changed

3 files changed

+118
-117
lines changed

modules/imap/handler_modules.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,8 +1934,7 @@ public function process() {
19341934
$this->out('show_pagination_links', $this->user_config->get('pagination_links_setting', true));
19351935
$this->out('auto_advance_email_enabled', $this->user_config->get('auto_advance_email_setting', true));
19361936

1937-
$parts = explode('_', 'imap_' . $form['imap_server_id'] . '_' . $form['folder'], 3);
1938-
$details = Hm_IMAP_List::dump($parts[1]);
1937+
$details = Hm_IMAP_List::dump($form['imap_server_id']);
19391938
$mailbox_name = $details['name'];
19401939

19411940

modules/imap/site.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -986,57 +986,58 @@ $(function () {
986986

987987
if ($.isEmptyObject(data)) {
988988
Hm_Notices.show(
989-
"Please check at least one condition to create a filter.",
990-
"danger"
991-
);
992-
$btn.prop("disabled", false);
993-
return;
994-
}
995-
996-
edit_filter_modal.open();
997-
998-
// After modal content is ready, auto-fill conditions
999-
setTimeout(() => {
1000-
const allFields = hm_sieve_condition_fields();
1001-
const availableFields = [
1002-
...allFields.Message.map((f) => f.name),
1003-
...allFields.Header.map((f) => f.name),
1004-
];
989+
"Please check at least one condition to create a filter.",
990+
"danger"
991+
);
992+
$btn.prop("disabled", false);
993+
return;
994+
}
1005995

1006-
for (const [key, value] of Object.entries(data)) {
1007-
// If key is not in available fields, skip it
1008-
if (!availableFields.includes(key)) {
1009-
console.warn("Skipping unrecognized field:", key);
1010-
continue;
1011-
}
996+
edit_filter_modal.open();
1012997

1013-
add_filter_condition();
998+
const allFields = hm_sieve_condition_fields();
999+
const availableFields = [
1000+
...allFields.Message.map((f) => f.name),
1001+
...allFields.Header.map((f) => f.name),
1002+
];
10141003

1015-
const $lastRow = $(".sieve_list_conditions_modal tr").last();
1016-
const $selectField = $lastRow.find(".add_condition_sieve_filters");
1017-
const $selectOp = $lastRow.find(".condition_options");
1018-
const $inputVal = $lastRow.find('input[name="sieve_selected_option_value[]"]');
1019-
$selectField.val(key);
1020-
$selectOp.val("Contains");
1021-
$inputVal.val(value);
1004+
for (const [key, value] of Object.entries(data)) {
1005+
// If key is not in available fields, skip it
1006+
if (!availableFields.includes(key)) {
1007+
continue;
1008+
}
10221009

1023-
}
1010+
add_filter_condition();
10241011

1025-
if (data["reply-to"]) {
1012+
const $lastRow = $(".sieve_list_conditions_modal tr").last();
1013+
const $selectField = $lastRow.find(
1014+
".add_condition_sieve_filters"
1015+
);
1016+
const $selectOp = $lastRow.find(".condition_options");
1017+
const $inputVal = $lastRow.find(
1018+
'input[name="sieve_selected_option_value[]"]'
1019+
);
1020+
$selectField.val(key);
1021+
$selectOp.val("Contains");
1022+
$inputVal.val(value);
1023+
}
10261024

1027-
add_filter_action("autoreply");
1025+
if (data["reply-to"]) {
1026+
add_filter_action("autoreply");
10281027

1029-
const $lastRow = $(".filter_actions_modal_table tr").last();
1030-
const $select = $lastRow.find(".sieve_actions_select");
1031-
$select.val("autoreply").trigger("change");
1028+
const $lastRow = $(".filter_actions_modal_table tr").last();
1029+
const $select = $lastRow.find(".sieve_actions_select");
1030+
$select.val("autoreply").trigger("change");
10321031

1033-
// Focus the input field for the message
1034-
const $input = $lastRow.find('input[name="sieve_selected_action_value[]"]');
1035-
if ($input.length) {
1036-
$input.focus();
1037-
}
1038-
}
1039-
}, 250);
1032+
// Focus the input field for the message
1033+
const $input = $lastRow.find(
1034+
'input[name="sieve_selected_action_value[]"]'
1035+
);
1036+
if ($input.length) {
1037+
$input.focus();
1038+
}
1039+
}
1040+
10401041
});
10411042
});
10421043

modules/sievefilters/site.js

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -443,51 +443,48 @@ const Hm_Filters = (function (my) {
443443
}
444444
});
445445

446-
let extra_options =
447-
'<td class="col-sm-3"><input type="hidden" class="condition_extra_value form-control form-control-sm" name="sieve_selected_extra_option_value[]" /></td>';
448-
$(".sieve_list_conditions_modal").append(
449-
" <tr>" +
450-
' <td class="col-sm-2">' +
451-
' <select class="add_condition_sieve_filters form-control form-control-sm" name="sieve_selected_conditions_field[]">' +
452-
' <optgroup label="Message">' +
453-
message_fields +
454-
" </optgroup>" +
455-
' <optgroup label="Header">' +
456-
header_fields +
457-
" </optgroup>" +
458-
" </select>" +
459-
" </td>" +
460-
extra_options +
461-
' <td class="col-sm-3">' +
462-
' <select class="condition_options form-control form-control-sm" name="sieve_selected_conditions_options[]">' +
463-
' <option value="Contains">' +
464-
" Contains" +
465-
" </option>" +
466-
' <option value="!Contains">' +
467-
" Not Contains" +
468-
" </option>" +
469-
' <option value="Matches">' +
470-
" Matches" +
471-
" </option>" +
472-
' <option value="!Matches">' +
473-
" Not Matches" +
474-
" </option>" +
475-
' <option value="Regex">' +
476-
" Regex" +
477-
" </option>" +
478-
' <option value="!Regex">' +
479-
" Not Regex" +
480-
" </option>" +
481-
" </select>" +
482-
" </td>" +
483-
' <td class="col-sm-3">' +
484-
' <input type="text" name="sieve_selected_option_value[]" class="form-control form-control-sm" />' +
485-
" </td>" +
486-
' <td class="col-sm-1 text-end align-middle">' +
487-
' <a href="#" class="delete_condition_modal_button btn btn-sm btn-secondary">Delete</a>' +
488-
" </td>" +
489-
" </tr>"
490-
);
446+
const extra_options = `
447+
<td class="col-sm-3">
448+
<input type="hidden"
449+
class="condition_extra_value form-control form-control-sm"
450+
name="sieve_selected_extra_option_value[]" />
451+
</td>
452+
`;
453+
454+
$(".sieve_list_conditions_modal").append(`
455+
<tr>
456+
<td class="col-sm-2">
457+
<select class="add_condition_sieve_filters form-control form-control-sm"
458+
name="sieve_selected_conditions_field[]">
459+
<optgroup label="Message">
460+
${message_fields}
461+
</optgroup>
462+
<optgroup label="Header">
463+
${header_fields}
464+
</optgroup>
465+
</select>
466+
</td>
467+
${extra_options}
468+
<td class="col-sm-3">
469+
<select class="condition_options form-control form-control-sm"
470+
name="sieve_selected_conditions_options[]">
471+
<option value="Contains">Contains</option>
472+
<option value="!Contains">Not Contains</option>
473+
<option value="Matches">Matches</option>
474+
<option value="!Matches">Not Matches</option>
475+
<option value="Regex">Regex</option>
476+
<option value="!Regex">Not Regex</option>
477+
</select>
478+
</td>
479+
480+
<td class="col-sm-3">
481+
<input type="text" name="sieve_selected_option_value[]" class="form-control form-control-sm" />
482+
</td>
483+
<td class="col-sm-1 text-end align-middle">
484+
<a href="#" class="delete_condition_modal_button btn btn-sm btn-secondary">Delete</a>
485+
</td>
486+
</tr>
487+
`);
491488
};
492489

493490
my.add_filter_action = function (default_value = "") {
@@ -506,27 +503,32 @@ const Hm_Filters = (function (my) {
506503
possible_actions_html +=
507504
'<option value="' + value.name + '">' + value.description + "</option>";
508505
});
509-
let extra_options =
510-
'<td class="col-sm-3"><input type="hidden" class="condition_extra_action_value form-control form-control-sm" name="sieve_selected_extra_action_value[]" /></td>';
511-
$(".filter_actions_modal_table").append(
512-
'<tr class="border" default_value="' +
513-
default_value +
514-
'">' +
515-
' <td class="col-sm-3">' +
516-
' <select class="sieve_actions_select form-control form-control-sm" name="sieve_selected_actions[]">' +
517-
" " +
518-
possible_actions_html +
519-
" </select>" +
520-
" </td>" +
521-
extra_options +
522-
' <td class="col-sm-5">' +
523-
' <input type="hidden" name="sieve_selected_action_value[]" value="">' +
524-
" </input>" +
525-
' <td class="col-sm-1 text-end align-middle">' +
526-
' <a href="#" class="delete_action_modal_button btn btn-sm btn-secondary">Delete</a>' +
527-
" </td>" +
528-
"</tr>"
529-
);
506+
507+
const extra_options = `
508+
<td class="col-sm-3">
509+
<input type="hidden"
510+
class="condition_extra_action_value form-control form-control-sm"
511+
name="sieve_selected_extra_action_value[]" />
512+
</td>
513+
`;
514+
515+
$(".filter_actions_modal_table").append(`
516+
<tr class="border" default_value="${default_value}">
517+
<td class="col-sm-3">
518+
<select class="sieve_actions_select form-control form-control-sm"
519+
name="sieve_selected_actions[]">
520+
${possible_actions_html}
521+
</select>
522+
</td>
523+
${extra_options}
524+
<td class="col-sm-5">
525+
<input type="hidden" name="sieve_selected_action_value[]" value="">
526+
</td>
527+
<td class="col-sm-1 text-end align-middle">
528+
<a href="#" class="delete_action_modal_button btn btn-sm btn-secondary">Delete</a>
529+
</td>
530+
</tr>
531+
`);
530532
};
531533

532534
return my;
@@ -540,10 +542,9 @@ const Hm_Filters = (function (my) {
540542
* MODAL EVENTS
541543
**************************************************************************************/
542544
var hm_sieve_button_events = function (edit_filter_modal, edit_script_modal) {
543-
544545
$(document)
545-
.off("click")
546-
.on("click", ".sievefilters_accounts_title", function () {
546+
.off("click.sieveToggle")
547+
.on("click.sieveToggle", ".sievefilters_accounts_title", function () {
547548
$(this).parent().find(".sievefilters_accounts").toggleClass("d-none");
548549
});
549550

@@ -577,23 +578,23 @@ var hm_sieve_button_events = function (edit_filter_modal, edit_script_modal) {
577578
*/
578579
$(document).on("click", ".delete_else_action_modal_button", function (e) {
579580
e.preventDefault();
580-
$(this).parent().parent().remove();
581+
$(this).closest("tr").remove();
581582
});
582583

583584
/**
584585
* Delete action Button
585586
*/
586587
$(document).on("click", ".delete_action_modal_button", function (e) {
587588
e.preventDefault();
588-
$(this).parent().parent().remove();
589+
$(this).closest("tr").remove();
589590
});
590591

591592
/**
592593
* Delete Condition Button
593594
*/
594595
$(document).on("click", ".delete_condition_modal_button", function (e) {
595596
e.preventDefault();
596-
$(this).parent().parent().remove();
597+
$(this).closest("tr").remove();
597598
});
598599

599600
/**

0 commit comments

Comments
 (0)