annotate plugins/advanced_search/advanced_search.js @ 34:50ac5484d514

one fix to distro
author Charlie Root
date Sun, 27 May 2018 16:53:56 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1 (function($) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
2 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
3 * The fontend scripts for an advanced search.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
4 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
5 * @version 2.1.6
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
6 * @licence GNU GPLv3+
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
7 * @author Wilwert Claude
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
8 * @author Ludovicy Steve
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
9 * @author Chris Moules
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
10 * @website http://www.gms.lu
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
11 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
12
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
13 $.stack = {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
14 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
15 * This object is used to buffer all the server side information which doesn't change. So the script
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
16 * doesn't have to send an ajax-request for every new added row.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
17 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
18 * @name stack
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
19 * @namespace
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
20 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
21 date_criteria: {},
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
22 flag_criteria: {},
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
23 email_criteria: {},
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
24 row: null,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
25 messages: null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
26 };
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
27
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
28 var search_loading = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
29
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
30 $(document).on("change", "#button_display_option", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
31 var img = $('img', $(this).closest('p'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
32 var src = img.attr('src');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
33 if(this.value == 'messagemenu') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
34 src = src.replace('menu_location_b.jpg', 'menu_location_a.jpg');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
35 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
36 src = src.replace('menu_location_a.jpg', 'menu_location_b.jpg');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
37 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
38 img.attr('src', src);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
39 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
40
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
41 $(document).on("change", "#_show_message_mbox_info, #_show_message_label_header", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
42 var img = $('img', $(this).closest('p'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
43 if($(this).is(':checked')) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
44 img.removeClass('disabled');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
45 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
46 img.addClass('disabled');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
47 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
48 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
49
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
50 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
51 * The callback function of the initial dialog call. It creates the dialog and buffers the serverside
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
52 * informations into an object.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
53 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
54 * @param {object} r The serverside informations
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
55 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
56 rcmail.addEventListener('plugin.show', function(r) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
57 $.stack.date_criteria = r.date_criteria;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
58 $.stack.flag_criteria = r.flag_criteria;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
59 $.stack.email_criteria = r.email_criteria;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
60 $.stack.row = r.row;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
61 $.stack.html = r.html;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
62
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
63 var $html = $(r.html);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
64 var saved_searches_label = rcmail.gettext('saved_searches', 'advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
65 var saved_searches = '<span class="saved_searches"> <label for="select_saved_search">' + saved_searches_label + ': <select name="select_saved_search" id="select_saved_search"><option value=""></option></select></label></span>';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
66 title = $('<div>' + r.title + saved_searches + '<div>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
67 var saved_searches_select = $('[name=select_saved_search]', title);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
68 if (r.saved_searches.length) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
69 var i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
70 for (i in r.saved_searches) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
71 saved_searches_select.append('<option value="' + r.saved_searches[i] + '">' + r.saved_searches[i] + '</option>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
72 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
73 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
74 $html.dialog({
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
75 width: 640,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
76 height: 300,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
77 resizable: true,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
78 draggable: true,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
79 title: title,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
80 dialogClass: "advanced_search_dialog",
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
81 close: function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
82 $('body').css('overflow', 'auto');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
83 },
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
84 create: function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
85 $('body').css('overflow', 'hidden');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
86 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
87 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
88
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
89 saved_searches_select.bind("blur click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
90 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
91 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
92
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
93 saved_searches_select.bind("mouseenter", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
94 saved_searches_select.focus();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
95 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
96
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
97 saved_searches_select.bind('change', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
98 var search_name = $(this).val();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
99 if (search_name == "") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
100 $('#adsearch-popup').html($.stack.html);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
101 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
102 rcmail.http_request('plugin.get_saved_search', { search_name : search_name });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
103 $('[name=delete]', '#adsearch-popup').show();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
104 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
105 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
106
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
107 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
108
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
109 rcmail.addEventListener('plugin.load_saved_search', function(search) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
110 var $form = $("#adsearch-popup form"),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
111 $tr = $('tr', $('tbody', $form)).not(':first').not(':last'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
112 $last = $('tr:last', $('tbody', $form));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
113 saved_search = search.search,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
114 data = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
115 $tr.remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
116 $("[name=folder]", $form).val(search.folder);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
117 $("[name=subfolder]", $form).prop('checked', search.sub_folders == "true");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
118 $('span.sub-folders', $form).css('display', search.folder == 'all' ? 'none' : 'inline');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
119
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
120 var i = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
121 for (i; i < saved_search.length; i++) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
122 var row;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
123 if (i == 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
124 row = $('<tr>' + $("tr:eq(1)", $.stack.html).html() + '</tr>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
125 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
126 row = $($.stack.row);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
127 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
128 $("[name=method]", row).val(saved_search[i].method);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
129 $("[name=filter]", row).val(saved_search[i].filter);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
130 $("[name=not]", row).prop('checked', saved_search[i]['not'] == "true");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
131 $("[name=filter-exclude]", row).prop('checked', saved_search[i]['excluded'] == "true");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
132 $last.before(row);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
133 $("[name=filter]", row).trigger("change");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
134 $("[name=filter-val]", row).val(saved_search[i]['filter-val']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
135 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
136 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
137 //messagelistcontainer table thead
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
138 rcmail.addEventListener('plugin.advanced_search_add_header', function(evt) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
139 if($("#messagelistcontainer #rcavbox1").length == 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
140 var Mbox = rcmail.gettext('mbox', 'advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
141 $("#messagelistcontainer table.fixedcopy thead tr:first").append('<td class="mbox" id="rcavbox1"><span class="mbox">' + Mbox + '</span></td>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
142 $("#messagelistcontainer table#messagelist thead tr:first").append('<td class="mbox" id="rcavbox2"><span class="mbox">' + Mbox + '</span></td>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
143 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
144 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
145
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
146 rcmail.addEventListener('plugin.advanced_search_del_header', function(evt) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
147 $("#messagelistcontainer #rcavbox1").remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
148 $("#messagelistcontainer #rcavbox2").remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
149 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
150
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
151 rcube_webmail.prototype.advanced_search_add_mbox = function (mbox, count, showMbox) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
152 if (!this.gui_objects.messagelist || !this.message_list) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
153 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
154 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
155
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
156 var colspan = showMbox == true ? 9 : 8;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
157 $(rcmail.message_list.list).append('<tr class="aslabel_mbox"><td><span class="aslabel_found">' + count + '</span></td><td colspan="' + colspan + '">' + mbox + '</td></tr>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
158 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
159
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
160 rcube_webmail.prototype.advanced_search_active = function(param) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
161 var page = param.replace('_page=', '');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
162 rcmail.http_request('plugin.trigger_search_pagination', { _page : page });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
163 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
164
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
165 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
166 * Builds the search to send to the server
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
167 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
168 var get_search_data = function()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
169 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
170 var $form = $("#adsearch-popup form"),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
171 $tr = $('tr', $('tbody', $form)).not(':first').not(':last'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
172 data = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
173
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
174 if ($tr.length) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
175 $tr.each(function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
176 var item = {not: $('input[name=not]', $(this)).prop('checked'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
177 excluded: $('input[name=filter-exclude]', $(this)).prop('checked'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
178 filter: $('option:selected', $('select[name=filter]', $(this))).val(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
179 'filter-val': $('input[name=filter-val]', $(this)).val()};
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
180
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
181 if ($('select[name=method]', $(this)).length) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
182 item.method = $('option:selected', $('select[name=method]', $(this))).val();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
183 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
184
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
185 data.push(item);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
186 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
187 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
188
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
189 return data;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
190 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
191
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
192 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
193 * The onclick event handler for the search button. This generates the search query and sends them
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
194 * to the server. It also stores the wrapped set of the old rows into an object for later cleanup.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
195 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
196 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
197 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
198 $(document).on("click", 'input[name=search]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
199 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
200
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
201 rcmail.clear_message_list();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
202
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
203 $.stack.messages = $('tr', $('tbody', '#messagelist'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
204
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
205 var $form = $("#adsearch-popup form");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
206 search_loading = rcmail.set_busy(true, 'loading');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
207 rcmail.http_request('plugin.trigger_search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
208 {search: get_search_data(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
209 current_folder: rcmail.env.mailbox,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
210 folder: $('select[name=folder]', $form).val(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
211 sub_folders: $('input[name=subfolder]', $form).prop('checked')});
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
212
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
213 $("#adsearch-popup").closest('div.ui-dialog-content').dialog('close');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
214 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
215
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
216 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
217 * The onclick event handler of the "reset search" button, which resets the advanced search
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
218 * back to its initial state.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
219 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
220 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
221 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
222 $(document).on("click", 'input[name=reset]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
223 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
224 $('#adsearch-popup').html($.stack.html);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
225 $('[name=select_saved_search]').val("");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
226 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
227
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
228 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
229 * The onclick event handler for the "add" button. This adds one new row to the query dialog
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
230 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
231 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
232 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
233 $(document).on("click", 'button[name=add]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
234 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
235
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
236 $(this).closest('tr').after($.stack.row);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
237 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
238
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
239 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
240 * The onclick event handler for the "delete" button. This removes the containing row from
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
241 * the query dialog
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
242 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
243 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
244 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
245 $(document).on("click", 'button[name=delete]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
246 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
247
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
248 $(this).closest('tr').remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
249 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
250
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
251 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
252 * The change event handler for the filter selector.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
253 * Make the input field context relevent.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
254 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
255 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
256 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
257 $(document).on("click", 'select[name=filter]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
258 var $row_input = $(this).nextUntil('tr', 'input[name=filter-val]'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
259 old_avs_type = $row_input.data("avs_type");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
260
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
261 if ($.inArray($(this).val(), $.stack.date_criteria) >= 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
262 if(old_avs_type !== "date") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
263 $row_input.val('');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
264 $row_input.datepicker({dateFormat: rcmail.env.date_format});
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
265 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
266
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
267 $row_input.data("avs_type", "date");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
268 } else if ($.inArray($(this).val(), $.stack.email_criteria) >= 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
269 if(old_avs_type !== "email") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
270 rcmail.init_address_input_events($row_input, "");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
271 rcmail.addEventListener('autocomplete_insert', function(e){
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
272 e.field.value = e.insert.replace(/.*<(\S*?@\S*?)>.*/, "$1");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
273 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
274 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
275
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
276 $row_input.data("avs_type", "email");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
277 } else if ($.inArray($(this).val(), $.stack.flag_criteria) >= 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
278 if (old_avs_type !== "flag_criteria") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
279 $row_input.val('');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
280 $row_input.hide();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
281 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
282
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
283 $row_input.data("avs_type", "flag_criteria");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
284 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
285 $row_input.data("avs_type", "none");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
286 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
287
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
288 switch (old_avs_type) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
289 case "date":
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
290 if (($row_input.data("avs_type") !== "date") && $row_input.hasClass("hasDatepicker")) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
291 $row_input.datepicker("destroy");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
292 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
293 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
294 case "email":
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
295 if (($row_input.data("avs_type") !== "email")) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
296 $row_input.removeAttr("autocomplete");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
297 $row_input.unbind('keydown');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
298 $row_input.unbind('keypress');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
299 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
300 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
301 case "flag_criteria":
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
302 if (($row_input.data("avs_type") !== "flag_criteria") && !$row_input.is(":visible")) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
303 $row_input.show();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
304 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
305 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
306 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
307 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
308
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
309 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
310 * The change event handler for the folder select box. It makes the subfolder checkbox invisible
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
311 * when selecting the "all folders" option
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
312 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
313 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
314 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
315 $(document).on("click", 'select[name=folder]', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
316 $('span.sub-folders', $(this).closest('form')).css('display', $(this).val() == 'all' ? 'none' : 'inline');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
317 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
318
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
319 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
320 * The onclick event handler for the menu entry of the advanced search. This makes the initial call
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
321 * of the advanced search and fires a query to the server to get every important information.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
322 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
323 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
324 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
325 $(document).on("click", 'a.icon.advanced-search, a.button.advanced-search', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
326 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
327
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
328 if (!$('#adsearch-popup').length) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
329 rcmail.http_request('plugin.display_advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
330 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
331 $("#adsearch-popup").closest('div.ui-dialog-content').dialog('open');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
332 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
333 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
334
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
335 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
336 * Stop propagation of keydown and keypress events.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
337 * This should stop these events being processed by other listeners in the mailbox.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
338 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
339 * @param {object} e The event element
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
340 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
341 $(document).on("keydown keypress", "#adsearch-popup", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
342 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
343 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
344
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
345 $(document).on("click", "#adsearch-popup input.delete_search", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
346 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
347 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
348 var search_name = $("[name=select_saved_search]").val();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
349 var txt = {};
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
350 txt['cancel'] = rcmail.get_label('advanced_search.cancel');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
351 txt['delete'] = rcmail.get_label('advanced_search.delete');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
352 $( "<p><strong>" + search_name + "</strong></p>" ).dialog({
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
353 resizable: true,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
354 height:180,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
355 modal: true,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
356 title: rcmail.gettext('advanced_search.deletesearch'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
357 buttons: [
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
358 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
359 text: txt['delete'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
360 click: function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
361 rcmail.http_request('plugin.delete_search', {search_name: search_name});
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
362 $("[value=" + search_name + "]", "[name=select_saved_search]").remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
363 $("[name=select_saved_search]").val("").trigger("change");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
364 $( this ).dialog( "close" );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
365 },
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
366 },
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
367 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
368 text: txt['cancel'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
369 click: function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
370 $( this ).dialog( "close" );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
371 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
372 }]
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
373
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
374 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
375 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
376
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
377 $(document).on("click", "#save_the_search", function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
378 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
379 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
380 var labelName = rcmail.gettext('name', 'advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
381 var labelSave = rcmail.gettext('save', 'advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
382 var labelCancel = rcmail.gettext('cancel', 'advanced_search');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
383 var save_search = '<table>'
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
384 + ' <tr><td>' + labelName + ' </td><td><input type="text" name="search_name" /></td></tr>'
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
385 + ' <tr><td></td><td><input type="submit" class="button mainaction" value="' + labelSave + '" /> <input type="reset" class="button reset" value="' + labelCancel + '" /></td></tr>'
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
386 + '</table>';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
387 save_search = $(save_search);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
388 $("[name=search_name]", save_search).val($("[name=select_saved_search]").val());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
389
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
390 save_search.dialog({
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
391 title: rcmail.gettext('advanced_search.save_the_search'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
392 dialogClass: 'saveTheSearch',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
393 close: function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
394 $(this).remove();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
395 },
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
396 width: $("#adsearch-popup").width(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
397 height: $("#adsearch-popup").height(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
398 modal: true
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
399 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
400 $(".mainaction", save_search).bind('click', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
401 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
402 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
403 var search_name = $("[name=search_name]", save_search).val();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
404 var $form = $("#adsearch-popup form");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
405 rcmail.http_request('plugin.save_search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
406 {search: get_search_data(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
407 search_name: search_name,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
408 folder: $('select[name=folder]', $form).val(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
409 sub_folders: $('input[name=subfolder]', $form).prop('checked')});
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
410 var isNewSearch = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
411 $("[name=select_saved_search] option").each(function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
412 if ($(this).attr("value") == search_name) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
413 isNewSearch = false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
414 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
415 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
416 if (isNewSearch) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
417 $("[name=select_saved_search]").append('<option value="' + search_name + '">' + search_name + '</option>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
418 $("[name=select_saved_search]").val(search_name);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
419 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
420 save_search.dialog('close');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
421 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
422
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
423 $(".reset", save_search).bind('click', function(e) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
424 e.preventDefault();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
425 e.stopPropagation();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
426 save_search.dialog('close');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
427 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
428
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
429 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
430
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
431 var advanced_search_redirect_draft_messages = function(check) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
432 if (rcmail.env.search_request == "advanced_search_active") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
433 if (rcmail.task == 'mail') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
434 uid = rcmail.get_single_uid();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
435 if (uid && (!rcmail.env.uid || uid != rcmail.env.uid || check)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
436 if ((rcmail.env.mailbox == rcmail.env.drafts_mailbox) || check) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
437 url = {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
438 _mbox: this.env.mailbox,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
439 _search: 'advanced_search_active'
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
440 };
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
441 url[this.env.mailbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid'] = uid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
442 this.goto_url('compose', url, true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
443 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
444 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
445 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
446 return true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
447 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
448 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
449 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
450
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
451 var advanced_search_perform_action = function(props, action) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
452
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
453 var raw_selection = rcmail.message_list.get_selection();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
454 var md5_folders = rcmail.env.as_md5_folders;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
455 var i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
456 var selections = {};
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
457 for (i in raw_selection) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
458 raw_selection[i];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
459 var parts = raw_selection[i].split('__MB__');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
460 var mid = parts[0];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
461 var md5Mbox = parts[1];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
462 var mbox = md5_folders[md5Mbox];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
463 if (!selections[mbox]) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
464 selections[mbox] = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
465 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
466 selections[mbox].push(mid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
467 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
468
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
469 if (i != undefined) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
470 // show wait message
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
471 if (rcmail.env.action == 'show') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
472 lock = rcmail.set_busy(true, 'movingmessage');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
473 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
474 rcmail.show_contentframe(false);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
475 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
476 // Hide message command buttons until a message is selected
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
477 rcmail.enable_command(rcmail.env.message_commands, false);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
478 var j;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
479 for (j in selections) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
480 rcmail.select_folder(j, '', true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
481 rcmail.env.mailbox = j;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
482 var uids = selections[j].join(',');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
483 var lock = false,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
484 post_data = rcmail.selection_post_data({
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
485 _target_mbox: props.id,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
486 _uid: uids
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
487 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
488 rcmail._with_selected_messages(action, post_data, lock);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
489 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
490 // Make sure we have no selection
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
491 rcmail.env.uid = undefined;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
492 rcmail.message_list.selection = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
493 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
494
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
495 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
496
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
497 var advanced_search_check_multi_mbox = function () {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
498 var raw_selection = rcmail.message_list.get_selection();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
499 var md5_folders = rcmail.env.as_md5_folders;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
500 var i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
501 var mcount = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
502 var selections = {};
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
503 for (i in raw_selection) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
504 raw_selection[i];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
505 var parts = raw_selection[i].split('__MB__');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
506 var mid = parts[0];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
507 var md5Mbox = parts[1];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
508 var mbox = md5_folders[md5Mbox];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
509 if (!selections[mbox]) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
510 selections[mbox] = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
511 mcount++;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
512 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
513 selections[mbox].push(mid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
514 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
515
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
516 return {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
517 isMulti: mcount > 1,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
518 selections: selections
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
519 };
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
520 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
521
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
522 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
523 * The roundcube init funtion, which registers and enables the advanced search command.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
524 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
525 rcmail.addEventListener('init', function() {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
526 rcmail.register_command('plugin.advanced_search', true, true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
527 rcmail.enable_command('plugin.advanced_search', true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
528
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
529 rcmail.addEventListener('plugin.search_complete', function(r) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
530 rcmail.set_busy(false, 'loading', search_loading);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
531 /* Start registering event listeners for handling drag/drop, marking, flagging etc... */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
532 rcmail.addEventListener('beforeedit', function (command) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
533 rcmail.env.framed = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
534 if (advanced_search_redirect_draft_messages(true)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
535 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
536 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
537 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
538
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
539 rcmail.message_list.addEventListener('dblclick', function (o) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
540 advanced_search_redirect_draft_messages();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
541 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
542
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
543 rcmail.message_list.addEventListener('select', function (list) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
544 if (rcmail.env.search_request == "advanced_search_active") {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
545 if (list.selection.length == 1) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
546 var parts = list.selection[0].split('__MB__');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
547 var mid = parts[0];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
548 var md5Mbox = parts[1];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
549 var mbox = rcmail.env.as_md5_folders[md5Mbox];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
550 rcmail.env.uid = mid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
551 if (rcmail.env.mailbox != mbox) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
552 var ex = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
553 li = rcmail.get_folder_li(mbox, '', true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
554 parent = $(li).parents(".mailbox");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
555 parent.each(function () {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
556 div = $(this.getElementsByTagName('div')[0]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
557 a = $(this.getElementsByTagName('a')[0]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
558 if (div.hasClass('collapsed')) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
559 ex.push($(a).attr("rel"));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
560 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
561 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
562 for (var i = ex.length - 1; i >= 0; i--) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
563 rcmail.command('collapse-folder', ex[i]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
564 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
565 rcmail.select_folder(mbox, '', true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
566 rcmail.env.mailbox = mbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
567 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
568 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
569 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
570 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
571 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
572
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
573 rcmail.addEventListener('beforemoveto', function (props) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
574 if (rcmail.env.search_request == 'advanced_search_active') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
575 advanced_search_perform_action(props, 'moveto');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
576
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
577 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
578 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
579 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
580
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
581 rcmail.addEventListener('beforedelete', function (props) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
582 if (rcmail.env.search_request == 'advanced_search_active') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
583 advanced_search_perform_action(props, 'delete');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
584
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
585 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
586 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
587 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
588
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
589 rcmail.addEventListener('beforemark', function (flag) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
590 if (rcmail.env.search_request == 'advanced_search_active') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
591 var res = advanced_search_check_multi_mbox();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
592 //Update on server
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
593 var i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
594 var sel = res.selections;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
595 for (i in sel) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
596 var uids = sel[i].join(',');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
597 var lock = false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
598 var post_data = {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
599 _uid: uids,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
600 _flag: flag,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
601 _mbox: i,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
602 _remote: 1
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
603 };
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
604 rcmail.http_post('mark', post_data, lock);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
605 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
606 var raw_selection = rcmail.message_list.get_selection();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
607 for(i in raw_selection) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
608 var key = raw_selection[i];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
609 switch (flag) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
610 case 'read':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
611 rcmail.message_list.rows[key].unread = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
612 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
613 case 'unread':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
614 rcmail.message_list.rows[key].unread = 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
615 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
616 case 'flagged':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
617 rcmail.message_list.rows[key].flagged = 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
618 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
619 case 'unflagged':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
620 rcmail.message_list.rows[key].flagged = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
621 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
622 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
623 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
624 //Refresh ui
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
625 var messages = [];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
626 var selections = rcmail.message_list.get_selection();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
627 var j;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
628 for (j in selections) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
629 messages.push('#rcmrow' + selections[j]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
630 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
631 var selector = messages.join(', ');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
632 var selection = $(selector);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
633 switch (flag) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
634 case 'read':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
635 selection.removeClass('unread');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
636 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
637 case 'unread':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
638 selection.addClass('unread');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
639 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
640 case 'flagged':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
641 selection.addClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
642 $("td.flag span", selection).removeClass('unflagged').addClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
643 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
644 case 'unflagged':
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
645 selection.removeClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
646 $("td.flag span", selection).removeClass('flagged').addClass('unflagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
647 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
648 default:
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
649 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
650 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
651 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
652 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
653 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
654
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
655 rcmail.addEventListener('beforeforward', function (props) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
656 if (rcmail.env.search_request == 'advanced_search_active' && rcmail.message_list.selection.length > 1) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
657 var res = advanced_search_check_multi_mbox();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
658 if (res.isMulti == true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
659 //Selections from more then one folder
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
660 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
661 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
662 //Only one folder, redirecting
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
663 var i, url, sel = res.selections;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
664 for (i in sel) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
665 url = '&_forward_uid=' + sel[i].join(',') + '&_mbox=' + i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
666 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
667 url += '&_attachment=1&_action=compose';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
668 window.location = location.pathname + rcmail.env.comm_path + url;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
669
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
670 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
671 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
672 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
673 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
674
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
675 rcmail.addEventListener('beforeforward-attachment', function (props) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
676 if (rcmail.env.search_request == 'advanced_search_active' && rcmail.message_list.selection.length > 1) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
677 var res = advanced_search_check_multi_mbox();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
678 if (res.isMulti == true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
679 //Selections from more then one folder
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
680 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
681 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
682 //Only one folder, redirecting
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
683 var i, url, sel = res.selections;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
684 for (i in sel) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
685 url = '&_forward_uid=' + sel[i].join(',') + '&_mbox=' + i;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
686 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
687 url += '&_attachment=1&_action=compose';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
688 window.location = location.pathname + rcmail.env.comm_path + url;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
689
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
690 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
691 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
692 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
693 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
694
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
695 rcmail.addEventListener('beforetoggle_flag', function (props) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
696 if (rcmail.env.search_request == 'advanced_search_active') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
697 var flag = $(props).hasClass('unflagged') ? 'flagged' : 'unflagged';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
698 var tr = $(props).closest('tr');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
699 var id = tr.attr('id').replace('rcmrow', '');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
700 var parts = id.split('__MB__');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
701 var lock = false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
702 var mbox = rcmail.env.as_md5_folders[parts[1]];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
703 var post_data = {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
704 _uid: parts[0],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
705 _flag: flag,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
706 _mbox: mbox,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
707 _remote: 1
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
708 };
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
709 rcmail.http_post('mark', post_data, lock);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
710 if (flag == 'flagged') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
711 tr.addClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
712 $("td.flag span", tr).removeClass('unflagged').addClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
713 rcmail.message_list.rows[id].flagged = 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
714 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
715 tr.removeClass('flagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
716 $("td.flag span", tr).removeClass('flagged').addClass('unflagged');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
717 rcmail.message_list.rows[id].flagged = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
718 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
719 return false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
720 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
721 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
722 /* End registering event listeners */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
723 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
724
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
725 });
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
726 })(jQuery);