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