From ecf295f6ef2b83c5e51cc74adf833fd8e18b6cfb Mon Sep 17 00:00:00 2001 From: alecpl Date: Tue, 14 Jun 2011 13:45:26 +0000 Subject: - Added searching in all addressbook sources (global-search) - Added addressbook source selection in contacts import --- program/js/app.js | 87 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js index 88297e91d..2c8fad6d2 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -336,7 +336,7 @@ function rcube_webmail() if (this.contact_list && this.contact_list.rowcount > 0) this.enable_command('export', true); - this.enable_command('add', 'import', !this.env.readonly); + this.enable_command('add', 'import', this.env.writable_source); this.enable_command('list', 'listgroup', 'advanced-search', true); break; @@ -529,12 +529,12 @@ function rcube_webmail() if (this.env.trash_mailbox) this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage'); } - else if (this.task=='addressbook') { + else if (this.task == 'addressbook') { if (!this.env.search_request || (props != this.env.source)) this.reset_qsearch(); this.list_contacts(props); - this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[this.env.source].readonly)); + this.enable_command('add', 'import', this.env.writable_source); } break; @@ -988,8 +988,14 @@ function rcube_webmail() if (s && this.env.mailbox) this.list_mailbox(this.env.mailbox); - else if (s && this.task == 'addressbook') + else if (s && this.task == 'addressbook') { + if (this.env.source == '') { + for (var n in this.env.address_sources) break; + this.env.source = n; + this.env.group = ''; + } this.list_contacts(this.env.source, this.env.group); + } break; case 'listgroup': @@ -3651,15 +3657,34 @@ function rcube_webmail() if (this.preview_timer) clearTimeout(this.preview_timer); - var id, frame, ref = this; + var n, id, sid, ref = this, writable = false, + source = this.env.source ? this.env.address_sources[this.env.source] : null; + if (id = list.get_single_selection()) this.preview_timer = window.setTimeout(function(){ ref.load_contact(id, 'show'); }, 200); else if (this.env.contentframe) this.show_contentframe(false); + // no source = search result, we'll need to detect if any of + // selected contacts are in writable addressbook to enable edit/delete + if (list.selection.length) { + if (!source) { + for (n in list.selection) { + sid = String(list.selection[n]).replace(/^[^-]+-/, ''); + if (sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly) { + writable = true; + break; + } + } + } + else { + writable = !source.readonly; + } + } + this.enable_command('compose', list.selection.length > 0); - this.enable_command('edit', (id && this.env.address_sources && !this.env.address_sources[this.env.source].readonly) ? true : false); - this.enable_command('delete', list.selection.length && this.env.address_sources && !this.env.address_sources[this.env.source].readonly); + this.enable_command('edit', id && writable); + this.enable_command('delete', list.selection.length && writable); return false; }; @@ -3797,12 +3822,12 @@ function rcube_webmail() if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm'))) return; - var id, a_cids = [], qs = ''; + var id, n, a_cids = [], qs = ''; if (this.env.cid) a_cids.push(this.env.cid); else { - for (var n=0; n 1 || this.env.group != '') { + this.select_folder('', (this.env.group ? 'G'+this.env.source+this.env.group : this.env.source)); + this.env.group = ''; + this.env.source = ''; + } + }; + /*********************************************************/ /********* user settings methods *********/ @@ -5468,9 +5499,20 @@ function rcube_webmail() switch (response.action) { case 'delete': if (this.task == 'addressbook') { - var uid = this.contact_list.get_selection(); + var sid, uid = this.contact_list.get_selection(), writable = false; + + if (uid && this.contact_list.rows[uid]) { + // search results, get source ID from record ID + if (this.env.source == '') { + sid = String(uid).replace(/^[^-]+-/, ''); + writable = sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly; + } + else { + writable = !this.env.address_sources[this.env.source].readonly; + } + } this.enable_command('compose', (uid && this.contact_list.rows[uid])); - this.enable_command('delete', 'edit', (uid && this.contact_list.rows[uid] && this.env.address_sources && !this.env.address_sources[this.env.source].readonly)); + this.enable_command('delete', 'edit', writable); this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0)); } @@ -5519,10 +5561,9 @@ function rcube_webmail() this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0)); if (response.action == 'list' || response.action == 'search') { - this.enable_command('group-create', - (this.env.address_sources[this.env.source].groups && !this.env.address_sources[this.env.source].readonly)); - this.enable_command('group-rename', 'group-delete', - (this.env.address_sources[this.env.source].groups && this.env.group && !this.env.address_sources[this.env.source].readonly)); + var source = this.env.source != '' ? this.env.address_sources[this.env.source] : null; + this.enable_command('group-create', (source && source.groups && !source.readonly)); + this.enable_command('group-rename', 'group-delete', (source && source.groups && this.env.group && !source.readonly)); this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount }); } } @@ -5580,7 +5621,7 @@ function rcube_webmail() return frame_name; }; - + // starts interval for keep-alive/check-recent signal this.start_keepalive = function() { -- cgit v1.2.3