summaryrefslogtreecommitdiff
path: root/program/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'program/js/app.js')
-rw-r--r--program/js/app.js163
1 files changed, 134 insertions, 29 deletions
diff --git a/program/js/app.js b/program/js/app.js
index bba796f20..4c9b11a1f 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -843,14 +843,14 @@ function rcube_webmail()
case 'move':
case 'moveto': // deprecated
if (this.task == 'mail')
- this.move_messages(props);
+ this.move_messages(props, obj);
else if (this.task == 'addressbook')
this.move_contacts(props);
break;
case 'copy':
if (this.task == 'mail')
- this.copy_messages(props);
+ this.copy_messages(props, obj);
else if (this.task == 'addressbook')
this.copy_contacts(props);
break;
@@ -1412,8 +1412,6 @@ function rcube_webmail()
this.drag_start = function(list)
{
- var model = this.task == 'mail' ? this.env.mailboxes : this.env.contactfolders;
-
this.drag_active = true;
if (this.preview_timer)
@@ -2613,10 +2611,12 @@ function rcube_webmail()
};
// copy selected messages to the specified mailbox
- this.copy_messages = function(mbox)
+ this.copy_messages = function(mbox, obj)
{
if (mbox && typeof mbox === 'object')
mbox = mbox.id;
+ else if (!mbox)
+ return this.folder_selector(obj, function(folder) { ref.command('copy', folder); });
// exit if current or no mailbox specified
if (!mbox || mbox == this.env.mailbox)
@@ -2633,10 +2633,12 @@ function rcube_webmail()
};
// move selected messages to the specified mailbox
- this.move_messages = function(mbox)
+ this.move_messages = function(mbox, obj)
{
if (mbox && typeof mbox === 'object')
mbox = mbox.id;
+ else if (!mbox)
+ return this.folder_selector(obj, function(folder) { ref.command('move', folder); });
// exit if current or no mailbox specified
if (!mbox || mbox == this.env.mailbox)
@@ -2663,20 +2665,7 @@ function rcube_webmail()
// delete selected messages from the current mailbox
this.delete_messages = function(event)
{
- var uid, i, len, trash = this.env.trash_mailbox,
- list = this.message_list,
- selection = list ? list.get_selection() : [];
-
- // exit if no mailbox specified or if selection is empty
- if (!this.env.uid && !selection.length)
- return;
-
- // also select childs of collapsed rows
- for (i=0, len=selection.length; i<len; i++) {
- uid = selection[i];
- if (list.rows[uid].has_children && !list.rows[uid].expanded)
- list.select_children(uid);
- }
+ var list = this.message_list, trash = this.env.trash_mailbox;
// if config is set to flag for deletion
if (this.env.flag_for_deletion) {
@@ -2716,7 +2705,7 @@ function rcube_webmail()
this._with_selected_messages('delete', post_data);
};
- // Send a specifc move/delete request with UIDs of all selected messages
+ // Send a specific move/delete request with UIDs of all selected messages
// @private
this._with_selected_messages = function(action, post_data, lock)
{
@@ -5758,19 +5747,23 @@ function rcube_webmail()
.prop({checked: subscribed ? true : false, disabled: is_protected ? true : false});
// add to folder/row-ID map
- this.env.subscriptionrows[id] = [name, display_name, 0];
+ this.env.subscriptionrows[id] = [name, display_name, false];
// sort folders (to find a place where to insert the row)
// replace delimiter with \0 character to fix sorting
// issue where 'Abc Abc' would be placed before 'Abc/def'
var replace_from = RegExp(RegExp.escape(this.env.delimiter), 'g'),
replace_to = String.fromCharCode(0);
+
$.each(this.env.subscriptionrows, function(k,v) {
- var n = v[0];
- n = n.replace(replace_from, replace_to);
- v.push(n);
+ if (v.length < 4) {
+ var n = v[0];
+ n = n.replace(replace_from, replace_to);
+ v.push(n);
+ }
folders.push(v);
});
+
folders.sort(function(a, b) {
var len = a.length - 1; n1 = a[len], n2 = b[len];
return n1 < n2 ? -1 : 1;
@@ -6563,6 +6556,105 @@ function rcube_webmail()
elem.onclick = function() { rcmail.command('show-headers', '', elem); };
};
+ // create folder selector popup, position and display it
+ this.folder_selector = function(obj, callback)
+ {
+ var container = this.folder_selector_element;
+
+ if (!container) {
+ var rows = [],
+ delim = this.env.delimiter,
+ ul = $('<ul class="toolbarmenu iconized">'),
+ li = document.createElement('li'),
+ link = document.createElement('a'),
+ span = document.createElement('span');
+
+ container = $('<div id="folder-selector" class="popupmenu"></div>');
+ link.href = '#';
+ link.className = 'icon';
+
+ // loop over sorted folders list
+ $.each(this.env.mailboxes_list, function() {
+ var tmp, n = 0, s = 0,
+ folder = ref.env.mailboxes[this],
+ id = folder.id,
+ a = link.cloneNode(false), row = li.cloneNode(false);
+
+ if (folder.virtual)
+ a.className += ' virtual';
+ else {
+ a.className += ' active';
+ a.onclick = function() { container.hide().data('callback')(folder.id); };
+ }
+
+ if (folder['class'])
+ a.className += ' ' + folder['class'];
+
+ // calculate/set indentation level
+ while ((s = id.indexOf(delim, s)) >= 0) {
+ n++; s++;
+ }
+ a.style.paddingLeft = n ? (n * 16) + 'px' : 0;
+
+ // add folder name element
+ tmp = span.cloneNode(false);
+ $(tmp).text(folder.name);
+ a.appendChild(tmp);
+
+ row.appendChild(a);
+ rows.push(row);
+ });
+
+ ul.append(rows).appendTo(container);
+
+ // temporarily show element to calculate its size
+ container.css({left: '-1000px', top: '-1000px'})
+ .appendTo($('body')).show();
+
+ // set max-height if the list is long
+ if (rows.length > 10)
+ container.css('max-height', $('li', container)[0].offsetHeight * 10 + 9)
+
+ // hide selector on click out of selector element
+ var fn = function(e) { if (e.target != container.get(0)) container.hide(); };
+ $(document.body).on('mouseup', fn);
+ $('iframe').contents().on('mouseup', fn)
+ .load(function(e) { try { $(this).contents().on('mouseup', fn); } catch(e) {}; });
+
+ this.folder_selector_element = container;
+ }
+
+ // position menu on the screen
+ this.element_position(container, obj);
+
+ container.show().data('callback', callback);
+ };
+
+ // position a menu element on the screen in relation to other object
+ this.element_position = function(element, obj)
+ {
+ var obj = $(obj), win = $(window),
+ width = obj.width(),
+ height = obj.height(),
+ win_height = win.height(),
+ elem_height = $(element).height(),
+ elem_width = $(element).width(),
+ pos = obj.offset(),
+ top = pos.top,
+ left = pos.left + width;
+
+ if (top + elem_height > win_height) {
+ top -= elem_height - height;
+ if (top < 0)
+ top = Math.max(0, (win_height - elem_height) / 2);
+ }
+
+ if (left + elem_width > win.width())
+ left -= elem_width + width;
+
+ element.css({left: left + 'px', top: top + 'px'});
+ };
+
/********************************************************/
/********* html to text conversion functions *********/
@@ -6832,6 +6924,16 @@ function rcube_webmail()
case 'refresh':
case 'check-recent':
+ // update message flags
+ $.each(this.env.recent_flags || {}, function(uid, flags) {
+ ref.set_message(uid, 'deleted', flags.deleted);
+ ref.set_message(uid, 'replied', flags.answered);
+ ref.set_message(uid, 'unread', !flags.seen);
+ ref.set_message(uid, 'forwarded', flags.forwarded);
+ ref.set_message(uid, 'flagged', flags.flagged);
+ });
+ delete this.env.recent_flags;
+
case 'getunread':
case 'search':
this.env.qsearch = null;
@@ -6844,7 +6946,6 @@ function rcube_webmail()
if ((response.action == 'list' || response.action == 'search') && this.message_list) {
this.msglist_select(this.message_list);
- this.message_list.resize();
this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
}
}
@@ -6855,7 +6956,6 @@ function rcube_webmail()
this.enable_command('search-create', this.env.source == '');
this.enable_command('search-delete', this.env.search_id);
this.update_group_commands();
- this.contact_list.resize();
this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
}
}
@@ -7157,13 +7257,18 @@ function rcube_webmail()
if (this.gui_objects.mailboxlist)
params._folderlist = 1;
- if (this.gui_objects.messagelist)
- params._list = 1;
if (this.gui_objects.quotadisplay)
params._quota = 1;
if (this.env.search_request)
params._search = this.env.search_request;
+ if (this.gui_objects.messagelist) {
+ params._list = 1;
+
+ // message uids for flag updates check
+ params._uids = $.map(this.message_list.rows, function(row, uid) { return uid; }).join(',');
+ }
+
return params;
};