annotate program/js/app.js @ 2:0cac1d1e799f

weld in some support for Dates column
author Charlie Root
date Tue, 16 Jan 2018 17:54:18 -0500
parents 4681f974d28b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2 * Roundcube Webmail Client Script
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 * This file is part of the Roundcube Webmail client
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 * @licstart The following is the entire license notice for the
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 * JavaScript code in this file.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * Copyright (C) 2005-2015, The Roundcube Dev Team
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 * Copyright (C) 2011-2015, Kolab Systems AG
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 * The JavaScript code in this page is free software: you can
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 * redistribute it and/or modify it under the terms of the GNU
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * General Public License (GNU GPL) as published by the Free Software
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 * Foundation, either version 3 of the License, or (at your option)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 * any later version. The code is distributed WITHOUT ANY WARRANTY;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 * without even the implied warranty of MERCHANTABILITY or FITNESS
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 * As additional permission under GNU GPL version 3 section 7, you
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 * may distribute non-source (e.g., minimized or compacted) forms of
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * that code without the copy of the GNU GPL normally required by
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * section 4, provided you include this license notice and a URL
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * through which recipients can access the Corresponding Source.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * @licend The above is the entire license notice
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 * for the JavaScript code in this file.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 * @author Thomas Bruederli <roundcube@gmail.com>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 * @author Charles McNulty <charles@charlesmcnulty.com>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 * @requires jquery.js, common.js, list.js
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 function rcube_webmail()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 this.labels = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 this.buttons = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 this.buttons_sel = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 this.gui_objects = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 this.gui_containers = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 this.commands = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 this.command_handlers = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 this.onloads = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 this.messages = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 this.group2expand = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 this.http_request_jobs = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 this.menu_stack = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 // webmail client settings
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 this.dblclick_time = 500;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 this.message_time = 5000;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 this.preview_delay_select = 400;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 this.preview_delay_click = 60;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 this.identifier_expr = /[^0-9a-z_-]/gi;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 // environment defaults
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 this.env = {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 request_timeout: 180, // seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 draft_autosave: 0, // seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 comm_path: './',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 recipients_separator: ',',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 recipients_delimiter: ', ',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 popup_width: 1150,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 popup_width_small: 900
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 // create protected reference to myself
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 this.ref = 'rcmail';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 var ref = this;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 // set jQuery ajax options
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 $.ajaxSetup({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 cache: false,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 timeout: this.env.request_timeout * 1000,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 error: function(request, status, err){ ref.http_error(request, status, err); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 beforeSend: function(xmlhttp){ xmlhttp.setRequestHeader('X-Roundcube-Request', ref.env.request_token); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 // unload fix
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 $(window).on('beforeunload', function() { ref.unload = true; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 // set environment variable(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 this.set_env = function(p, value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 if (p != null && typeof p === 'object' && !value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 for (var n in p)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 this.env[n] = p[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 this.env[p] = value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 // add a localized label to the client environment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 this.add_label = function(p, value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 if (typeof p == 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 this.labels[p] = value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 else if (typeof p == 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 $.extend(this.labels, p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 // add a button to the button list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 this.register_button = function(command, id, type, act, sel, over)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 var button_prop = {id:id, type:type};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 if (act) button_prop.act = act;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 if (sel) button_prop.sel = sel;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 if (over) button_prop.over = over;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 if (!this.buttons[command])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 this.buttons[command] = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 this.buttons[command].push(button_prop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 if (this.loaded)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 init_button(command, button_prop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 // register a specific gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 this.gui_object = function(name, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 this.gui_objects[name] = this.loaded ? rcube_find_object(id) : id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 // register a container object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 this.gui_container = function(name, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 this.gui_containers[name] = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 // add a GUI element (html node) to a specified container
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 this.add_element = function(elm, container)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 if (this.gui_containers[container] && this.gui_containers[container].jquery)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 this.gui_containers[container].append(elm);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 // register an external handler for a certain command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 this.register_command = function(command, callback, enable)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 this.command_handlers[command] = callback;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 if (enable)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 this.enable_command(command, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 // execute the given script on load
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 this.add_onload = function(f)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 this.onloads.push(f);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 // initialize webmail client
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 this.init = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 var n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 this.task = this.env.task;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 // check browser capabilities (never use version checks here)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 if (this.env.server_error != 409 && (!bw.dom || !bw.xmlhttp_test())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 this.goto_url('error', '_code=0x199');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 if (!this.env.blankpage)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 this.env.blankpage = this.assets_path('program/resources/blank.gif');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 // find all registered gui containers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 for (n in this.gui_containers)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 this.gui_containers[n] = $('#'+this.gui_containers[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 // find all registered gui objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 for (n in this.gui_objects)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 this.gui_objects[n] = rcube_find_object(this.gui_objects[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 // clickjacking protection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 if (n = this.env.x_frame_options) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 // bust frame if not allowed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 if (n.toLowerCase() == 'deny' && top.location.href != self.location.href)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 top.location.href = self.location.href;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 else if (/^allow-from[\s\t]+(.+)$/i.test(n) && RegExp.$1.indexOf(top.location.origin) != 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 throw 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 else if (top.location.hostname != self.location.hostname)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 throw 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 } catch (e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 // possible clickjacking attack: disable all form elements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 $('form').each(function(){ ref.lock_form(this, true); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 this.display_message("Blocked: possible clickjacking attack!", 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 // init registered buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 this.init_buttons();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 // tell parent window that this frame is loaded
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 if (this.is_framed()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 parent.rcmail.set_busy(false, null, parent.rcmail.env.frame_lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 parent.rcmail.env.frame_lock = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 // enable general commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 this.enable_command('close', 'logout', 'mail', 'addressbook', 'settings', 'save-pref',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 'compose', 'undo', 'about', 'switch-task', 'menu-open', 'menu-close', 'menu-save', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 // set active task button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 this.set_button(this.task, 'sel');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 if (this.env.permaurl)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 this.enable_command('permaurl', 'extwin', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 switch (this.task) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 case 'mail':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 // enable mail commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 this.enable_command('list', 'checkmail', 'add-contact', 'search', 'reset-search', 'collapse-folder', 'import-messages', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 if (this.gui_objects.messagelist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 this.env.widescreen_list_template = [
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 {className: 'threads', cells: ['threads']},
2
0cac1d1e799f weld in some support for Dates column
Charlie Root
parents: 0
diff changeset
224 {className: 'subject', cells: ['fromto', 'date', 'status', 'subject','dates']},
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 {className: 'flags', cells: ['flag', 'attachment']}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 ];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 multiselect:true, multiexpand:true, draggable:true, keyboard:true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 column_movable:this.env.col_movable, dblclick_time:this.dblclick_time
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 this.message_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 .addEventListener('initrow', function(o) { ref.init_message_row(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 .addEventListener('dblclick', function(o) { ref.msglist_dbl_click(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 .addEventListener('keypress', function(o) { ref.msglist_keypress(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 .addEventListener('select', function(o) { ref.msglist_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 .addEventListener('dragstart', function(o) { ref.drag_start(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 .addEventListener('dragmove', function(e) { ref.drag_move(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 .addEventListener('dragend', function(e) { ref.drag_end(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 .addEventListener('expandcollapse', function(o) { ref.msglist_expand(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 .addEventListener('column_replace', function(o) { ref.msglist_set_coltypes(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 .addEventListener('listupdate', function(o) { ref.triggerEvent('listupdate', o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 .init();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 // TODO: this should go into the list-widget code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 $(this.message_list.thead).on('click', 'a.sortcol', function(e){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 return ref.command('sort', $(this).attr('rel'), this);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 this.enable_command('toggle_status', 'toggle_flag', 'sort', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 this.enable_command('set-listmode', this.env.threads && !this.is_multifolder_listing());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 // load messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 this.command('list');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 $(this.gui_objects.qsearchbox).val(this.env.search_text).focusin(function() { ref.message_list.blur(); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 this.set_button_titles();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 this.env.message_commands = ['show', 'reply', 'reply-all', 'reply-list',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 'move', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 'print', 'load-attachment', 'download-attachment', 'show-headers', 'hide-headers', 'download',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 'forward', 'forward-inline', 'forward-attachment', 'change-format'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 if (this.env.action == 'show' || this.env.action == 'preview') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 this.enable_command(this.env.message_commands, this.env.uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 this.enable_command('reply-list', this.env.list_post);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 if (this.env.action == 'show') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 this.http_request('pagenav', {_uid: this.env.uid, _mbox: this.env.mailbox, _search: this.env.search_request},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 this.display_message('', 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 if (this.env.mail_read_time > 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 setTimeout(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 ref.http_post('mark', {_uid: ref.env.uid, _flag: 'read', _mbox: ref.env.mailbox, _quiet: 1});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 }, this.env.mail_read_time * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 if (this.env.blockedobjects) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 if (this.gui_objects.remoteobjectsmsg)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 this.gui_objects.remoteobjectsmsg.style.display = 'block';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 this.enable_command('load-images', 'always-load', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 // make preview/message frame visible
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 if (this.env.action == 'preview' && this.is_framed()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 this.enable_command('compose', 'add-contact', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 parent.rcmail.show_contentframe(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 // initialize drag-n-drop on attachments, so they can e.g.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 // be dropped into mail compose attachments in another window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 if (this.gui_objects.attachments)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 $('li > a', this.gui_objects.attachments).not('.drop').on('dragstart', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 var n, href = this.href, dt = e.originalEvent.dataTransfer;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 if (dt) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 // inject username to the uri
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 href = href.replace(/^https?:\/\//, function(m) { return m + urlencode(ref.env.username) + '@'});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 // cleanup the node to get filename without the size test
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 n = $(this).clone();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 n.children().remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 dt.setData('roundcube-uri', href);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 dt.setData('roundcube-name', $.trim(n.text()));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 else if (this.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 this.env.address_group_stack = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 'toggle-editor', 'list-addresses', 'pushgroup', 'search', 'reset-search', 'extwin',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 'insert-response', 'save-response', 'menu-open', 'menu-close', 'load-attachment',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 'download-attachment', 'open-attachment', 'rename-attachment'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 if (this.env.drafts_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 this.env.compose_commands.push('savedraft')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 this.enable_command(this.env.compose_commands, 'identities', 'responses', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 // add more commands (not enabled)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 $.merge(this.env.compose_commands, ['add-recipient', 'firstpage', 'previouspage', 'nextpage', 'lastpage']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 if (window.googie) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 this.env.editor_config.spellchecker = googie;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 this.env.editor_config.spellcheck_observer = function(s) { ref.spellcheck_state(); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 this.env.compose_commands.push('spellcheck')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 this.enable_command('spellcheck', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 // initialize HTML editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 this.editor_init(this.env.editor_config, this.env.composebody);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 // init canned response functions
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 if (this.gui_objects.responseslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 $('a.insertresponse', this.gui_objects.responseslist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 .attr('unselectable', 'on')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 .mousedown(function(e) { return rcube_event.cancel(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 .on('mouseup keypress', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 if (e.type == 'mouseup' || rcube_event.get_keycode(e) == 13) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 ref.command('insert-response', $(this).attr('rel'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 $(document.body).trigger('mouseup'); // hides the menu
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 // avoid textarea loosing focus when hitting the save-response button/link
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 $.each(this.buttons['save-response'] || [], function (i, v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 $('#' + v.id).mousedown(function(e){ return rcube_event.cancel(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 // init message compose form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 this.init_messageform();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 else if (this.env.action == 'get') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 this.enable_command('download', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 // Mozilla's PDF.js viewer does not allow printing from host page (#5125)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 // to minimize user confusion we disable the Print button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 if (bw.mz && this.env.mimetype == 'application/pdf') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 n = 0; // there will be two onload events, first for the preload page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 $(this.gui_objects.messagepartframe).on('load', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 if (n++) try { if (this.contentWindow.document) ref.enable_command('print', true); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 catch (e) {/* ignore */}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 this.enable_command('print', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 if (this.env.is_message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 this.enable_command('reply', 'reply-all', 'edit', 'viewsource',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 'forward', 'forward-inline', 'forward-attachment', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 if (this.env.list_post)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 this.enable_command('reply-list', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 // center and scale the image in preview frame
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 if (this.env.mimetype.startsWith('image/'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 $(this.gui_objects.messagepartframe).on('load', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 var css = 'img { max-width:100%; max-height:100%; } ' // scale
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 + 'body { display:flex; align-items:center; justify-content:center; height:100%; margin:0; }'; // align
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 $(this).contents().find('head').append('<style type="text/css">'+ css + '</style>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 // show printing dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 else if (this.env.action == 'print' && this.env.uid
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 && !this.env.is_pgp_content && !this.env.pgp_mime_part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 this.print_dialog();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 // get unread count for each mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 if (this.gui_objects.mailboxlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 this.env.unread_counts = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 this.gui_objects.folderlist = this.gui_objects.mailboxlist;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 this.http_request('getunread', {_page: this.env.current_page});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 // init address book widget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 if (this.gui_objects.contactslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 this.contact_list = new rcube_list_widget(this.gui_objects.contactslist,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 { multiselect:true, draggable:false, keyboard:true });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 this.contact_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 .addEventListener('initrow', function(o) { ref.triggerEvent('insertrow', { cid:o.uid, row:o }); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 .addEventListener('select', function(o) { ref.compose_recipient_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 .addEventListener('dblclick', function(o) { ref.compose_add_recipient(); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 .addEventListener('keypress', function(o) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 if (o.key_pressed == o.ENTER_KEY) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 if (!ref.compose_add_recipient()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 // execute link action on <enter> if not a recipient entry
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 if (o.last_selected && String(o.last_selected).charAt(0) == 'G') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 $(o.rows[o.last_selected].obj).find('a').first().click();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 .init();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 // remember last focused address field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 $('#_to,#_cc,#_bcc').focus(function() { ref.env.focused_field = this; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 if (this.gui_objects.addressbookslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 this.gui_objects.folderlist = this.gui_objects.addressbookslist;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 this.enable_command('list-addresses', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 // ask user to send MDN
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 if (this.env.mdn_request && this.env.uid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 var postact = 'sendmdn',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 postdata = {_uid: this.env.uid, _mbox: this.env.mailbox};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 if (!confirm(this.get_label('mdnrequest'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 postdata._flag = 'mdnsent';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 postact = 'mark';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 this.http_post(postact, postdata);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 this.check_mailvelope(this.env.action);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 // detect browser capabilities
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 if (!this.is_framed() && !this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 this.browser_capabilities_check();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 case 'addressbook':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 this.env.address_group_stack = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 if (this.gui_objects.folderlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 this.env.contactfolders = $.extend($.extend({}, this.env.address_sources), this.env.contactgroups);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 this.enable_command('add', 'import', this.env.writable_source);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 this.enable_command('list', 'listgroup', 'pushgroup', 'popgroup', 'listsearch', 'search', 'reset-search', 'advanced-search', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 if (this.gui_objects.contactslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460 this.contact_list = new rcube_list_widget(this.gui_objects.contactslist,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 {multiselect:true, draggable:this.gui_objects.folderlist?true:false, keyboard:true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 this.contact_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 .addEventListener('initrow', function(o) { ref.triggerEvent('insertrow', { cid:o.uid, row:o }); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 .addEventListener('keypress', function(o) { ref.contactlist_keypress(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 .addEventListener('select', function(o) { ref.contactlist_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 .addEventListener('dragstart', function(o) { ref.drag_start(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 .addEventListener('dragmove', function(e) { ref.drag_move(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 .addEventListener('dragend', function(e) { ref.drag_end(e); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 .init();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 $(this.gui_objects.qsearchbox).focusin(function() { ref.contact_list.blur(); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 this.update_group_commands();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 this.command('list');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 if (this.gui_objects.savedsearchlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 this.savedsearchlist = new rcube_treelist_widget(this.gui_objects.savedsearchlist, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 id_prefix: 'rcmli',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 id_encode: this.html_identifier_encode,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 id_decode: this.html_identifier_decode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 this.savedsearchlist.addEventListener('select', function(node) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 ref.triggerEvent('selectfolder', { folder:node.id, prefix:'rcmli' }); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 this.set_page_buttons();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 if (this.env.cid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 this.enable_command('show', 'edit', 'qrcode', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 // register handlers for group assignment via checkboxes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 if (this.gui_objects.editform) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 $('input.groupmember').change(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 ref.group_member_change(this.checked ? 'add' : 'del', ref.env.cid, ref.env.source, this.value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 if (this.gui_objects.editform) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501 this.enable_command('save', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 if (this.env.action == 'add' || this.env.action == 'edit' || this.env.action == 'search')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 this.init_contact_form();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505 else if (this.env.action == 'print') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 this.print_dialog();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 case 'settings':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 this.enable_command('preferences', 'identities', 'responses', 'save', 'folders', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 if (this.env.action == 'identities') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 this.enable_command('add', this.env.identities_level < 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 else if (this.env.action == 'edit-identity' || this.env.action == 'add-identity') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 this.enable_command('save', 'edit', 'toggle-editor', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 this.enable_command('delete', this.env.identities_level < 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 // initialize HTML editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 this.editor_init(this.env.editor_config, 'rcmfd_signature');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 else if (this.env.action == 'folders') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 else if (this.env.action == 'edit-folder' && this.gui_objects.editform) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 this.enable_command('save', 'folder-size', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 parent.rcmail.env.exists = this.env.messagecount;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 parent.rcmail.enable_command('purge', this.env.messagecount);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 else if (this.env.action == 'responses') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 this.enable_command('add', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 if (this.gui_objects.identitieslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 {multiselect:false, draggable:false, keyboard:true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 this.identity_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 .addEventListener('select', function(o) { ref.identity_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 .addEventListener('keypress', function(o) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 if (o.key_pressed == o.ENTER_KEY) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 ref.identity_select(o);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 .init()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 .focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 else if (this.gui_objects.sectionslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 this.sections_list = new rcube_list_widget(this.gui_objects.sectionslist, {multiselect:false, draggable:false, keyboard:true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 this.sections_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 .addEventListener('select', function(o) { ref.section_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 .addEventListener('keypress', function(o) { if (o.key_pressed == o.ENTER_KEY) ref.section_select(o); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 .init()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 .focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 else if (this.gui_objects.subscriptionlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 this.init_subscription_list();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 else if (this.gui_objects.responseslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 this.responses_list = new rcube_list_widget(this.gui_objects.responseslist, {multiselect:false, draggable:false, keyboard:true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 this.responses_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 .addEventListener('select', function(list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 var win, id = list.get_single_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 ref.enable_command('delete', !!id && $.inArray(id, ref.env.readonly_responses) < 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 if (id && (win = ref.get_frame_window(ref.env.contentframe))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 ref.set_busy(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 ref.location_href({ _action:'edit-response', _key:id, _framed:1 }, win);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 .init()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 .focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 case 'login':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 var tz, tz_name, jstz = window.jstz,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 input_user = $('#rcmloginuser'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 input_tz = $('#rcmlogintz');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 input_user.keyup(function(e) { return ref.login_user_keyup(e); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 if (input_user.val() == '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 input_user.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 $('#rcmloginpwd').focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 // detect client timezone
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 if (jstz && (tz = jstz.determine()))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591 tz_name = tz.name();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 input_tz.val(tz_name ? tz_name : (new Date().getStdTimezoneOffset() / -60));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 // display 'loading' message on form submit, lock submit button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 $('form').submit(function () {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 $('input[type=submit]', this).prop('disabled', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 ref.clear_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 ref.display_message('', 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 this.enable_command('login', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 // select first input field in an edit form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 if (this.gui_objects.editform)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 $("input,select,textarea", this.gui_objects.editform)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 .not(':hidden').not(':disabled').first().select().focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 // prevent from form submit with Enter key in file input fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 if (bw.ie)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 $('input[type=file]').keydown(function(e) { if (e.keyCode == '13') e.preventDefault(); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 // flag object as complete
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 this.loaded = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 this.env.lastrefresh = new Date();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 // show message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 if (this.pending_message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 this.display_message.apply(this, this.pending_message);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 // init treelist widget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 if (this.gui_objects.folderlist && window.rcube_treelist_widget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 // some plugins may load rcube_treelist_widget and there's one case
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 // when this will cause problems - addressbook widget in compose,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 // which already has been initialized using rcube_list_widget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 && this.gui_objects.folderlist != this.gui_objects.addressbookslist
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 this.treelist = new rcube_treelist_widget(this.gui_objects.folderlist, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 selectable: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 id_prefix: 'rcmli',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 parent_focus: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 id_encode: this.html_identifier_encode,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 id_decode: this.html_identifier_decode,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 check_droptarget: function(node) { return !node.virtual && ref.check_droptarget(node.id) }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 this.treelist
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 .addEventListener('collapse', function(node) { ref.folder_collapsed(node) })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 .addEventListener('expand', function(node) { ref.folder_collapsed(node) })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 .addEventListener('beforeselect', function(node) { return !ref.busy; })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 .addEventListener('select', function(node) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 ref.triggerEvent('selectfolder', { folder:node.id, prefix:'rcmli' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 ref.mark_all_read_state();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 // activate html5 file drop feature (if browser supports it and if configured)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 if (this.gui_objects.filedrop && this.env.filedrop && ((window.XMLHttpRequest && XMLHttpRequest.prototype && XMLHttpRequest.prototype.sendAsBinary) || window.FormData)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 $(document.body).on('dragover dragleave drop', function(e) { return ref.document_drag_hover(e, e.type == 'dragover'); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 $(this.gui_objects.filedrop).addClass('droptarget')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 .on('dragover dragleave', function(e) { return ref.file_drag_hover(e, e.type == 'dragover'); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 .get(0).addEventListener('drop', function(e) { return ref.file_dropped(e); }, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 // catch document (and iframe) mouse clicks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 var body_mouseup = function(e) { return ref.doc_mouse_up(e); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 $(document.body)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 .mouseup(body_mouseup)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 .keydown(function(e) { return ref.doc_keypress(e); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 rcube_webmail.set_iframe_events({mouseup: body_mouseup});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 // trigger init event hook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 this.triggerEvent('init', { task:this.task, action:this.env.action });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 // execute all foreign onload scripts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 // @deprecated
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 for (n in this.onloads) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 if (typeof this.onloads[n] === 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 eval(this.onloads[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 else if (typeof this.onloads[n] === 'function')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 this.onloads[n]();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 // start keep-alive and refresh intervals
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 this.start_refresh();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 this.start_keepalive();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682 this.log = function(msg)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 if (this.env.devel_mode && window.console && console.log)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 console.log(msg);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 /********* client command interface *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 // execute a specific command on the web client
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 this.command = function(command, props, obj, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 var ret, uid, cid, url, flag, aborted = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 if (obj && obj.blur && !(event && rcube_event.is_keyboard(event)))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698 obj.blur();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 // do nothing if interface is locked by another command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 // with exception for searching reset and menu
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702 if (this.busy && !(command == 'reset-search' && this.last_command == 'search') && !command.match(/^menu-/))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 // let the browser handle this click (shift/ctrl usually opens the link in a new window/tab)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 if ((obj && obj.href && String(obj.href).indexOf('#') < 0) && rcube_event.get_modifier(event)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710 // command not supported or allowed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711 if (!this.commands[command]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 // pass command to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 if (this.is_framed())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 parent.rcmail.command(command, props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 // check input before leaving compose step
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720 if (this.task == 'mail' && this.env.action == 'compose' && !this.env.server_error && command != 'save-pref'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 && $.inArray(command, this.env.compose_commands) < 0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 if (!this.env.is_sent && this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 // remove copy from local storage if compose screen is left intentionally
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 this.remove_compose_data(this.env.compose_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 this.compose_skip_unsavedcheck = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 this.last_command = command;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 // process external commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 if (typeof this.command_handlers[command] === 'function') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 ret = this.command_handlers[command](props, obj, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 return ret !== undefined ? ret : (obj ? false : true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 else if (typeof this.command_handlers[command] === 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 ret = window[this.command_handlers[command]](props, obj, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740 return ret !== undefined ? ret : (obj ? false : true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 // trigger plugin hooks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 this.triggerEvent('actionbefore', {props:props, action:command, originalEvent:event});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 ret = this.triggerEvent('before'+command, props || event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 if (ret !== undefined) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 // abort if one of the handlers returned false
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 if (ret === false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 props = ret;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 ret = undefined;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 // process internal command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 switch (command) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 case 'login':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 if (this.gui_objects.loginform)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 this.gui_objects.loginform.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 // commands to switch task
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 case 'logout':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 case 'mail':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 case 'addressbook':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 case 'settings':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 this.switch_task(command);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 case 'about':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 this.redirect('?_task=settings&_action=about', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 case 'permaurl':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 if (obj && obj.href && obj.target)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 else if (this.env.permaurl)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 parent.location.href = this.env.permaurl;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 case 'extwin':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 if (this.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 var form = this.gui_objects.messageform,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 win = this.open_window('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788 if (win) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 this.save_compose_form_local();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 this.compose_skip_unsavedcheck = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 $("input[name='_action']", form).val('compose');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 form.action = this.url('mail/compose', { _id: this.env.compose_id, _extwin: 1 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 form.target = win.name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 form.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 this.open_window(this.env.permaurl, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 case 'change-format':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 url = this.env.permaurl + '&_format=' + props;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805 if (this.env.action == 'preview')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 url = url.replace(/_action=show/, '_action=preview') + '&_framed=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 if (this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 url += '&_extwin=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 location.href = url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 case 'menu-open':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 if (props && props.menu == 'attachmentmenu') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 var mimetype = this.env.attachments[props.id];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 if (mimetype && mimetype.mimetype) // in compose format is different
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 mimetype = mimetype.mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 this.enable_command('open-attachment', mimetype && this.env.mimetypes && $.inArray(mimetype, this.env.mimetypes) >= 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 this.show_menu(props, props.show || undefined, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823 case 'menu-close':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 this.hide_menu(props, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 case 'menu-save':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 this.triggerEvent(command, {props:props, originalEvent:event});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 case 'open':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 if (uid = this.get_single_uid()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 obj.href = this.url('show', this.params_from_uid(uid));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 case 'close':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 if (this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 window.close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 case 'list':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 if (props && props != '') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 this.reset_qsearch(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 if (this.env.action == 'compose' && this.env.extwin) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 window.close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 else if (this.task == 'mail') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 this.list_mailbox(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 this.set_button_titles();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 else if (this.task == 'addressbook')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 this.list_contacts(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 case 'set-listmode':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 this.set_list_options(null, undefined, undefined, props == 'threads' ? 1 : 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 case 'sort':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 var sort_order = this.env.sort_order,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 sort_col = !this.env.disabled_sort_col ? props : this.env.sort_col;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 if (!this.env.disabled_sort_order)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 sort_order = this.env.sort_col == sort_col && sort_order == 'ASC' ? 'DESC' : 'ASC';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 // set table header and update env
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 this.set_list_sorting(sort_col, sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 // reload message list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 this.list_mailbox('', '', sort_col+'_'+sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 case 'nextpage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 this.list_page('next');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 case 'lastpage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 this.list_page('last');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 case 'previouspage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 this.list_page('prev');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 case 'firstpage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 this.list_page('first');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 case 'expunge':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 if (this.env.exists)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 this.expunge_mailbox(this.env.mailbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 case 'purge':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 case 'empty-mailbox':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 if (this.env.exists)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 this.purge_mailbox(this.env.mailbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 // common commands used in multiple tasks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 case 'show':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 if (this.task == 'mail') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 uid = this.get_single_uid();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 if (uid && (!this.env.uid || uid != this.env.uid)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 if (this.env.mailbox == this.env.drafts_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 this.show_message(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 else if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 cid = props ? props : this.get_single_cid();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 if (cid && !(this.env.action == 'show' && cid == this.env.cid))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 this.load_contact(cid, 'show');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 case 'add':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 if (this.task == 'addressbook')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923 this.load_contact(0, 'add');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 else if (this.task == 'settings' && this.env.action == 'responses') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 var frame;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 if ((frame = this.get_frame_window(this.env.contentframe))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 this.set_busy(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 this.location_href({ _action:'add-response', _framed:1 }, frame);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 else if (this.task == 'settings') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 this.identity_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933 this.load_identity(0, 'add-identity');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 case 'edit':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 if (this.task == 'addressbook' && (cid = this.get_single_cid()))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 this.load_contact(cid, 'edit');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 else if (this.task == 'settings' && props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 this.load_identity(props, 'edit-identity');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 else if (this.task == 'mail' && (uid = this.get_single_uid())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 url = { _mbox: this.get_message_mailbox(uid) };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 this.open_compose_step(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 case 'save':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 var input, form = this.gui_objects.editform;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 if (form) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952 // adv. search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 if (this.env.action == 'search') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 // user prefs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 else if ((input = $("input[name='_pagesize']", form)) && input.length && isNaN(parseInt(input.val()))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 alert(this.get_label('nopagesizewarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 input.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 // contacts/identities
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 // reload form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 if (props == 'reload') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 form.action += '&_reload=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 else if (this.task == 'settings' && (this.env.identities_level % 2) == 0 &&
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 (input = $("input[name='_email']", form)) && input.length && !rcube_check_email(input.val())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 alert(this.get_label('noemailwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 input.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 // add selected source (on the list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 if (parent.rcmail && parent.rcmail.env.source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 form.action = this.add_url(form.action, '_orig_source', parent.rcmail.env.source);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 form.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 case 'delete':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 // mail task
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 if (this.task == 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 this.delete_messages(event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 // addressbook task
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 else if (this.task == 'addressbook')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 this.delete_contacts();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 // settings: canned response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 else if (this.task == 'settings' && this.env.action == 'responses')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 this.delete_response();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 // settings: user identities
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 else if (this.task == 'settings')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 this.delete_identity();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 // mail task commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 case 'move':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 case 'moveto': // deprecated
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 if (this.task == 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 this.move_messages(props, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 else if (this.task == 'addressbook')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 this.move_contacts(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 case 'copy':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 if (this.task == 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 this.copy_messages(props, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 else if (this.task == 'addressbook')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 this.copy_contacts(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 case 'mark':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 if (props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 this.mark_message(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 case 'toggle_status':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 case 'toggle_flag':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 flag = command == 'toggle_flag' ? 'flagged' : 'read';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 if (uid = props) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 // toggle flagged/unflagged
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 if (flag == 'flagged') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 if (this.message_list.rows[uid].flagged)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 flag = 'unflagged';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 // toggle read/unread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 else if (this.message_list.rows[uid].deleted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 flag = 'undelete';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 else if (!this.message_list.rows[uid].unread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 flag = 'unread';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 this.mark_message(flag, uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 case 'always-load':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 if (this.env.uid && this.env.sender) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 this.add_contact(this.env.sender);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 setTimeout(function(){ ref.command('load-images'); }, 300);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 case 'load-images':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 if (this.env.uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 this.show_message(this.env.uid, true, this.env.action=='preview');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 case 'load-attachment':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 case 'open-attachment':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 case 'download-attachment':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 var params, mimetype = this.env.attachments[props];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 if (this.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 params = {_file: props, _id: this.env.compose_id};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 mimetype = mimetype ? mimetype.mimetype : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 params = {_mbox: this.env.mailbox, _uid: this.env.uid, _part: props};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 // open attachment in frame if it's of a supported mimetype
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 if (command != 'download-attachment' && mimetype && this.env.mimetypes && $.inArray(mimetype, this.env.mimetypes) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 if (this.open_window(this.url('get', $.extend({_frame: 1}, params))))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 params._download = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 // prevent from page unload warning in compose
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 this.compose_skip_unsavedcheck = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 this.goto_url('get', params, false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 this.compose_skip_unsavedcheck = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081 case 'select-all':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 this.select_all_mode = props ? false : true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 this.dummy_select = true; // prevent msg opening if there's only one msg on the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 if (props == 'invert')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 this.message_list.invert_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087 this.message_list.select_all(props == 'page' ? '' : props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 this.dummy_select = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091 case 'select-none':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 this.select_all_mode = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 this.message_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 case 'expand-all':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 this.env.autoexpand_threads = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098 this.message_list.expand_all();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 case 'expand-unread':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 this.env.autoexpand_threads = 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 this.message_list.collapse_all();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 this.expand_unread();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 case 'collapse-all':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 this.env.autoexpand_threads = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 this.message_list.collapse_all();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 case 'nextmessage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 if (this.env.next_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 this.show_message(this.env.next_uid, false, this.env.action == 'preview');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 case 'lastmessage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 if (this.env.last_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 this.show_message(this.env.last_uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122 case 'previousmessage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 if (this.env.prev_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 this.show_message(this.env.prev_uid, false, this.env.action == 'preview');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 case 'firstmessage':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128 if (this.env.first_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129 this.show_message(this.env.first_uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 case 'compose':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 url = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135 if (this.task == 'mail') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 url = {_mbox: this.env.mailbox, _search: this.env.search_request};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137 if (props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138 url._to = props;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140 // modify url if we're in addressbook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 else if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 // switch to mail compose step directly
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 if (props && props.indexOf('@') > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 url._to = props;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 var a_cids = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 // use contact id passed as command parameter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 if (props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 a_cids.push(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151 // get selected contacts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 else if (this.contact_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 a_cids = this.contact_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 if (a_cids.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 this.http_post('mailto', { _cid: a_cids.join(','), _source: this.env.source }, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 else if (this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 this.http_post('mailto', { _gid: this.env.group, _source: this.env.source }, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 else if (props && typeof props == 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 url._to = props;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166 else if (props && typeof props == 'object') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 $.extend(url, props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 this.open_compose_step(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173 case 'spellcheck':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174 if (this.spellcheck_state()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 this.editor.spellcheck_stop();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178 this.editor.spellcheck_start();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182 case 'savedraft':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 // Reset the auto-save timer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 clearTimeout(this.save_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 // compose form did not change (and draft wasn't saved already)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 if (this.env.draft_id && this.cmp_hash == this.compose_field_hash()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 this.auto_save_start();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 this.submit_messageform(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 case 'send':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 if (!props.nocheck && !this.env.is_sent && !this.check_compose_input(command))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 // Reset the auto-save timer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 clearTimeout(this.save_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202 this.submit_messageform();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 case 'send-attachment':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 // Reset the auto-save timer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 clearTimeout(this.save_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209 if (!(flag = this.upload_file(props || this.gui_objects.uploadform, 'upload'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 if (flag !== false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 alert(this.get_label('selectimportfile'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 aborted = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 case 'insert-sig':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217 this.change_identity($("[name='_from']")[0], true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 case 'list-addresses':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 this.list_contacts(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 this.enable_command('add-recipient', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 case 'add-recipient':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 this.compose_add_recipient(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 case 'reply-all':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 case 'reply-list':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 case 'reply':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 if (uid = this.get_single_uid()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 url = {_reply_uid: uid, _mbox: this.get_message_mailbox(uid), _search: this.env.search_request};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 if (command == 'reply-all')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 // do reply-list, when list is detected and popup menu wasn't used
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 url._all = (!props && this.env.reply_all_mode == 1 && this.commands['reply-list'] ? 'list' : 'all');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 else if (command == 'reply-list')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 url._all = 'list';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 this.open_compose_step(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 case 'forward-attachment':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245 case 'forward-inline':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 case 'forward':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 var uids = this.env.uid ? [this.env.uid] : (this.message_list ? this.message_list.get_selection() : []);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 if (uids.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 url = { _forward_uid: this.uids_to_list(uids), _mbox: this.env.mailbox, _search: this.env.search_request };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 if (command == 'forward-attachment' || (!props && this.env.forward_attachment) || uids.length > 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 url._attachment = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 this.open_compose_step(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 case 'print':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257 if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 if (uid = this.contact_list.get_single_selection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 url = '&_action=print&_cid=' + uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 if (this.env.source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 url += '&_source=' + urlencode(this.env.source);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 this.open_window(this.env.comm_path + url, true, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 else if (this.env.action == 'get' && !this.env.is_message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 this.gui_objects.messagepartframe.contentWindow.print();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 else if (uid = this.get_single_uid()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 url = this.url('print', this.params_from_uid(uid, {_safe: this.env.safemode ? 1 : 0}));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 if (this.open_window(url, true, true)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 if (this.env.action != 'show' && this.env.action != 'get')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 this.mark_message('read', uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 case 'viewsource':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 if (uid = this.get_single_uid())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 this.open_window(this.url('viewsource', this.params_from_uid(uid)), true, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 case 'download':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283 if (this.env.action == 'get') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 location.href = this.secure_url(location.href.replace(/_frame=/, '_download='));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 else if (uid = this.get_single_uid()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 this.goto_url('viewsource', this.params_from_uid(uid, {_save: 1}), false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 // quicksearch
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 case 'search':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 ret = this.qsearch(props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296 // reset quicksearch
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 case 'reset-search':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 var n, s = this.env.search_request || this.env.qsearch;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 this.reset_qsearch(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 if (s && this.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 if (this.contact_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 this.list_contacts_clear();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 else if (s && this.env.mailbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 this.list_mailbox(this.env.mailbox, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 else if (s && this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 if (this.env.source == '') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311 for (n in this.env.address_sources) break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 this.env.source = n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313 this.env.group = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 this.list_contacts(this.env.source, this.env.group, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 case 'pushgroup':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 // add group ID and current search to stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 var group = {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 id: props.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 search_request: this.env.search_request,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 page: this.env.current_page,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 search: this.env.search_request && this.gui_objects.qsearchbox ? this.gui_objects.qsearchbox.value : null
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 this.env.address_group_stack.push(group);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329 if (obj && event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 rcube_event.cancel(event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332 case 'listgroup':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333 this.reset_qsearch();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 this.list_contacts(props.source, props.id, 1, group);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337 case 'popgroup':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338 if (this.env.address_group_stack.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 var old = this.env.address_group_stack.pop();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340 this.reset_qsearch();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 if (old.search_request) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 // this code is executed when going back to the search result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344 if (old.search && this.gui_objects.qsearchbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 $(this.gui_objects.qsearchbox).val(old.search);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346 this.env.search_request = old.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347 this.list_contacts_remote(null, null, this.env.current_page = old.page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1350 this.list_contacts(props.source, this.env.address_group_stack[this.env.address_group_stack.length-1].id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 case 'import-messages':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1355 var form = props || this.gui_objects.importform,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 importlock = this.set_busy(true, 'importwait');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358 $('input[name="_unlock"]', form).val(importlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360 if (!(flag = this.upload_file(form, 'import', importlock))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361 this.set_busy(false, null, importlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 if (flag !== false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1363 alert(this.get_label('selectimportfile'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364 aborted = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1366 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1368 case 'import':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 if (this.env.action == 'import' && this.gui_objects.importform) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370 var file = document.getElementById('rcmimportfile');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371 if (file && !file.value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1372 alert(this.get_label('selectimportfile'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373 aborted = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376 this.gui_objects.importform.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 this.set_busy(true, 'importwait');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378 this.lock_form(this.gui_objects.importform, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 this.goto_url('import', (this.env.source ? '_target='+urlencode(this.env.source)+'&' : ''));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1384 case 'export':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1385 if (this.contact_list.rowcount > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1386 this.goto_url('export', { _source: this.env.source, _gid: this.env.group, _search: this.env.search_request }, false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1387 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1388 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1389
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1390 case 'export-selected':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391 if (this.contact_list.rowcount > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392 this.goto_url('export', { _source: this.env.source, _gid: this.env.group, _cid: this.contact_list.get_selection().join(',') }, false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1393 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 case 'upload-photo':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1397 this.upload_contact_photo(props || this.gui_objects.uploadform);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1398 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 case 'delete-photo':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1401 this.replace_contact_photo('-del-');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1402 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1404 // user settings commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1405 case 'preferences':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 case 'identities':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407 case 'responses':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1408 case 'folders':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1409 this.goto_url('settings/' + command);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412 case 'undo':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1413 this.http_request('undo', '', this.display_message('', 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1415
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1416 // unified command call (command name == function name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417 default:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 var func = command.replace(/-/g, '_');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419 if (this[func] && typeof this[func] === 'function') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420 ret = this[func](props, obj, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1421 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425 if (!aborted && this.triggerEvent('after'+command, props) === false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426 ret = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 this.triggerEvent('actionafter', { props:props, action:command, aborted:aborted, ret:ret });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429 return ret === false ? false : obj ? false : true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1431
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432 // set command(s) enabled or disabled
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 this.enable_command = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 var i, n, args = Array.prototype.slice.call(arguments),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 enable = args.pop(), cmd;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1438 for (n=0; n<args.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1439 cmd = args[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1440 // argument of type array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 if (typeof cmd === 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442 this.commands[cmd] = enable;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443 this.set_button(cmd, (enable ? 'act' : 'pas'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444 this.triggerEvent('enable-command', {command: cmd, status: enable});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 // push array elements into commands array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1448 for (i in cmd)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1449 args.push(cmd[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 this.command_enabled = function(cmd)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456 return this.commands[cmd];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 // lock/unlock interface
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1460 this.set_busy = function(a, message, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462 if (a && message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1463 var msg = this.get_label(message);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1464 if (msg == message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1465 msg = 'Loading...';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1467 id = this.display_message(msg, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1469 else if (!a && id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470 this.hide_message(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 this.busy = a;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1474 //document.body.style.cursor = a ? 'wait' : 'default';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476 if (this.gui_objects.editform)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477 this.lock_form(this.gui_objects.editform, a);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1478
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1479 return id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1480 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 // return a localized string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 this.get_label = function(name, domain)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485 if (domain && this.labels[domain+'.'+name])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 return this.labels[domain+'.'+name];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487 else if (this.labels[name])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 return this.labels[name];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 return name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1492
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493 // alias for convenience reasons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 this.gettext = this.get_label;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 // switch to another application task
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497 this.switch_task = function(task)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1498 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1499 if (this.task === task && task != 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1500 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1502 var url = this.get_task_url(task);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504 if (task == 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 url += '&_mbox=INBOX';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506 else if (task == 'logout' && !this.env.server_error) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1507 url = this.secure_url(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508 this.clear_compose_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1510
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1511 this.redirect(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1514 this.get_task_url = function(task, url)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1515 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1516 if (!url)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1517 url = this.env.comm_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1518
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1519 if (url.match(/[?&]_task=[a-zA-Z0-9_-]+/))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1520 return url.replace(/_task=[a-zA-Z0-9_-]+/, '_task=' + task);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1521 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1522 return url.replace(/\?.*$/, '') + '?_task=' + task;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1523 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1524
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1525 this.reload = function(delay)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527 if (this.is_framed())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 parent.rcmail.reload(delay);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529 else if (delay)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530 setTimeout(function() { ref.reload(); }, delay);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 else if (window.location)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532 location.href = this.url('', {_extwin: this.env.extwin});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1534
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535 // Add variable to GET string, replace old value if exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 this.add_url = function(url, name, value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1538 value = urlencode(value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1539
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 if (/(\?.*)$/.test(url)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 var urldata = RegExp.$1,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542 datax = RegExp('((\\?|&)'+RegExp.escape(name)+'=[^&]*)');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 if (datax.test(urldata)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545 urldata = urldata.replace(datax, RegExp.$2 + name + '=' + value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548 urldata += '&' + name + '=' + value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 return url.replace(/(\?.*)$/, urldata);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 return url + '?' + name + '=' + value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 // append CSRF protection token to the given url
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557 this.secure_url = function(url)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1558 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559 return this.add_url(url, '_token', this.env.request_token);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 this.is_framed = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564 return this.env.framed && parent.rcmail && parent.rcmail != this && typeof parent.rcmail.command == 'function';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 this.save_pref = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 var request = {_name: prop.name, _value: prop.value};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571 if (prop.session)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572 request._session = prop.session;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573 if (prop.env)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 this.env[prop.env] = prop.value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576 this.http_post('save-pref', request);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 this.html_identifier = function(str, encode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 return encode ? this.html_identifier_encode(str) : String(str).replace(this.identifier_expr, '_');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 this.html_identifier_encode = function(str)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586 return Base64.encode(String(str)).replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589 this.html_identifier_decode = function(str)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591 str = String(str).replace(/-/g, '+').replace(/_/g, '/');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 while (str.length % 4) str += '=';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 return Base64.decode(str);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 /********* event handling methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603 this.drag_menu = function(e, target)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1605 var modkey = rcube_event.get_modifier(e),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 menu = this.gui_objects.dragmenu;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 if (menu && modkey == SHIFT_KEY && this.commands['copy']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609 var pos = rcube_event.get_mouse_pos(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 this.env.drag_target = target;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611 this.show_menu(this.gui_objects.dragmenu.id, true, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 $(menu).css({top: (pos.y-10)+'px', left: (pos.x-10)+'px'});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 this.drag_menu_action = function(action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 var menu = this.gui_objects.dragmenu;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 if (menu) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623 $(menu).hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 this.command(action, this.env.drag_target);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 this.env.drag_target = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 this.drag_start = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 this.drag_active = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633 if (this.preview_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634 clearTimeout(this.preview_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636 // prepare treelist widget for dragging interactions
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 if (this.treelist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 this.treelist.drag_start();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 this.drag_end = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 var list, model;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 if (this.treelist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 this.treelist.drag_end();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648 // execute drag & drop action when mouse was released
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649 if (list = this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 model = this.env.mailboxes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651 else if (list = this.contact_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652 model = this.env.contactfolders;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 if (this.drag_active && model && this.env.last_folder_target) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 var target = model[this.env.last_folder_target];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 list.draglayer.hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 if (this.contact_list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 if (!this.contacts_drag_menu(e, target))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 this.command('move', target);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 else if (!this.drag_menu(e, target))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 this.command('move', target);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 this.drag_active = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 this.env.last_folder_target = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670 this.drag_move = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 if (this.gui_objects.folderlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673 var drag_target, oldclass,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674 layerclass = 'draglayernormal',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 mouse = rcube_event.get_mouse_pos(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 if (this.contact_list && this.contact_list.draglayer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678 oldclass = this.contact_list.draglayer.attr('class');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1679
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 // mouse intersects a valid drop target on the treelist
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 if (this.treelist && (drag_target = this.treelist.intersects(mouse, true))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682 this.env.last_folder_target = drag_target;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683 layerclass = 'draglayer' + (this.check_droptarget(drag_target) > 1 ? 'copy' : 'normal');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 // Clear target, otherwise drag end will trigger move into last valid droptarget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687 this.env.last_folder_target = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 if (layerclass != oldclass && this.contact_list && this.contact_list.draglayer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691 this.contact_list.draglayer.attr('class', layerclass);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695 this.collapse_folder = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697 if (this.treelist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698 this.treelist.toggle(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701 this.folder_collapsed = function(node)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703 var prefname = this.env.task == 'addressbook' ? 'collapsed_abooks' : 'collapsed_folders',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 old = this.env[prefname];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 if (node.collapsed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707 this.env[prefname] = this.env[prefname] + '&'+urlencode(node.id)+'&';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709 // select the folder if one of its childs is currently selected
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1710 // don't select if it's virtual (#1488346)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 if (!node.virtual && this.env.mailbox && this.env.mailbox.startsWith(node.id + this.env.delimiter))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 this.command('list', node.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 var reg = new RegExp('&'+urlencode(node.id)+'&');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 this.env[prefname] = this.env[prefname].replace(reg, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 if (!this.drag_active) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 if (old !== this.env[prefname])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 this.command('save-pref', { name: prefname, value: this.env[prefname] });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723 if (this.env.unread_counts)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 this.set_unread_count_display(node.id, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1727
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728 // global mouse-click handler to cleanup some UI elements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 this.doc_mouse_up = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 var list, id, target = rcube_event.get_target(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 // ignore event if jquery UI dialog is open
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 if ($(target).closest('.ui-dialog, .ui-widget-overlay').length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737 // remove focus from list widgets
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 if (window.rcube_list_widget && rcube_list_widget._instances.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739 $.each(rcube_list_widget._instances, function(i,list){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 if (list && !rcube_mouse_is_over(e, list.list.parentNode))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 list.blur();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745 // reset 'pressed' buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746 if (this.buttons_sel) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747 for (id in this.buttons_sel)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 if (typeof id !== 'function')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 this.button_out(this.buttons_sel[id], id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 this.buttons_sel = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 // reset popup menus; delayed to have updated menu_stack data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 setTimeout(function(e){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755 var obj, skip, config, id, i, parents = $(target).parents();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 for (i = ref.menu_stack.length - 1; i >= 0; i--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757 id = ref.menu_stack[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 obj = $('#' + id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 if (obj.is(':visible')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761 && target != obj.data('opener')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 && target != obj.get(0) // check if scroll bar was clicked (#1489832)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 && !parents.is(obj.data('opener'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764 && id != skip
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 && (obj.attr('data-editable') != 'true' || !$(target).parents('#' + id).length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 && (obj.attr('data-sticky') != 'true' || !rcube_mouse_is_over(e, obj.get(0)))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768 ref.hide_menu(id, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1770 skip = obj.data('parent');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 }, 10, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1775 // global keypress event handler
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776 this.doc_keypress = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1778 // Helper method to move focus to the next/prev active menu item
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1779 var focus_menu_item = function(dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780 var obj, item, mod = dir < 0 ? 'prevAll' : 'nextAll', limit = dir < 0 ? 'last' : 'first';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 if (ref.focused_menu && (obj = $('#'+ref.focused_menu))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782 item = obj.find(':focus').closest('li')[mod](':has(:not([aria-disabled=true]))').find('a,input')[limit]();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783 if (!item.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784 item = obj.find(':focus').closest('ul')[mod](':has(:not([aria-disabled=true]))').find('a,input')[limit]();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785 return item.focus().length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791 var target = e.target || {},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 keyCode = rcube_event.get_keycode(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794 if (e.keyCode != 27 && (!this.menu_keyboard_active || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798 switch (keyCode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1799 case 38:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1800 case 40:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1801 case 63232: // "up", in safari keypress
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1802 case 63233: // "down", in safari keypress
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 focus_menu_item(keyCode == 38 || keyCode == 63232 ? -1 : 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1806 case 9: // tab
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 if (this.focused_menu) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 var mod = rcube_event.get_modifier(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809 if (!focus_menu_item(mod == SHIFT_KEY ? -1 : 1)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 this.hide_menu(this.focused_menu, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815 case 27: // esc
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1816 if (this.menu_stack.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 this.hide_menu(this.menu_stack[this.menu_stack.length-1], e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 this.msglist_select = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 if (this.preview_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827 clearTimeout(this.preview_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 var selected = list.get_single_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 this.enable_command(this.env.message_commands, selected != null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 if (selected) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1833 // Hide certain command buttons when Drafts folder is selected
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1834 if (this.env.mailbox == this.env.drafts_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1835 this.enable_command('reply', 'reply-all', 'reply-list', 'forward', 'forward-attachment', 'forward-inline', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 // Disable reply-list when List-Post header is not set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1837 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1838 var msg = this.env.messages[selected];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1839 if (!msg.ml)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 this.enable_command('reply-list', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1843 // Multi-message commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1844 this.enable_command('delete', 'move', 'copy', 'mark', 'forward', 'forward-attachment', list.selection.length > 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1845
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846 // reset all-pages-selection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847 if (selected || (list.selection.length && list.selection.length != list.rowcount))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 this.select_all_mode = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1849
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850 // start timer for message preview (wait for double click)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851 if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852 // try to be responsive and try not to overload the server when user is pressing up/down key repeatedly
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853 var now = new Date().getTime();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 var time_diff = now - (this._last_msglist_select_time || 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 var preview_pane_delay = this.preview_delay_click;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857 // user is selecting messages repeatedly, wait until this ends (use larger delay)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858 if (time_diff < this.preview_delay_select) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 preview_pane_delay = this.preview_delay_select;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 if (this.preview_timer) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861 clearTimeout(this.preview_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 if (this.env.contentframe) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868 this._last_msglist_select_time = now;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1869 this.preview_timer = setTimeout(function() { ref.msglist_get_preview(); }, preview_pane_delay);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871 else if (this.env.contentframe) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1875
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876 this.msglist_dbl_click = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878 if (this.preview_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 clearTimeout(this.preview_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 var uid = list.get_single_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883 if (uid && (this.env.messages[uid].mbox || this.env.mailbox) == this.env.drafts_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885 else if (uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1886 this.show_message(uid, false, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1887 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1888
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 this.msglist_keypress = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 if (list.modkey == CONTROL_KEY)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894 if (list.key_pressed == list.ENTER_KEY)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 this.command('show');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 else if (list.key_pressed == list.DELETE_KEY || list.key_pressed == list.BACKSPACE_KEY)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897 this.command('delete');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 else if (list.key_pressed == 33)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899 this.command('previouspage');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900 else if (list.key_pressed == 34)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901 this.command('nextpage');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904 this.msglist_get_preview = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 var uid = this.get_single_uid();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 if (uid && this.env.contentframe && !this.drag_active)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1908 this.show_message(uid, false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1909 else if (this.env.contentframe)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1910 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1911 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1912
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1913 this.msglist_expand = function(row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915 if (this.env.messages[row.uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 this.env.messages[row.uid].expanded = row.expanded;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917 $(row.obj)[row.expanded?'addClass':'removeClass']('expanded');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920 this.msglist_set_coltypes = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 var i, found, name, cols = list.thead.rows[0].cells;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924 this.env.listcols = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 for (i=0; i<cols.length; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 if (cols[i].id && cols[i].id.startsWith('rcm')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 name = cols[i].id.slice(3);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 this.env.listcols.push(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 if ((found = $.inArray('flag', this.env.listcols)) >= 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 this.env.flagged_col = found;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 if ((found = $.inArray('subject', this.env.listcols)) >= 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936 this.env.subject_col = found;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 this.command('save-pref', { name: 'list_cols', value: this.env.listcols, session: 'list_attrib/columns' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941 this.check_droptarget = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943 switch (this.task) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 case 'mail':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 return (this.env.mailboxes[id]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 && !this.env.mailboxes[id].virtual
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 && (this.env.mailboxes[id].id != this.env.mailbox || this.is_multifolder_listing())) ? 1 : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949 case 'addressbook':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 var target;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 if (id != this.env.source && (target = this.env.contactfolders[id])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 // droptarget is a group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 if (target.type == 'group') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 if (target.id != this.env.group && !this.env.contactfolders[target.source].readonly) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 var is_other = this.env.selection_sources.length > 1 || $.inArray(target.source, this.env.selection_sources) == -1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 return !is_other || this.commands.move ? 1 : 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959 // droptarget is a (writable) addressbook and it's not the source
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960 else if (!target.readonly && (this.env.selection_sources.length > 1 || $.inArray(id, this.env.selection_sources) == -1)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 return this.commands.move ? 1 : 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 // open popup window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 this.open_window = function(url, small, toolbar)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 var wname = 'rcmextwin' + new Date().getTime();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974 url += (url.match(/\?/) ? '&' : '?') + '_extwin=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 if (this.env.standard_windows)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 var extwin = window.open(url, wname);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979 var win = this.is_framed() ? parent.window : window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980 page = $(win),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1981 page_width = page.width(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982 page_height = bw.mz ? $('body', win).height() : page.height(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 w = Math.min(small ? this.env.popup_width_small : this.env.popup_width, page_width),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984 h = page_height, // always use same height
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985 l = (win.screenLeft || win.screenX) + 20,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 t = (win.screenTop || win.screenY) + 20,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987 extwin = window.open(url, wname,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 'width='+w+',height='+h+',top='+t+',left='+l+',resizable=yes,location=no,scrollbars=yes'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 +(toolbar ? ',toolbar=yes,menubar=yes,status=yes' : ',toolbar=no,menubar=no,status=no'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 // detect popup blocker (#1489618)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993 // don't care this might not work with all browsers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 if (!extwin || extwin.closed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995 this.display_message(this.get_label('windowopenerror'), 'warning');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 // write loading... message to empty windows
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 if (!url && extwin.document) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001 extwin.document.write('<html><body>' + this.get_label('loading') + '</body></html>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004 // allow plugins to grab the window reference (#1489413)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005 this.triggerEvent('openwindow', { url:url, handle:extwin });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 // focus window, delayed to bring to front
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008 setTimeout(function() { extwin && extwin.focus(); }, 10);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010 return extwin;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2015 /********* (message) list functionality *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018 this.init_message_row = function(row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 var i, fn = {}, uid = row.uid,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021 status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 if (uid && this.env.messages[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024 $.extend(row, this.env.messages[uid]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026 // set eventhandler to status icon
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027 if (row.icon = document.getElementById(status_icon)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028 fn.icon = function(e) { ref.command('toggle_status', uid); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031 // save message icon position too
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2032 if (this.env.status_col != null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 row.msgicon = document.getElementById('msgicn'+row.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 row.msgicon = row.icon;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 // set eventhandler to flag icon
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038 if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.id))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 fn.flagicon = function(e) { ref.command('toggle_flag', uid); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 // set event handler to thread expand/collapse icon
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.id))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2044 fn.expando = function(e) { ref.expand_message_row(e, uid); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047 // attach events
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 $.each(fn, function(i, f) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049 row[i].onclick = function(e) { f(e); return rcube_event.cancel(e); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050 if (bw.touch && row[i].addEventListener) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 row[i].addEventListener('touchend', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052 if (e.changedTouches.length == 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 f(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056 }, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 this.triggerEvent('insertrow', { uid:uid, row:row });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 // create a table row in the message list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064 this.add_message_row = function(uid, cols, flags, attop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2066 if (!this.gui_objects.messagelist || !this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2067 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2068
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2069 // Prevent from adding messages from different folder (#1487752)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2070 if (flags.mbox != this.env.mailbox && !flags.skip_mbox_check)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2071 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2072
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2073 // When deleting messages fast it may happen that the same message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2074 // from the next page could be added many times, we prevent this here
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2075 if (this.message_list.rows[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2076 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2077
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2078 if (!this.env.messages[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2079 this.env.messages[uid] = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2080
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2081 // merge flags over local message object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2082 $.extend(this.env.messages[uid], {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2083 deleted: flags.deleted?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2084 replied: flags.answered?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2085 unread: !flags.seen?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2086 forwarded: flags.forwarded?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2087 flagged: flags.flagged?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2088 has_children: flags.has_children?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2089 depth: flags.depth?flags.depth:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2090 unread_children: flags.unread_children || 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2091 flagged_children: flags.flagged_children || 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2092 parent_uid: flags.parent_uid || 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2093 selected: this.select_all_mode || this.message_list.in_selection(uid),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2094 ml: flags.ml?1:0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2095 ctype: flags.ctype,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2096 mbox: flags.mbox,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2097 // flags from plugins
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2098 flags: flags.extra_flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2099 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2101 var c, n, col, html, css_class, label, status_class = '', status_label = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2102 tree = '', expando = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2103 list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2104 rows = list.rows,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2105 message = this.env.messages[uid],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2106 msg_id = this.html_identifier(uid,true),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2107 row_class = 'message'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2108 + (!flags.seen ? ' unread' : '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2109 + (flags.deleted ? ' deleted' : '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2110 + (flags.flagged ? ' flagged' : '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2111 + (message.selected ? ' selected' : ''),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2112 row = { cols:[], style:{}, id:'rcmrow'+msg_id, uid:uid };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2113
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2114 // message status icons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2115 css_class = 'msgicon';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2116 if (this.env.status_col === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2117 css_class += ' status';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2118 if (flags.deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2119 status_class += ' deleted';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2120 status_label += this.get_label('deleted') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2121 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2122 else if (!flags.seen) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2123 status_class += ' unread';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2124 status_label += this.get_label('unread') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2125 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2126 else if (flags.unread_children > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2127 status_class += ' unreadchildren';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2128 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2129 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2130 if (flags.answered) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2131 status_class += ' replied';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2132 status_label += this.get_label('replied') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2133 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2134 if (flags.forwarded) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2135 status_class += ' forwarded';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2136 status_label += this.get_label('forwarded') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2137 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2138
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2139 // update selection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2140 if (message.selected && !list.in_selection(uid))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2141 list.selection.push(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2142
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2143 // threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2144 if (this.env.threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2145 if (message.depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2146 // This assumes that div width is hardcoded to 15px,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2147 tree += '<span id="rcmtab' + msg_id + '" class="branch" style="width:' + (message.depth * 15) + 'px;">&nbsp;&nbsp;</span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2149 if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2150 || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) &&
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2151 (!rows[message.parent_uid] || !rows[message.parent_uid].expanded))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2152 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2153 row.style.display = 'none';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2154 message.expanded = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2155 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2156 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2157 message.expanded = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2159 row_class += ' thread expanded';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2160 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2161 else if (message.has_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2162 if (message.expanded === undefined && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2163 message.expanded = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2164 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2165
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2166 expando = '<div id="rcmexpando' + row.id + '" class="' + (message.expanded ? 'expanded' : 'collapsed') + '">&nbsp;&nbsp;</div>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2167 row_class += ' thread' + (message.expanded ? ' expanded' : '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2168 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2170 if (flags.unread_children && flags.seen && !message.expanded)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2171 row_class += ' unroot';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2172
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2173 if (flags.flagged_children && !message.expanded)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2174 row_class += ' flaggedroot';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2175 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2176
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2177 tree += '<span id="msgicn'+row.id+'" class="'+css_class+status_class+'" title="'+status_label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2178 row.className = row_class;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2179
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2180 // build subject link
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2181 if (cols.subject) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2182 var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2183 uid_param = flags.mbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2184 query = { _mbox: flags.mbox };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2185 query[uid_param] = uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2186 cols.subject = '<a href="' + this.url(action, query) + '" onclick="return rcube_event.keyboard_only(event)"' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2187 ' onmouseover="rcube_webmail.long_subject_title(this,'+(message.depth+1)+')" tabindex="-1"><span>'+cols.subject+'</span></a>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2188 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2189
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2190 // add each submitted col
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2191 for (n in this.env.listcols) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2192 c = this.env.listcols[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2193 col = {className: String(c).toLowerCase(), events:{}};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2195 if (this.env.coltypes[c] && this.env.coltypes[c].hidden) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2196 col.className += ' hidden';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2197 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2198
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2199 if (c == 'flag') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2200 css_class = (flags.flagged ? 'flagged' : 'unflagged');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2201 label = this.get_label(css_class);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2202 html = '<span id="flagicn'+row.id+'" class="'+css_class+'" title="'+label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2203 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2204 else if (c == 'attachment') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2205 label = this.get_label('withattachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2206 if (flags.attachmentClass)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2207 html = '<span class="'+flags.attachmentClass+'" title="'+label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2208 else if (/application\/|multipart\/(m|signed)/.test(flags.ctype))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2209 html = '<span class="attachment" title="'+label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2210 else if (/multipart\/report/.test(flags.ctype))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2211 html = '<span class="report"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2212 else if (flags.ctype == 'multipart/encrypted' || flags.ctype == 'application/pkcs7-mime')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2213 html = '<span class="encrypted"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2214 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2215 html = '&nbsp;';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2216 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2217 else if (c == 'status') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2218 label = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2219 if (flags.deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2220 css_class = 'deleted';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2221 label = this.get_label('deleted');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2222 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2223 else if (!flags.seen) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2224 css_class = 'unread';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2225 label = this.get_label('unread');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2226 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2227 else if (flags.unread_children > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2228 css_class = 'unreadchildren';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2229 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2230 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2231 css_class = 'msgicon';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2232 html = '<span id="statusicn'+row.id+'" class="'+css_class+status_class+'" title="'+label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2233 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2234 else if (c == 'threads')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2235 html = expando;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2236 else if (c == 'subject') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2237 html = tree + cols[c];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2238 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2239 else if (c == 'priority') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2240 if (flags.prio > 0 && flags.prio < 6) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2241 label = this.get_label('priority') + ' ' + flags.prio;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2242 html = '<span class="prio'+flags.prio+'" title="'+label+'"></span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2243 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2244 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2245 html = '&nbsp;';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2246 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2247 else if (c == 'folder') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2248 html = '<span onmouseover="rcube_webmail.long_subject_title(this)">' + cols[c] + '<span>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2249 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2250 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2251 html = cols[c];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2252
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2253 col.innerHTML = html;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2254 row.cols.push(col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2255 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2256
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2257 if (this.env.layout == 'widescreen')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2258 row = this.widescreen_message_row(row, uid, message);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2259
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2260 list.insert_row(row, attop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2261
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2262 // remove 'old' row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2263 if (attop && this.env.pagesize && list.rowcount > this.env.pagesize) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2264 var uid = list.get_last_row();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2265 list.remove_row(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2266 list.clear_selection(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2267 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2268 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2269
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2270 // Converts standard message list record into "widescreen" (3-column) layout
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2271 this.widescreen_message_row = function(row, uid, message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2272 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2273 var domrow = document.createElement('tr');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2274
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2275 domrow.id = row.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2276 domrow.uid = row.uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2277 domrow.className = row.className;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2278 if (row.style) $.extend(domrow.style, row.style);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2279
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2280 $.each(this.env.widescreen_list_template, function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2281 if (!ref.env.threading && this.className == 'threads')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2282 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2283
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2284 var i, n, e, col, domcol,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2285 domcell = document.createElement('td');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2286
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2287 if (this.className) domcell.className = this.className;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2288
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2289 for (i=0; this.cells && i < this.cells.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2290 for (n=0; row.cols && n < row.cols.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2291 if (this.cells[i] == row.cols[n].className) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2292 col = row.cols[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2293 domcol = document.createElement('span');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2294 domcol.className = this.cells[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2295 if (this.className == 'subject' && domcol.className != 'subject')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2296 domcol.className += ' skip-on-drag';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2297 if (col.innerHTML)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2298 domcol.innerHTML = col.innerHTML;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2299 domcell.appendChild(domcol);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2300 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2301 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2302 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2303 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2304
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2305 domrow.appendChild(domcell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2306 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2307
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2308 if (this.env.threading && message.depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2309 $('td.subject', domrow).attr('style', 'padding-left:' + Math.min(90, message.depth * 15) + 'px !important');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2310 $('span.branch', domrow).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2311 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2312
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2313 return domrow;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2314 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2315
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2316 this.set_list_sorting = function(sort_col, sort_order)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2317 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2318 var sort_old = this.env.sort_col == 'arrival' ? 'date' : this.env.sort_col,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2319 sort_new = sort_col == 'arrival' ? 'date' : sort_col;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2320
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2321 // set table header class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2322 $('#rcm' + sort_old).removeClass('sorted' + this.env.sort_order.toUpperCase());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2323 if (sort_new)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2324 $('#rcm' + sort_new).addClass('sorted' + sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2325
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2326 // if sorting by 'arrival' is selected, click on date column should not switch to 'date'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2327 $('#rcmdate > a').prop('rel', sort_col == 'arrival' ? 'arrival' : 'date');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2328
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2329 this.env.sort_col = sort_col;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2330 this.env.sort_order = sort_order;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2331 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2333 this.set_list_options = function(cols, sort_col, sort_order, threads, layout)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2334 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2335 var update, post_data = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2336
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2337 if (sort_col === undefined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2338 sort_col = this.env.sort_col;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2339 if (!sort_order)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2340 sort_order = this.env.sort_order;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2342 if (this.env.sort_col != sort_col || this.env.sort_order != sort_order) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2343 update = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2344 this.set_list_sorting(sort_col, sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2345 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2346
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2347 if (this.env.threading != threads) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2348 update = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2349 post_data._threads = threads;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2350 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2351
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2352 if (layout && this.env.layout != layout) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2353 this.triggerEvent('layout-change', {old_layout: this.env.layout, new_layout: layout});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2354 update = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2355 this.env.layout = post_data._layout = layout;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2356 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2358 if (cols && cols.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2359 // make sure new columns are added at the end of the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2360 var i, idx, name, newcols = [], oldcols = this.env.listcols;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2361 for (i=0; i<oldcols.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2362 name = oldcols[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2363 idx = $.inArray(name, cols);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2364 if (idx != -1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2365 newcols.push(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2366 delete cols[idx];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2367 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2368 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2369 for (i=0; i<cols.length; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2370 if (cols[i])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2371 newcols.push(cols[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2372
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2373 if (newcols.join() != oldcols.join()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2374 update = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2375 post_data._cols = newcols.join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2376 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2377 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2378
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2379 if (update)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2380 this.list_mailbox('', '', sort_col+'_'+sort_order, post_data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2381 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2382
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2383 // when user double-clicks on a row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2384 this.show_message = function(id, safe, preview)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2385 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2386 if (!id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2387 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2388
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2389 var win, target = window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2390 url = this.params_from_uid(id, {_caps: this.browser_capabilities()});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2391
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2392 if (preview && (win = this.get_frame_window(this.env.contentframe))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2393 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2394 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2395 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2396
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2397 if (safe)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2398 url._safe = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2400 // also send search request to get the right messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2401 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2402 url._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2403
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2404 if (this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2405 url._extwin = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2406
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2407 url = this.url(preview ? 'preview': 'show', url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2408
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2409 if (preview && String(target.location.href).indexOf(url) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2410 this.show_contentframe(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2411 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2412 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2413 if (!preview && this.env.message_extwin && !this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2414 this.open_window(url, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2415 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2416 this.location_href(url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2417 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2418 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2419
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2420 // update message status and unread counter after marking a message as read
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2421 this.set_unread_message = function(id, folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2422 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2423 var self = this;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2424
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2425 // find window with messages list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2426 if (!self.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2427 self = self.opener();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2428
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2429 if (!self && window.parent)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2430 self = parent.rcmail;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2431
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2432 if (!self || !self.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2433 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2434
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2435 // this may fail in multifolder mode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2436 if (self.set_message(id, 'unread', false) === false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2437 self.set_message(id + '-' + folder, 'unread', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2438
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2439 if (self.env.unread_counts[folder] > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2440 self.env.unread_counts[folder] -= 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2441 self.set_unread_count(folder, self.env.unread_counts[folder], folder == 'INBOX' && !self.is_multifolder_listing());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2442 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2443 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2444
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2445 this.show_contentframe = function(show)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2446 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2447 var frame, win, name = this.env.contentframe;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2448
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2449 if (frame = this.get_frame_element(name)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2450 if (!show && (win = this.get_frame_window(name))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2451 if (win.location.href.indexOf(this.env.blankpage) < 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2452 if (win.stop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2453 win.stop();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2454 else // IE
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2455 win.document.execCommand('Stop');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2456
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2457 win.location.href = this.env.blankpage;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2458 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2459 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2460 else if (!bw.safari && !bw.konq)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2461 $(frame)[show ? 'show' : 'hide']();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2462 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2463
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2464 if (!show && this.env.frame_lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2465 this.set_busy(false, null, this.env.frame_lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2466 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2467
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2468 this.get_frame_element = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2469 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2470 var frame;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2471
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2472 if (id && (frame = document.getElementById(id)))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2473 return frame;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2474 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2475
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2476 this.get_frame_window = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2477 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2478 var frame = this.get_frame_element(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2479
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2480 if (frame && frame.name && window.frames)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2481 return window.frames[frame.name];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2482 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2483
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2484 this.lock_frame = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2485 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2486 if (!this.env.frame_lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2487 (this.is_framed() ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2488 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2489
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2490 // list a specific page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2491 this.list_page = function(page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2492 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2493 if (page == 'next')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2494 page = this.env.current_page+1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2495 else if (page == 'last')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2496 page = this.env.pagecount;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2497 else if (page == 'prev' && this.env.current_page > 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2498 page = this.env.current_page-1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2499 else if (page == 'first' && this.env.current_page > 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2500 page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2501
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2502 if (page > 0 && page <= this.env.pagecount) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2503 this.env.current_page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2504
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2505 if (this.task == 'addressbook' || this.contact_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2506 this.list_contacts(this.env.source, this.env.group, page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2507 else if (this.task == 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2508 this.list_mailbox(this.env.mailbox, page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2509 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2510 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2511
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2512 // sends request to check for recent messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2513 this.checkmail = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2514 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2515 var lock = this.set_busy(true, 'checkingmail'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2516 params = this.check_recent_params();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2517
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2518 this.http_post('check-recent', params, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2519 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2521 // list messages of a specific mailbox using filter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2522 this.filter_mailbox = function(filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2523 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2524 if (this.filter_disabled)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2525 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2526
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2527 var lock = this.set_busy(true, 'searching');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2528
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2529 this.clear_message_list();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2530
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2531 // reset vars
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2532 this.env.current_page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2533 this.env.search_filter = filter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2534 this.http_request('search', this.search_params(false, filter), lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2535 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2536
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2537 // reload the current message listing
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2538 this.refresh_list = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2539 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2540 this.list_mailbox(this.env.mailbox, this.env.current_page || 1, null, { _clear:1 }, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2541 if (this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2542 this.message_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2543 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2544
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2545 // list messages of a specific mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2546 this.list_mailbox = function(mbox, page, sort, url, update_only)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2547 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2548 var win, target = window;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2549
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2550 if (typeof url != 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2551 url = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2552
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2553 if (!mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2554 mbox = this.env.mailbox ? this.env.mailbox : 'INBOX';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2555
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2556 // add sort to url if set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2557 if (sort)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2558 url._sort = sort;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2559
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2560 // folder change, reset page, search scope, etc.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2561 if (this.env.mailbox != mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2562 page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2563 this.env.current_page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2564 this.env.search_scope = 'base';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2565 this.select_all_mode = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2566 this.reset_search_filter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2567 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2568 // also send search request to get the right messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2569 else if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2570 url._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2571
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2572 if (!update_only) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2573 // unselect selected messages and clear the list and message data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2574 this.clear_message_list();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2575
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2576 if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2577 url._refresh = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2578
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2579 this.select_folder(mbox, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2580 this.unmark_folder(mbox, 'recent', '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2581 this.env.mailbox = mbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2582 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2584 // load message list remotely
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2585 if (this.gui_objects.messagelist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2586 this.list_mailbox_remote(mbox, page, url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2587 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2588 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2589
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2590 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2591 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2592 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2593 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2594
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2595 if (this.env.uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2596 url._uid = this.env.uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2597
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2598 // load message list to target frame/window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2599 if (mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2600 this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2601 url._mbox = mbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2602 if (page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2603 url._page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2604 this.location_href(url, target);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2605 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2606 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2607
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2608 this.clear_message_list = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2609 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2610 this.env.messages = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2611
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2612 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2613 if (this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2614 this.message_list.clear(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2615 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2616
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2617 // send remote request to load message list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2618 this.list_mailbox_remote = function(mbox, page, url)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2619 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2620 var lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2621
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2622 if (typeof url != 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2623 url = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2624 url._mbox = mbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2625 if (page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2626 url._page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2627
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2628 this.http_request('list', url, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2629 this.update_state({ _mbox: mbox, _page: (page && page > 1 ? page : null) });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2630 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2631
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2632 // removes messages that doesn't exists from list selection array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2633 this.update_selection = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2634 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2635 var list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2636 selected = list.selection,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2637 rows = list.rows,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2638 i, selection = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2639
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2640 for (i in selected)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2641 if (rows[selected[i]])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2642 selection.push(selected[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2643
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2644 list.selection = selection;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2645
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2646 // reset preview frame, if currently previewed message is not selected (has been removed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2647 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2648 var win = this.get_frame_window(this.env.contentframe),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2649 id = win.rcmail.env.uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2650
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2651 if (id && !list.in_selection(id))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2652 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2653 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2654 catch (e) {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2655 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2656
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2657 // expand all threads with unread children
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2658 this.expand_unread = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2659 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2660 var r, tbody = this.message_list.tbody,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2661 new_row = tbody.firstChild;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2662
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2663 while (new_row) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2664 if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid]) && r.unread_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2665 this.message_list.expand_all(r);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2666 this.set_unread_children(r.uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2667 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2668
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2669 new_row = new_row.nextSibling;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2670 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2671
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2672 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2673 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2674
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2675 // thread expanding/collapsing handler
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2676 this.expand_message_row = function(e, uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2677 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2678 var row = this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2679
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2680 // handle unread_children/flagged_children mark
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2681 row.expanded = !row.expanded;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2682 this.set_unread_children(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2683 this.set_flagged_children(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2684 row.expanded = !row.expanded;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2685
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2686 this.message_list.expand_row(e, uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2687 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2688
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2689 // message list expanding
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2690 this.expand_threads = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2691 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2692 if (!this.env.threading || !this.env.autoexpand_threads || !this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2693 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2694
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2695 switch (this.env.autoexpand_threads) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2696 case 2: this.expand_unread(); break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2697 case 1: this.message_list.expand_all(); break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2698 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2699 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2700
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2701 // Initializes threads indicators/expanders after list update
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2702 this.init_threads = function(roots, mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2703 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2704 // #1487752
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2705 if (mbox && mbox != this.env.mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2706 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2707
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2708 for (var n=0, len=roots.length; n<len; n++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2709 this.add_tree_icons(roots[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2710 this.expand_threads();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2711 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2712
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2713 // adds threads tree icons to the list (or specified thread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2714 this.add_tree_icons = function(root)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2715 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2716 var i, l, r, n, len, pos, tmp = [], uid = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2717 row, rows = this.message_list.rows;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2718
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2719 if (root)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2720 row = rows[root] ? rows[root].obj : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2721 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2722 row = this.message_list.tbody.firstChild;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2723
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2724 while (row) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2725 if (row.nodeType == 1 && (r = rows[row.uid])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2726 if (r.depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2727 for (i=tmp.length-1; i>=0; i--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2728 len = tmp[i].length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2729 if (len > r.depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2730 pos = len - r.depth;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2731 if (!(tmp[i][pos] & 2))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2732 tmp[i][pos] = tmp[i][pos] ? tmp[i][pos]+2 : 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2733 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2734 else if (len == r.depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2735 if (!(tmp[i][0] & 2))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2736 tmp[i][0] += 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2737 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2738 if (r.depth > len)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2739 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2740 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2741
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2742 tmp.push(new Array(r.depth));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2743 tmp[tmp.length-1][0] = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2744 uid.push(r.uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2745 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2746 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2747 if (tmp.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2748 for (i in tmp) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2749 this.set_tree_icons(uid[i], tmp[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2750 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2751 tmp = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2752 uid = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2753 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2754 if (root && row != rows[root].obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2755 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2756 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2757 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2758 row = row.nextSibling;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2759 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2760
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2761 if (tmp.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2762 for (i in tmp) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2763 this.set_tree_icons(uid[i], tmp[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2764 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2765 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2766 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2767
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2768 // adds tree icons to specified message row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2769 this.set_tree_icons = function(uid, tree)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2770 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2771 var i, divs = [], html = '', len = tree.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2772
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2773 for (i=0; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2774 if (tree[i] > 2)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2775 divs.push({'class': 'l3', width: 15});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2776 else if (tree[i] > 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2777 divs.push({'class': 'l2', width: 15});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2778 else if (tree[i] > 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2779 divs.push({'class': 'l1', width: 15});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2780 // separator div
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2781 else if (divs.length && !divs[divs.length-1]['class'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2782 divs[divs.length-1].width += 15;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2783 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2784 divs.push({'class': null, width: 15});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2785 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2787 for (i=divs.length-1; i>=0; i--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2788 if (divs[i]['class'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2789 html += '<div class="tree '+divs[i]['class']+'" />';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2790 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2791 html += '<div style="width:'+divs[i].width+'px" />';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2792 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2793
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2794 if (html)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2795 $('#rcmtab'+this.html_identifier(uid, true)).html(html);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2796 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2797
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2798 // update parent in a thread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2799 this.update_thread_root = function(uid, flag)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2800 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2801 if (!this.env.threading)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2802 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2803
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2804 var root = this.message_list.find_root(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2806 if (uid == root)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2807 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2809 var p = this.message_list.rows[root];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2810
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2811 if (flag == 'read' && p.unread_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2812 p.unread_children--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2813 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2814 else if (flag == 'unread' && p.has_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2815 // unread_children may be undefined
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2816 p.unread_children = (p.unread_children || 0) + 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2817 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2818 else if (flag == 'unflagged' && p.flagged_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2819 p.flagged_children--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2820 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2821 else if (flag == 'flagged' && p.has_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2822 p.flagged_children = (p.flagged_children || 0) + 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2823 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2824 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2825 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2826 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2827
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2828 this.set_message_icon(root);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2829 this.set_unread_children(root);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2830 this.set_flagged_children(root);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2831 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2832
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2833 // update thread indicators for all messages in a thread below the specified message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2834 // return number of removed/added root level messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2835 this.update_thread = function(uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2836 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2837 if (!this.env.threading || !this.message_list.rows[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2838 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2839
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2840 var r, parent, count = 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2841 list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2842 rows = list.rows,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2843 row = rows[uid],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2844 depth = rows[uid].depth,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2845 roots = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2846
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2847 if (!row.depth) // root message: decrease roots count
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2848 count--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2849
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2850 // update unread_children for thread root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2851 if (row.depth && row.unread) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2852 parent = list.find_root(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2853 rows[parent].unread_children--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2854 this.set_unread_children(parent);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2855 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2856
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2857 // update unread_children for thread root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2858 if (row.depth && row.flagged) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2859 parent = list.find_root(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2860 rows[parent].flagged_children--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2861 this.set_flagged_children(parent);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2862 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2863
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2864 parent = row.parent_uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2865
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2866 // childrens
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2867 row = row.obj.nextSibling;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2868 while (row) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2869 if (row.nodeType == 1 && (r = rows[row.uid])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2870 if (!r.depth || r.depth <= depth)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2871 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2872
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2873 r.depth--; // move left
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2874 // reset width and clear the content of a tab, icons will be added later
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2875 $('#rcmtab'+r.id).width(r.depth * 15).html('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2876 if (!r.depth) { // a new root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2877 count++; // increase roots count
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2878 r.parent_uid = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2879 if (r.has_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2880 // replace 'leaf' with 'collapsed'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2881 $('#'+r.id+' .leaf:first')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2882 .attr('id', 'rcmexpando' + r.id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2883 .attr('class', (r.obj.style.display != 'none' ? 'expanded' : 'collapsed'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2884 .mousedown({uid: r.uid}, function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2885 return ref.expand_message_row(e, e.data.uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2886 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2887
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2888 r.unread_children = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2889 roots.push(r);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2890 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2891 // show if it was hidden
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2892 if (r.obj.style.display == 'none')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2893 $(r.obj).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2894 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2895 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2896 if (r.depth == depth)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2897 r.parent_uid = parent;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2898 if (r.unread && roots.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2899 roots[roots.length-1].unread_children++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2900 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2901 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2902 row = row.nextSibling;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2903 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2904
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2905 // update unread_children/flagged_children for roots
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2906 for (r=0; r<roots.length; r++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2907 this.set_unread_children(roots[r].uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2908 this.set_flagged_children(roots[r].uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2909 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2910
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2911 return count;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2912 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2913
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2914 this.delete_excessive_thread_rows = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2915 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2916 var rows = this.message_list.rows,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2917 tbody = this.message_list.tbody,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2918 row = tbody.firstChild,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2919 cnt = this.env.pagesize + 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2920
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2921 while (row) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2922 if (row.nodeType == 1 && (r = rows[row.uid])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2923 if (!r.depth && cnt)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2924 cnt--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2925
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2926 if (!cnt)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2927 this.message_list.remove_row(row.uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2928 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2929 row = row.nextSibling;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2930 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2931 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2932
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2933 // set message icon
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2934 this.set_message_icon = function(uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2935 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2936 var css_class, label = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2937 row = this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2938
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2939 if (!row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2940 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2941
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2942 if (row.icon) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2943 css_class = 'msgicon';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2944 if (row.deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2945 css_class += ' deleted';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2946 label += this.get_label('deleted') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2947 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2948 else if (row.unread) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2949 css_class += ' unread';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2950 label += this.get_label('unread') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2951 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2952 else if (row.unread_children)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2953 css_class += ' unreadchildren';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2954 if (row.msgicon == row.icon) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2955 if (row.replied) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2956 css_class += ' replied';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2957 label += this.get_label('replied') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2958 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2959 if (row.forwarded) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2960 css_class += ' forwarded';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2961 label += this.get_label('forwarded') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2962 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2963 css_class += ' status';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2964 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2966 $(row.icon).attr('class', css_class).attr('title', label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2967 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2969 if (row.msgicon && row.msgicon != row.icon) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2970 label = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2971 css_class = 'msgicon';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2972 if (!row.unread && row.unread_children) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2973 css_class += ' unreadchildren';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2974 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2975 if (row.replied) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2976 css_class += ' replied';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2977 label += this.get_label('replied') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2978 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2979 if (row.forwarded) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2980 css_class += ' forwarded';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2981 label += this.get_label('forwarded') + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2982 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2983
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2984 $(row.msgicon).attr('class', css_class).attr('title', label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2985 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2986
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2987 if (row.flagicon) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2988 css_class = (row.flagged ? 'flagged' : 'unflagged');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2989 label = this.get_label(css_class);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2990 $(row.flagicon).attr('class', css_class)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2991 .attr('aria-label', label)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2992 .attr('title', label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2993 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2994 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2995
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2996 // set message status
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2997 this.set_message_status = function(uid, flag, status)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2998 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2999 var row = this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3000
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3001 if (!row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3002 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3003
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3004 if (flag == 'unread') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3005 if (row.unread != status)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3006 this.update_thread_root(uid, status ? 'unread' : 'read');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3007 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3008 else if (flag == 'flagged') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3009 this.update_thread_root(uid, status ? 'flagged' : 'unflagged');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3010 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3011
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3012 if ($.inArray(flag, ['unread', 'deleted', 'replied', 'forwarded', 'flagged']) > -1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3013 row[flag] = status;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3014 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3015
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3016 // set message row status, class and icon
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3017 this.set_message = function(uid, flag, status)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3018 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3019 var row = this.message_list && this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3020
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3021 if (!row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3022 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3023
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3024 if (flag)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3025 this.set_message_status(uid, flag, status);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3026
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3027 if ($.inArray(flag, ['unread', 'deleted', 'flagged']) > -1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3028 $(row.obj)[row[flag] ? 'addClass' : 'removeClass'](flag);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3029
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3030 this.set_unread_children(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3031 this.set_message_icon(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3032 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3033
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3034 // sets unroot (unread_children) class of parent row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3035 this.set_unread_children = function(uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3036 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3037 var row = this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3038
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3039 if (row.parent_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3040 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3041
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3042 var enable = !row.unread && row.unread_children && !row.expanded;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3043 $(row.obj)[enable ? 'addClass' : 'removeClass']('unroot');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3044 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3045
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3046 // sets flaggedroot (flagged_children) class of parent row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3047 this.set_flagged_children = function(uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3048 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3049 var row = this.message_list.rows[uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3050
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3051 if (row.parent_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3052 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3053
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3054 var enable = row.flagged_children && !row.expanded;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3055 $(row.obj)[enable ? 'addClass' : 'removeClass']('flaggedroot');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3056 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3057
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3058 // copy selected messages to the specified mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3059 this.copy_messages = function(mbox, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3060 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3061 if (mbox && typeof mbox === 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3062 mbox = mbox.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3063 else if (!mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3064 return this.folder_selector(event, function(folder) { ref.command('copy', folder); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3065
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3066 // exit if current or no mailbox specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3067 if (!mbox || mbox == this.env.mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3068 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3069
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3070 var post_data = this.selection_post_data({_target_mbox: mbox});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3071
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3072 // exit if selection is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3073 if (!post_data._uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3074 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3075
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3076 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3077 this.http_post('copy', post_data, this.display_message(this.get_label('copyingmessage'), 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3078 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3079
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3080 // move selected messages to the specified mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3081 this.move_messages = function(mbox, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3082 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3083 if (mbox && typeof mbox === 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3084 mbox = mbox.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3085 else if (!mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3086 return this.folder_selector(event, function(folder) { ref.command('move', folder); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3088 // exit if current or no mailbox specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3089 if (!mbox || (mbox == this.env.mailbox && !this.is_multifolder_listing()))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3090 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3091
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3092 var lock = false, post_data = this.selection_post_data({_target_mbox: mbox});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3093
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3094 // exit if selection is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3095 if (!post_data._uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3096 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3097
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3098 // show wait message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3099 if (this.env.action == 'show')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3100 lock = this.set_busy(true, 'movingmessage');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3101 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3102 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3103
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3104 // Hide message command buttons until a message is selected
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3105 this.enable_command(this.env.message_commands, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3106
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3107 this.with_selected_messages('move', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3108 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3109
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3110 // delete selected messages from the current mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3111 this.delete_messages = function(event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3112 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3113 var list = this.message_list, trash = this.env.trash_mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3115 // if config is set to flag for deletion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3116 if (this.env.flag_for_deletion) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3117 this.mark_message('delete');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3118 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3119 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3120 // if there isn't a defined trash mailbox or we are in it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3121 else if (!trash || this.env.mailbox == trash)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3122 this.permanently_remove_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3123 // we're in Junk folder and delete_junk is enabled
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3124 else if (this.env.delete_junk && this.env.junk_mailbox && this.env.mailbox == this.env.junk_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3125 this.permanently_remove_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3126 // if there is a trash mailbox defined and we're not currently in it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3127 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3128 // if shift was pressed delete it immediately
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3129 if ((list && list.modkey == SHIFT_KEY) || (event && rcube_event.get_modifier(event) == SHIFT_KEY)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3130 if (confirm(this.get_label('deletemessagesconfirm')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3131 this.permanently_remove_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3132 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3133 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3134 this.move_messages(trash);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3135 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3136
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3137 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3138 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3139
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3140 // delete the selected messages permanently
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3141 this.permanently_remove_messages = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3142 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3143 var post_data = this.selection_post_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3144
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3145 // exit if selection is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3146 if (!post_data._uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3147 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3149 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3150 this.with_selected_messages('delete', post_data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3151 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3152
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3153 // Send a specific move/delete request with UIDs of all selected messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3154 this.with_selected_messages = function(action, post_data, lock, http_action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3155 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3156 var count = 0, msg,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3157 remove = (action == 'delete' || !this.is_multifolder_listing());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3159 // update the list (remove rows, clear selection)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3160 if (this.message_list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3161 var n, id, root, roots = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3162 selection = this.message_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3163
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3164 for (n=0, len=selection.length; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3165 id = selection[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3167 if (this.env.threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3168 count += this.update_thread(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3169 root = this.message_list.find_root(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3170 if (root != id && $.inArray(root, roots) < 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3171 roots.push(root);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3172 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3173 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3174 if (remove)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3175 this.message_list.remove_row(id, (this.env.display_next && n == selection.length-1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3176 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3177 // make sure there are no selected rows
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3178 if (!this.env.display_next && remove)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3179 this.message_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3180 // update thread tree icons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3181 for (n=0, len=roots.length; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3182 this.add_tree_icons(roots[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3183 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3184 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3185
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3186 if (count < 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3187 post_data._count = (count*-1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3188 // remove threads from the end of the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3189 else if (count > 0 && remove)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3190 this.delete_excessive_thread_rows();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3191
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3192 if (!remove)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3193 post_data._refresh = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3195 if (!lock) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3196 msg = action == 'move' ? 'movingmessage' : 'deletingmessage';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3197 lock = this.display_message(this.get_label(msg), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3198 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3199
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3200 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3201 this.http_post(http_action || action, post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3202 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3203
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3204 // build post data for message delete/move/copy/flag requests
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3205 this.selection_post_data = function(data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3206 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3207 if (typeof(data) != 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3208 data = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3209
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3210 data._mbox = this.env.mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3211
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3212 if (!data._uid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3213 var uids = this.env.uid ? [this.env.uid] : this.message_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3214 data._uid = this.uids_to_list(uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3215 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3216
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3217 if (this.env.action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3218 data._from = this.env.action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3219
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3220 // also send search request to get the right messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3221 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3222 data._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3223
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3224 if (this.env.display_next && this.env.next_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3225 data._next_uid = this.env.next_uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3226
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3227 return data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3228 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3229
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3230 // set a specific flag to one or more messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3231 this.mark_message = function(flag, uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3232 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3233 var a_uids = [], r_uids = [], len, n, id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3234 list = this.message_list;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3235
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3236 if (uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3237 a_uids[0] = uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3238 else if (this.env.uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3239 a_uids[0] = this.env.uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3240 else if (list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3241 a_uids = list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3243 if (!list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3244 r_uids = a_uids;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3245 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3246 list.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3247 for (n=0, len=a_uids.length; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3248 id = a_uids[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3249 if ((flag == 'read' && list.rows[id].unread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3250 || (flag == 'unread' && !list.rows[id].unread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3251 || (flag == 'delete' && !list.rows[id].deleted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3252 || (flag == 'undelete' && list.rows[id].deleted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3253 || (flag == 'flagged' && !list.rows[id].flagged)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3254 || (flag == 'unflagged' && list.rows[id].flagged))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3255 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3256 r_uids.push(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3257 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3258 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3259 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3261 // nothing to do
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3262 if (!r_uids.length && !this.select_all_mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3263 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3265 switch (flag) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3266 case 'read':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3267 case 'unread':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3268 this.toggle_read_status(flag, r_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3269 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3270 case 'delete':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3271 case 'undelete':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3272 this.toggle_delete_status(r_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3273 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3274 case 'flagged':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3275 case 'unflagged':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3276 this.toggle_flagged_status(flag, a_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3277 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3278 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3279 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3280
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3281 // set class to read/unread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3282 this.toggle_read_status = function(flag, a_uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3283 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3284 var i, len = a_uids.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3285 post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: flag}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3286 lock = this.display_message(this.get_label('markingmessage'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3287
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3288 // mark all message rows as read/unread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3289 for (i=0; i<len; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3290 this.set_message(a_uids[i], 'unread', (flag == 'unread' ? true : false));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3291
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3292 this.http_post('mark', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3293 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3294
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3295 // set image to flagged or unflagged
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3296 this.toggle_flagged_status = function(flag, a_uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3297 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3298 var i, len = a_uids.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3299 post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: flag}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3300 lock = this.display_message(this.get_label('markingmessage'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3301
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3302 // mark all message rows as flagged/unflagged
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3303 for (i=0; i<len; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3304 this.set_message(a_uids[i], 'flagged', (flag == 'flagged' ? true : false));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3305
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3306 this.http_post('mark', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3307 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3308
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3309 // mark all message rows as deleted/undeleted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3310 this.toggle_delete_status = function(a_uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3311 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3312 var len = a_uids.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3313 i, uid, all_deleted = true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3314 rows = this.message_list ? this.message_list.rows : {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3315
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3316 if (len == 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3317 if (!this.message_list || (rows[a_uids[0]] && !rows[a_uids[0]].deleted))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3318 this.flag_as_deleted(a_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3319 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3320 this.flag_as_undeleted(a_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3321
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3322 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3325 for (i=0; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3326 uid = a_uids[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3327 if (rows[uid] && !rows[uid].deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3328 all_deleted = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3329 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3330 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3331 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3333 if (all_deleted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3334 this.flag_as_undeleted(a_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3335 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3336 this.flag_as_deleted(a_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3338 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3339 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3340
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3341 this.flag_as_undeleted = function(a_uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3342 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3343 var i, len = a_uids.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3344 post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: 'undelete'}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3345 lock = this.display_message(this.get_label('markingmessage'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3346
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3347 for (i=0; i<len; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3348 this.set_message(a_uids[i], 'deleted', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3349
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3350 this.http_post('mark', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3351 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3352
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3353 this.flag_as_deleted = function(a_uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3354 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3355 var r_uids = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3356 post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: 'delete'}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3357 lock = this.display_message(this.get_label('markingmessage'), 'loading'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3358 list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3359 rows = list ? list.rows : {},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3360 count = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3361
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3362 for (var i=0, len=a_uids.length; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3363 uid = a_uids[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3364 if (rows[uid]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3365 if (rows[uid].unread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3366 r_uids[r_uids.length] = uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3367
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3368 if (this.env.skip_deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3369 count += this.update_thread(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3370 list.remove_row(uid, (this.env.display_next && i == list.selection.length-1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3371 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3372 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3373 this.set_message(uid, 'deleted', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3374 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3375 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3376
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3377 // make sure there are no selected rows
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3378 if (this.env.skip_deleted && list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3379 if (!this.env.display_next || !list.rowcount)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3380 list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3381 if (count < 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3382 post_data._count = (count*-1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3383 else if (count > 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3384 // remove threads from the end of the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3385 this.delete_excessive_thread_rows();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3386 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3387
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3388 // set of messages to mark as seen
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3389 if (r_uids.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3390 post_data._ruid = this.uids_to_list(r_uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3391
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3392 if (this.env.skip_deleted && this.env.display_next && this.env.next_uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3393 post_data._next_uid = this.env.next_uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3394
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3395 this.http_post('mark', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3396 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3397
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3398 // flag as read without mark request (called from backend)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3399 // argument should be a coma-separated list of uids
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3400 this.flag_deleted_as_read = function(uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3401 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3402 var uid, i, len,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3403 rows = this.message_list ? this.message_list.rows : {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3404
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3405 if (typeof uids == 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3406 uids = uids.split(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3407
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3408 for (i=0, len=uids.length; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3409 uid = uids[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3410 if (rows[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3411 this.set_message(uid, 'unread', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3412 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3413 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3414
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3415 // Converts array of message UIDs to comma-separated list for use in URL
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3416 // with select_all mode checking
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3417 this.uids_to_list = function(uids)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3418 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3419 return this.select_all_mode ? '*' : (uids.length <= 1 ? uids.join(',') : uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3420 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3421
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3422 // Sets title of the delete button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3423 this.set_button_titles = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3424 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3425 var label = 'deletemessage';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3426
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3427 if (!this.env.flag_for_deletion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3428 && this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3429 && (!this.env.delete_junk || !this.env.junk_mailbox || this.env.mailbox != this.env.junk_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3430 )
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3431 label = 'movemessagetotrash';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3432
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3433 this.set_alttext('delete', label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3434 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3435
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3436 // Initialize input element for list page jump
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3437 this.init_pagejumper = function(element)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3438 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3439 $(element).addClass('rcpagejumper')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3440 .on('focus', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3441 // create and display popup with page selection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3442 var i, html = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3443
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3444 for (i = 1; i <= ref.env.pagecount; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3445 html += '<li>' + i + '</li>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3446
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3447 html = '<ul class="toolbarmenu">' + html + '</ul>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3448
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3449 if (!ref.pagejump) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3450 ref.pagejump = $('<div id="pagejump-selector" class="popupmenu"></div>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3451 .appendTo(document.body)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3452 .on('click', 'li', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3453 if (!ref.busy)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3454 $(element).val($(this).text()).change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3455 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3456 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3457
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3458 if (ref.pagejump.data('count') != i)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3459 ref.pagejump.html(html);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3461 ref.pagejump.attr('rel', '#' + this.id).data('count', i);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3462
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3463 // display page selector
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3464 ref.show_menu('pagejump-selector', true, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3465 $(this).keydown();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3466 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3467 // keyboard navigation
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3468 .on('keydown keyup click', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3469 var current, selector = $('#pagejump-selector'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3470 ul = $('ul', selector),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3471 list = $('li', ul),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3472 height = ul.height(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3473 p = parseInt(this.value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3474
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3475 if (e.which != 27 && e.which != 9 && e.which != 13 && !selector.is(':visible'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3476 return ref.show_menu('pagejump-selector', true, e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3477
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3478 if (e.type == 'keydown') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3479 // arrow-down
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3480 if (e.which == 40) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3481 if (list.length > p)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3482 this.value = (p += 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3483 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3484 // arrow-up
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3485 else if (e.which == 38) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3486 if (p > 1 && list.length > p - 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3487 this.value = (p -= 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3488 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3489 // enter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3490 else if (e.which == 13) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3491 return $(this).change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3492 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3493 // esc, tab
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3494 else if (e.which == 27 || e.which == 9) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3495 return $(element).val(ref.env.current_page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3496 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3497 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3498
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3499 $('li.selected', ul).removeClass('selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3500
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3501 if ((current = $(list[p - 1])).length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3502 current.addClass('selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3503 $('#pagejump-selector').scrollTop(((ul.height() / list.length) * (p - 1)) - selector.height() / 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3504 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3505 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3506 .on('change', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3507 // go to specified page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3508 var p = parseInt(this.value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3509 if (p && p != ref.env.current_page && !ref.busy) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3510 ref.hide_menu('pagejump-selector');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3511 ref.list_page(p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3513 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3514 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3515
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3516 // Update page-jumper state on list updates
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3517 this.update_pagejumper = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3518 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3519 $('input.rcpagejumper').val(this.env.current_page).prop('disabled', this.env.pagecount < 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3520 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3521
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3522 // check for mailvelope API
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3523 this.check_mailvelope = function(action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3524 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3525 if (typeof window.mailvelope !== 'undefined') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3526 this.mailvelope_load(action);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3527 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3528 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3529 $(window).on('mailvelope', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3530 ref.mailvelope_load(action);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3531 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3532 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3533 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3534
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3535 // Load Mailvelope functionality (and initialize keyring if needed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3536 this.mailvelope_load = function(action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3537 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3538 if (this.env.browser_capabilities)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3539 this.env.browser_capabilities['pgpmime'] = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3540
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3541 var keyring = this.env.user_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3542
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3543 mailvelope.getKeyring(keyring).then(function(kr) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3544 ref.mailvelope_keyring = kr;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3545 ref.mailvelope_init(action, kr);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3546 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3547 // attempt to create a new keyring for this app/user
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3548 mailvelope.createKeyring(keyring).then(function(kr) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3549 ref.mailvelope_keyring = kr;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3550 ref.mailvelope_init(action, kr);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3551 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3552 console.error(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3553 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3554 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3555 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3556
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3557 // Initializes Mailvelope editor or display container
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3558 this.mailvelope_init = function(action, keyring)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3559 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3560 if (!window.mailvelope)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3561 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3562
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3563 if (action == 'show' || action == 'preview' || action == 'print') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3564 // decrypt text body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3565 if (this.env.is_pgp_content) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3566 var data = $(this.env.is_pgp_content).text();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3567 ref.mailvelope_display_container(this.env.is_pgp_content, data, keyring);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3568 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3569 // load pgp/mime message and pass it to the mailvelope display container
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3570 else if (this.env.pgp_mime_part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3571 var msgid = this.display_message(this.get_label('loadingdata'), 'loading'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3572 selector = this.env.pgp_mime_container;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3573
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3574 $.ajax({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3575 type: 'GET',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3576 url: this.url('get', { '_mbox': this.env.mailbox, '_uid': this.env.uid, '_part': this.env.pgp_mime_part }),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3577 error: function(o, status, err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3578 ref.http_error(o, status, err, msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3579 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3580 success: function(data) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3581 ref.mailvelope_display_container(selector, data, keyring, msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3582 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3583 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3584 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3585 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3586 else if (action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3587 this.env.compose_commands.push('compose-encrypted');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3588
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3589 var is_html = $('input[name="_is_html"]').val() > 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3590
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3591 if (this.env.pgp_mime_message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3592 // fetch PGP/Mime part and open load into Mailvelope editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3593 var lock = this.set_busy(true, this.get_label('loadingdata'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3594
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3595 $.ajax({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3596 type: 'GET',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3597 url: this.url('get', this.env.pgp_mime_message),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3598 error: function(o, status, err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3599 ref.http_error(o, status, err, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3600 ref.enable_command('compose-encrypted', !is_html);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3601 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3602 success: function(data) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3603 ref.set_busy(false, null, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3604
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3605 if (is_html) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3606 ref.command('toggle-editor', {html: false, noconvert: true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3607 $('#' + ref.env.composebody).val('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3608 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3609
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3610 ref.compose_encrypted({ quotedMail: data });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3611 ref.enable_command('compose-encrypted', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3612 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3613 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3614 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3615 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3616 // enable encrypted compose toggle
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3617 this.enable_command('compose-encrypted', !is_html);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3618 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3619
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3620 // make sure to disable encryption button after toggling editor into HTML mode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3621 this.addEventListener('actionafter', function(args) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3622 if (args.ret && args.action == 'toggle-editor')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3623 ref.enable_command('compose-encrypted', !args.props.html);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3624 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3625 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3626 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3627
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3628 // handler for the 'compose-encrypted' command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3629 this.compose_encrypted = function(props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3630 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3631 var options, container = $('#' + this.env.composebody).parent();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3632
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3633 // remove Mailvelope editor if active
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3634 if (ref.mailvelope_editor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3635 ref.mailvelope_editor = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3636 ref.compose_skip_unsavedcheck = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3637 ref.set_button('compose-encrypted', 'act');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3638
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3639 container.removeClass('mailvelope')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3640 .find('iframe:not([aria-hidden=true])').remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3641 $('#' + ref.env.composebody).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3642 $("[name='_pgpmime']").remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3643
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3644 // disable commands that operate on the compose body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3645 ref.enable_command('spellcheck', 'insert-sig', 'toggle-editor', 'insert-response', 'save-response', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3646 ref.triggerEvent('compose-encrypted', { active:false });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3647 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3648 // embed Mailvelope editor container
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3649 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3650 if (this.spellcheck_state())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3651 this.editor.spellcheck_stop();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3652
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3653 if (props.quotedMail) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3654 options = { quotedMail: props.quotedMail, quotedMailIndent: false };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3655 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3656 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3657 options = { predefinedText: $('#' + this.env.composebody).val() };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3658 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3659
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3660 if (this.env.compose_mode == 'reply') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3661 options.quotedMailIndent = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3662 options.quotedMailHeader = this.env.compose_reply_header;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3663 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3664
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3665 mailvelope.createEditorContainer('#' + container.attr('id'), ref.mailvelope_keyring, options).then(function(editor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3666 ref.mailvelope_editor = editor;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3667 ref.compose_skip_unsavedcheck = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3668 ref.set_button('compose-encrypted', 'sel');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3669
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3670 container.addClass('mailvelope');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3671 $('#' + ref.env.composebody).hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3672
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3673 // disable commands that operate on the compose body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3674 ref.enable_command('spellcheck', 'insert-sig', 'toggle-editor', 'insert-response', 'save-response', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3675 ref.triggerEvent('compose-encrypted', { active:true });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3676
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3677 // notify user about loosing attachments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3678 if (ref.env.attachments && !$.isEmptyObject(ref.env.attachments)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3679 alert(ref.get_label('encryptnoattachments'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3680
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3681 $.each(ref.env.attachments, function(name, attach) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3682 ref.remove_from_attachment_list(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3683 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3684 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3685 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3686 console.error(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3687 console.log(options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3688 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3689 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3690 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3691
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3692 // callback to replace the message body with the full armored
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3693 this.mailvelope_submit_messageform = function(draft, saveonly)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3694 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3695 // get recipients
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3696 var recipients = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3697 $.each(['to', 'cc', 'bcc'], function(i,field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3698 var pos, rcpt, val = $.trim($('[name="_' + field + '"]').val());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3699 while (val.length && rcube_check_email(val, true)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3700 rcpt = RegExp.$2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3701 recipients.push(rcpt);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3702 val = val.substr(val.indexOf(rcpt) + rcpt.length + 1).replace(/^\s*,\s*/, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3703 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3704 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3705
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3706 // check if we have keys for all recipients
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3707 var isvalid = recipients.length > 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3708 ref.mailvelope_keyring.validKeyForAddress(recipients).then(function(status) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3709 var missing_keys = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3710 $.each(status, function(k,v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3711 if (v === false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3712 isvalid = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3713 missing_keys.push(k);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3714 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3715 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3716
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3717 // list recipients with missing keys
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3718 if (!isvalid && missing_keys.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3719 // display dialog with missing keys
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3720 ref.simple_dialog(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3721 ref.get_label('nopubkeyfor').replace('$email', missing_keys.join(', ')) +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3722 '<p>' + ref.get_label('searchpubkeyservers') + '</p>',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3723 'encryptedsendialog',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3724 function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3725 ref.mailvelope_search_pubkeys(missing_keys, function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3726 return true; // close dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3727 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3728 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3729 {button: 'search'}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3730 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3731 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3732 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3733
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3734 if (!isvalid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3735 if (!recipients.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3736 alert(ref.get_label('norecipientwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3737 $("[name='_to']").focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3738 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3739 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3740 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3741
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3742 // add sender identity to recipients to be able to decrypt our very own message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3743 var senders = [], selected_sender = ref.env.identities[$("[name='_from'] option:selected").val()];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3744 $.each(ref.env.identities, function(k, sender) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3745 senders.push(sender.email);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3746 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3747
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3748 ref.mailvelope_keyring.validKeyForAddress(senders).then(function(status) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3749 valid_sender = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3750 $.each(status, function(k,v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3751 if (v !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3752 valid_sender = k;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3753 if (valid_sender == selected_sender) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3754 return false; // break
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3755 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3756 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3757 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3758
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3759 if (!valid_sender) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3760 if (!confirm(ref.get_label('nopubkeyforsender'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3761 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3762 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3763 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3764
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3765 recipients.push(valid_sender);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3766
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3767 ref.mailvelope_editor.encrypt(recipients).then(function(armored) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3768 // all checks passed, send message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3769 var form = ref.gui_objects.messageform,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3770 hidden = $("[name='_pgpmime']", form),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3771 msgid = ref.set_busy(true, draft || saveonly ? 'savingmessage' : 'sendingmessage')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3772
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3773 form.target = 'savetarget';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3774 form._draft.value = draft ? '1' : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3775 form.action = ref.add_url(form.action, '_unlock', msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3776 form.action = ref.add_url(form.action, '_framed', 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3777
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3778 if (saveonly) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3779 form.action = ref.add_url(form.action, '_saveonly', 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3780 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3781
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3782 // send pgp conent via hidden field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3783 if (!hidden.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3784 hidden = $('<input type="hidden" name="_pgpmime">').appendTo(form);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3785 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3786 hidden.val(armored);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3787
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3788 form.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3789
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3790 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3791 console.log(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3792 }); // mailvelope_editor.encrypt()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3793
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3794 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3795 console.error(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3796 }); // mailvelope_keyring.validKeyForAddress(senders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3797
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3798 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3799 console.error(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3800 }); // mailvelope_keyring.validKeyForAddress(recipients)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3801
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3802 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3803 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3804
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3805 // wrapper for the mailvelope.createDisplayContainer API call
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3806 this.mailvelope_display_container = function(selector, data, keyring, msgid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3807 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3808 var error_handler = function(error) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3809 // remove mailvelope frame with the error message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3810 $(selector + ' > iframe').remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3811 ref.hide_message(msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3812 ref.display_message(error.message, 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3813 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3814
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3815 mailvelope.createDisplayContainer(selector, data, keyring, { showExternalContent: this.env.safemode }).then(function(status) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3816 if (status.error && status.error.message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3817 return error_handler(status.error);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3818 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3819
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3820 ref.hide_message(msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3821 $(selector).addClass('mailvelope').children().not('iframe').hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3823 // on success we can remove encrypted part from the attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3824 if (ref.env.pgp_mime_part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3825 $('#attach' + ref.env.pgp_mime_part).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3826
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3827 setTimeout(function() { $(window).resize(); }, 10);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3828 }, error_handler);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3829 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3831 // subroutine to query keyservers for public keys
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3832 this.mailvelope_search_pubkeys = function(emails, resolve, import_handler)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3833 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3834 // query with publickey.js
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3835 var deferreds = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3836 pk = new PublicKey(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3837 lock = ref.display_message(ref.get_label('loading'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3838
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3839 $.each(emails, function(i, email) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3840 var d = $.Deferred();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3841 pk.search(email, function(results, errorCode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3842 if (errorCode !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3843 // rejecting would make all fail
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3844 // d.reject(email);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3845 d.resolve([email]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3846 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3847 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3848 d.resolve([email].concat(results));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3849 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3850 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3851 deferreds.push(d);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3852 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3853
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3854 $.when.apply($, deferreds).then(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3855 var missing_keys = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3856 key_selection = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3857
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3858 // alanyze results of all queries
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3859 $.each(arguments, function(i, result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3860 var email = result.shift();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3861 if (!result.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3862 missing_keys.push(email);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3863 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3864 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3865 key_selection = key_selection.concat(result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3866 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3867 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3868
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3869 ref.hide_message(lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3870 resolve(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3871
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3872 // show key import dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3873 if (key_selection.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3874 ref.mailvelope_key_import_dialog(key_selection, import_handler);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3875 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3876 // some keys could not be found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3877 if (missing_keys.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3878 ref.display_message(ref.get_label('nopubkeyfor').replace('$email', missing_keys.join(', ')), 'warning');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3879 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3880 }).fail(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3881 console.error('Pubkey lookup failed with', arguments);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3882 ref.hide_message(lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3883 ref.display_message('pubkeysearcherror', 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3884 resolve(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3885 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3886 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3887
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3888 // list the given public keys in a dialog with options to import
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3889 // them into the local Maivelope keyring
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3890 this.mailvelope_key_import_dialog = function(candidates, import_handler)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3891 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3892 var ul = $('<div>').addClass('listing pgpkeyimport');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3893 $.each(candidates, function(i, keyrec) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3894 var li = $('<div>').addClass('key');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3895 if (keyrec.revoked) li.addClass('revoked');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3896 if (keyrec.disabled) li.addClass('disabled');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3897 if (keyrec.expired) li.addClass('expired');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3898
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3899 li.append($('<label>').addClass('keyid').text(ref.get_label('keyid')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3900 li.append($('<a>').text(keyrec.keyid.substr(-8).toUpperCase())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3901 .attr('href', keyrec.info)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3902 .attr('target', '_blank')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3903 .attr('tabindex', '-1'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3904
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3905 li.append($('<label>').addClass('keylen').text(ref.get_label('keylength')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3906 li.append($('<span>').text(keyrec.keylen));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3907
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3908 if (keyrec.expirationdate) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3909 li.append($('<label>').addClass('keyexpired').text(ref.get_label('keyexpired')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3910 li.append($('<span>').text(new Date(keyrec.expirationdate * 1000).toDateString()));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3911 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3912
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3913 if (keyrec.revoked) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3914 li.append($('<span>').addClass('keyrevoked').text(ref.get_label('keyrevoked')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3915 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3916
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3917 var ul_ = $('<ul>').addClass('uids');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3918 $.each(keyrec.uids, function(j, uid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3919 var li_ = $('<li>').addClass('uid');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3920 if (uid.revoked) li_.addClass('revoked');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3921 if (uid.disabled) li_.addClass('disabled');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3922 if (uid.expired) li_.addClass('expired');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3924 ul_.append(li_.text(uid.uid));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3925 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3926
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3927 li.append(ul_);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3928 li.append($('<input>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3929 .attr('type', 'button')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3930 .attr('rel', keyrec.keyid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3931 .attr('value', ref.get_label('import'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3932 .addClass('button importkey')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3933 .prop('disabled', keyrec.revoked || keyrec.disabled || keyrec.expired));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3934
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3935 ul.append(li);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3936 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3937
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3938 // display dialog with missing keys
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3939 ref.show_popup_dialog(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3940 $('<div>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3941 .append($('<p>').html(ref.get_label('encryptpubkeysfound')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3942 .append(ul),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3943 ref.get_label('importpubkeys'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3944 [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3945 text: ref.get_label('close'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3946 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3947 (ref.is_framed() ? parent.$ : $)(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3948 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3949 }]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3950 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3951
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3952 // delegate handler for import button clicks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3953 ul.on('click', 'input.button.importkey', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3954 var btn = $(this),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3955 keyid = btn.attr('rel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3956 pk = new PublicKey(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3957 lock = ref.display_message(ref.get_label('loading'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3958
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3959 // fetch from keyserver and import to Mailvelope keyring
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3960 pk.get(keyid, function(armored, errorCode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3961 ref.hide_message(lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3962
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3963 if (errorCode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3964 ref.display_message(ref.get_label('keyservererror'), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3965 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3966 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3967
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3968 if (import_handler) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3969 import_handler(armored);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3970 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3971 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3972
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3973 // import to keyring
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3974 ref.mailvelope_keyring.importPublicKey(armored).then(function(status) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3975 if (status === 'REJECTED') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3976 // alert(ref.get_label('Key import was rejected'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3977 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3978 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3979 var $key = keyid.substr(-8).toUpperCase();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3980 btn.closest('.key').fadeOut();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3981 ref.display_message(ref.get_label('keyimportsuccess').replace('$key', $key), 'confirmation');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3982 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3983 }, function(err) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3984 console.log(err);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3985 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3986 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3987 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3988
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3989 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3990
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3992 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3993 /********* mailbox folders methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3994 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3995
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3996 this.expunge_mailbox = function(mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3997 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3998 var lock, post_data = {_mbox: mbox};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3999
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4000 // lock interface if it's the active mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4001 if (mbox == this.env.mailbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4002 lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4003 post_data._reload = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4004 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4005 post_data._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4006 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4007
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4008 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4009 this.http_post('expunge', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4010 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4011
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4012 this.purge_mailbox = function(mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4013 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4014 var lock, post_data = {_mbox: mbox};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4015
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4016 if (!confirm(this.get_label('purgefolderconfirm')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4017 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4018
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4019 // lock interface if it's the active mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4020 if (mbox == this.env.mailbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4021 lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4022 post_data._reload = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4023 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4024
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4025 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4026 this.http_post('purge', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4027 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4028
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4029 // test if purge command is allowed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4030 this.purge_mailbox_test = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4031 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4032 return (this.env.exists && (
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4033 this.env.mailbox == this.env.trash_mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4034 || this.env.mailbox == this.env.junk_mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4035 || this.env.mailbox.startsWith(this.env.trash_mailbox + this.env.delimiter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4036 || this.env.mailbox.startsWith(this.env.junk_mailbox + this.env.delimiter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4037 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4038 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4039
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4040 // Mark all messages as read in:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4041 // - selected folder (mode=cur)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4042 // - selected folder and its subfolders (mode=sub)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4043 // - all folders (mode=all)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4044 this.mark_all_read = function(mbox, mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4045 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4046 var state, content, nodes = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4047 list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4048 folder = mbox || this.env.mailbox,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4049 post_data = {_uid: '*', _flag: 'read', _mbox: folder, _folders: mode};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4050
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4051 if (typeof mode != 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4052 state = this.mark_all_read_state(folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4053 if (!state)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4054 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4055
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4056 if (state > 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4057 // build content of the dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4058 $.each({cur: 1, sub: 2, all: 4}, function(i, v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4059 var label = $('<label>').attr('style', 'display:block; line-height:22px'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4060 text = $('<span>').text(ref.get_label('folders-' + i)),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4061 input = $('<input>').attr({type: 'radio', value: i, name: 'mode'});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4062
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4063 if (!(state & v)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4064 label.attr('class', 'disabled');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4065 input.attr('disabled', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4066 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4067
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4068 nodes.push(label.append(input).append(text));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4069 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4071 content = $('<div>').append(nodes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4072 $('input:not([disabled]):first', content).attr('checked', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4073
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4074 this.show_popup_dialog(content, this.get_label('markallread'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4075 [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4076 'class': 'mainaction',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4077 text: this.get_label('mark'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4078 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4079 ref.mark_all_read(folder, $('input:checked', this).val());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4080 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4082 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4083 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4084 text: this.get_label('cancel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4085 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4086 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4087 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4088 }]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4089 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4090
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4091 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4092 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4093
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4094 post_data._folders = 'cur'; // only current folder has unread messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4095 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4096
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4097 // mark messages on the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4098 $.each(list ? list.rows : [], function(uid, row) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4099 if (!row.unread)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4100 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4102 var mbox = ref.env.messages[uid].mbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4103 if (mode == 'all' || mbox == ref.env.mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4104 || (mode == 'sub' && mbox.startsWith(ref.env.mailbox + ref.env.delimiter))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4105 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4106 ref.set_message(uid, 'unread', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4107 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4108 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4109
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4110 // send the request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4111 this.http_post('mark', post_data, this.display_message(this.get_label('markingmessage'), 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4112 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4113
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4114 // Enable/disable mark-all-read action depending on folders state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4115 this.mark_all_read_state = function(mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4116 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4117 var state = 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4118 li = this.treelist.get_item(mbox || this.env.mailbox),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4119 folder_item = $(li).is('.unread') ? 1 : 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4120 subfolder_items = $('li.unread', li).length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4121 all_items = $('li.unread', ref.gui_objects.folderlist).length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4122
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4123 state += folder_item;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4124 state += subfolder_items ? 2 : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4125 state += all_items > folder_item + subfolder_items ? 4 : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4127 this.enable_command('mark-all-read', state > 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4128
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4129 return state;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4130 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4131
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4132
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4133 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4134 /********* login form methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4135 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4136
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4137 // handler for keyboard events on the _user field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4138 this.login_user_keyup = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4139 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4140 var key = rcube_event.get_keycode(e),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4141 passwd = $('#rcmloginpwd');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4142
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4143 // enter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4144 if (key == 13 && passwd.length && !passwd.val()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4145 passwd.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4146 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4147 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4149 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4150 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4151
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4152
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4153 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4154 /********* message compose methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4155 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4156
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4157 this.open_compose_step = function(p)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4158 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4159 var url = this.url('mail/compose', p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4161 // open new compose window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4162 if (this.env.compose_extwin && !this.env.extwin) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4163 this.open_window(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4164 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4165 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4166 this.redirect(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4167 if (this.env.extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4168 window.resizeTo(Math.max(this.env.popup_width, $(window).width()), $(window).height() + 24);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4169 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4170 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4172 // init message compose form: set focus and eventhandlers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4173 this.init_messageform = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4174 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4175 if (!this.gui_objects.messageform)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4176 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4178 var i, elem, pos, input_from = $("[name='_from']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4179 input_to = $("[name='_to']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4180 input_subject = $("input[name='_subject']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4181 input_message = $("[name='_message']").get(0),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4182 html_mode = $("input[name='_is_html']").val() == '1',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4183 ac_fields = ['cc', 'bcc', 'replyto', 'followupto'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4184 ac_props, opener_rc = this.opener();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4185
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4186 // close compose step in opener
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4187 if (opener_rc && opener_rc.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4188 setTimeout(function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4189 if (opener.history.length > 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4190 opener.history.back();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4191 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4192 opener_rc.redirect(opener_rc.get_task_url('mail'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4193 }, 100);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4194 this.env.opened_extwin = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4195 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4196
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4197 // configure parallel autocompletion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4198 if (this.env.autocomplete_threads > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4199 ac_props = {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4200 threads: this.env.autocomplete_threads,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4201 sources: this.env.autocomplete_sources
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4202 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4203 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4205 // init live search events
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4206 this.init_address_input_events(input_to, ac_props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4207 for (i in ac_fields) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4208 this.init_address_input_events($("[name='_"+ac_fields[i]+"']"), ac_props);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4209 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4210
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4211 if (!html_mode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4212 pos = this.env.top_posting && this.env.compose_mode ? 0 : input_message.value.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4213
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4214 // add signature according to selected identity
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4215 // if we have HTML editor, signature is added in a callback
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4216 if (input_from.prop('type') == 'select-one') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4217 // for some reason the caret initially is not at pos=0 in Firefox 51 (#5628)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4218 this.set_caret_pos(input_message, 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4219 this.change_identity(input_from[0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4220 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4221
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4222 // set initial cursor position
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4223 this.set_caret_pos(input_message, pos);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4224
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4225 // scroll to the bottom of the textarea (#1490114)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4226 if (pos) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4227 $(input_message).scrollTop(input_message.scrollHeight);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4228 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4229 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4230
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4231 // check for locally stored compose data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4232 if (this.env.save_localstorage)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4233 this.compose_restore_dialog(0, html_mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4234
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4235 if (input_to.val() == '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4236 elem = input_to;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4237 else if (input_subject.val() == '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4238 elem = input_subject;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4239 else if (input_message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4240 elem = input_message;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4241
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4242 // focus first empty element (need to be visible on IE8)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4243 this.env.compose_focus_elem = $(elem).filter(':visible').focus().get(0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4244
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4245 // get summary of all field values
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4246 this.compose_field_hash(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4247
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4248 // start the auto-save timer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4249 this.auto_save_start();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4250 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4251
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4252 this.compose_restore_dialog = function(j, html_mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4253 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4254 var i, key, formdata, index = this.local_storage_get_item('compose.index', []);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4255
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4256 var show_next = function(i) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4257 if (++i < index.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4258 ref.compose_restore_dialog(i, html_mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4259 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4261 for (i = j || 0; i < index.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4262 key = index[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4263 formdata = this.local_storage_get_item('compose.' + key, null, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4264 if (!formdata) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4265 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4266 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4267 // restore saved copy of current compose_id
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4268 if (formdata.changed && key == this.env.compose_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4269 this.restore_compose_form(key, html_mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4270 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4271 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4272 // skip records from 'other' drafts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4273 if (this.env.draft_id && formdata.draft_id && formdata.draft_id != this.env.draft_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4274 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4275 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4276 // skip records on reply
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4277 if (this.env.reply_msgid && formdata.reply_msgid != this.env.reply_msgid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4278 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4279 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4280 // show dialog asking to restore the message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4281 if (formdata.changed && formdata.session != this.env.session_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4282 this.show_popup_dialog(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4283 this.get_label('restoresavedcomposedata')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4284 .replace('$date', new Date(formdata.changed).toLocaleString())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4285 .replace('$subject', formdata._subject)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4286 .replace(/\n/g, '<br/>'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4287 this.get_label('restoremessage'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4288 [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4289 text: this.get_label('restore'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4290 'class': 'mainaction',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4291 click: function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4292 ref.restore_compose_form(key, html_mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4293 ref.remove_compose_data(key); // remove old copy
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4294 ref.save_compose_form_local(); // save under current compose_id
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4295 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4296 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4297 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4298 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4299 text: this.get_label('delete'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4300 'class': 'delete',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4301 click: function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4302 ref.remove_compose_data(key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4303 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4304 show_next(i);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4305 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4306 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4307 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4308 text: this.get_label('ignore'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4309 click: function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4310 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4311 show_next(i);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4312 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4313 }]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4314 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4315 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4316 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4317 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4318 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4319
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4320 this.init_address_input_events = function(obj, props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4321 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4322 this.env.recipients_delimiter = this.env.recipients_separator + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4323
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4324 obj.keydown(function(e) { return ref.ksearch_keydown(e, this, props); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4325 .attr({ 'autocomplete': 'off', 'aria-autocomplete': 'list', 'aria-expanded': 'false', 'role': 'combobox' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4326
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4327 // hide the popup on any click
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4328 $(document).on('click', function() { ref.ksearch_hide(); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4329 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4330
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4331 this.submit_messageform = function(draft, saveonly)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4332 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4333 var form = this.gui_objects.messageform;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4334
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4335 if (!form)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4336 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4338 // the message has been sent but not saved, ask the user what to do
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4339 if (!saveonly && this.env.is_sent) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4340 return this.simple_dialog(this.get_label('messageissent'), '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4341 function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4342 ref.submit_messageform(false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4343 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4344 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4345 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4346 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4347
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4348 // delegate sending to Mailvelope routine
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4349 if (this.mailvelope_editor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4350 return this.mailvelope_submit_messageform(draft, saveonly);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4351 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4352
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4353 // all checks passed, send message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4354 var msgid = this.set_busy(true, draft || saveonly ? 'savingmessage' : 'sendingmessage'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4355 lang = this.spellcheck_lang(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4356 files = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4358 // send files list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4359 $('li', this.gui_objects.attachmentlist).each(function() { files.push(this.id.replace(/^rcmfile/, '')); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4360 $('input[name="_attachments"]', form).val(files.join());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4361
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4362 form.target = 'savetarget';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4363 form._draft.value = draft ? '1' : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4364 form.action = this.add_url(form.action, '_unlock', msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4365 form.action = this.add_url(form.action, '_lang', lang);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4366 form.action = this.add_url(form.action, '_framed', 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4367
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4368 if (saveonly) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4369 form.action = this.add_url(form.action, '_saveonly', 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4370 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4372 // register timer to notify about connection timeout
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4373 this.submit_timer = setTimeout(function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4374 ref.set_busy(false, null, msgid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4375 ref.display_message(ref.get_label('requesttimedout'), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4376 }, this.env.request_timeout * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4378 form.submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4379 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4380
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4381 this.compose_recipient_select = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4382 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4383 var id, n, recipients = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4384 for (n=0; n < list.selection.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4385 id = list.selection[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4386 if (this.env.contactdata[id])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4387 recipients++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4388 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4389 this.enable_command('add-recipient', recipients);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4390 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4391
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4392 this.compose_add_recipient = function(field)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4393 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4394 // find last focused field name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4395 if (!field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4396 field = $(this.env.focused_field).filter(':visible');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4397 field = field.length ? field.attr('id').replace('_', '') : 'to';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4398 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4400 var recipients = [], input = $('#_'+field), delim = this.env.recipients_delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4401
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4402 if (this.contact_list && this.contact_list.selection.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4403 for (var id, n=0; n < this.contact_list.selection.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4404 id = this.contact_list.selection[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4405 if (id && this.env.contactdata[id]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4406 recipients.push(this.env.contactdata[id]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4407
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4408 // group is added, expand it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4409 if (id.charAt(0) == 'E' && this.env.contactdata[id].indexOf('@') < 0 && input.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4410 var gid = id.substr(1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4411 this.group2expand[gid] = { name:this.env.contactdata[id], input:input.get(0) };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4412 this.http_request('group-expand', {_source: this.env.source, _gid: gid}, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4413 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4414 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4415 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4416 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4417
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4418 if (recipients.length && input.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4419 var oldval = input.val(), rx = new RegExp(RegExp.escape(delim) + '\\s*$');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4420 if (oldval && !rx.test(oldval))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4421 oldval += delim + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4422 input.val(oldval + recipients.join(delim + ' ') + delim + ' ').change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4423 this.triggerEvent('add-recipient', { field:field, recipients:recipients });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4424 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4425
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4426 return recipients.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4427 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4428
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4429 // checks the input fields before sending a message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4430 this.check_compose_input = function(cmd)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4431 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4432 // check input fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4433 var key, recipients, dialog,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4434 limit = this.env.max_disclosed_recipients,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4435 input_to = $("[name='_to']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4436 input_cc = $("[name='_cc']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4437 input_bcc = $("[name='_bcc']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4438 input_from = $("[name='_from']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4439 input_subject = $("[name='_subject']"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4440 get_recipients = function(fields) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4441 fields = $.map(fields, function(v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4442 v = $.trim(v.val());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4443 return v.length ? v : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4444 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4445 return fields.join(',').replace(/^[\s,;]+/, '').replace(/[\s,;]+$/, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4446 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4447
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4448 // check sender (if have no identities)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4449 if (input_from.prop('type') == 'text' && !rcube_check_email(input_from.val(), true)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4450 alert(this.get_label('nosenderwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4451 input_from.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4452 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4453 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4454
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4455 // check for empty recipient
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4456 if (!rcube_check_email(get_recipients([input_to, input_cc, input_bcc]), true)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4457 alert(this.get_label('norecipientwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4458 input_to.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4459 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4460 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4461
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4462 // check if all files has been uploaded
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4463 for (key in this.env.attachments) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4464 if (typeof this.env.attachments[key] === 'object' && !this.env.attachments[key].complete) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4465 alert(this.get_label('notuploadedwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4466 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4467 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4468 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4469
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4470 // check disclosed recipients limit
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4471 if (limit && !this.env.disclosed_recipients_warned
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4472 && rcube_check_email(recipients = get_recipients([input_to, input_cc]), true, true) > limit
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4473 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4474 var save_func = function(move_to_bcc) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4475 if (move_to_bcc) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4476 var bcc = input_bcc.val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4477 input_bcc.val((bcc ? (bcc + ', ') : '') + recipients).change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4478 input_to.val('').change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4479 input_cc.val('').change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4480 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4481
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4482 dialog.dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4483 if (ref.check_compose_input(cmd))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4484 ref.command(cmd, { nocheck:true }); // repeat command which triggered this
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4485 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4486
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4487 dialog = this.show_popup_dialog(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4488 this.get_label('disclosedrecipwarning'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4489 this.get_label('disclosedreciptitle'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4490 [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4491 text: this.get_label('sendmessage'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4492 click: function() { save_func(false); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4493 'class': 'mainaction'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4494 }, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4495 text: this.get_label('bccinstead'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4496 click: function() { save_func(true); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4497 }, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4498 text: this.get_label('cancel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4499 click: function() { dialog.dialog('close'); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4500 }],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4501 {dialogClass: 'warning'}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4502 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4503
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4504 this.env.disclosed_recipients_warned = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4505 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4506 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4507
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4508 // display localized warning for missing subject
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4509 if (!this.env.nosubject_warned && input_subject.val() == '') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4510 var prompt_value = $('<input>').attr({type: 'text', size: 40}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4511 myprompt = $('<div class="prompt">')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4512 .append($('<div class="message">').text(this.get_label('nosubjectwarning')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4513 .append(prompt_value),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4514 save_func = function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4515 input_subject.val(prompt_value.val());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4516 dialog.dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4517 if (ref.check_compose_input(cmd))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4518 ref.command(cmd, { nocheck:true }); // repeat command which triggered this
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4519 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4521 dialog = this.show_popup_dialog(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4522 myprompt,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4523 this.get_label('nosubjecttitle'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4524 [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4525 text: this.get_label('sendmessage'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4526 click: function() { save_func(); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4527 'class': 'mainaction'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4528 }, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4529 text: this.get_label('cancel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4530 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4531 input_subject.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4532 dialog.dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4533 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4534 }],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4535 {dialogClass: 'warning'}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4536 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4537
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4538 prompt_value.select().keydown(function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4539 if (e.which == 13) save_func();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4540 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4541
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4542 this.env.nosubject_warned = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4543 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4544 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4545
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4546 // check for empty body (only possible if not mailvelope encrypted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4547 if (!this.mailvelope_editor && !this.editor.get_content() && !confirm(this.get_label('nobodywarning'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4548 this.editor.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4549 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4550 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4551
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4552 // move body from html editor to textarea (just to be sure, #1485860)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4553 this.editor.save();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4554
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4555 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4556 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4557
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4558 this.toggle_editor = function(props, obj, e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4559 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4560 // @todo: this should work also with many editors on page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4561 var result = this.editor.toggle(props.html, props.noconvert || false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4562
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4563 // satisfy the expectations of aftertoggle-editor event subscribers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4564 props.mode = props.html ? 'html' : 'plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4565
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4566 if (!result && e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4567 // fix selector value if operation failed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4568 props.mode = props.html ? 'plain' : 'html';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4569 $(e.target).filter('select').val(props.mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4570 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4571
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4572 if (result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4573 // update internal format flag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4574 $("input[name='_is_html']").val(props.html ? 1 : 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4575 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4576
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4577 return result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4578 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4579
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4580 // Inserts a predefined response to the compose editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4581 this.insert_response = function(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4582 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4583 return this.editor.replace(this.env.textresponses[key]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4584 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4585
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4586 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4587 * Open the dialog to save a new canned response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4588 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4589 this.save_response = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4590 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4591 // show dialog to enter a name and to modify the text to be saved
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4592 var buttons = {}, text = this.editor.get_content({selection: true, format: 'text', nosig: true}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4593 html = '<form class="propform">' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4594 '<div class="prop block"><label>' + this.get_label('responsename') + '</label>' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4595 '<input type="text" name="name" id="ffresponsename" size="40" /></div>' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4596 '<div class="prop block"><label>' + this.get_label('responsetext') + '</label>' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4597 '<textarea name="text" id="ffresponsetext" cols="40" rows="8"></textarea></div>' +
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4598 '</form>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4599
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4600 buttons[this.get_label('save')] = function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4601 var name = $('#ffresponsename').val(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4602 text = $('#ffresponsetext').val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4603
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4604 if (!text) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4605 $('#ffresponsetext').select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4606 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4607 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4608 if (!name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4609 name = text.replace(/[\r\n]+/g, ' ').substring(0,40);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4610
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4611 var lock = ref.display_message(ref.get_label('savingresponse'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4612 ref.http_post('settings/responses', { _insert:1, _name:name, _text:text }, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4613 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4614 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4615
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4616 buttons[this.get_label('cancel')] = function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4617 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4618 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4619
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4620 this.show_popup_dialog(html, this.get_label('newresponse'), buttons, {button_classes: ['mainaction']});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4621
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4622 $('#ffresponsetext').val(text);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4623 $('#ffresponsename').select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4624 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4625
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4626 this.add_response_item = function(response)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4627 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4628 var key = response.key;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4629 this.env.textresponses[key] = response;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4630
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4631 // append to responses list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4632 if (this.gui_objects.responseslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4633 var li = $('<li>').appendTo(this.gui_objects.responseslist);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4634 $('<a>').addClass('insertresponse active')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4635 .attr('href', '#')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4636 .attr('rel', key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4637 .attr('tabindex', '0')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4638 .html(this.quote_html(response.name))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4639 .appendTo(li)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4640 .mousedown(function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4641 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4642 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4643 .on('mouseup keypress', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4644 if (e.type == 'mouseup' || rcube_event.get_keycode(e) == 13) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4645 ref.command('insert-response', $(this).attr('rel'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4646 $(document.body).trigger('mouseup'); // hides the menu
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4647 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4648 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4649 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4650 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4651 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4652
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4653 this.edit_responses = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4654 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4655 // TODO: implement inline editing of responses
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4656 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4657
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4658 this.delete_response = function(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4659 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4660 if (!key && this.responses_list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4661 var selection = this.responses_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4662 key = selection[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4663 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4664
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4665 // submit delete request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4666 if (key && confirm(this.get_label('deleteresponseconfirm'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4667 this.http_post('settings/delete-response', { _key: key }, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4668 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4669 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4670
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4671 // updates spellchecker buttons on state change
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4672 this.spellcheck_state = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4673 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4674 var active = this.editor.spellcheck_state();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4676 $.each(this.buttons.spellcheck || [], function(i, v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4677 $('#' + v.id)[active ? 'addClass' : 'removeClass']('selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4678 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4679
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4680 return active;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4681 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4682
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4683 // get selected language
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4684 this.spellcheck_lang = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4685 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4686 return this.editor.get_language();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4687 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4688
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4689 this.spellcheck_lang_set = function(lang)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4690 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4691 this.editor.set_language(lang);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4692 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4693
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4694 // resume spellchecking, highlight provided mispellings without new ajax request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4695 this.spellcheck_resume = function(data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4696 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4697 this.editor.spellcheck_resume(data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4698 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4699
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4700 this.set_draft_id = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4701 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4702 if (id && id != this.env.draft_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4703 var filter = {task: 'mail', action: ''},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4704 rc = this.opener(false, filter) || this.opener(true, filter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4705
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4706 // refresh the drafts folder in the opener window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4707 if (rc && rc.env.mailbox == this.env.drafts_mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4708 rc.command('checkmail');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4709
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4710 this.env.draft_id = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4711 $("input[name='_draft_saveid']").val(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4712
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4713 // reset history of hidden iframe used for saving draft (#1489643)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4714 // but don't do this on timer-triggered draft-autosaving (#1489789)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4715 if (window.frames['savetarget'] && window.frames['savetarget'].history && !this.draft_autosave_submit && !this.mailvelope_editor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4716 window.frames['savetarget'].history.back();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4717 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4718
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4719 this.draft_autosave_submit = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4720 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4721
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4722 // always remove local copy upon saving as draft
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4723 this.remove_compose_data(this.env.compose_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4724 this.compose_skip_unsavedcheck = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4725 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4726
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4727 this.auto_save_start = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4728 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4729 if (this.env.draft_autosave) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4730 this.draft_autosave_submit = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4731 this.save_timer = setTimeout(function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4732 ref.draft_autosave_submit = true; // set auto-saved flag (#1489789)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4733 ref.command("savedraft");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4734 }, this.env.draft_autosave * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4735 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4736
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4737 // save compose form content to local storage every 5 seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4738 if (!this.local_save_timer && window.localStorage && this.env.save_localstorage) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4739 // track typing activity and only save on changes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4740 this.compose_type_activity = this.compose_type_activity_last = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4741 $(document).keypress(function(e) { ref.compose_type_activity++; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4742
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4743 this.local_save_timer = setInterval(function(){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4744 if (ref.compose_type_activity > ref.compose_type_activity_last) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4745 ref.save_compose_form_local();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4746 ref.compose_type_activity_last = ref.compose_type_activity;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4747 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4748 }, 5000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4749
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4750 $(window).on('unload', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4751 // remove copy from local storage if compose screen is left after warning
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4752 if (!ref.env.server_error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4753 ref.remove_compose_data(ref.env.compose_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4754 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4755 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4756
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4757 // check for unsaved changes before leaving the compose page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4758 if (!window.onbeforeunload) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4759 window.onbeforeunload = function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4760 if (!ref.compose_skip_unsavedcheck && ref.cmp_hash != ref.compose_field_hash()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4761 return ref.get_label('notsentwarning');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4762 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4763 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4764 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4765
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4766 // Unlock interface now that saving is complete
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4767 this.busy = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4768 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4770 this.compose_field_hash = function(save)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4771 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4772 // check input fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4773 var i, id, val, str = '', hash_fields = ['to', 'cc', 'bcc', 'subject'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4774
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4775 for (i=0; i<hash_fields.length; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4776 if (val = $('[name="_' + hash_fields[i] + '"]').val())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4777 str += val + ':';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4778
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4779 str += this.editor.get_content({refresh: false});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4780
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4781 if (this.env.attachments)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4782 for (id in this.env.attachments)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4783 str += id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4784
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4785 // we can't detect changes in the Mailvelope editor so assume it changed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4786 if (this.mailvelope_editor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4787 str += ';' + new Date().getTime();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4788 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4789
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4790 if (save)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4791 this.cmp_hash = str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4792
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4793 return str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4794 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4795
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4796 // store the contents of the compose form to localstorage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4797 this.save_compose_form_local = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4798 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4799 // feature is disabled
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4800 if (!this.env.save_localstorage)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4801 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4802
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4803 var formdata = { session:this.env.session_id, changed:new Date().getTime() },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4804 ed, empty = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4806 // get fresh content from editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4807 this.editor.save();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4809 if (this.env.draft_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4810 formdata.draft_id = this.env.draft_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4811 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4812 if (this.env.reply_msgid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4813 formdata.reply_msgid = this.env.reply_msgid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4814 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4815
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4816 $('input, select, textarea', this.gui_objects.messageform).each(function(i, elem) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4817 switch (elem.tagName.toLowerCase()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4818 case 'input':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4819 if (elem.type == 'button' || elem.type == 'submit' || (elem.type == 'hidden' && elem.name != '_is_html')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4820 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4821 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4822 formdata[elem.name] = elem.type != 'checkbox' || elem.checked ? $(elem).val() : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4823
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4824 if (formdata[elem.name] != '' && elem.type != 'hidden')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4825 empty = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4826 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4827
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4828 case 'select':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4829 formdata[elem.name] = $('option:checked', elem).val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4830 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4831
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4832 default:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4833 formdata[elem.name] = $(elem).val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4834 if (formdata[elem.name] != '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4835 empty = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4836 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4837 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4838
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4839 if (!empty) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4840 var index = this.local_storage_get_item('compose.index', []),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4841 key = this.env.compose_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4843 if ($.inArray(key, index) < 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4844 index.push(key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4845 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4846
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4847 this.local_storage_set_item('compose.' + key, formdata, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4848 this.local_storage_set_item('compose.index', index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4849 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4850 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4851
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4852 // write stored compose data back to form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4853 this.restore_compose_form = function(key, html_mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4854 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4855 var ed, formdata = this.local_storage_get_item('compose.' + key, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4856
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4857 if (formdata && typeof formdata == 'object') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4858 $.each(formdata, function(k, value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4859 if (k[0] == '_') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4860 var elem = $("*[name='"+k+"']");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4861 if (elem[0] && elem[0].type == 'checkbox') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4862 elem.prop('checked', value != '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4863 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4864 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4865 elem.val(value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4866 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4867 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4868 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4869
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4870 // initialize HTML editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4871 if ((formdata._is_html == '1' && !html_mode) || (formdata._is_html != '1' && html_mode)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4872 this.command('toggle-editor', {id: this.env.composebody, html: !html_mode, noconvert: true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4873 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4874 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4875 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4876
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4877 // remove stored compose data from localStorage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4878 this.remove_compose_data = function(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4879 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4880 var index = this.local_storage_get_item('compose.index', []);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4881
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4882 if ($.inArray(key, index) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4883 this.local_storage_remove_item('compose.' + key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4884 this.local_storage_set_item('compose.index', $.grep(index, function(val,i) { return val != key; }));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4885 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4886 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4887
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4888 // clear all stored compose data of this user
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4889 this.clear_compose_data = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4890 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4891 var i, index = this.local_storage_get_item('compose.index', []);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4892
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4893 for (i=0; i < index.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4894 this.local_storage_remove_item('compose.' + index[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4895 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4896
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4897 this.local_storage_remove_item('compose.index');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4898 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4899
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4900 this.change_identity = function(obj, show_sig)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4901 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4902 if (!obj || !obj.options)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4903 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4904
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4905 if (!show_sig)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4906 show_sig = this.env.show_sig;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4907
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4908 var id = obj.options[obj.selectedIndex].value,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4909 sig = this.env.identity,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4910 delim = this.env.recipients_separator,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4911 rx_delim = RegExp.escape(delim);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4912
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4913 // enable manual signature insert
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4914 if (this.env.signatures && this.env.signatures[id]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4915 this.enable_command('insert-sig', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4916 this.env.compose_commands.push('insert-sig');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4917 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4918 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4919 this.enable_command('insert-sig', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4920
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4921 // first function execution
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4922 if (!this.env.identities_initialized) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4923 this.env.identities_initialized = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4924 if (this.env.show_sig_later)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4925 this.env.show_sig = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4926 if (this.env.opened_extwin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4927 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4928 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4929
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4930 // update reply-to/bcc fields with addresses defined in identities
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4931 $.each(['replyto', 'bcc'], function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4932 var rx, key = this,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4933 old_val = sig && ref.env.identities[sig] ? ref.env.identities[sig][key] : '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4934 new_val = id && ref.env.identities[id] ? ref.env.identities[id][key] : '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4935 input = $('[name="_'+key+'"]'), input_val = input.val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4936
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4937 // remove old address(es)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4938 if (old_val && input_val) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4939 rx = new RegExp('\\s*' + RegExp.escape(old_val) + '\\s*');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4940 input_val = input_val.replace(rx, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4941 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4942
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4943 // cleanup
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4944 rx = new RegExp(rx_delim + '\\s*' + rx_delim, 'g');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4945 input_val = String(input_val).replace(rx, delim);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4946 rx = new RegExp('^[\\s' + rx_delim + ']+');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4947 input_val = input_val.replace(rx, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4948
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4949 // add new address(es)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4950 if (new_val && input_val.indexOf(new_val) == -1 && input_val.indexOf(new_val.replace(/"/g, '')) == -1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4951 if (input_val) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4952 rx = new RegExp('[' + rx_delim + '\\s]+$')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4953 input_val = input_val.replace(rx, '') + delim + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4954 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4955
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4956 input_val += new_val + delim + ' ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4957 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4958
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4959 if (old_val || new_val)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4960 input.val(input_val).change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4961 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4962
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4963 this.editor.change_signature(id, show_sig);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4964 this.env.identity = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4965 this.triggerEvent('change_identity');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4966 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4967 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4969 // Open file selection dialog for defined upload form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4970 // Works only on click and only with smart-upload forms
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4971 this.upload_input = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4972 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4973 $('#' + name + ' input[type="file"]').click();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4974 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4976 // upload (attachment) file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4977 this.upload_file = function(form, action, lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4978 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4979 if (!form)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4980 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4981
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4982 // count files and size on capable browser
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4983 var size = 0, numfiles = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4984
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4985 $.each($(form).get(0).elements || [], function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4986 if (this.type != 'file')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4987 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4988
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4989 var i, files = this.files ? this.files.length : (this.value ? 1 : 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4990
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4991 // check file size
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4992 if (this.files) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4993 for (i=0; i < files; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4994 size += this.files[i].size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4995 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4996
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4997 numfiles += files;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4998 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4999
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5000 // create hidden iframe and post upload form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5001 if (numfiles) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5002 if (this.env.max_filesize && this.env.filesizeerror && size > this.env.max_filesize) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5003 this.display_message(this.env.filesizeerror, 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5004 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5005 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5007 if (this.env.max_filecount && this.env.filecounterror && numfiles > this.env.max_filecount) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5008 this.display_message(this.env.filecounterror, 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5009 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5010 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5011
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5012 var frame_name = this.async_upload_form(form, action || 'upload', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5013 var d, content = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5014 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5015 if (this.contentDocument) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5016 d = this.contentDocument;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5017 } else if (this.contentWindow) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5018 d = this.contentWindow.document;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5019 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5020 content = d.childNodes[1].innerHTML;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5021 } catch (err) {}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5022
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5023 if (!content.match(/add2attachment/) && (!bw.opera || (ref.env.uploadframe && ref.env.uploadframe == e.data.ts))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5024 if (!content.match(/display_message/))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5025 ref.display_message(ref.get_label('fileuploaderror'), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5026 ref.remove_from_attachment_list(e.data.ts);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5027
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5028 if (lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5029 ref.set_busy(false, null, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5030 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5031 // Opera hack: handle double onload
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5032 if (bw.opera)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5033 ref.env.uploadframe = e.data.ts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5034 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5035
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5036 // display upload indicator and cancel button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5037 var content = '<span>' + this.get_label('uploading' + (numfiles > 1 ? 'many' : '')) + '</span>',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5038 ts = frame_name.replace(/^rcmupload/, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5039
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5040 this.add2attachment_list(ts, { name:'', html:content, classname:'uploading', frame:frame_name, complete:false });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5041
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5042 // upload progress support
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5043 if (this.env.upload_progress_time) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5044 this.upload_progress_start('upload', ts);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5045 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5046
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5047 // set reference to the form object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5048 this.gui_objects.attachmentform = form;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5049 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5050 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5051 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5052
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5053 // add file name to attachment list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5054 // called from upload page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5055 this.add2attachment_list = function(name, att, upload_id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5056 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5057 if (upload_id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5058 this.triggerEvent('fileuploaded', {name: name, attachment: att, id: upload_id});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5059
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5060 if (!this.env.attachments)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5061 this.env.attachments = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5062
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5063 if (upload_id && this.env.attachments[upload_id])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5064 delete this.env.attachments[upload_id];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5065
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5066 this.env.attachments[name] = att;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5067
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5068 if (!this.gui_objects.attachmentlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5069 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5071 if (!att.complete && this.env.loadingicon)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5072 att.html = '<img src="'+this.env.loadingicon+'" alt="" class="uploading" />' + att.html;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5073
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5074 if (!att.complete && att.frame)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5075 att.html = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+name+'\', \''+att.frame+'\');" href="#cancelupload" class="cancelupload">'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5076 + (this.env.cancelicon ? '<img src="'+this.env.cancelicon+'" alt="'+this.get_label('cancel')+'" />' : this.get_label('cancel')) + '</a>' + att.html;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5077
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5078 var indicator, li = $('<li>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5079
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5080 li.attr('id', name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5081 .addClass(att.classname)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5082 .html(att.html)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5083 .on('mouseover', function() { rcube_webmail.long_subject_title_ex(this); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5084
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5085 // replace indicator's li
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5086 if (upload_id && (indicator = document.getElementById(upload_id))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5087 li.replaceAll(indicator);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5088 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5089 else { // add new li
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5090 li.appendTo(this.gui_objects.attachmentlist);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5091 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5092
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5093 // set tabindex attribute
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5094 var tabindex = $(this.gui_objects.attachmentlist).attr('data-tabindex') || '0';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5095 li.find('a').attr('tabindex', tabindex);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5096
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5097 this.triggerEvent('fileappended', {name: name, attachment: att, id: upload_id, item: li});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5098
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5099 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5100 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5102 this.remove_from_attachment_list = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5103 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5104 if (this.env.attachments) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5105 delete this.env.attachments[name];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5106 $('#'+name).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5107 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5108 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5109
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5110 this.remove_attachment = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5111 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5112 if (name && this.env.attachments[name])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5113 this.http_post('remove-attachment', { _id:this.env.compose_id, _file:name });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5115 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5116 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5117
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5118 this.cancel_attachment_upload = function(name, frame_name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5119 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5120 if (!name || !frame_name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5121 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5122
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5123 this.remove_from_attachment_list(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5124 $("iframe[name='"+frame_name+"']").remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5125 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5126 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5127
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5128 this.upload_progress_start = function(action, name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5129 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5130 setTimeout(function() { ref.http_request(action, {_progress: name}); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5131 this.env.upload_progress_time * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5132 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5133
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5134 this.upload_progress_update = function(param)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5135 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5136 var elem = $('#'+param.name + ' > span');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5137
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5138 if (!elem.length || !param.text)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5139 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5140
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5141 elem.text(param.text);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5142
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5143 if (!param.done)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5144 this.upload_progress_start(param.action, param.name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5145 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5146
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5147 // rename uploaded attachment (in compose)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5148 this.rename_attachment = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5149 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5150 var attachment = this.env.attachments ? this.env.attachments[id] : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5151
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5152 if (!attachment)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5153 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5154
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5155 var input = $('<input>').attr({type: 'text', size: 50}).val(attachment.name),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5156 content = $('<label>').text(this.get_label('namex')).append(input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5157
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5158 this.simple_dialog(content, 'attachmentrename', function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5159 var name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5160 if ((name = input.val()) && name != attachment.name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5161 ref.http_post('rename-attachment', {_id: ref.env.compose_id, _file: id, _name: name},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5162 ref.set_busy(true, 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5163 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5164 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5165 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5166 {open: function() { input.select(); }}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5167 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5168 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5170 // update attachments list with the new name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5171 this.rename_attachment_handler = function(id, name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5172 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5173 var attachment = this.env.attachments ? this.env.attachments[id] : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5174 item = $('#' + id + ' > a.filename'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5175 link = $('<a>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5176
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5177 if (!attachment || !name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5178 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5179
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5180 attachment.name = name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5181
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5182 // update attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5183 if (item.length == 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5184 // create a new element with new attachment name and cloned size
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5185 link.text(name).append($('span', item).clone());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5186 // update attachment name element
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5187 item.html(link.html());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5188 // reset parent's title which may contain the old name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5189 item.parent().attr('title', '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5190 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5191 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5192
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5193 // send remote request to add a new contact
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5194 this.add_contact = function(value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5195 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5196 if (value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5197 this.http_post('addcontact', {_address: value});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5198
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5199 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5200 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5201
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5202 // send remote request to search mail or contacts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5203 this.qsearch = function(value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5204 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5205 // Note: Some plugins would like to do search without value,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5206 // so we keep value != '' check to allow that use-case. Which means
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5207 // e.g. that qsearch() with no argument will execute the search.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5208 if (value != '' || $(this.gui_objects.qsearchbox).val() || $(this.gui_objects.search_interval).val()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5209 var r, lock = this.set_busy(true, 'searching'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5210 url = this.search_params(value),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5211 action = this.env.action == 'compose' && this.contact_list ? 'search-contacts' : 'search';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5212
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5213 if (this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5214 this.clear_message_list();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5215 else if (this.contact_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5216 this.list_contacts_clear();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5217
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5218 if (this.env.source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5219 url._source = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5220 if (this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5221 url._gid = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5222
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5223 // reset vars
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5224 this.env.current_page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5225
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5226 r = this.http_request(action, url, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5227
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5228 this.env.qsearch = {lock: lock, request: r};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5229 this.enable_command('set-listmode', this.env.threads && (this.env.search_scope || 'base') == 'base');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5230
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5231 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5232 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5233
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5234 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5235 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5236
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5237 this.continue_search = function(request_id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5238 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5239 var lock = this.set_busy(true, 'stillsearching');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5240
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5241 setTimeout(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5242 var url = ref.search_params();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5243 url._continue = request_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5244 ref.env.qsearch = { lock: lock, request: ref.http_request('search', url, lock) };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5245 }, 100);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5246 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5247
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5248 // build URL params for search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5249 this.search_params = function(search, filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5250 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5251 var n, url = {}, mods_arr = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5252 mods = this.env.search_mods,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5253 scope = this.env.search_scope || 'base',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5254 mbox = scope == 'all' ? '*' : this.env.mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5255
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5256 if (!filter && this.gui_objects.search_filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5257 filter = this.gui_objects.search_filter.value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5258
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5259 if (!search && this.gui_objects.qsearchbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5260 search = this.gui_objects.qsearchbox.value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5261
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5262 if (filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5263 url._filter = filter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5265 if (this.gui_objects.search_interval)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5266 url._interval = $(this.gui_objects.search_interval).val();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5267
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5268 if (search) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5269 url._q = search;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5270
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5271 if (mods && this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5272 mods = mods[mbox] || mods['*'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5273
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5274 if (mods) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5275 for (n in mods)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5276 mods_arr.push(n);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5277 url._headers = mods_arr.join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5278 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5279 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5280
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5281 if (scope)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5282 url._scope = scope;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5283 if (mbox && scope != 'all')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5284 url._mbox = mbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5285
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5286 return url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5287 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5288
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5289 // reset search filter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5290 this.reset_search_filter = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5291 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5292 this.filter_disabled = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5293 if (this.gui_objects.search_filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5294 $(this.gui_objects.search_filter).val('ALL').change();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5295 this.filter_disabled = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5296 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5297
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5298 // reset quick-search form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5299 this.reset_qsearch = function(all)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5300 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5301 if (this.gui_objects.qsearchbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5302 this.gui_objects.qsearchbox.value = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5303
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5304 if (this.gui_objects.search_interval)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5305 $(this.gui_objects.search_interval).val('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5306
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5307 if (this.env.qsearch)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5308 this.abort_request(this.env.qsearch);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5309
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5310 if (all) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5311 this.env.search_scope = 'base';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5312 this.reset_search_filter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5313 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5314
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5315 this.env.qsearch = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5316 this.env.search_request = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5317 this.env.search_id = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5318 this.select_all_mode = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5319
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5320 this.enable_command('set-listmode', this.env.threads);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5321 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5322
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5323 this.set_searchscope = function(scope)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5324 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5325 var old = this.env.search_scope;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5326 this.env.search_scope = scope;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5327
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5328 // re-send search query with new scope
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5329 if (scope != old && this.env.search_request) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5330 if (!this.qsearch(this.gui_objects.qsearchbox.value) && this.env.search_filter && this.env.search_filter != 'ALL')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5331 this.filter_mailbox(this.env.search_filter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5332 if (scope != 'all')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5333 this.select_folder(this.env.mailbox, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5334 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5335 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5336
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5337 this.set_searchinterval = function(interval)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5338 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5339 var old = this.env.search_interval;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5340 this.env.search_interval = interval;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5342 // re-send search query with new interval
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5343 if (interval != old && this.env.search_request) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5344 if (!this.qsearch(this.gui_objects.qsearchbox.value) && this.env.search_filter && this.env.search_filter != 'ALL')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5345 this.filter_mailbox(this.env.search_filter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5346 if (interval)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5347 this.select_folder(this.env.mailbox, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5349 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5350
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5351 this.set_searchmods = function(mods)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5352 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5353 var mbox = this.env.mailbox,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5354 scope = this.env.search_scope || 'base';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5355
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5356 if (scope == 'all')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5357 mbox = '*';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5358
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5359 if (!this.env.search_mods)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5360 this.env.search_mods = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5361
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5362 if (mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5363 this.env.search_mods[mbox] = mods;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5364 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5365
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5366 this.is_multifolder_listing = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5367 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5368 return this.env.multifolder_listing !== undefined ? this.env.multifolder_listing :
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5369 (this.env.search_request && (this.env.search_scope || 'base') != 'base');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5370 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5372 // action executed after mail is sent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5373 this.sent_successfully = function(type, msg, folders, save_error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5374 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5375 this.display_message(msg, type);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5376 this.compose_skip_unsavedcheck = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5378 if (this.env.extwin) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5379 if (!save_error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5380 this.lock_form(this.gui_objects.messageform);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5381
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5382 var filter = {task: 'mail', action: ''},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5383 rc = this.opener(false, filter) || this.opener(true, filter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5384
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5385 if (rc) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5386 rc.display_message(msg, type);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5387 // refresh the folder where sent message was saved or replied message comes from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5388 if (folders && $.inArray(rc.env.mailbox, folders) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5389 rc.command('checkmail');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5390 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5391 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5392
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5393 if (!save_error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5394 setTimeout(function() { window.close(); }, 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5395 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5396 else if (!save_error) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5397 // before redirect we need to wait some time for Chrome (#1486177)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5398 setTimeout(function() { ref.list_mailbox(); }, 500);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5399 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5400
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5401 if (save_error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5402 this.env.is_sent = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5403 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5404
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5405
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5406 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5407 /********* keyboard live-search methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5408 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5409
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5410 // handler for keyboard events on address-fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5411 this.ksearch_keydown = function(e, obj, props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5412 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5413 if (this.ksearch_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5414 clearTimeout(this.ksearch_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5415
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5416 var key = rcube_event.get_keycode(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5417
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5418 switch (key) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5419 case 38: // arrow up
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5420 case 40: // arrow down
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5421 if (!this.ksearch_visible())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5422 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5423
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5424 var dir = key == 38 ? 1 : 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5425 highlight = document.getElementById('rcmkSearchItem' + this.ksearch_selected);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5426
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5427 if (!highlight)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5428 highlight = this.ksearch_pane.__ul.firstChild;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5429
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5430 if (highlight)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5431 this.ksearch_select(dir ? highlight.previousSibling : highlight.nextSibling);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5432
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5433 return rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5434
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5435 case 9: // tab
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5436 if (rcube_event.get_modifier(e) == SHIFT_KEY || !this.ksearch_visible()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5437 this.ksearch_hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5438 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5439 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5440
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5441 case 13: // enter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5442 if (!this.ksearch_visible())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5443 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5444
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5445 // insert selected address and hide ksearch pane
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5446 this.insert_recipient(this.ksearch_selected);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5447 this.ksearch_hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5448
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5449 // Don't cancel on Tab, we want to jump to the next field (#5659)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5450 return key == 9 ? null : rcube_event.cancel(e);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5451
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5452 case 27: // escape
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5453 this.ksearch_hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5454 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5455
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5456 case 37: // left
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5457 case 39: // right
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5458 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5459 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5461 // start timer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5462 this.ksearch_timer = setTimeout(function(){ ref.ksearch_get_results(props); }, 200);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5463 this.ksearch_input = obj;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5464
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5465 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5466 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5467
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5468 this.ksearch_visible = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5469 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5470 return this.ksearch_selected !== null && this.ksearch_selected !== undefined && this.ksearch_value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5471 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5472
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5473 this.ksearch_select = function(node)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5474 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5475 if (this.ksearch_pane && node) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5476 this.ksearch_pane.find('li.selected').removeClass('selected').removeAttr('aria-selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5477 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5478
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5479 if (node) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5480 $(node).addClass('selected').attr('aria-selected', 'true');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5481 this.ksearch_selected = node._rcm_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5482 $(this.ksearch_input).attr('aria-activedescendant', 'rcmkSearchItem' + this.ksearch_selected);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5483 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5484 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5485
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5486 this.insert_recipient = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5487 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5488 if (id === null || !this.env.contacts[id] || !this.ksearch_input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5489 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5490
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5491 // get cursor pos
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5492 var inp_value = this.ksearch_input.value,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5493 cpos = this.get_caret_pos(this.ksearch_input),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5494 p = inp_value.lastIndexOf(this.ksearch_value, cpos),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5495 trigger = false,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5496 insert = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5497 // replace search string with full address
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5498 pre = inp_value.substring(0, p),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5499 end = inp_value.substring(p+this.ksearch_value.length, inp_value.length);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5500
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5501 this.ksearch_destroy();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5502
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5503 // insert all members of a group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5504 if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].type == 'group' && !this.env.contacts[id].email) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5505 insert += this.env.contacts[id].name + this.env.recipients_delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5506 this.group2expand[this.env.contacts[id].id] = $.extend({ input: this.ksearch_input }, this.env.contacts[id]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5507 this.http_request('mail/group-expand', {_source: this.env.contacts[id].source, _gid: this.env.contacts[id].id}, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5508 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5509 else if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5510 insert = this.env.contacts[id].name + this.env.recipients_delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5511 trigger = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5513 else if (typeof this.env.contacts[id] === 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5514 insert = this.env.contacts[id] + this.env.recipients_delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5515 trigger = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5516 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5517
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5518 this.ksearch_input.value = pre + insert + end;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5519
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5520 // set caret to insert pos
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5521 this.set_caret_pos(this.ksearch_input, p + insert.length);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5522
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5523 if (trigger) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5524 this.triggerEvent('autocomplete_insert', { field:this.ksearch_input, insert:insert, data:this.env.contacts[id], search:this.ksearch_value_last, result_type:'person' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5525 this.ksearch_value_last = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5526 this.compose_type_activity++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5527 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5528 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5529
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5530 this.replace_group_recipients = function(id, recipients)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5531 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5532 if (this.group2expand[id]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5533 this.group2expand[id].input.value = this.group2expand[id].input.value.replace(this.group2expand[id].name, recipients);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5534 this.triggerEvent('autocomplete_insert', { field:this.group2expand[id].input, insert:recipients, data:this.group2expand[id], search:this.ksearch_value_last, result_type:'group' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5535 this.ksearch_value_last = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5536 this.group2expand[id] = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5537 this.compose_type_activity++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5538 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5539 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5540
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5541 // address search processor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5542 this.ksearch_get_results = function(props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5543 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5544 var inp_value = this.ksearch_input ? this.ksearch_input.value : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5545
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5546 if (inp_value === null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5547 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5548
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5549 if (this.ksearch_pane && this.ksearch_pane.is(":visible"))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5550 this.ksearch_pane.hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5551
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5552 // get string from current cursor pos to last comma
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5553 var cpos = this.get_caret_pos(this.ksearch_input),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5554 p = inp_value.lastIndexOf(this.env.recipients_separator, cpos-1),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5555 q = inp_value.substring(p+1, cpos),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5556 min = this.env.autocomplete_min_length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5557 data = this.ksearch_data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5558
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5559 // trim query string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5560 q = $.trim(q);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5561
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5562 // Don't (re-)search if the last results are still active
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5563 if (q == this.ksearch_value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5564 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5565
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5566 this.ksearch_destroy();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5567
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5568 if (q.length && q.length < min) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5569 if (!this.ksearch_info) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5570 this.ksearch_info = this.display_message(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5571 this.get_label('autocompletechars').replace('$min', min));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5572 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5573 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5574 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5575
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5576 var old_value = this.ksearch_value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5577 this.ksearch_value = q;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5578 this.ksearch_value_last = q; // Group expansion clears ksearch_value before calling autocomplete_insert trigger, therefore store it in separate variable for later consumption.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5579
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5580 // ...string is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5581 if (!q.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5582 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5584 // ...new search value contains old one and previous search was not finished or its result was empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5585 if (old_value && old_value.length && q.startsWith(old_value) && (!data || data.num <= 0) && this.env.contacts && !this.env.contacts.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5586 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5587
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5588 var sources = props && props.sources ? props.sources : [''];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5589 var reqid = this.multi_thread_http_request({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5590 items: sources,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5591 threads: props && props.threads ? props.threads : 1,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5592 action: props && props.action ? props.action : 'mail/autocomplete',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5593 postdata: { _search:q, _source:'%s' },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5594 lock: this.display_message(this.get_label('searching'), 'loading')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5595 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5596
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5597 this.ksearch_data = { id:reqid, sources:sources.slice(), num:sources.length };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5598 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5599
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5600 this.ksearch_query_results = function(results, search, reqid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5601 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5602 // trigger multi-thread http response callback
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5603 this.multi_thread_http_response(results, reqid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5604
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5605 // search stopped in meantime?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5606 if (!this.ksearch_value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5607 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5608
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5609 // ignore this outdated search response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5610 if (this.ksearch_input && search != this.ksearch_value)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5611 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5612
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5613 // display search results
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5614 var i, id, len, ul, text, type, init,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5615 value = this.ksearch_value,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5616 maxlen = this.env.autocomplete_max ? this.env.autocomplete_max : 15;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5617
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5618 // create results pane if not present
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5619 if (!this.ksearch_pane) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5620 ul = $('<ul>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5621 this.ksearch_pane = $('<div>').attr('id', 'rcmKSearchpane').attr('role', 'listbox')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5622 .css({ position:'absolute', 'z-index':30000 }).append(ul).appendTo(document.body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5623 this.ksearch_pane.__ul = ul[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5624 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5625
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5626 ul = this.ksearch_pane.__ul;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5627
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5628 // remove all search results or add to existing list if parallel search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5629 if (reqid && this.ksearch_pane.data('reqid') == reqid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5630 maxlen -= ul.childNodes.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5631 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5632 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5633 this.ksearch_pane.data('reqid', reqid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5634 init = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5635 // reset content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5636 ul.innerHTML = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5637 this.env.contacts = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5638 // move the results pane right under the input box
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5639 var pos = $(this.ksearch_input).offset();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5640 this.ksearch_pane.css({ left:pos.left+'px', top:(pos.top + this.ksearch_input.offsetHeight)+'px', display: 'none'});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5641 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5642
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5643 // add each result line to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5644 if (results && (len = results.length)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5645 for (i=0; i < len && maxlen > 0; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5646 text = typeof results[i] === 'object' ? (results[i].display || results[i].name) : results[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5647 type = typeof results[i] === 'object' ? results[i].type : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5648 id = i + this.env.contacts.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5649 $('<li>').attr('id', 'rcmkSearchItem' + id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5650 .attr('role', 'option')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5651 .html('<i class="icon"></i>' + this.quote_html(text.replace(new RegExp('('+RegExp.escape(value)+')', 'ig'), '##$1%%')).replace(/##([^%]+)%%/g, '<b>$1</b>'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5652 .addClass(type || '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5653 .appendTo(ul)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5654 .mouseover(function() { ref.ksearch_select(this); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5655 .mouseup(function() { ref.ksearch_click(this); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5656 .get(0)._rcm_id = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5657 maxlen -= 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5658 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5659 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5660
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5661 if (ul.childNodes.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5662 // set the right aria-* attributes to the input field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5663 $(this.ksearch_input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5664 .attr('aria-haspopup', 'true')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5665 .attr('aria-expanded', 'true')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5666 .attr('aria-owns', 'rcmKSearchpane');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5667
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5668 this.ksearch_pane.show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5669
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5670 // select the first
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5671 if (!this.env.contacts.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5672 this.ksearch_select($('li:first', ul).get(0));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5673 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5674 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5676 if (len)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5677 this.env.contacts = this.env.contacts.concat(results);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5678
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5679 if (this.ksearch_data.id == reqid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5680 this.ksearch_data.num--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5681 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5682
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5683 this.ksearch_click = function(node)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5684 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5685 if (this.ksearch_input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5686 this.ksearch_input.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5687
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5688 this.insert_recipient(node._rcm_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5689 this.ksearch_hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5690 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5691
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5692 this.ksearch_blur = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5693 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5694 if (this.ksearch_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5695 clearTimeout(this.ksearch_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5697 this.ksearch_input = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5698 this.ksearch_hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5699 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5700
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5701 this.ksearch_hide = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5702 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5703 this.ksearch_selected = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5704 this.ksearch_value = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5705
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5706 if (this.ksearch_pane)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5707 this.ksearch_pane.hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5708
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5709 $(this.ksearch_input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5710 .attr('aria-haspopup', 'false')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5711 .attr('aria-expanded', 'false')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5712 .removeAttr('aria-activedescendant')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5713 .removeAttr('aria-owns');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5714
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5715 this.ksearch_destroy();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5716 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5717
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5718 // Clears autocomplete data/requests
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5719 this.ksearch_destroy = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5720 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5721 if (this.ksearch_data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5722 this.multi_thread_request_abort(this.ksearch_data.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5723
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5724 if (this.ksearch_info)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5725 this.hide_message(this.ksearch_info);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5726
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5727 if (this.ksearch_msg)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5728 this.hide_message(this.ksearch_msg);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5729
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5730 this.ksearch_data = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5731 this.ksearch_info = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5732 this.ksearch_msg = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5733 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5734
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5735
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5736 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5737 /********* address book methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5738 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5739
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5740 this.contactlist_keypress = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5741 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5742 if (list.key_pressed == list.DELETE_KEY)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5743 this.command('delete');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5744 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5745
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5746 this.contactlist_select = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5747 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5748 if (this.preview_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5749 clearTimeout(this.preview_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5750
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5751 var n, id, sid, contact, writable = false,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5752 selected = list.selection.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5753 source = this.env.source ? this.env.address_sources[this.env.source] : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5754
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5755 // we don't have dblclick handler here, so use 50 instead of this.dblclick_time
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5756 if (this.env.contentframe && !list.multi_selecting && (id = list.get_single_selection()))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5757 this.preview_timer = setTimeout(function() { ref.load_contact(id, 'show'); }, this.preview_delay_click);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5758 else if (this.env.contentframe)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5759 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5760
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5761 if (selected) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5762 list.draggable = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5763
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5764 // no source = search result, we'll need to detect if any of
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5765 // selected contacts are in writable addressbook to enable edit/delete
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5766 // we'll also need to know sources used in selection for copy
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5767 // and group-addmember operations (drag&drop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5768 this.env.selection_sources = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5770 if (source) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5771 this.env.selection_sources.push(this.env.source);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5772 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5773
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5774 for (n in list.selection) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5775 contact = list.data[list.selection[n]];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5776 if (!source) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5777 sid = String(list.selection[n]).replace(/^[^-]+-/, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5778 if (sid && this.env.address_sources[sid]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5779 writable = writable || (!this.env.address_sources[sid].readonly && !contact.readonly);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5780 this.env.selection_sources.push(sid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5781 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5782 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5783 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5784 writable = writable || (!source.readonly && !contact.readonly);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5785 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5787 if (contact._type != 'group')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5788 list.draggable = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5789 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5790
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5791 this.env.selection_sources = $.unique(this.env.selection_sources);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5792 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5793
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5794 // if a group is currently selected, and there is at least one contact selected
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5795 // thend we can enable the group-remove-selected command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5796 this.enable_command('group-remove-selected', this.env.group && selected && writable);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5797 this.enable_command('compose', this.env.group || selected);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5798 this.enable_command('print', selected == 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5799 this.enable_command('export-selected', 'copy', selected > 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5800 this.enable_command('edit', id && writable);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5801 this.enable_command('delete', 'move', selected && writable);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5802
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5803 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5804 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5806 this.list_contacts = function(src, group, page, search)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5807 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5808 var win, folder, index = -1, url = {},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5809 refresh = src === undefined && group === undefined && page === undefined,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5810 target = window;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5811
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5812 if (!src)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5813 src = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5814
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5815 if (refresh)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5816 group = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5817
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5818 if (src != this.env.source) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5819 page = this.env.current_page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5820 this.reset_qsearch();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5821 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5822 else if (!refresh && group != this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5823 page = this.env.current_page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5824
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5825 if (this.env.search_id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5826 folder = 'S'+this.env.search_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5827 else if (!this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5828 folder = group ? 'G'+src+group : src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5829
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5830 this.env.source = src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5831 this.env.group = group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5832
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5833 // truncate groups listing stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5834 $.each(this.env.address_group_stack, function(i, v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5835 if (ref.env.group == v.id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5836 index = i;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5837 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5838 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5839 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5840
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5841 this.env.address_group_stack = index < 0 ? [] : this.env.address_group_stack.slice(0, index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5843 // make sure the current group is on top of the stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5844 if (this.env.group) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5845 if (!search) search = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5846 search.id = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5847 this.env.address_group_stack.push(search);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5848
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5849 // mark the first group on the stack as selected in the directory list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5850 folder = 'G'+src+this.env.address_group_stack[0].id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5851 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5852 else if (this.gui_objects.addresslist_title) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5853 $(this.gui_objects.addresslist_title).text(this.get_label('contacts'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5854 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5855
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5856 if (!this.env.search_id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5857 this.select_folder(folder, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5858
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5859 // load contacts remotely
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5860 if (this.gui_objects.contactslist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5861 this.list_contacts_remote(src, group, page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5862 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5863 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5864
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5865 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5866 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5867 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5868 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5869
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5870 if (group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5871 url._gid = group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5872 if (page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5873 url._page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5874 if (src)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5875 url._source = src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5876
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5877 // also send search request to get the correct listing
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5878 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5879 url._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5880
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5881 this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5882 this.location_href(url, target);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5883 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5884
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5885 // send remote request to load contacts list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5886 this.list_contacts_remote = function(src, group, page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5887 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5888 // clear message list first
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5889 this.list_contacts_clear();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5891 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5892 var url = {}, lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5893
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5894 if (src)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5895 url._source = src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5896 if (page)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5897 url._page = page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5898 if (group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5899 url._gid = group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5900
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5901 this.env.source = src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5902 this.env.group = group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5903
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5904 // also send search request to get the right records
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5905 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5906 url._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5907
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5908 this.http_request(this.env.task == 'mail' ? 'list-contacts' : 'list', url, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5909
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5910 if (this.env.task != 'mail')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5911 this.update_state({_source: src, _page: page && page > 1 ? page : null, _gid: group});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5912 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5913
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5914 this.list_contacts_clear = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5915 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5916 this.contact_list.data = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5917 this.contact_list.clear(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5918 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5919 this.enable_command('delete', 'move', 'copy', 'print', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5920 this.enable_command('compose', this.env.group);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5921 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5922
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5923 this.set_group_prop = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5924 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5925 if (this.gui_objects.addresslist_title) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5926 var boxtitle = $(this.gui_objects.addresslist_title).html(''); // clear contents
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5927
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5928 // add link to pop back to parent group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5929 if (this.env.address_group_stack.length > 1
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5930 || (this.env.address_group_stack.length == 1 && this.env.address_group_stack[0].search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5931 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5932 $('<a href="#list">...</a>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5933 .attr('title', this.get_label('uponelevel'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5934 .addClass('poplink')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5935 .appendTo(boxtitle)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5936 .click(function(e){ return ref.command('popgroup','',this); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5937 boxtitle.append('&nbsp;&raquo;&nbsp;');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5938 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5939
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5940 boxtitle.append($('<span>').text(prop ? prop.name : this.get_label('contacts')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5941 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5942 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5943
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5944 // load contact record
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5945 this.load_contact = function(cid, action, framed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5946 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5947 var win, url = {}, target = window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5948 rec = this.contact_list ? this.contact_list.data[cid] : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5949
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5950 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5951 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5952 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5953 this.show_contentframe(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5954
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5955 // load dummy content, unselect selected row(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5956 if (!cid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5957 this.contact_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5958
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5959 this.enable_command('compose', rec && rec.email);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5960 this.enable_command('export-selected', 'print', rec && rec._type != 'group');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5961 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5962 else if (framed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5963 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5964
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5965 if (action && (cid || action == 'add') && !this.drag_active) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5966 if (this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5967 url._gid = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5969 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5970 url._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5971
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5972 url._action = action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5973 url._source = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5974 url._cid = cid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5976 this.location_href(url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5977 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5978
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5979 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5980 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5981
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5982 // add/delete member to/from the group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5983 this.group_member_change = function(what, cid, source, gid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5984 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5985 if (what != 'add')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5986 what = 'del';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5987
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5988 var label = this.get_label(what == 'add' ? 'addingmember' : 'removingmember'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5989 lock = this.display_message(label, 'loading'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5990 post_data = {_cid: cid, _source: source, _gid: gid};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5992 this.http_post('group-'+what+'members', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5993 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5994
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5995 this.contacts_drag_menu = function(e, to)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5996 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5997 var dest = to.type == 'group' ? to.source : to.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5998 source = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5999
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6000 if (!this.env.address_sources[dest] || this.env.address_sources[dest].readonly)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6001 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6002
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6003 // search result may contain contacts from many sources, but if there is only one...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6004 if (source == '' && this.env.selection_sources.length == 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6005 source = this.env.selection_sources[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6007 if (to.type == 'group' && dest == source) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6008 var cid = this.contact_list.get_selection().join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6009 this.group_member_change('add', cid, dest, to.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6010 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6011 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6012 // move action is not possible, "redirect" to copy if menu wasn't requested
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6013 else if (!this.commands.move && rcube_event.get_modifier(e) != SHIFT_KEY) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6014 this.copy_contacts(to);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6015 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6016 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6017
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6018 return this.drag_menu(e, to);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6019 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6020
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6021 // copy contact(s) to the specified target (group or directory)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6022 this.copy_contacts = function(to)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6023 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6024 var dest = to.type == 'group' ? to.source : to.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6025 source = this.env.source,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6026 group = this.env.group ? this.env.group : '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6027 cid = this.contact_list.get_selection().join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6028
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6029 if (!cid || !this.env.address_sources[dest] || this.env.address_sources[dest].readonly)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6030 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6031
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6032 // search result may contain contacts from many sources, but if there is only one...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6033 if (source == '' && this.env.selection_sources.length == 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6034 source = this.env.selection_sources[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6035
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6036 // tagret is a group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6037 if (to.type == 'group') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6038 if (dest == source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6039 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6041 var lock = this.display_message(this.get_label('copyingcontact'), 'loading'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6042 post_data = {_cid: cid, _source: this.env.source, _to: dest, _togid: to.id, _gid: group};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6043
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6044 this.http_post('copy', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6045 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6046 // target is an addressbook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6047 else if (to.id != source) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6048 var lock = this.display_message(this.get_label('copyingcontact'), 'loading'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6049 post_data = {_cid: cid, _source: this.env.source, _to: to.id, _gid: group};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6050
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6051 this.http_post('copy', post_data, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6052 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6053 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6054
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6055 // move contact(s) to the specified target (group or directory)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6056 this.move_contacts = function(to)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6057 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6058 var dest = to.type == 'group' ? to.source : to.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6059 source = this.env.source,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6060 group = this.env.group ? this.env.group : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6061
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6062 if (!this.env.address_sources[dest] || this.env.address_sources[dest].readonly)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6063 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6064
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6065 // search result may contain contacts from many sources, but if there is only one...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6066 if (source == '' && this.env.selection_sources.length == 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6067 source = this.env.selection_sources[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6068
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6069 if (to.type == 'group') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6070 if (dest == source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6071 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6072
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6073 this._with_selected_contacts('move', {_to: dest, _togid: to.id});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6074 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6075 // target is an addressbook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6076 else if (to.id != source)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6077 this._with_selected_contacts('move', {_to: to.id});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6078 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6079
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6080 // delete contact(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6081 this.delete_contacts = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6082 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6083 var undelete = this.env.source && this.env.address_sources[this.env.source].undelete;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6084
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6085 if (!undelete && !confirm(this.get_label('deletecontactconfirm')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6086 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6088 return this._with_selected_contacts('delete');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6089 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6090
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6091 this._with_selected_contacts = function(action, post_data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6092 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6093 var selection = this.contact_list ? this.contact_list.get_selection() : [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6094
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6095 // exit if no contact specified or if selection is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6096 if (!selection.length && !this.env.cid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6097 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6098
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6099 var n, a_cids = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6100 label = action == 'delete' ? 'contactdeleting' : 'movingcontact',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6101 lock = this.display_message(this.get_label(label), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6102
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6103 if (this.env.cid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6104 a_cids.push(this.env.cid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6105 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6106 for (n=0; n<selection.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6107 id = selection[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6108 a_cids.push(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6109 this.contact_list.remove_row(id, (n == selection.length-1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6110 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6112 // hide content frame if we delete the currently displayed contact
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6113 if (selection.length == 1)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6114 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6115 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6116
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6117 if (!post_data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6118 post_data = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6119
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6120 post_data._source = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6121 post_data._from = this.env.action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6122 post_data._cid = a_cids.join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6123
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6124 if (this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6125 post_data._gid = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6127 // also send search request to get the right records from the next page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6128 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6129 post_data._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6130
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6131 // send request to server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6132 this.http_post(action, post_data, lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6133
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6134 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6135 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6136
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6137 // update a contact record in the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6138 this.update_contact_row = function(cid, cols_arr, newcid, source, data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6139 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6140 var list = this.contact_list;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6141
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6142 cid = this.html_identifier(cid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6143
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6144 // when in searching mode, concat cid with the source name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6145 if (!list.rows[cid]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6146 cid = cid + '-' + source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6147 if (newcid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6148 newcid = newcid + '-' + source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6149 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6150
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6151 list.update_row(cid, cols_arr, newcid, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6152 list.data[cid] = data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6153 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6154
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6155 // add row to contacts list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6156 this.add_contact_row = function(cid, cols, classes, data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6157 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6158 if (!this.gui_objects.contactslist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6159 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6161 var c, col, list = this.contact_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6162 row = { cols:[] };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6163
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6164 row.id = 'rcmrow' + this.html_identifier(cid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6165 row.className = 'contact ' + (classes || '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6167 if (list.in_selection(cid))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6168 row.className += ' selected';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6170 // add each submitted col
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6171 for (c in cols) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6172 col = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6173 col.className = String(c).toLowerCase();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6174 col.innerHTML = cols[c];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6175 row.cols.push(col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6176 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6178 // store data in list member
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6179 list.data[cid] = data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6180 list.insert_row(row);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6181
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6182 this.enable_command('export', list.rowcount > 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6183 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6185 this.init_contact_form = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6186 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6187 var col;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6188
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6189 if (this.env.coltypes) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6190 this.set_photo_actions($('#ff_photo').val());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6191 for (col in this.env.coltypes)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6192 this.init_edit_field(col, null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6193 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6195 $('.contactfieldgroup .row a.deletebutton').click(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6196 ref.delete_edit_field(this);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6197 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6198 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6199
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6200 $('select.addfieldmenu').change(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6201 ref.insert_edit_field($(this).val(), $(this).attr('rel'), this);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6202 this.selectedIndex = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6203 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6205 // enable date pickers on date fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6206 if ($.datepicker && this.env.date_format) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6207 $.datepicker.setDefaults({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6208 dateFormat: this.env.date_format,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6209 changeMonth: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6210 changeYear: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6211 yearRange: '-120:+10',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6212 showOtherMonths: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6213 selectOtherMonths: true
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6214 // onSelect: function(dateText) { $(this).focus().val(dateText); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6215 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6216 $('input.datepicker').datepicker();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6217 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6218
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6219 // Submit search form on Enter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6220 if (this.env.action == 'search')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6221 $(this.gui_objects.editform).append($('<input type="submit">').hide())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6222 .submit(function() { $('input.mainaction').click(); return false; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6223 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6224
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6225 // group creation dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6226 this.group_create = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6227 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6228 var input = $('<input>').attr('type', 'text'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6229 content = $('<label>').text(this.get_label('namex')).append(input),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6230 source = this.env.source;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6231
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6232 this.simple_dialog(content, 'newgroup',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6233 function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6234 var name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6235 if (name = input.val()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6236 ref.http_post('group-create', {_source: source, _name: name},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6237 ref.set_busy(true, 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6238 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6239 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6240 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6241 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6243 // group rename dialog
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6244 this.group_rename = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6245 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6246 if (!this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6247 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6248
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6249 var group_name = this.env.contactgroups['G' + this.env.source + this.env.group].name,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6250 input = $('<input>').attr('type', 'text').val(group_name),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6251 content = $('<label>').text(this.get_label('namex')).append(input),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6252 source = this.env.source,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6253 group = this.env.group;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6254
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6255 this.simple_dialog(content, 'grouprename',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6256 function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6257 var name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6258 if ((name = input.val()) && name != group_name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6259 ref.http_post('group-rename', {_source: source, _gid: group, _name: name},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6260 ref.set_busy(true, 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6261 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6262 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6263 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6264 {open: function() { input.select(); }}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6265 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6266 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6267
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6268 this.group_delete = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6269 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6270 if (this.env.group && confirm(this.get_label('deletegroupconfirm'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6271 var lock = this.set_busy(true, 'groupdeleting');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6272 this.http_post('group-delete', {_source: this.env.source, _gid: this.env.group}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6273 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6274 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6275
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6276 // callback from server upon group-delete command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6277 this.remove_group_item = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6278 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6279 var key = 'G'+prop.source+prop.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6280
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6281 if (this.treelist.remove(key)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6282 this.triggerEvent('group_delete', { source:prop.source, id:prop.id });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6283 delete this.env.contactfolders[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6284 delete this.env.contactgroups[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6285 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6286
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6287 if (prop.source == this.env.source && prop.id == this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6288 this.list_contacts(prop.source, 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6289 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6291 //remove selected contacts from current active group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6292 this.group_remove_selected = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6293 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6294 this.http_post('group-delmembers', {_cid: this.contact_list.selection,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6295 _source: this.env.source, _gid: this.env.group});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6296 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6297
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6298 //callback after deleting contact(s) from current group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6299 this.remove_group_contacts = function(props)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6300 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6301 if (this.env.group !== undefined && (this.env.group === props.gid)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6302 var n, selection = this.contact_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6303 for (n=0; n<selection.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6304 id = selection[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6305 this.contact_list.remove_row(id, (n == selection.length-1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6306 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6307 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6308 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6309
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6310 // callback for creating a new contact group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6311 this.insert_contact_group = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6312 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6313 prop.type = 'group';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6314
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6315 var key = 'G'+prop.source+prop.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6316 link = $('<a>').attr('href', '#')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6317 .attr('rel', prop.source+':'+prop.id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6318 .click(function() { return ref.command('listgroup', prop, this); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6319 .html(prop.name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6320
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6321 this.env.contactfolders[key] = this.env.contactgroups[key] = prop;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6322 this.treelist.insert({ id:key, html:link, classes:['contactgroup'] }, prop.source, 'contactgroup');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6323
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6324 this.triggerEvent('group_insert', { id:prop.id, source:prop.source, name:prop.name, li:this.treelist.get_item(key) });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6325 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6326
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6327 // callback for renaming a contact group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6328 this.update_contact_group = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6329 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6330 var key = 'G'+prop.source+prop.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6331 newnode = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6333 // group ID has changed, replace link node and identifiers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6334 if (prop.newid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6335 var newkey = 'G'+prop.source+prop.newid,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6336 newprop = $.extend({}, prop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6338 this.env.contactfolders[newkey] = this.env.contactfolders[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6339 this.env.contactfolders[newkey].id = prop.newid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6340 this.env.group = prop.newid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6342 delete this.env.contactfolders[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6343 delete this.env.contactgroups[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6344
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6345 newprop.id = prop.newid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6346 newprop.type = 'group';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6347
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6348 newnode.id = newkey;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6349 newnode.html = $('<a>').attr('href', '#')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6350 .attr('rel', prop.source+':'+prop.newid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6351 .click(function() { return ref.command('listgroup', newprop, this); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6352 .html(prop.name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6353 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6354 // update displayed group name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6355 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6356 $(this.treelist.get_item(key)).children().first().html(prop.name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6357 this.env.contactfolders[key].name = this.env.contactgroups[key].name = prop.name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6358
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6359 if (prop.source == this.env.source && prop.id == this.env.group)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6360 this.set_group_prop(prop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6361 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6362
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6363 // update list node and re-sort it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6364 this.treelist.update(key, newnode, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6365
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6366 this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:this.treelist.get_item(key), newid:prop.newid });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6367 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6368
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6369 this.update_group_commands = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6370 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6371 var source = this.env.source != '' ? this.env.address_sources[this.env.source] : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6372 supported = source && source.groups && !source.readonly;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6373
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6374 this.enable_command('group-create', supported);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6375 this.enable_command('group-rename', 'group-delete', supported && this.env.group);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6376 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6378 this.init_edit_field = function(col, elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6379 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6380 var label = this.env.coltypes[col].label;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6381
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6382 if (!elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6383 elem = $('.ff_' + col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6384
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6385 if (label)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6386 elem.placeholder(label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6387 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6388
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6389 this.insert_edit_field = function(col, section, menu)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6390 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6391 // just make pre-defined input field visible
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6392 var elem = $('#ff_'+col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6393 if (elem.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6394 elem.show().focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6395 $(menu).children('option[value="'+col+'"]').prop('disabled', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6396 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6397 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6398 var lastelem = $('.ff_'+col),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6399 appendcontainer = $('#contactsection'+section+' .contactcontroller'+col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6400
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6401 if (!appendcontainer.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6402 var sect = $('#contactsection'+section),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6403 lastgroup = $('.contactfieldgroup', sect).last();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6404 appendcontainer = $('<fieldset>').addClass('contactfieldgroup contactcontroller'+col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6405 if (lastgroup.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6406 appendcontainer.insertAfter(lastgroup);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6407 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6408 sect.prepend(appendcontainer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6409 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6410
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6411 if (appendcontainer.length && appendcontainer.get(0).nodeName == 'FIELDSET') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6412 var input, colprop = this.env.coltypes[col],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6413 input_id = 'ff_' + col + (colprop.count || 0),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6414 row = $('<div>').addClass('row'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6415 cell = $('<div>').addClass('contactfieldcontent data'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6416 label = $('<div>').addClass('contactfieldlabel label');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6417
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6418 if (colprop.subtypes_select)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6419 label.html(colprop.subtypes_select);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6420 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6421 label.html('<label for="' + input_id + '">' + colprop.label + '</label>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6422
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6423 var name_suffix = colprop.limit != 1 ? '[]' : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6424
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6425 if (colprop.type == 'text' || colprop.type == 'date') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6426 input = $('<input>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6427 .addClass('ff_'+col)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6428 .attr({type: 'text', name: '_'+col+name_suffix, size: colprop.size, id: input_id})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6429 .appendTo(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6430
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6431 this.init_edit_field(col, input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6432
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6433 if (colprop.type == 'date' && $.datepicker)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6434 input.datepicker();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6435 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6436 else if (colprop.type == 'textarea') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6437 input = $('<textarea>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6438 .addClass('ff_'+col)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6439 .attr({ name: '_'+col+name_suffix, cols:colprop.size, rows:colprop.rows, id: input_id })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6440 .appendTo(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6441
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6442 this.init_edit_field(col, input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6443 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6444 else if (colprop.type == 'composite') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6445 var i, childcol, cp, first, templ, cols = [], suffices = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6446
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6447 // read template for composite field order
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6448 if ((templ = this.env[col+'_template'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6449 for (i=0; i < templ.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6450 cols.push(templ[i][1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6451 suffices.push(templ[i][2]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6452 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6453 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6454 else { // list fields according to appearance in colprop
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6455 for (childcol in colprop.childs)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6456 cols.push(childcol);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6457 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6458
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6459 for (i=0; i < cols.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6460 childcol = cols[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6461 cp = colprop.childs[childcol];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6462 input = $('<input>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6463 .addClass('ff_'+childcol)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6464 .attr({ type: 'text', name: '_'+childcol+name_suffix, size: cp.size })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6465 .appendTo(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6466 cell.append(suffices[i] || " ");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6467 this.init_edit_field(childcol, input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6468 if (!first) first = input;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6469 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6470 input = first; // set focus to the first of this composite fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6471 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6472 else if (colprop.type == 'select') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6473 input = $('<select>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6474 .addClass('ff_'+col)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6475 .attr({ 'name': '_'+col+name_suffix, id: input_id })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6476 .appendTo(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6477
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6478 var options = input.attr('options');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6479 options[options.length] = new Option('---', '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6480 if (colprop.options)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6481 $.each(colprop.options, function(i, val){ options[options.length] = new Option(val, i); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6482 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6483
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6484 if (input) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6485 var delbutton = $('<a href="#del"></a>')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6486 .addClass('contactfieldbutton deletebutton')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6487 .attr({title: this.get_label('delete'), rel: col})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6488 .html(this.env.delbutton)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6489 .click(function(){ ref.delete_edit_field(this); return false })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6490 .appendTo(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6491
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6492 row.append(label).append(cell).appendTo(appendcontainer.show());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6493 input.first().focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6494
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6495 // disable option if limit reached
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6496 if (!colprop.count) colprop.count = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6497 if (++colprop.count == colprop.limit && colprop.limit)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6498 $(menu).children('option[value="'+col+'"]').prop('disabled', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6499 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6500 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6501 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6502 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6503
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6504 this.delete_edit_field = function(elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6505 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6506 var col = $(elem).attr('rel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6507 colprop = this.env.coltypes[col],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6508 fieldset = $(elem).parents('fieldset.contactfieldgroup'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6509 addmenu = fieldset.parent().find('select.addfieldmenu');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6510
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6511 // just clear input but don't hide the last field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6512 if (--colprop.count <= 0 && colprop.visible)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6513 $(elem).parent().children('input').val('').blur();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6514 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6515 $(elem).parents('div.row').remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6516 // hide entire fieldset if no more rows
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6517 if (!fieldset.children('div.row').length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6518 fieldset.hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6519 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6521 // enable option in add-field selector or insert it if necessary
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6522 if (addmenu.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6523 var option = addmenu.children('option[value="'+col+'"]');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6524 if (option.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6525 option.prop('disabled', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6526 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6527 option = $('<option>').attr('value', col).html(colprop.label).appendTo(addmenu);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6528 addmenu.show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6529 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6530 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6531
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6532 this.upload_contact_photo = function(form)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6533 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6534 if (form && form.elements._photo.value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6535 this.async_upload_form(form, 'upload-photo', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6536 ref.set_busy(false, null, ref.file_upload_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6537 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6538
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6539 // display upload indicator
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6540 this.file_upload_id = this.set_busy(true, 'uploading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6542 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6543
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6544 this.replace_contact_photo = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6545 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6546 var img_src = id == '-del-' ? this.env.photo_placeholder :
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6547 this.env.comm_path + '&_action=photo&_source=' + this.env.source + '&_cid=' + (this.env.cid || 0) + '&_photo=' + id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6548
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6549 this.set_photo_actions(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6550 $(this.gui_objects.contactphoto).children('img').attr('src', img_src);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6551 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6552
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6553 this.photo_upload_end = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6554 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6555 this.set_busy(false, null, this.file_upload_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6556 delete this.file_upload_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6557 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6558
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6559 this.set_photo_actions = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6560 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6561 var n, buttons = this.buttons['upload-photo'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6562 for (n=0; buttons && n < buttons.length; n++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6563 $('a#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6564
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6565 $('#ff_photo').val(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6566 this.enable_command('upload-photo', this.env.coltypes.photo ? true : false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6567 this.enable_command('delete-photo', this.env.coltypes.photo && id != '-del-');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6568 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6569
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6570 // load advanced search page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6571 this.advanced_search = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6572 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6573 var win, url = {_form: 1, _action: 'search'}, target = window;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6574
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6575 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6576 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6577 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6578 this.contact_list.clear_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6579 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6580
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6581 this.location_href(url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6582
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6583 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6584 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6585
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6586 // unselect directory/group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6587 this.unselect_directory = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6588 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6589 this.select_folder('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6590 this.enable_command('search-delete', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6591 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6592
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6593 // callback for creating a new saved search record
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6594 this.insert_saved_search = function(name, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6595 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6596 var key = 'S'+id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6597 link = $('<a>').attr('href', '#')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6598 .attr('rel', id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6599 .click(function() { return ref.command('listsearch', id, this); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6600 .html(name),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6601 prop = { name:name, id:id };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6602
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6603 this.savedsearchlist.insert({ id:key, html:link, classes:['contactsearch'] }, null, 'contactsearch');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6604 this.select_folder(key,'',true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6605 this.enable_command('search-delete', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6606 this.env.search_id = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6607
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6608 this.triggerEvent('abook_search_insert', prop);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6609 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6610
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6611 // creates a dialog for saved search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6612 this.search_create = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6613 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6614 var input = $('<input>').attr('type', 'text'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6615 content = $('<label>').text(this.get_label('namex')).append(input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6616
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6617 this.simple_dialog(content, 'searchsave',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6618 function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6619 var name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6620 if (name = input.val()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6621 ref.http_post('search-create', {_search: ref.env.search_request, _name: name},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6622 ref.set_busy(true, 'loading'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6623 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6624 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6625 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6626 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6627 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6628
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6629 this.search_delete = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6630 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6631 if (this.env.search_request) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6632 var lock = this.set_busy(true, 'savedsearchdeleting');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6633 this.http_post('search-delete', {_sid: this.env.search_id}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6634 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6635 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6636
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6637 // callback from server upon search-delete command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6638 this.remove_search_item = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6639 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6640 var li, key = 'S'+id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6641 if (this.savedsearchlist.remove(key)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6642 this.triggerEvent('search_delete', { id:id, li:li });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6643 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6644
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6645 this.env.search_id = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6646 this.env.search_request = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6647 this.list_contacts_clear();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6648 this.reset_qsearch();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6649 this.enable_command('search-delete', 'search-create', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6650 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6651
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6652 this.listsearch = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6653 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6654 var lock = this.set_busy(true, 'searching');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6655
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6656 if (this.contact_list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6657 this.list_contacts_clear();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6658 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6659
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6660 this.reset_qsearch();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6661
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6662 if (this.savedsearchlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6663 this.treelist.select('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6664 this.savedsearchlist.select('S'+id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6665 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6666 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6667 this.select_folder('S'+id, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6668
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6669 // reset vars
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6670 this.env.current_page = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6671 this.http_request('search', {_sid: id}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6672 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6673
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6674 // display a dialog with QR code image
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6675 this.qrcode = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6676 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6677 var title = this.get_label('qrcode'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6678 buttons = [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6679 text: this.get_label('close'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6680 'class': 'mainaction',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6681 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6682 (ref.is_framed() ? parent.$ : $)(this).dialog('destroy');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6683 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6684 }],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6685 img = new Image(300, 300);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6686
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6687 img.src = this.url('addressbook/qrcode', {_source: this.env.source, _cid: this.env.cid});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6688
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6689 return this.show_popup_dialog(img, title, buttons, {width: 310, height: 410});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6690 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6691
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6692
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6693 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6694 /********* user settings methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6695 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6697 // preferences section select and load options frame
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6698 this.section_select = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6699 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6700 var win, id = list.get_single_selection(), target = window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6701 url = {_action: 'edit-prefs', _section: id};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6702
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6703 if (id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6704 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6705 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6706 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6707 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6708 this.location_href(url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6709 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6710
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6711 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6712 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6713
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6714 this.identity_select = function(list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6715 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6716 var id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6717 if (id = list.get_single_selection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6718 this.enable_command('delete', list.rowcount > 1 && this.env.identities_level < 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6719 this.load_identity(id, 'edit-identity');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6720 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6721 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6722
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6723 // load identity record
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6724 this.load_identity = function(id, action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6725 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6726 if (action == 'edit-identity' && (!id || id == this.env.iid))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6727 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6728
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6729 var win, target = window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6730 url = {_action: action, _iid: id};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6731
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6732 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6733 url._framed = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6734 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6735 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6736
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6737 if (id || action == 'add-identity') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6738 this.location_href(url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6739 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6740
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6741 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6742 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6743
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6744 this.delete_identity = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6745 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6746 // exit if no identity is specified or if selection is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6747 var selection = this.identity_list.get_selection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6748 if (!(selection.length || this.env.iid))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6749 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6750
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6751 if (!id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6752 id = this.env.iid ? this.env.iid : selection[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6753
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6754 // submit request with appended token
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6755 if (id && confirm(this.get_label('deleteidentityconfirm')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6756 this.http_post('settings/delete-identity', { _iid: id }, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6757 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6758
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6759 this.update_identity_row = function(id, name, add)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6760 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6761 var list = this.identity_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6762 rid = this.html_identifier(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6763
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6764 if (add) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6765 list.insert_row({ id:'rcmrow'+rid, cols:[ { className:'mail', innerHTML:name } ] });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6766 list.select(rid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6767 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6768 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6769 list.update_row(rid, [ name ]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6770 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6771 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6772
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6773 this.update_response_row = function(response, oldkey)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6774 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6775 var list = this.responses_list;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6776
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6777 if (list && oldkey) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6778 list.update_row(oldkey, [ response.name ], response.key, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6779 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6780 else if (list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6781 list.insert_row({ id:'rcmrow'+response.key, cols:[ { className:'name', innerHTML:response.name } ] });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6782 list.select(response.key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6783 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6784 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6785
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6786 this.remove_response = function(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6787 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6788 var frame;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6789
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6790 if (this.env.textresponses) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6791 delete this.env.textresponses[key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6792 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6793
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6794 if (this.responses_list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6795 this.responses_list.remove_row(key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6796 if (frame = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6797 frame.location.href = this.env.blankpage;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6798 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6799 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6800
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6801 this.enable_command('delete', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6802 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6803
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6804 this.remove_identity = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6805 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6806 var frame, list = this.identity_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6807 rid = this.html_identifier(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6809 if (list && id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6810 list.remove_row(rid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6811 if (frame = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6812 frame.location.href = this.env.blankpage;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6813 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6814 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6815
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6816 this.enable_command('delete', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6817 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6818
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6819
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6820 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6821 /********* folder manager methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6822 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6823
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6824 this.init_subscription_list = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6825 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6826 var delim = RegExp.escape(this.env.delimiter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6827
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6828 this.last_sub_rx = RegExp('['+delim+']?[^'+delim+']+$');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6829
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6830 this.subscription_list = new rcube_treelist_widget(this.gui_objects.subscriptionlist, {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6831 selectable: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6832 tabexit: false,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6833 parent_focus: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6834 id_prefix: 'rcmli',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6835 id_encode: this.html_identifier_encode,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6836 id_decode: this.html_identifier_decode,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6837 searchbox: '#foldersearch'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6838 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6839
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6840 this.subscription_list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6841 .addEventListener('select', function(node) { ref.subscription_select(node.id); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6842 .addEventListener('collapse', function(node) { ref.folder_collapsed(node) })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6843 .addEventListener('expand', function(node) { ref.folder_collapsed(node) })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6844 .addEventListener('search', function(p) { if (p.query) ref.subscription_select(); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6845 .draggable({cancel: 'li.mailbox.root,input,div.treetoggle'})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6846 .droppable({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6847 // @todo: find better way, accept callback is executed for every folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6848 // on the list when dragging starts (and stops), this is slow, but
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6849 // I didn't find a method to check droptarget on over event
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6850 accept: function(node) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6851 if (!$(node).is('.mailbox'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6852 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6853
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6854 var source_folder = ref.folder_id2name($(node).attr('id')),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6855 dest_folder = ref.folder_id2name(this.id),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6856 source = ref.env.subscriptionrows[source_folder],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6857 dest = ref.env.subscriptionrows[dest_folder];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6858
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6859 return source && !source[2]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6860 && dest_folder != source_folder.replace(ref.last_sub_rx, '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6861 && !dest_folder.startsWith(source_folder + ref.env.delimiter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6862 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6863 drop: function(e, ui) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6864 var source = ref.folder_id2name(ui.draggable.attr('id')),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6865 dest = ref.folder_id2name(this.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6866
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6867 ref.subscription_move_folder(source, dest);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6868 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6869 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6870 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6871
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6872 this.folder_id2name = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6873 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6874 return id ? ref.html_identifier_decode(id.replace(/^rcmli/, '')) : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6875 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6876
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6877 this.subscription_select = function(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6878 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6879 var folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6880
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6881 if (id && id != '*' && (folder = this.env.subscriptionrows[id])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6882 this.env.mailbox = id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6883 this.show_folder(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6884 this.enable_command('delete-folder', !folder[2]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6885 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6886 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6887 this.env.mailbox = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6888 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6889 this.enable_command('delete-folder', 'purge', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6890 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6891 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6892
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6893 this.subscription_move_folder = function(from, to)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6894 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6895 if (from && to !== null && from != to && to != from.replace(this.last_sub_rx, '')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6896 var path = from.split(this.env.delimiter),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6897 basename = path.pop(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6898 newname = to === '' || to === '*' ? basename : to + this.env.delimiter + basename;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6899
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6900 if (newname != from) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6901 this.http_post('rename-folder', {_folder_oldname: from, _folder_newname: newname},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6902 this.set_busy(true, 'foldermoving'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6903 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6904 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6905 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6906
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6907 // tell server to create and subscribe a new mailbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6908 this.create_folder = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6909 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6910 this.show_folder('', this.env.mailbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6911 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6912
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6913 // delete a specific mailbox with all its messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6914 this.delete_folder = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6915 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6916 if (!name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6917 name = this.env.mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6918
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6919 if (name && confirm(this.get_label('deletefolderconfirm'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6920 this.http_post('delete-folder', {_mbox: name}, this.set_busy(true, 'folderdeleting'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6921 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6922 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6924 // Add folder row to the table and initialize it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6925 this.add_folder_row = function (id, name, display_name, is_protected, subscribed, class_name, refrow, subfolders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6926 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6927 if (!this.gui_objects.subscriptionlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6928 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6929
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6930 // reset searching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6931 if (this.subscription_list.is_search()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6932 this.subscription_select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6933 this.subscription_list.reset_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6934 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6935
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6936 // disable drag-n-drop temporarily
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6937 this.subscription_list.draggable('destroy').droppable('destroy');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6938
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6939 var row, n, tmp, tmp_name, rowid, collator, pos, p, parent = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6940 folders = [], list = [], slist = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6941 list_element = $(this.gui_objects.subscriptionlist);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6942 row = refrow ? refrow : $($('li', list_element).get(1)).clone(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6943
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6944 if (!row.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6945 // Refresh page if we don't have a table row to clone
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6946 this.goto_url('folders');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6947 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6948 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6949
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6950 // set ID, reset css class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6951 row.attr({id: 'rcmli' + this.html_identifier_encode(id), 'class': class_name});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6952
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6953 if (!refrow || !refrow.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6954 // remove old data, subfolders and toggle
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6955 $('ul,div.treetoggle', row).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6956 row.removeData('filtered');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6957 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6958
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6959 // set folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6960 $('a:first', row).text(display_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6961
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6962 // update subscription checkbox
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6963 $('input[name="_subscribed[]"]:first', row).val(id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6964 .prop({checked: subscribed ? true : false, disabled: is_protected ? true : false});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6966 // add to folder/row-ID map
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6967 this.env.subscriptionrows[id] = [name, display_name, false];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6969 // copy folders data to an array for sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6970 $.each(this.env.subscriptionrows, function(k, v) { v[3] = k; folders.push(v); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6971
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6972 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6973 // use collator if supported (FF29, IE11, Opera15, Chrome24)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6974 collator = new Intl.Collator(this.env.locale.replace('_', '-'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6975 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6976 catch (e) {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6977
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6978 // sort folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6979 folders.sort(function(a, b) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6980 var i, f1, f2,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6981 path1 = a[0].split(ref.env.delimiter),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6982 path2 = b[0].split(ref.env.delimiter),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6983 len = path1.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6984
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6985 for (i=0; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6986 f1 = path1[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6987 f2 = path2[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6988
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6989 if (f1 !== f2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6990 if (f2 === undefined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6991 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6992 if (collator)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6993 return collator.compare(f1, f2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6994 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6995 return f1 < f2 ? -1 : 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6996 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6997 else if (i == len-1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6998 return -1
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6999 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7000 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7001 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7002
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7003 for (n in folders) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7004 p = folders[n][3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7005 // protected folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7006 if (folders[n][2]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7007 tmp_name = p + this.env.delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7008 // prefix namespace cannot have subfolders (#1488349)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7009 if (tmp_name == this.env.prefix_ns)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7010 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7011 slist.push(p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7012 tmp = tmp_name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7013 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7014 // protected folder's child
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7015 else if (tmp && p.startsWith(tmp))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7016 slist.push(p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7017 // other
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7018 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7019 list.push(p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7020 tmp = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7021 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7022 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7023
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7024 // check if subfolder of a protected folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7025 for (n=0; n<slist.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7026 if (id.startsWith(slist[n] + this.env.delimiter))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7027 rowid = slist[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7028 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7029
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7030 // find folder position after sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7031 for (n=0; !rowid && n<list.length; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7032 if (n && list[n] == id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7033 rowid = list[n-1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7034 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7035
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7036 // add row to the table
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7037 if (rowid && (n = this.subscription_list.get_item(rowid, true))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7038 // find parent folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7039 if (pos = id.lastIndexOf(this.env.delimiter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7040 parent = id.substring(0, pos);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7041 parent = this.subscription_list.get_item(parent, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7042
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7043 // add required tree elements to the parent if not already there
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7044 if (!$('div.treetoggle', parent).length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7045 $('<div>&nbsp;</div>').addClass('treetoggle collapsed').appendTo(parent);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7046 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7047 if (!$('ul', parent).length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7048 $('<ul>').css('display', 'none').appendTo(parent);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7049 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7050 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7051
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7052 if (parent && n == parent) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7053 $('ul:first', parent).append(row);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7054 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7055 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7056 while (p = $(n).parent().parent().get(0)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7057 if (parent && p == parent)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7058 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7059 if (!$(p).is('li.mailbox'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7060 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7061 n = p;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7062 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7063
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7064 $(n).after(row);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7065 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7066 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7067 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7068 list_element.append(row);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7069 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7071 // add subfolders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7072 $.extend(this.env.subscriptionrows, subfolders || {});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7073
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7074 // update list widget
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7075 this.subscription_list.reset(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7076 this.subscription_select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7077
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7078 // expand parent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7079 if (parent) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7080 this.subscription_list.expand(this.folder_id2name(parent.id));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7082
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7083 row = row.show().get(0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7084 if (row.scrollIntoView)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7085 row.scrollIntoView();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7086
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7087 return row;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7088 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7089
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7090 // replace an existing table row with a new folder line (with subfolders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7091 this.replace_folder_row = function(oldid, id, name, display_name, is_protected, class_name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7092 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7093 if (!this.gui_objects.subscriptionlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7094 if (this.is_framed()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7095 // @FIXME: for some reason this 'parent' variable need to be prefixed with 'window.'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7096 return window.parent.rcmail.replace_folder_row(oldid, id, name, display_name, is_protected, class_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7097 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7098
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7099 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7100 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7102 // reset searching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7103 if (this.subscription_list.is_search()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7104 this.subscription_select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7105 this.subscription_list.reset_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7106 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7107
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7108 var subfolders = {},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7109 row = this.subscription_list.get_item(oldid, true),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7110 parent = $(row).parent(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7111 old_folder = this.env.subscriptionrows[oldid],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7112 prefix_len_id = oldid.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7113 prefix_len_name = old_folder[0].length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7114 subscribed = $('input[name="_subscribed[]"]:first', row).prop('checked');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7115
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7116 // no renaming, only update class_name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7117 if (oldid == id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7118 $(row).attr('class', class_name || '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7119 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7120 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7121
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7122 // update subfolders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7123 $('li', row).each(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7124 var fname = ref.folder_id2name(this.id),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7125 folder = ref.env.subscriptionrows[fname],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7126 newid = id + fname.slice(prefix_len_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7127
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7128 this.id = 'rcmli' + ref.html_identifier_encode(newid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7129 $('input[name="_subscribed[]"]:first', this).val(newid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7130 folder[0] = name + folder[0].slice(prefix_len_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7131
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7132 subfolders[newid] = folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7133 delete ref.env.subscriptionrows[fname];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7134 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7135
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7136 // get row off the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7137 row = $(row).detach();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7138
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7139 delete this.env.subscriptionrows[oldid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7140
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7141 // remove parent list/toggle elements if not needed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7142 if (parent.get(0) != this.gui_objects.subscriptionlist && !$('li', parent).length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7143 $('ul,div.treetoggle', parent.parent()).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7144 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7145
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7146 // move the existing table row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7147 this.add_folder_row(id, name, display_name, is_protected, subscribed, class_name, row, subfolders);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7148 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7149
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7150 // remove the table row of a specific mailbox from the table
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7151 this.remove_folder_row = function(folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7152 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7153 // reset searching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7154 if (this.subscription_list.is_search()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7155 this.subscription_select();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7156 this.subscription_list.reset_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7157 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7159 var list = [], row = this.subscription_list.get_item(folder, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7161 // get subfolders if any
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7162 $('li', row).each(function() { list.push(ref.folder_id2name(this.id)); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7163
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7164 // remove folder row (and subfolders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7165 this.subscription_list.remove(folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7167 // update local list variable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7168 list.push(folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7169 $.each(list, function(i, v) { delete ref.env.subscriptionrows[v]; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7170 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7172 this.subscribe = function(folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7173 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7174 if (folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7175 var lock = this.display_message(this.get_label('foldersubscribing'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7176 this.http_post('subscribe', {_mbox: folder}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7177 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7178 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7179
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7180 this.unsubscribe = function(folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7181 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7182 if (folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7183 var lock = this.display_message(this.get_label('folderunsubscribing'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7184 this.http_post('unsubscribe', {_mbox: folder}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7185 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7186 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7187
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7188 // when user select a folder in manager
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7189 this.show_folder = function(folder, path, force)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7190 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7191 var win, target = window,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7192 url = '&_action=edit-folder&_mbox='+urlencode(folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7193
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7194 if (path)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7195 url += '&_path='+urlencode(path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7196
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7197 if (win = this.get_frame_window(this.env.contentframe)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7198 target = win;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7199 url += '&_framed=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7200 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7201
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7202 if (String(target.location.href).indexOf(url) >= 0 && !force)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7203 this.show_contentframe(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7204 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7205 this.location_href(this.env.comm_path+url, target, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7206 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7207
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7208 // disables subscription checkbox (for protected folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7209 this.disable_subscription = function(folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7210 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7211 var row = this.subscription_list.get_item(folder, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7212 if (row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7213 $('input[name="_subscribed[]"]:first', row).prop('disabled', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7214 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7215
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7216 // resets state of subscription checkbox (e.g. on error)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7217 this.reset_subscription = function(folder, state)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7218 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7219 var row = this.subscription_list.get_item(folder, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7220 if (row)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7221 $('input[name="_subscribed[]"]:first', row).prop('checked', state);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7222 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7223
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7224 this.folder_size = function(folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7225 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7226 var lock = this.set_busy(true, 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7227 this.http_post('folder-size', {_mbox: folder}, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7228 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7229
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7230 this.folder_size_update = function(size)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7231 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7232 $('#folder-size').replaceWith(size);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7233 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7234
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7235 // filter folders by namespace
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7236 this.folder_filter = function(prefix)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7237 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7238 this.subscription_list.reset_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7239
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7240 this.subscription_list.container.children('li').each(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7241 var i, folder = ref.folder_id2name(this.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7242 // show all folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7243 if (prefix == '---') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7244 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7245 // got namespace prefix
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7246 else if (prefix) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7247 if (folder !== prefix) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7248 $(this).data('filtered', true).hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7249 return
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7250 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7251 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7252 // no namespace prefix, filter out all other namespaces
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7253 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7254 // first get all namespace roots
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7255 for (i in ref.env.ns_roots) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7256 if (folder === ref.env.ns_roots[i]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7257 $(this).data('filtered', true).hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7258 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7259 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7260 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7261 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7262
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7263 $(this).removeData('filtered').show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7264 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7265 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7266
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7267 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7268 /********* GUI functionality *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7269 /*********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7270
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7271 var init_button = function(cmd, prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7272 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7273 var elm = document.getElementById(prop.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7274 if (!elm)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7275 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7276
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7277 var preload = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7278 if (prop.type == 'image') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7279 elm = elm.parentNode;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7280 preload = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7281 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7282
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7283 elm._command = cmd;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7284 elm._id = prop.id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7285 if (prop.sel) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7286 elm.onmousedown = function(e) { return ref.button_sel(this._command, this._id); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7287 elm.onmouseup = function(e) { return ref.button_out(this._command, this._id); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7288 if (preload)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7289 new Image().src = prop.sel;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7290 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7291 if (prop.over) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7292 elm.onmouseover = function(e) { return ref.button_over(this._command, this._id); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7293 elm.onmouseout = function(e) { return ref.button_out(this._command, this._id); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7294 if (preload)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7295 new Image().src = prop.over;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7296 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7297 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7298
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7299 // set event handlers on registered buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7300 this.init_buttons = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7301 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7302 for (var cmd in this.buttons) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7303 if (typeof cmd !== 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7304 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7305
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7306 for (var i=0; i<this.buttons[cmd].length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7307 init_button(cmd, this.buttons[cmd][i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7308 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7309 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7310 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7311
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7312 // set button to a specific state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7313 this.set_button = function(command, state)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7314 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7315 var n, button, obj, $obj, a_buttons = this.buttons[command],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7316 len = a_buttons ? a_buttons.length : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7317
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7318 for (n=0; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7319 button = a_buttons[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7320 obj = document.getElementById(button.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7321
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7322 if (!obj || button.status === state)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7323 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7325 // get default/passive setting of the button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7326 if (button.type == 'image' && !button.status) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7327 button.pas = obj._original_src ? obj._original_src : obj.src;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7328 // respect PNG fix on IE browsers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7329 if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7330 button.pas = RegExp.$1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7331 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7332 else if (!button.status)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7333 button.pas = String(obj.className);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7334
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7335 button.status = state;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7336
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7337 // set image according to button state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7338 if (button.type == 'image' && button[state]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7339 obj.src = button[state];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7340 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7341 // set class name according to button state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7342 else if (button[state] !== undefined) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7343 obj.className = button[state];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7344 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7345 // disable/enable input buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7346 if (button.type == 'input') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7347 obj.disabled = state == 'pas';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7349 else if (button.type == 'uibutton') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7350 button.status = state;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7351 $(obj).button('option', 'disabled', state == 'pas');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7352 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7353 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7354 $obj = $(obj);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7355 $obj
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7356 .attr('tabindex', state == 'pas' || state == 'sel' ? '-1' : ($obj.attr('data-tabindex') || '0'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7357 .attr('aria-disabled', state == 'pas' || state == 'sel' ? 'true' : 'false');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7358 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7359 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7360 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7361
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7362 // display a specific alttext
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7363 this.set_alttext = function(command, label)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7364 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7365 var n, button, obj, link, a_buttons = this.buttons[command],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7366 len = a_buttons ? a_buttons.length : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7367
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7368 for (n=0; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7369 button = a_buttons[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7370 obj = document.getElementById(button.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7372 if (button.type == 'image' && obj) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7373 obj.setAttribute('alt', this.get_label(label));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7374 if ((link = obj.parentNode) && link.tagName.toLowerCase() == 'a')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7375 link.setAttribute('title', this.get_label(label));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7376 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7377 else if (obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7378 obj.setAttribute('title', this.get_label(label));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7379 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7380 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7381
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7382 // mouse over button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7383 this.button_over = function(command, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7384 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7385 this.button_event(command, id, 'over');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7386 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7387
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7388 // mouse down on button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7389 this.button_sel = function(command, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7390 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7391 this.button_event(command, id, 'sel');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7392 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7393
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7394 // mouse out of button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7395 this.button_out = function(command, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7396 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7397 this.button_event(command, id, 'act');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7398 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7400 // event of button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7401 this.button_event = function(command, id, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7402 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7403 var n, button, obj, a_buttons = this.buttons[command],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7404 len = a_buttons ? a_buttons.length : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7405
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7406 for (n=0; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7407 button = a_buttons[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7408 if (button.id == id && button.status == 'act') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7409 if (button[event] && (obj = document.getElementById(button.id))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7410 obj[button.type == 'image' ? 'src' : 'className'] = button[event];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7411 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7412
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7413 if (event == 'sel') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7414 this.buttons_sel[id] = command;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7415 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7416 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7417 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7418 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7419
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7420 // write to the document/window title
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7421 this.set_pagetitle = function(title)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7422 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7423 if (title && document.title)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7424 document.title = title;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7425 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7426
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7427 // display a system message, list of types in common.css (below #message definition)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7428 this.display_message = function(msg, type, timeout, key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7429 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7430 // pass command to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7431 if (this.is_framed())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7432 return parent.rcmail.display_message(msg, type, timeout);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7433
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7434 if (!this.gui_objects.message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7435 // save message in order to display after page loaded
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7436 if (type != 'loading')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7437 this.pending_message = [msg, type, timeout, key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7438 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7439 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7440
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7441 if (!type)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7442 type = 'notice';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7443
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7444 if (!key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7445 key = this.html_identifier(msg);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7446
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7447 var date = new Date(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7448 id = type + date.getTime();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7449
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7450 if (!timeout) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7451 switch (type) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7452 case 'error':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7453 case 'warning':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7454 timeout = this.message_time * 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7455 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7456
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7457 case 'uploading':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7458 timeout = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7459 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7461 default:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7462 timeout = this.message_time;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7463 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7464 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7465
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7466 if (type == 'loading') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7467 key = 'loading';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7468 timeout = this.env.request_timeout * 1000;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7469 if (!msg)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7470 msg = this.get_label('loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7471 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7472
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7473 // The same message is already displayed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7474 if (this.messages[key]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7475 // replace label
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7476 if (this.messages[key].obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7477 this.messages[key].obj.html(msg);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7478 // store label in stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7479 if (type == 'loading') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7480 this.messages[key].labels.push({'id': id, 'msg': msg});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7481 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7482 // add element and set timeout
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7483 this.messages[key].elements.push(id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7484 setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7485 return id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7486 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7487
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7488 // create DOM object and display it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7489 var obj = $('<div>').addClass(type).html(msg).data('key', key),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7490 cont = $(this.gui_objects.message).append(obj).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7491
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7492 this.messages[key] = {'obj': obj, 'elements': [id]};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7493
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7494 if (type == 'loading') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7495 this.messages[key].labels = [{'id': id, 'msg': msg}];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7496 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7497 else if (type != 'uploading') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7498 obj.click(function() { return ref.hide_message(obj); })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7499 .attr('role', 'alert');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7500 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7501
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7502 this.triggerEvent('message', { message:msg, type:type, timeout:timeout, object:obj });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7503
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7504 if (timeout > 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7505 setTimeout(function() { ref.hide_message(id, type != 'loading'); }, timeout);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7506
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7507 return id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7508 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7509
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7510 // make a message to disapear
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7511 this.hide_message = function(obj, fade)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7512 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7513 // pass command to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7514 if (this.is_framed())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7515 return parent.rcmail.hide_message(obj, fade);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7516
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7517 if (!this.gui_objects.message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7518 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7519
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7520 var k, n, i, o, m = this.messages;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7521
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7522 // Hide message by object, don't use for 'loading'!
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7523 if (typeof obj === 'object') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7524 o = $(obj);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7525 k = o.data('key');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7526 this.hide_message_object(o, fade);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7527 if (m[k])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7528 delete m[k];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7529 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7530 // Hide message by id
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7531 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7532 for (k in m) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7533 for (n in m[k].elements) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7534 if (m[k] && m[k].elements[n] == obj) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7535 m[k].elements.splice(n, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7536 // hide DOM element if last instance is removed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7537 if (!m[k].elements.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7538 this.hide_message_object(m[k].obj, fade);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7539 delete m[k];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7540 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7541 // set pending action label for 'loading' message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7542 else if (k == 'loading') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7543 for (i in m[k].labels) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7544 if (m[k].labels[i].id == obj) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7545 delete m[k].labels[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7546 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7547 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7548 o = m[k].labels[i].msg;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7549 m[k].obj.html(o);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7550 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7551 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7552 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7553 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7554 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7555 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7556 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7557 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7558
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7559 // hide message object and remove from the DOM
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7560 this.hide_message_object = function(o, fade)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7561 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7562 if (fade)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7563 o.fadeOut(600, function() {$(this).remove(); });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7564 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7565 o.hide().remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7566 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7567
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7568 // remove all messages immediately
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7569 this.clear_messages = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7570 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7571 // pass command to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7572 if (this.is_framed())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7573 return parent.rcmail.clear_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7574
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7575 var k, n, m = this.messages;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7576
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7577 for (k in m)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7578 for (n in m[k].elements)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7579 if (m[k].obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7580 this.hide_message_object(m[k].obj);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7581
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7582 this.messages = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7583 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7584
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7585 // display uploading message with progress indicator
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7586 // data should contain: name, total, current, percent, text
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7587 this.display_progress = function(data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7588 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7589 if (!data || !data.name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7590 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7591
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7592 var msg = this.messages['progress' + data.name];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7593
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7594 if (!data.label)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7595 data.label = this.get_label('uploadingmany');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7596
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7597 if (!msg) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7598 if (!data.percent || data.percent < 100)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7599 this.display_message(data.label, 'uploading', 0, 'progress' + data.name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7600 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7601 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7602
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7603 if (!data.total || data.percent >= 100) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7604 this.hide_message(msg.obj);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7605 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7606 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7607
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7608 if (data.text)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7609 data.label += ' ' + data.text;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7610
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7611 msg.obj.text(data.label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7612 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7613
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7614 // open a jquery UI dialog with the given content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7615 this.show_popup_dialog = function(content, title, buttons, options)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7616 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7617 // forward call to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7618 if (this.is_framed()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7619 return parent.rcmail.show_popup_dialog(content, title, buttons, options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7620 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7621
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7622 var popup = $('<div class="popup">');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7623
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7624 if (typeof content == 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7625 popup.append(content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7626 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7627 popup.html(content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7628
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7629 options = $.extend({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7630 title: title,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7631 buttons: buttons,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7632 modal: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7633 resizable: true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7634 width: 500,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7635 close: function(event, ui) { $(this).remove(); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7636 }, options || {});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7637
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7638 popup.dialog(options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7639
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7640 // resize and center popup
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7641 var win = $(window), w = win.width(), h = win.height(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7642 width = popup.width(), height = popup.height();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7643
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7644 popup.dialog('option', {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7645 height: Math.min(h - 40, height + 75 + (buttons ? 50 : 0)),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7646 width: Math.min(w - 20, width + 36)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7647 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7648
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7649 // assign special classes to dialog buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7650 $.each(options.button_classes || [], function(i, v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7651 if (v) $($('.ui-dialog-buttonpane button.ui-button', popup.parent()).get(i)).addClass(v);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7652 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7653
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7654 return popup;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7655 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7656
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7657 // show_popup_dialog() wrapper for simple dialogs with Save and Cancel buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7658 this.simple_dialog = function(content, title, button_func, options)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7659 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7660 var title = this.get_label(title),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7661 buttons = [{
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7662 text: this.get_label((options || {}).button || 'save'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7663 'class': 'mainaction',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7664 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7665 if (button_func())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7666 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7667 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7668 },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7669 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7670 text: ref.get_label('cancel'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7671 click: function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7672 $(this).dialog('close');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7673 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7674 }];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7676 return this.show_popup_dialog(content, title, buttons, options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7677 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7678
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7679 // enable/disable buttons for page shifting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7680 this.set_page_buttons = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7681 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7682 this.enable_command('nextpage', 'lastpage', this.env.pagecount > this.env.current_page);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7683 this.enable_command('previouspage', 'firstpage', this.env.current_page > 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7684
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7685 this.update_pagejumper();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7686 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7687
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7688 // mark a mailbox as selected and set environment variable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7689 this.select_folder = function(name, prefix, encode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7690 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7691 if (this.savedsearchlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7692 this.savedsearchlist.select('');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7693 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7694
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7695 if (this.treelist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7696 this.treelist.select(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7697 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7698 else if (this.gui_objects.folderlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7699 $('li.selected', this.gui_objects.folderlist).removeClass('selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7700 $(this.get_folder_li(name, prefix, encode)).addClass('selected');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7701
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7702 // trigger event hook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7703 this.triggerEvent('selectfolder', { folder:name, prefix:prefix });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7704 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7705 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7706
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7707 // adds a class to selected folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7708 this.mark_folder = function(name, class_name, prefix, encode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7709 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7710 $(this.get_folder_li(name, prefix, encode)).addClass(class_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7711 this.triggerEvent('markfolder', {folder: name, mark: class_name, status: true});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7712 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7713
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7714 // adds a class to selected folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7715 this.unmark_folder = function(name, class_name, prefix, encode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7716 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7717 $(this.get_folder_li(name, prefix, encode)).removeClass(class_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7718 this.triggerEvent('markfolder', {folder: name, mark: class_name, status: false});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7719 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7720
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7721 // helper method to find a folder list item
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7722 this.get_folder_li = function(name, prefix, encode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7723 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7724 if (!prefix)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7725 prefix = 'rcmli';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7726
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7727 if (this.gui_objects.folderlist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7728 name = this.html_identifier(name, encode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7729 return document.getElementById(prefix+name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7730 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7731 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7733 // for reordering column array (Konqueror workaround)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7734 // and for setting some message list global variables
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7735 this.set_message_coltypes = function(listcols, repl, smart_col)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7736 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7737 var list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7738 thead = list ? list.thead : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7739 repl, cell, col, n, len, tr;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7740
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7741 this.env.listcols = listcols;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7742
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7743 if (!this.env.coltypes)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7744 this.env.coltypes = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7745
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7746 // replace old column headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7747 if (thead) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7748 if (repl) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7749 thead.innerHTML = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7750 tr = document.createElement('tr');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7751
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7752 for (c=0, len=repl.length; c < len; c++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7753 cell = document.createElement('th');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7754 cell.innerHTML = repl[c].html || '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7755 if (repl[c].id) cell.id = repl[c].id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7756 if (repl[c].className) cell.className = repl[c].className;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7757 tr.appendChild(cell);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7758 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7759 thead.appendChild(tr);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7760 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7761
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7762 for (n=0, len=this.env.listcols.length; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7763 col = this.env.listcols[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7764 if ((cell = thead.rows[0].cells[n]) && (col == 'from' || col == 'to' || col == 'fromto')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7765 $(cell).attr('rel', col).find('span,a').text(this.get_label(col == 'fromto' ? smart_col : col));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7766 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7767 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7768 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7770 this.env.subject_col = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7771 this.env.flagged_col = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7772 this.env.status_col = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7773
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7774 if (this.env.coltypes.folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7775 this.env.coltypes.folder.hidden = !(this.env.search_request || this.env.search_id) || this.env.search_scope == 'base';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7776
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7777 if ((n = $.inArray('subject', this.env.listcols)) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7778 this.env.subject_col = n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7779 if (list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7780 list.subject_col = n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7781 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7782 if ((n = $.inArray('flag', this.env.listcols)) >= 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7783 this.env.flagged_col = n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7784 if ((n = $.inArray('status', this.env.listcols)) >= 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7785 this.env.status_col = n;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7787 if (list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7788 list.hide_column('folder', (this.env.coltypes.folder && this.env.coltypes.folder.hidden) || $.inArray('folder', this.env.listcols) < 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7789 list.init_header();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7790 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7791 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7792
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7793 // replace content of row count display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7794 this.set_rowcount = function(text, mbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7795 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7796 // #1487752
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7797 if (mbox && mbox != this.env.mailbox)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7798 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7799
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7800 $(this.gui_objects.countdisplay).html(text);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7801
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7802 // update page navigation buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7803 this.set_page_buttons();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7804 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7806 // replace content of mailboxname display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7807 this.set_mailboxname = function(content)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7808 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7809 if (this.gui_objects.mailboxname && content)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7810 this.gui_objects.mailboxname.innerHTML = content;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7811 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7812
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7813 // replace content of quota display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7814 this.set_quota = function(content)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7815 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7816 if (this.gui_objects.quotadisplay && content && content.type == 'text')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7817 $(this.gui_objects.quotadisplay).text((content.percent||0) + '%').attr('title', content.title);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7818
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7819 this.triggerEvent('setquota', content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7820 this.env.quota_content = content;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7821 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7823 // update trash folder state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7824 this.set_trash_count = function(count)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7825 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7826 this[(count ? 'un' : '') + 'mark_folder'](this.env.trash_mailbox, 'empty', '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7827 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7828
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7829 // update the mailboxlist
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7830 this.set_unread_count = function(mbox, count, set_title, mark)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7831 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7832 if (!this.gui_objects.mailboxlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7833 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7834
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7835 this.env.unread_counts[mbox] = count;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7836 this.set_unread_count_display(mbox, set_title);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7837
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7838 if (mark)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7839 this.mark_folder(mbox, mark, '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7840 else if (!count)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7841 this.unmark_folder(mbox, 'recent', '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7843 this.mark_all_read_state();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7844 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7845
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7846 // update the mailbox count display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7847 this.set_unread_count_display = function(mbox, set_title)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7848 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7849 var reg, link, text_obj, item, mycount, childcount, div;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7850
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7851 if (item = this.get_folder_li(mbox, '', true)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7852 mycount = this.env.unread_counts[mbox] ? this.env.unread_counts[mbox] : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7853 link = $(item).children('a').eq(0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7854 text_obj = link.children('span.unreadcount');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7855 if (!text_obj.length && mycount)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7856 text_obj = $('<span>').addClass('unreadcount').appendTo(link);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7857 reg = /\s+\([0-9]+\)$/i;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7858
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7859 childcount = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7860 if ((div = item.getElementsByTagName('div')[0]) &&
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7861 div.className.match(/collapsed/)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7862 // add children's counters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7863 for (var k in this.env.unread_counts)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7864 if (k.startsWith(mbox + this.env.delimiter))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7865 childcount += this.env.unread_counts[k];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7866 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7867
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7868 if (mycount && text_obj.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7869 text_obj.html(this.env.unreadwrap.replace(/%[sd]/, mycount));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7870 else if (text_obj.length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7871 text_obj.remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7872
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7873 // set parent's display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7874 reg = new RegExp(RegExp.escape(this.env.delimiter) + '[^' + RegExp.escape(this.env.delimiter) + ']+$');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7875 if (mbox.match(reg))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7876 this.set_unread_count_display(mbox.replace(reg, ''), false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7877
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7878 // set the right classes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7879 if ((mycount+childcount)>0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7880 $(item).addClass('unread');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7881 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7882 $(item).removeClass('unread');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7883 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7884
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7885 // set unread count to window title
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7886 reg = /^\([0-9]+\)\s+/i;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7887 if (set_title && document.title) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7888 var new_title = '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7889 doc_title = String(document.title);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7891 if (mycount && doc_title.match(reg))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7892 new_title = doc_title.replace(reg, '('+mycount+') ');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7893 else if (mycount)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7894 new_title = '('+mycount+') '+doc_title;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7895 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7896 new_title = doc_title.replace(reg, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7897
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7898 this.set_pagetitle(new_title);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7899 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7900 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7901
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7902 // display fetched raw headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7903 this.set_headers = function(content)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7904 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7905 if (this.gui_objects.all_headers_row && this.gui_objects.all_headers_box && content)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7906 $(this.gui_objects.all_headers_box).html(content).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7907 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7908
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7909 // display all-headers row and fetch raw message headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7910 this.show_headers = function(props, elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7911 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7912 if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box || !this.env.uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7913 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7914
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7915 $(elem).removeClass('show-headers').addClass('hide-headers');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7916 $(this.gui_objects.all_headers_row).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7917 elem.onclick = function() { ref.command('hide-headers', '', elem); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7918
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7919 // fetch headers only once
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7920 if (!this.gui_objects.all_headers_box.innerHTML) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7921 this.http_post('headers', {_uid: this.env.uid, _mbox: this.env.mailbox},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7922 this.display_message(this.get_label('loading'), 'loading')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7923 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7924 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7925 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7926
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7927 // hide all-headers row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7928 this.hide_headers = function(props, elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7929 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7930 if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7931 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7932
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7933 $(elem).removeClass('hide-headers').addClass('show-headers');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7934 $(this.gui_objects.all_headers_row).hide();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7935 elem.onclick = function() { ref.command('show-headers', '', elem); };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7936 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7937
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7938 // create folder selector popup, position and display it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7939 this.folder_selector = function(event, callback)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7940 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7941 var container = this.folder_selector_element;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7942
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7943 if (!container) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7944 var rows = [],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7945 delim = this.env.delimiter,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7946 ul = $('<ul class="toolbarmenu">'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7947 link = document.createElement('a');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7948
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7949 container = $('<div id="folder-selector" class="popupmenu"></div>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7950 link.href = '#';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7951 link.className = 'icon';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7952
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7953 // loop over sorted folders list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7954 $.each(this.env.mailboxes_list, function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7955 var n = 0, s = 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7956 folder = ref.env.mailboxes[this],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7957 id = folder.id,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7958 a = $(link.cloneNode(false)),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7959 row = $('<li>');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7960
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7961 if (folder.virtual)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7962 a.addClass('virtual').attr('aria-disabled', 'true').attr('tabindex', '-1');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7963 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7964 a.addClass('active').data('id', folder.id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7966 if (folder['class'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7967 a.addClass(folder['class']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7969 // calculate/set indentation level
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7970 while ((s = id.indexOf(delim, s)) >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7971 n++; s++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7972 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7973 a.css('padding-left', n ? (n * 16) + 'px' : 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7974
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7975 // add folder name element
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7976 a.append($('<span>').text(folder.name));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7977
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7978 row.append(a);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7979 rows.push(row);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7980 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7981
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7982 ul.append(rows).appendTo(container);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7983
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7984 // temporarily show element to calculate its size
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7985 container.css({left: '-1000px', top: '-1000px'})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7986 .appendTo($('body')).show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7987
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7988 // set max-height if the list is long
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7989 if (rows.length > 10)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7990 container.css('max-height', $('li', container)[0].offsetHeight * 10 + 9);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7992 // register delegate event handler for folder item clicks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7993 container.on('click', 'a.active', function(e){
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7994 container.data('callback')($(this).data('id'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7995 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7996 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7997
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7998 this.folder_selector_element = container;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7999 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8000
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8001 container.data('callback', callback);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8002
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8003 // position menu on the screen
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8004 this.show_menu('folder-selector', true, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8005 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8007
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8008 /***********************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8009 /********* popup menu functions *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8010 /***********************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8011
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8012 // Show/hide a specific popup menu
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8013 this.show_menu = function(prop, show, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8014 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8015 var name = typeof prop == 'object' ? prop.menu : prop,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8016 obj = $('#'+name),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8017 ref = event && event.target ? $(event.target) : $(obj.attr('rel') || '#'+name+'link'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8018 keyboard = rcube_event.is_keyboard(event),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8019 align = obj.attr('data-align') || '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8020 stack = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8021
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8022 // find "real" button element
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8023 if (ref.get(0).tagName != 'A' && ref.closest('a').length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8024 ref = ref.closest('a');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8025
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8026 if (typeof prop == 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8027 prop = { menu:name };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8028
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8029 // let plugins or skins provide the menu element
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8030 if (!obj.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8031 obj = this.triggerEvent('menu-get', { name:name, props:prop, originalEvent:event });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8032 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8033
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8034 if (!obj || !obj.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8035 // just delegate the action to subscribers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8036 return this.triggerEvent(show === false ? 'menu-close' : 'menu-open', { name:name, props:prop, originalEvent:event });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8037 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8038
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8039 // move element to top for proper absolute positioning
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8040 obj.appendTo(document.body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8041
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8042 if (typeof show == 'undefined')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8043 show = obj.is(':visible') ? false : true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8044
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8045 if (show && ref.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8046 var win = $(window),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8047 pos = ref.offset(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8048 above = align.indexOf('bottom') >= 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8049
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8050 stack = ref.attr('role') == 'menuitem' || ref.closest('[role=menuitem]').length > 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8051
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8052 ref.offsetWidth = ref.outerWidth();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8053 ref.offsetHeight = ref.outerHeight();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8054 if (!above && pos.top + ref.offsetHeight + obj.height() > win.height()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8055 above = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8056 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8057 if (align.indexOf('right') >= 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8058 pos.left = pos.left + ref.outerWidth() - obj.width();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8059 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8060 else if (stack) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8061 pos.left = pos.left + ref.offsetWidth - 5;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8062 pos.top -= ref.offsetHeight;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8063 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8064 if (pos.left + obj.width() > win.width()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8065 pos.left = win.width() - obj.width() - 12;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8066 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8067 pos.top = Math.max(0, pos.top + (above ? -obj.height() : ref.offsetHeight));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8068 obj.css({ left:pos.left+'px', top:pos.top+'px' });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8069 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8071 // add menu to stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8072 if (show) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8073 // truncate stack down to the one containing the ref link
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8074 for (var i = this.menu_stack.length - 1; stack && i >= 0; i--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8075 if (!$(ref).parents('#'+this.menu_stack[i]).length && $(event.target).parent().attr('role') != 'menuitem')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8076 this.hide_menu(this.menu_stack[i], event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8077 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8078 if (stack && this.menu_stack.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8079 obj.data('parent', $.last(this.menu_stack));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8080 obj.css('z-index', ($('#'+$.last(this.menu_stack)).css('z-index') || 0) + 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8082 else if (!stack && this.menu_stack.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8083 this.hide_menu(this.menu_stack[0], event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8084 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8085
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8086 obj.show().attr('aria-hidden', 'false').data('opener', ref.attr('aria-expanded', 'true').get(0));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8087 this.triggerEvent('menu-open', { name:name, obj:obj, props:prop, originalEvent:event });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8088 this.menu_stack.push(name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8089
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8090 this.menu_keyboard_active = show && keyboard;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8091 if (this.menu_keyboard_active) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8092 this.focused_menu = name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8093 obj.find('a,input:not(:disabled)').not('[aria-disabled=true]').first().focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8094 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8095 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8096 else { // close menu
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8097 this.hide_menu(name, event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8098 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8099
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8100 return show;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8101 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8102
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8103 // hide the given popup menu (and it's childs)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8104 this.hide_menu = function(name, event)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8105 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8106 if (!this.menu_stack.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8107 // delegate to subscribers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8108 this.triggerEvent('menu-close', { name:name, props:{ menu:name }, originalEvent:event });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8109 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8110 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8112 var obj, keyboard = rcube_event.is_keyboard(event);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8113 for (var j=this.menu_stack.length-1; j >= 0; j--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8114 obj = $('#' + this.menu_stack[j]).hide().attr('aria-hidden', 'true').data('parent', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8115 this.triggerEvent('menu-close', { name:this.menu_stack[j], obj:obj, props:{ menu:this.menu_stack[j] }, originalEvent:event });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8116 if (this.menu_stack[j] == name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8117 j = -1; // stop loop
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8118 if (obj.data('opener')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8119 $(obj.data('opener')).attr('aria-expanded', 'false');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8120 if (keyboard)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8121 obj.data('opener').focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8122 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8123 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8124 this.menu_stack.pop();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8125 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8127 // focus previous menu in stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8128 if (this.menu_stack.length && keyboard) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8129 this.menu_keyboard_active = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8130 this.focused_menu = $.last(this.menu_stack);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8131 if (!obj || !obj.data('opener'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8132 $('#'+this.focused_menu).find('a,input:not(:disabled)').not('[aria-disabled=true]').first().focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8133 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8134 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8135 this.focused_menu = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8136 this.menu_keyboard_active = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8137 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8138 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8139
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8140
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8141 // position a menu element on the screen in relation to other object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8142 this.element_position = function(element, obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8143 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8144 var obj = $(obj), win = $(window),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8145 width = obj.outerWidth(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8146 height = obj.outerHeight(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8147 menu_pos = obj.data('menu-pos'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8148 win_height = win.height(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8149 elem_height = $(element).height(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8150 elem_width = $(element).width(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8151 pos = obj.offset(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8152 top = pos.top,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8153 left = pos.left + width;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8154
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8155 if (menu_pos == 'bottom') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8156 top += height;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8157 left -= width;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8158 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8159 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8160 left -= 5;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8161
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8162 if (top + elem_height > win_height) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8163 top -= elem_height - height;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8164 if (top < 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8165 top = Math.max(0, (win_height - elem_height) / 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8166 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8167
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8168 if (left + elem_width > win.width())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8169 left -= elem_width + width;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8170
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8171 element.css({left: left + 'px', top: top + 'px'});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8172 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8173
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8174 // initialize HTML editor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8175 this.editor_init = function(config, id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8176 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8177 this.editor = new rcube_text_editor(config, id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8178 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8179
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8180
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8181 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8182 /********* html to text conversion functions *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8183 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8185 this.html2plain = function(html, func)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8186 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8187 return this.format_converter(html, 'html', func);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8188 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8189
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8190 this.plain2html = function(plain, func)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8191 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8192 return this.format_converter(plain, 'plain', func);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8193 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8195 this.format_converter = function(text, format, func)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8196 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8197 // warn the user (if converted content is not empty)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8198 if (!text
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8199 || (format == 'html' && !(text.replace(/<[^>]+>|&nbsp;|\xC2\xA0|\s/g, '')).length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8200 || (format != 'html' && !(text.replace(/\xC2\xA0|\s/g, '')).length)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8201 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8202 // without setTimeout() here, textarea is filled with initial (onload) content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8203 if (func)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8204 setTimeout(function() { func(''); }, 50);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8205 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8206 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8207
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8208 var confirmed = this.env.editor_warned || confirm(this.get_label('editorwarning'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8209
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8210 this.env.editor_warned = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8211
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8212 if (!confirmed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8213 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8214
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8215 var url = '?_task=utils&_action=' + (format == 'html' ? 'html2text' : 'text2html'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8216 lock = this.set_busy(true, 'converting');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8217
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8218 $.ajax({ type: 'POST', url: url, data: text, contentType: 'application/octet-stream',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8219 error: function(o, status, err) { ref.http_error(o, status, err, lock); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8220 success: function(data) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8221 ref.set_busy(false, null, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8222 if (func) func(data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8223 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8224 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8225
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8226 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8227 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8228
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8229
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8230 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8231 /********* remote request methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8232 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8233
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8234 // compose a valid url with the given parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8235 this.url = function(action, query)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8236 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8237 var querystring = typeof query === 'string' ? query : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8238
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8239 if (typeof action !== 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8240 query = action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8241 else if (!query || typeof query !== 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8242 query = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8243
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8244 if (action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8245 query._action = action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8246 else if (this.env.action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8247 query._action = this.env.action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8248
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8249 var url = this.env.comm_path, k, param = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8250
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8251 // overwrite task name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8252 if (action && action.match(/([a-z0-9_-]+)\/([a-z0-9-_.]+)/)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8253 query._action = RegExp.$2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8254 url = url.replace(/\_task=[a-z0-9_-]+/, '_task=' + RegExp.$1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8255 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8256
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8257 // remove undefined values
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8258 for (k in query) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8259 if (query[k] !== undefined && query[k] !== null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8260 param[k] = query[k];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8261 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8262
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8263 if (param = $.param(param))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8264 url += (url.indexOf('?') > -1 ? '&' : '?') + param;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8265
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8266 if (querystring)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8267 url += (url.indexOf('?') > -1 ? '&' : '?') + querystring;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8268
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8269 return url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8270 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8271
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8272 this.redirect = function(url, lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8273 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8274 if (lock || lock === null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8275 this.set_busy(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8276
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8277 if (this.is_framed()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8278 parent.rcmail.redirect(url, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8279 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8280 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8281 if (this.env.extwin) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8282 if (typeof url == 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8283 url += (url.indexOf('?') < 0 ? '?' : '&') + '_extwin=1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8284 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8285 url._extwin = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8286 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8287 this.location_href(url, window);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8288 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8289 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8291 this.goto_url = function(action, query, lock, secure)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8292 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8293 var url = this.url(action, query)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8294 if (secure) url = this.secure_url(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8295 this.redirect(url, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8296 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8297
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8298 this.location_href = function(url, target, frame)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8299 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8300 if (frame)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8301 this.lock_frame();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8302
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8303 if (typeof url == 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8304 url = this.env.comm_path + '&' + $.param(url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8305
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8306 // simulate real link click to force IE to send referer header
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8307 if (bw.ie && target == window)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8308 $('<a>').attr('href', url).appendTo(document.body).get(0).click();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8309 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8310 target.location.href = url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8311
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8312 // reset keep-alive interval
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8313 this.start_keepalive();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8314 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8315
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8316 // update browser location to remember current view
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8317 this.update_state = function(query)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8318 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8319 if (window.history.replaceState)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8320 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8321 // This may throw security exception in Firefox (#5400)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8322 window.history.replaceState({}, document.title, rcmail.url('', query));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8324 catch(e) { /* ignore */ };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8325 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8326
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8327 // send a http request to the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8328 this.http_request = function(action, data, lock, type)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8329 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8330 if (type != 'POST')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8331 type = 'GET';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8333 if (typeof data !== 'object')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8334 data = rcube_parse_query(data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8335
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8336 data._remote = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8337 data._unlock = lock ? lock : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8338
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8339 // trigger plugin hook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8340 var result = this.triggerEvent('request' + action, data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8342 // abort if one of the handlers returned false
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8343 if (result === false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8344 if (data._unlock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8345 this.set_busy(false, null, data._unlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8346 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8347 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8348 else if (result !== undefined) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8349 data = result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8350 if (data._action) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8351 action = data._action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8352 delete data._action;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8353 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8354 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8355
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8356 var url = this.url(action);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8358 // reset keep-alive interval
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8359 this.start_keepalive();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8360
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8361 // send request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8362 return $.ajax({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8363 type: type, url: url, data: data, dataType: 'json',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8364 success: function(data) { ref.http_response(data); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8365 error: function(o, status, err) { ref.http_error(o, status, err, lock, action); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8366 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8367 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8368
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8369 // send a http GET request to the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8370 this.http_get = this.http_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8372 // send a http POST request to the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8373 this.http_post = function(action, data, lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8374 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8375 return this.http_request(action, data, lock, 'POST');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8376 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8378 // aborts ajax request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8379 this.abort_request = function(r)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8380 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8381 if (r.request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8382 r.request.abort();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8383 if (r.lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8384 this.set_busy(false, null, r.lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8385 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8386
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8387 // handle HTTP response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8388 this.http_response = function(response)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8389 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8390 if (!response)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8391 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8392
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8393 if (response.unlock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8394 this.set_busy(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8395
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8396 this.triggerEvent('responsebefore', {response: response});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8397 this.triggerEvent('responsebefore'+response.action, {response: response});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8398
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8399 // set env vars
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8400 if (response.env)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8401 this.set_env(response.env);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8402
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8403 var i;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8404
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8405 // we have labels to add
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8406 if (typeof response.texts === 'object') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8407 for (i in response.texts)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8408 if (typeof response.texts[i] === 'string')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8409 this.add_label(i, response.texts[i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8410 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8411
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8412 // if we get javascript code from server -> execute it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8413 if (response.exec) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8414 eval(response.exec);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8415 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8416
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8417 // execute callback functions of plugins
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8418 if (response.callbacks && response.callbacks.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8419 for (i=0; i < response.callbacks.length; i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8420 this.triggerEvent(response.callbacks[i][0], response.callbacks[i][1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8421 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8422
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8423 // process the response data according to the sent action
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8424 switch (response.action) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8425 case 'mark':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8426 // Mark the message as Seen also in the opener/parent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8427 if ((this.env.action == 'show' || this.env.action == 'preview') && this.env.last_flag == 'SEEN')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8428 this.set_unread_message(this.env.uid, this.env.mailbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8429 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8430
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8431 case 'delete':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8432 if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8433 var sid, uid = this.contact_list.get_selection(), writable = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8434
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8435 if (uid && this.contact_list.rows[uid]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8436 // search results, get source ID from record ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8437 if (this.env.source == '') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8438 sid = String(uid).replace(/^[^-]+-/, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8439 writable = sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8440 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8441 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8442 writable = !this.env.address_sources[this.env.source].readonly;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8443 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8444 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8445 this.enable_command('compose', (uid && this.contact_list.rows[uid]));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8446 this.enable_command('delete', 'edit', writable);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8447 this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8448 this.enable_command('export-selected', 'print', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8449 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8450
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8451 case 'move':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8452 if (this.env.action == 'show') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8453 // re-enable commands on move/delete error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8454 this.enable_command(this.env.message_commands, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8455 if (!this.env.list_post)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8456 this.enable_command('reply-list', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8457 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8458 else if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8459 this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8460 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8461
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8462 case 'purge':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8463 case 'expunge':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8464 if (this.task == 'mail') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8465 if (!this.env.exists) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8466 // clear preview pane content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8467 if (this.env.contentframe)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8468 this.show_contentframe(false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8469 // disable commands useless when mailbox is empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8470 this.enable_command(this.env.message_commands, 'purge', 'expunge',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8471 'select-all', 'select-none', 'expand-all', 'expand-unread', 'collapse-all', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8472 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8473 if (this.message_list)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8474 this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8475 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8476 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8477
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8478 case 'refresh':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8479 case 'check-recent':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8480 // update message flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8481 $.each(this.env.recent_flags || {}, function(uid, flags) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8482 ref.set_message(uid, 'deleted', flags.deleted);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8483 ref.set_message(uid, 'replied', flags.answered);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8484 ref.set_message(uid, 'unread', !flags.seen);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8485 ref.set_message(uid, 'forwarded', flags.forwarded);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8486 ref.set_message(uid, 'flagged', flags.flagged);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8487 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8488 delete this.env.recent_flags;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8489
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8490 case 'getunread':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8491 case 'search':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8492 this.env.qsearch = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8493 case 'list':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8494 if (this.task == 'mail') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8495 var is_multifolder = this.is_multifolder_listing(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8496 list = this.message_list,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8497 uid = this.env.list_uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8498
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8499 this.enable_command('show', 'select-all', 'select-none', this.env.messagecount > 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8500 this.enable_command('expunge', this.env.exists && !is_multifolder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8501 this.enable_command('purge', this.purge_mailbox_test() && !is_multifolder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8502 this.enable_command('import-messages', !is_multifolder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8503 this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading && this.env.messagecount && !is_multifolder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8504
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8505 if (list) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8506 if (response.action == 'list' || response.action == 'search') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8507 // highlight message row when we're back from message page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8508 if (uid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8509 if (!list.rows[uid])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8510 uid += '-' + this.env.mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8511 if (list.rows[uid]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8512 list.select(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8513 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8514 delete this.env.list_uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8515 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8516
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8517 this.enable_command('set-listmode', this.env.threads && !is_multifolder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8518 if (list.rowcount > 0 && !$(document.activeElement).is('input,textarea'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8519 list.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8521 // trigger 'select' so all dependent actions update its state
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8522 // e.g. plugins use this event to activate buttons (#1490647)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8523 list.triggerEvent('select');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8524 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8525
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8526 if (response.action != 'getunread')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8527 this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:list.rowcount });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8528 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8529 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8530 else if (this.task == 'addressbook') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8531 this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8532
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8533 if (response.action == 'list' || response.action == 'search') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8534 this.enable_command('search-create', this.env.source == '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8535 this.enable_command('search-delete', this.env.search_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8536 this.update_group_commands();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8537 if (this.contact_list.rowcount > 0 && !$(document.activeElement).is('input,textarea'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8538 this.contact_list.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8539 this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8540 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8542 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8543
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8544 case 'list-contacts':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8545 case 'search-contacts':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8546 if (this.contact_list && this.contact_list.rowcount > 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8547 this.contact_list.focus();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8548 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8549 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8550
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8551 if (response.unlock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8552 this.hide_message(response.unlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8553
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8554 this.triggerEvent('responseafter', {response: response});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8555 this.triggerEvent('responseafter'+response.action, {response: response});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8556
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8557 // reset keep-alive interval
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8558 this.start_keepalive();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8559 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8560
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8561 // handle HTTP request errors
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8562 this.http_error = function(request, status, err, lock, action)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8563 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8564 var errmsg = request.statusText;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8565
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8566 this.set_busy(false, null, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8567 request.abort();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8568
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8569 // don't display error message on page unload (#1488547)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8570 if (this.unload)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8571 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8572
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8573 if (request.status && errmsg)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8574 this.display_message(this.get_label('servererror') + ' (' + errmsg + ')', 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8575 else if (status == 'timeout')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8576 this.display_message(this.get_label('requesttimedout'), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8577 else if (request.status == 0 && status != 'abort')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8578 this.display_message(this.get_label('connerror'), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8579
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8580 // redirect to url specified in location header if not empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8581 var location_url = request.getResponseHeader("Location");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8582 if (location_url && this.env.action != 'compose') // don't redirect on compose screen, contents might get lost (#1488926)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8583 this.redirect(location_url);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8584
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8585 // 403 Forbidden response (CSRF prevention) - reload the page.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8586 // In case there's a new valid session it will be used, otherwise
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8587 // login form will be presented (#1488960).
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8588 if (request.status == 403) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8589 (this.is_framed() ? parent : window).location.reload();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8590 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8591 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8592
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8593 // re-send keep-alive requests after 30 seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8594 if (action == 'keep-alive')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8595 setTimeout(function(){ ref.keep_alive(); ref.start_keepalive(); }, 30000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8596 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8597
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8598 // handler for session errors detected on the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8599 this.session_error = function(redirect_url)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8600 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8601 this.env.server_error = 401;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8602
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8603 // save message in local storage and do not redirect
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8604 if (this.env.action == 'compose') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8605 this.save_compose_form_local();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8606 this.compose_skip_unsavedcheck = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8607 // stop keep-alive and refresh processes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8608 this.env.session_lifetime = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8609 if (this._keepalive)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8610 clearInterval(this._keepalive);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8611 if (this._refresh)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8612 clearInterval(this._refresh);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8613 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8614 else if (redirect_url) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8615 setTimeout(function(){ ref.redirect(redirect_url, true); }, 2000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8616 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8617 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8618
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8619 // callback when an iframe finished loading
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8620 this.iframe_loaded = function(unlock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8621 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8622 this.set_busy(false, null, unlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8623
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8624 if (this.submit_timer)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8625 clearTimeout(this.submit_timer);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8626 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8627
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8628 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8629 Send multi-threaded parallel HTTP requests to the server for a list if items.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8630 The string '%' in either a GET query or POST parameters will be replaced with the respective item value.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8631 This is the argument object expected: {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8632 items: ['foo','bar','gna'], // list of items to send requests for
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8633 action: 'task/some-action', // Roudncube action to call
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8634 query: { q:'%s' }, // GET query parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8635 postdata: { source:'%s' }, // POST data (sends a POST request if present)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8636 threads: 3, // max. number of concurrent requests
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8637 onresponse: function(data){ }, // Callback function called for every response received from server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8638 whendone: function(alldata){ } // Callback function called when all requests have been sent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8639 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8640 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8641 this.multi_thread_http_request = function(prop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8642 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8643 var i, item, reqid = new Date().getTime(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8644 threads = prop.threads || 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8645
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8646 prop.reqid = reqid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8647 prop.running = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8648 prop.requests = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8649 prop.result = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8650 prop._items = $.extend([], prop.items); // copy items
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8651
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8652 if (!prop.lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8653 prop.lock = this.display_message(this.get_label('loading'), 'loading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8654
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8655 // add the request arguments to the jobs pool
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8656 this.http_request_jobs[reqid] = prop;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8657
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8658 // start n threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8659 for (i=0; i < threads; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8660 item = prop._items.shift();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8661 if (item === undefined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8662 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8663
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8664 prop.running++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8665 prop.requests.push(this.multi_thread_send_request(prop, item));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8666 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8667
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8668 return reqid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8669 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8670
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8671 // helper method to send an HTTP request with the given iterator value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8672 this.multi_thread_send_request = function(prop, item)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8673 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8674 var k, postdata, query;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8676 // replace %s in post data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8677 if (prop.postdata) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8678 postdata = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8679 for (k in prop.postdata) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8680 postdata[k] = String(prop.postdata[k]).replace('%s', item);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8681 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8682 postdata._reqid = prop.reqid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8683 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8684 // replace %s in query
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8685 else if (typeof prop.query == 'string') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8686 query = prop.query.replace('%s', item);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8687 query += '&_reqid=' + prop.reqid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8688 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8689 else if (typeof prop.query == 'object' && prop.query) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8690 query = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8691 for (k in prop.query) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8692 query[k] = String(prop.query[k]).replace('%s', item);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8693 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8694 query._reqid = prop.reqid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8695 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8697 // send HTTP GET or POST request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8698 return postdata ? this.http_post(prop.action, postdata) : this.http_request(prop.action, query);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8699 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8700
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8701 // callback function for multi-threaded http responses
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8702 this.multi_thread_http_response = function(data, reqid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8703 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8704 var prop = this.http_request_jobs[reqid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8705 if (!prop || prop.running <= 0 || prop.cancelled)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8706 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8707
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8708 prop.running--;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8709
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8710 // trigger response callback
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8711 if (prop.onresponse && typeof prop.onresponse == 'function') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8712 prop.onresponse(data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8713 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8714
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8715 prop.result = $.extend(prop.result, data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8716
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8717 // send next request if prop.items is not yet empty
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8718 var item = prop._items.shift();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8719 if (item !== undefined) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8720 prop.running++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8721 prop.requests.push(this.multi_thread_send_request(prop, item));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8722 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8723 // trigger whendone callback and mark this request as done
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8724 else if (prop.running == 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8725 if (prop.whendone && typeof prop.whendone == 'function') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8726 prop.whendone(prop.result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8727 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8728
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8729 this.set_busy(false, '', prop.lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8730
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8731 // remove from this.http_request_jobs pool
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8732 delete this.http_request_jobs[reqid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8733 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8734 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8735
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8736 // abort a running multi-thread request with the given identifier
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8737 this.multi_thread_request_abort = function(reqid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8738 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8739 var prop = this.http_request_jobs[reqid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8740 if (prop) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8741 for (var i=0; prop.running > 0 && i < prop.requests.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8742 if (prop.requests[i].abort)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8743 prop.requests[i].abort();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8744 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8745
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8746 prop.running = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8747 prop.cancelled = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8748 this.set_busy(false, '', prop.lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8749 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8750 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8751
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8752 // post the given form to a hidden iframe
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8753 this.async_upload_form = function(form, action, onload)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8754 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8755 // create hidden iframe
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8756 var ts = new Date().getTime(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8757 frame_name = 'rcmupload' + ts,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8758 frame = this.async_upload_form_frame(frame_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8759
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8760 // upload progress support
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8761 if (this.env.upload_progress_name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8762 var fname = this.env.upload_progress_name,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8763 field = $('input[name='+fname+']', form);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8764
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8765 if (!field.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8766 field = $('<input>').attr({type: 'hidden', name: fname});
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8767 field.prependTo(form);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8768 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8770 field.val(ts);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8771 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8772
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8773 // handle upload errors by parsing iframe content in onload
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8774 frame.on('load', {ts:ts}, onload);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8775
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8776 $(form).attr({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8777 target: frame_name,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8778 action: this.url(action, {_id: this.env.compose_id || '', _uploadid: ts, _from: this.env.action}),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8779 method: 'POST'})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8780 .attr(form.encoding ? 'encoding' : 'enctype', 'multipart/form-data')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8781 .submit();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8782
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8783 return frame_name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8784 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8785
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8786 // create iframe element for files upload
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8787 this.async_upload_form_frame = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8788 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8789 return $('<iframe>').attr({name: name, style: 'border: none; width: 0; height: 0; visibility: hidden'})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8790 .appendTo(document.body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8791 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8792
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8793 // html5 file-drop API
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8794 this.document_drag_hover = function(e, over)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8795 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8796 // don't e.preventDefault() here to not block text dragging on the page (#1490619)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8797 $(this.gui_objects.filedrop)[(over?'addClass':'removeClass')]('active');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8798 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8799
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8800 this.file_drag_hover = function(e, over)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8801 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8802 e.preventDefault();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8803 e.stopPropagation();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8804 $(this.gui_objects.filedrop)[(over?'addClass':'removeClass')]('hover');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8805 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8806
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8807 // handler when files are dropped to a designated area.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8808 // compose a multipart form data and submit it to the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8809 this.file_dropped = function(e)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8810 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8811 // abort event and reset UI
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8812 this.file_drag_hover(e, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8813
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8814 // prepare multipart form data composition
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8815 var uri, size = 0, numfiles = 0,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8816 files = e.target.files || e.dataTransfer.files,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8817 formdata = window.FormData ? new FormData() : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8818 fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8819 boundary = '------multipartformboundary' + (new Date).getTime(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8820 dashdash = '--', crlf = '\r\n',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8821 multipart = dashdash + boundary + crlf,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8822 args = {_id: this.env.compose_id || this.env.cid || '', _remote: 1, _from: this.env.action};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8823
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8824 if (!files || !files.length) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8825 // Roundcube attachment, pass its uri to the backend and attach
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8826 if (uri = e.dataTransfer.getData('roundcube-uri')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8827 var ts = new Date().getTime(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8828 // jQuery way to escape filename (#1490530)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8829 content = $('<span>').text(e.dataTransfer.getData('roundcube-name') || this.get_label('attaching')).html();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8831 args._uri = uri;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8832 args._uploadid = ts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8833
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8834 // add to attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8835 if (!this.add2attachment_list(ts, {name: '', html: content, classname: 'uploading', complete: false}))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8836 this.file_upload_id = this.set_busy(true, 'attaching');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8837
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8838 this.http_post(this.env.filedrop.action || 'upload', args);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8839 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8840 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8841 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8843 // inline function to submit the files to the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8844 var submit_data = function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8845 if (ref.env.max_filesize && ref.env.filesizeerror && size > ref.env.max_filesize) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8846 ref.display_message(ref.env.filesizeerror, 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8847 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8848 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8849
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8850 if (ref.env.max_filecount && ref.env.filecounterror && numfiles > ref.env.max_filecount) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8851 ref.display_message(ref.env.filecounterror, 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8852 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8853 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8854
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8855 var multiple = files.length > 1,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8856 ts = new Date().getTime(),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8857 // jQuery way to escape filename (#1490530)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8858 content = $('<span>').text(multiple ? ref.get_label('uploadingmany') : files[0].name).html();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8859
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8860 // add to attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8861 if (!ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false }))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8862 ref.file_upload_id = ref.set_busy(true, 'uploading');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8863
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8864 // complete multipart content and post request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8865 multipart += dashdash + boundary + dashdash + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8866
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8867 args._uploadid = ts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8868
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8869 $.ajax({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8870 type: 'POST',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8871 dataType: 'json',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8872 url: ref.url(ref.env.filedrop.action || 'upload', args),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8873 contentType: formdata ? false : 'multipart/form-data; boundary=' + boundary,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8874 processData: false,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8875 timeout: 0, // disable default timeout set in ajaxSetup()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8876 data: formdata || multipart,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8877 headers: {'X-Roundcube-Request': ref.env.request_token},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8878 xhr: function() { var xhr = jQuery.ajaxSettings.xhr(); if (!formdata && xhr.sendAsBinary) xhr.send = xhr.sendAsBinary; return xhr; },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8879 success: function(data){ ref.http_response(data); },
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8880 error: function(o, status, err) { ref.http_error(o, status, err, null, 'attachment'); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8881 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8882 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8883
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8884 // get contents of all dropped files
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8885 var last = this.env.filedrop.single ? 0 : files.length - 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8886 for (var j=0, i=0, f; j <= last && (f = files[i]); i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8887 if (!f.name) f.name = f.fileName;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8888 if (!f.size) f.size = f.fileSize;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8889 if (!f.type) f.type = 'application/octet-stream';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8891 // file name contains non-ASCII characters, do UTF8-binary string conversion.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8892 if (!formdata && /[^\x20-\x7E]/.test(f.name))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8893 f.name_bin = unescape(encodeURIComponent(f.name));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8894
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8895 // filter by file type if requested
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8896 if (this.env.filedrop.filter && !f.type.match(new RegExp(this.env.filedrop.filter))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8897 // TODO: show message to user
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8898 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8899 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8900
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8901 size += f.size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8902 numfiles++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8903
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8904 // do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8905 if (formdata) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8906 formdata.append(fieldname, f);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8907 if (j == last)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8908 return submit_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8909 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8910 // use FileReader supporetd by Firefox 3.6
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8911 else if (window.FileReader) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8912 var reader = new FileReader();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8913
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8914 // closure to pass file properties to async callback function
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8915 reader.onload = (function(file, j) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8916 return function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8917 multipart += 'Content-Disposition: form-data; name="' + fieldname + '"';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8918 multipart += '; filename="' + (f.name_bin || file.name) + '"' + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8919 multipart += 'Content-Length: ' + file.size + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8920 multipart += 'Content-Type: ' + file.type + crlf + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8921 multipart += reader.result + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8922 multipart += dashdash + boundary + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8924 if (j == last) // we're done, submit the data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8925 return submit_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8926 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8927 })(f,j);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8928 reader.readAsBinaryString(f);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8929 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8930 // Firefox 3
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8931 else if (f.getAsBinary) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8932 multipart += 'Content-Disposition: form-data; name="' + fieldname + '"';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8933 multipart += '; filename="' + (f.name_bin || f.name) + '"' + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8934 multipart += 'Content-Length: ' + f.size + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8935 multipart += 'Content-Type: ' + f.type + crlf + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8936 multipart += f.getAsBinary() + crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8937 multipart += dashdash + boundary +crlf;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8938
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8939 if (j == last)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8940 return submit_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8941 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8942
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8943 j++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8944 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8945 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8946
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8947 // starts interval for keep-alive signal
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8948 this.start_keepalive = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8949 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8950 if (!this.env.session_lifetime || this.env.framed || this.env.extwin || this.task == 'login' || this.env.action == 'print')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8951 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8952
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8953 if (this._keepalive)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8954 clearInterval(this._keepalive);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8955
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8956 // use Math to prevent from an integer overflow (#5273)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8957 // maximum interval is 15 minutes, minimum is 30 seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8958 var interval = Math.min(1800, this.env.session_lifetime) * 0.5 * 1000;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8959 this._keepalive = setInterval(function() { ref.keep_alive(); }, interval < 30000 ? 30000 : interval);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8960 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8961
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8962 // starts interval for refresh signal
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8963 this.start_refresh = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8964 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8965 if (!this.env.refresh_interval || this.env.framed || this.env.extwin || this.task == 'login' || this.env.action == 'print')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8966 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8967
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8968 if (this._refresh)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8969 clearInterval(this._refresh);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8970
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8971 this._refresh = setInterval(function(){ ref.refresh(); }, this.env.refresh_interval * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8972 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8973
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8974 // sends keep-alive signal
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8975 this.keep_alive = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8976 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8977 if (!this.busy)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8978 this.http_request('keep-alive');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8979 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8980
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8981 // sends refresh signal
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8982 this.refresh = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8983 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8984 if (this.busy) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8985 // try again after 10 seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8986 setTimeout(function(){ ref.refresh(); ref.start_refresh(); }, 10000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8987 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8988 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8989
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8990 var params = {}, lock = this.set_busy(true, 'refreshing');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8992 if (this.task == 'mail' && this.gui_objects.mailboxlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8993 params = this.check_recent_params();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8994
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8995 params._last = Math.floor(this.env.lastrefresh.getTime() / 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8996 this.env.lastrefresh = new Date();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8997
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8998 // plugins should bind to 'requestrefresh' event to add own params
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8999 this.http_post('refresh', params, lock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9000 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9001
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9002 // returns check-recent request parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9003 this.check_recent_params = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9004 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9005 var params = {_mbox: this.env.mailbox};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9007 if (this.gui_objects.mailboxlist)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9008 params._folderlist = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9009 if (this.gui_objects.quotadisplay)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9010 params._quota = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9011 if (this.env.search_request)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9012 params._search = this.env.search_request;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9013
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9014 if (this.gui_objects.messagelist) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9015 params._list = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9016
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9017 // message uids for flag updates check
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9018 params._uids = $.map(this.message_list.rows, function(row, uid) { return uid; }).join(',');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9019 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9020
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9021 return params;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9022 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9023
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9024
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9025 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9026 /********* helper methods *********/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9027 /********************************************************/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9028
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9029 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9030 * Quote html entities
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9031 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9032 this.quote_html = function(str)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9033 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9034 return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9035 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9037 // get window.opener.rcmail if available
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9038 this.opener = function(deep, filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9039 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9040 var i, win = window.opener;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9041
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9042 // catch Error: Permission denied to access property rcmail
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9043 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9044 if (win && !win.closed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9045 // try parent of the opener window, e.g. preview frame
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9046 if (deep && (!win.rcmail || win.rcmail.env.framed) && win.parent && win.parent.rcmail)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9047 win = win.parent;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9048
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9049 if (win.rcmail && filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9050 for (i in filter)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9051 if (win.rcmail.env[i] != filter[i])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9052 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9053
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9054 return win.rcmail;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9055 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9056 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9057 catch (e) {}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9058 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9059
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9060 // check if we're in show mode or if we have a unique selection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9061 // and return the message uid
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9062 this.get_single_uid = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9063 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9064 var uid = this.env.uid || (this.message_list ? this.message_list.get_single_selection() : null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9065 var result = ref.triggerEvent('get_single_uid', { uid: uid });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9066 return result || uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9067 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9068
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9069 // same as above but for contacts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9070 this.get_single_cid = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9071 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9072 var cid = this.env.cid || (this.contact_list ? this.contact_list.get_single_selection() : null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9073 var result = ref.triggerEvent('get_single_cid', { cid: cid });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9074 return result || cid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9075 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9076
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9077 // get the IMP mailbox of the message with the given UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9078 this.get_message_mailbox = function(uid)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9079 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9080 var msg = (this.env.messages && uid ? this.env.messages[uid] : null) || {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9081 return msg.mbox || this.env.mailbox;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9082 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9083
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9084 // build request parameters from single message id (maybe with mailbox name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9085 this.params_from_uid = function(uid, params)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9086 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9087 if (!params)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9088 params = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9089
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9090 params._uid = String(uid).split('-')[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9091 params._mbox = this.get_message_mailbox(uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9092
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9093 return params;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9094 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9095
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9096 // gets cursor position
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9097 this.get_caret_pos = function(obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9098 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9099 if (obj.selectionEnd !== undefined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9100 return obj.selectionEnd;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9102 return obj.value.length;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9103 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9104
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9105 // moves cursor to specified position
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9106 this.set_caret_pos = function(obj, pos)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9107 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9108 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9109 if (obj.setSelectionRange)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9110 obj.setSelectionRange(pos, pos);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9111 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9112 catch(e) {} // catch Firefox exception if obj is hidden
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9113 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9115 // get selected text from an input field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9116 this.get_input_selection = function(obj)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9117 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9118 var start = 0, end = 0, normalizedValue = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9119
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9120 if (typeof obj.selectionStart == "number" && typeof obj.selectionEnd == "number") {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9121 normalizedValue = obj.value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9122 start = obj.selectionStart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9123 end = obj.selectionEnd;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9124 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9125
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9126 return {start: start, end: end, text: normalizedValue.substr(start, end-start)};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9127 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9128
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9129 // disable/enable all fields of a form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9130 this.lock_form = function(form, lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9131 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9132 if (!form || !form.elements)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9133 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9134
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9135 var n, len, elm;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9136
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9137 if (lock)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9138 this.disabled_form_elements = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9139
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9140 for (n=0, len=form.elements.length; n<len; n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9141 elm = form.elements[n];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9142
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9143 if (elm.type == 'hidden')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9144 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9145 // remember which elem was disabled before lock
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9146 if (lock && elm.disabled)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9147 this.disabled_form_elements.push(elm);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9148 else if (lock || $.inArray(elm, this.disabled_form_elements) < 0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9149 elm.disabled = lock;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9150 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9151 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9152
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9153 this.mailto_handler_uri = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9154 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9155 return location.href.split('?')[0] + '?_task=mail&_action=compose&_to=%s';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9156 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9157
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9158 this.register_protocol_handler = function(name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9159 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9160 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9161 window.navigator.registerProtocolHandler('mailto', this.mailto_handler_uri(), name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9162 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9163 catch(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9164 this.display_message(String(e), 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9165 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9166 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9167
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9168 this.check_protocol_handler = function(name, elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9169 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9170 var nav = window.navigator;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9172 if (!nav || (typeof nav.registerProtocolHandler != 'function')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9173 $(elem).addClass('disabled').click(function(){ return false; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9174 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9175 else if (typeof nav.isProtocolHandlerRegistered == 'function') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9176 var status = nav.isProtocolHandlerRegistered('mailto', this.mailto_handler_uri());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9177 if (status)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9178 $(elem).parent().find('.mailtoprotohandler-status').html(status);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9179 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9180 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9181 $(elem).click(function() { ref.register_protocol_handler(name); return false; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9182 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9183 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9185 // Checks browser capabilities eg. PDF support, TIF support
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9186 this.browser_capabilities_check = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9187 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9188 if (!this.env.browser_capabilities)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9189 this.env.browser_capabilities = {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9190
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9191 $.each(['pdf', 'flash', 'tiff', 'webp'], function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9192 if (ref.env.browser_capabilities[this] === undefined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9193 ref.env.browser_capabilities[this] = ref[this + '_support_check']();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9194 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9195 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9196
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9197 // Returns browser capabilities string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9198 this.browser_capabilities = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9199 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9200 if (!this.env.browser_capabilities)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9201 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9202
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9203 var n, ret = [];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9205 for (n in this.env.browser_capabilities)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9206 ret.push(n + '=' + this.env.browser_capabilities[n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9207
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9208 return ret.join();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9209 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9210
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9211 this.tiff_support_check = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9212 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9213 this.image_support_check('tiff');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9214 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9215 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9216
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9217 this.webp_support_check = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9218 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9219 this.image_support_check('webp');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9220 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9221 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9222
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9223 this.image_support_check = function(type)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9224 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9225 window.setTimeout(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9226 var img = new Image();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9227 img.onload = function() { ref.env.browser_capabilities[type] = 1; };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9228 img.onerror = function() { ref.env.browser_capabilities[type] = 0; };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9229 img.src = ref.assets_path('program/resources/blank.' + type);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9230 }, 10);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9231 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9232
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9233 this.pdf_support_check = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9234 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9235 var i, plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {},
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9236 plugins = navigator.plugins,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9237 len = plugins.length,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9238 regex = /Adobe Reader|PDF|Acrobat/i;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9239
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9240 if (plugin && plugin.enabledPlugin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9241 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9243 if ('ActiveXObject' in window) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9244 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9245 if (plugin = new ActiveXObject("AcroPDF.PDF"))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9246 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9247 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9248 catch (e) {}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9249 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9250 if (plugin = new ActiveXObject("PDF.PdfCtrl"))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9251 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9252 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9253 catch (e) {}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9254 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9255
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9256 for (i=0; i<len; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9257 plugin = plugins[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9258 if (typeof plugin === 'String') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9259 if (regex.test(plugin))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9260 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9261 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9262 else if (plugin.name && regex.test(plugin.name))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9263 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9264 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9265
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9266 window.setTimeout(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9267 $('<object>').attr({
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9268 data: ref.assets_path('program/resources/dummy.pdf'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9269 type: 'application/pdf',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9270 style: 'position: "absolute"; top: -1000px; height: 1px; width: 1px'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9271 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9272 .on('load error', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9273 ref.env.browser_capabilities.pdf = e.type == 'load' ? 1 : 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9274 $(this).remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9275 })
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9276 .appendTo($('body'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9277 }, 10);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9278
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9279 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9280 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9281
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9282 this.flash_support_check = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9283 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9284 var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/x-shockwave-flash"] : {};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9285
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9286 if (plugin && plugin.enabledPlugin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9287 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9288
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9289 if ('ActiveXObject' in window) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9290 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9291 if (plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9292 return 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9293 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9294 catch (e) {}
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9295 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9296
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9297 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9298 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9299
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9300 this.assets_path = function(path)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9301 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9302 if (this.env.assets_path && !path.startsWith(this.env.assets_path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9303 path = this.env.assets_path + path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9304 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9305
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9306 return path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9307 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9308
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9309 // Cookie setter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9310 this.set_cookie = function(name, value, expires)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9311 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9312 setCookie(name, value, expires, this.env.cookie_path, this.env.cookie_domain, this.env.cookie_secure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9313 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9314
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9315 this.get_local_storage_prefix = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9316 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9317 if (!this.local_storage_prefix)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9318 this.local_storage_prefix = 'roundcube.' + (this.env.user_id || 'anonymous') + '.';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9319
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9320 return this.local_storage_prefix;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9321 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9322
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9323 // wrapper for localStorage.getItem(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9324 this.local_storage_get_item = function(key, deflt, encrypted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9325 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9326 var item, result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9327
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9328 // TODO: add encryption
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9329 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9330 item = localStorage.getItem(this.get_local_storage_prefix() + key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9331 result = JSON.parse(item);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9332 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9333 catch (e) { }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9334
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9335 return result || deflt || null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9336 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9338 // wrapper for localStorage.setItem(key, data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9339 this.local_storage_set_item = function(key, data, encrypted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9340 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9341 // try/catch to handle no localStorage support, but also error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9342 // in Safari-in-private-browsing-mode where localStorage exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9343 // but can't be used (#1489996)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9344 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9345 // TODO: add encryption
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9346 localStorage.setItem(this.get_local_storage_prefix() + key, JSON.stringify(data));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9347 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9349 catch (e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9350 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9351 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9352 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9353
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9354 // wrapper for localStorage.removeItem(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9355 this.local_storage_remove_item = function(key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9356 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9357 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9358 localStorage.removeItem(this.get_local_storage_prefix() + key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9359 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9360 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9361 catch (e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9362 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9363 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9364 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9365
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9366 this.print_dialog = function()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9367 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9368 if (bw.safari)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9369 setTimeout('window.print()', 10);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9370 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9371 window.print();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9372 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9373 } // end object rcube_webmail
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9374
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9375
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9376 // some static methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9377 rcube_webmail.long_subject_title = function(elem, indent)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9378 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9379 if (!elem.title) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9380 var $elem = $(elem);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9381 if ($elem.width() + (indent || 0) * 15 > $elem.parent().width())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9382 elem.title = rcube_webmail.subject_text(elem);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9383 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9384 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9385
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9386 rcube_webmail.long_subject_title_ex = function(elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9387 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9388 if (!elem.title) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9389 var $elem = $(elem),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9390 txt = $.trim($elem.text()),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9391 tmp = $('<span>').text(txt)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9392 .css({'position': 'absolute', 'float': 'left', 'visibility': 'hidden',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9393 'font-size': $elem.css('font-size'), 'font-weight': $elem.css('font-weight')})
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9394 .appendTo($('body')),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9395 w = tmp.width();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9396
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9397 tmp.remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9398 if (w + $('span.branch', $elem).width() * 15 > $elem.width())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9399 elem.title = rcube_webmail.subject_text(elem);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9400 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9401 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9402
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9403 rcube_webmail.subject_text = function(elem)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9404 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9405 var t = $(elem).clone();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9406 t.find('.skip-on-drag,.skip-content,.voice').remove();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9407 return t.text();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9408 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9409
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9410 // set event handlers on all iframe elements (and their contents)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9411 rcube_webmail.set_iframe_events = function(events)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9412 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9413 $('iframe').each(function() {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9414 var frame = $(this);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9415 $.each(events, function(event_name, event_handler) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9416 frame.on('load', function(e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9417 try { $(this).contents().on(event_name, event_handler); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9418 catch (e) {/* catch possible permission error in IE */ }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9419 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9420
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9421 try { frame.contents().on(event_name, event_handler); }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9422 catch (e) {/* catch possible permission error in IE */ }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9423 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9424 });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9425 };
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9426
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9427 rcube_webmail.prototype.get_cookie = getCookie;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9428
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9429 // copy event engine prototype
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9430 rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9431 rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9432 rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent;