Skip to content

Commit 5dab02f

Browse files
feat: add sieve filter action drag and drop
1 parent 7f03783 commit 5dab02f

File tree

2 files changed

+80
-57
lines changed

2 files changed

+80
-57
lines changed

modules/sievefilters/site.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
.sortable-ghost {
2+
background-color: var(--bs-secondary-bg-subtle);
3+
border: 2px dashed var(--bs-secondary);
4+
opacity: 0.6;
5+
}
6+
17
.tingle-modal * {
28
box-sizing: border-box
39
}

modules/sievefilters/site.js

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,72 @@
44
*/
55
var hm_sieve_condition_fields = function() {
66
return {
7-
'Message': [
7+
Message: [
88
{
9-
name: 'subject',
10-
description: 'Subject',
11-
type: 'string',
9+
name: "subject",
10+
description: "Subject",
11+
type: "string",
1212
selected: true,
13-
options: ['Contains', 'Matches', 'Regex']
13+
options: ["Contains", "Matches", "Regex"],
1414
},
1515
{
16-
name: 'body',
17-
description: 'Body',
18-
type: 'string',
19-
options: ['Contains', 'Matches', 'Regex']
16+
name: "body",
17+
description: "Message body",
18+
type: "string",
19+
options: ["Contains", "Matches", "Regex"],
2020
},
2121
{
22-
name: 'size',
23-
description: 'Size (KB)',
24-
type: 'int',
25-
options: ['Over', 'Under']
26-
}
22+
name: "size",
23+
description: "Size (KB)",
24+
type: "int",
25+
options: ["Over", "Under"],
26+
},
2727
],
28-
'Header': [
28+
Header: [
2929
{
30-
name: 'to',
31-
description: 'To',
32-
type: 'string',
30+
name: "to",
31+
description: "Recipient (To)",
32+
type: "string",
3333
extra_option: false,
34-
options: ['Contains', 'Matches', 'Regex']
34+
options: ["Contains", "Matches", "Regex"],
3535
},
3636
{
37-
name: 'from',
38-
description: 'From',
39-
type: 'string',
37+
name: "from",
38+
description: "Sender (From)",
39+
type: "string",
4040
extra_option: false,
41-
options: ['Contains', 'Matches', 'Regex']
41+
options: ["Contains", "Matches", "Regex"],
4242
},
4343
{
44-
name: 'cc',
45-
description: 'CC',
46-
type: 'string',
44+
name: "cc",
45+
description: "Copied recipient (CC)",
46+
type: "string",
4747
extra_option: false,
48-
options: ['Contains', 'Matches', 'Regex']
48+
options: ["Contains", "Matches", "Regex"],
4949
},
5050
{
51-
name: 'to_or_cc',
52-
description: 'To or CC',
53-
type: 'string',
51+
name: "to_or_cc",
52+
description: "Recipient (To or CC)",
53+
type: "string",
5454
extra_option: false,
55-
options: ['Contains', 'Matches', 'Regex']
55+
options: ["Contains", "Matches", "Regex"],
5656
},
5757
{
58-
name: 'bcc',
59-
description: 'BCC',
60-
type: 'string',
58+
name: "bcc",
59+
description: "Blind copied recipient (BCC)",
60+
type: "string",
6161
extra_option: false,
62-
options: ['Contains', 'Matches', 'Regex']
62+
options: ["Contains", "Matches", "Regex"],
6363
},
6464
{
65-
name: 'custom',
66-
description: 'Custom',
67-
type: 'string',
65+
name: "custom",
66+
description: "Custom",
67+
type: "string",
6868
extra_option: true,
69-
extra_option_description: 'Field Name',
70-
options: ['Contains', 'Matches', 'Regex']
71-
}
72-
]
69+
extra_option_description: "Field Name",
70+
options: ["Contains", "Matches", "Regex"],
71+
},
72+
],
7373
};
7474
};
7575

@@ -700,6 +700,19 @@ function sieveFiltersPageHandler() {
700700
add_filter_match_mode();
701701
});
702702

703+
/**
704+
* Actions Drag and Drop
705+
*/
706+
const actionsTbody = document.querySelector(".filter_actions_modal_table");
707+
708+
if (actionsTbody) {
709+
new Sortable(actionsTbody, {
710+
handle: ".drag-handle",
711+
animation: 150,
712+
ghostClass: "sortable-ghost",
713+
});
714+
}
715+
703716
function add_filter_action(default_value = '') {
704717
let possible_actions_html = '';
705718

@@ -711,21 +724,25 @@ function sieveFiltersPageHandler() {
711724
possible_actions_html += '<option value="'+value.name+'">' + value.description + '</option>';
712725
});
713726
let extra_options = '<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>';
714-
$('.filter_actions_modal_table').append(
715-
'<tr class="border" default_value="'+default_value+'">' +
716-
' <td class="col-sm-3">' +
717-
' <select class="sieve_actions_select form-control form-control-sm" name="sieve_selected_actions[]">' +
718-
' ' + possible_actions_html +
719-
' </select>' +
720-
' </td>' +
721-
extra_options +
722-
' <td class="col-sm-5">' +
723-
' <input type="hidden" name="sieve_selected_action_value[]" value="">' +
724-
' </input>' +
725-
' <td class="col-sm-1 text-end align-middle">' +
726-
' <a href="#" class="delete_action_modal_button btn btn-sm btn-secondary">Delete</a>' +
727-
' </td>' +
728-
'</tr>'
727+
$(".filter_actions_modal_table").append(
728+
'<tr class="border draggable_action_row" default_value="' +
729+
default_value +
730+
'">' +
731+
' <td class="col-sm-1 drag-handle" style="cursor: grab;">&#9776;</td>' +
732+
' <td class="col-sm-3">' +
733+
' <select class="sieve_actions_select form-control form-control-sm" name="sieve_selected_actions[]">' +
734+
" " +
735+
possible_actions_html +
736+
" </select>" +
737+
" </td>" +
738+
extra_options +
739+
' <td class="col-sm-5">' +
740+
' <input type="hidden" name="sieve_selected_action_value[]" value="">' +
741+
" </input>" +
742+
' <td class="col-sm-1 text-end align-middle">' +
743+
' <a href="#" class="delete_action_modal_button btn btn-sm btn-secondary">Delete</a>' +
744+
" </td>" +
745+
"</tr>"
729746
);
730747
}
731748

0 commit comments

Comments
 (0)