+ this.delete_edit_field = function(elem)
+ {
+ var col = $(elem).attr('rel'),
+ colprop = this.env.coltypes[col],
+ fieldset = $(elem).parents('fieldset.contactfieldgroup'),
+ addmenu = fieldset.parent().find('select.addfieldmenu');
+
+ // just clear input but don't hide the last field
+ if (--colprop.count <= 0 && colprop.visible)
+ $(elem).parent().children('input').val('').blur();
+ else {
+ $(elem).parents('div.row').remove();
+ // hide entire fieldset if no more rows
+ if (!fieldset.children('div.row').length)
+ fieldset.hide();
+ }
+
+ // enable option in add-field selector or insert it if necessary
+ if (addmenu.length) {
+ var option = addmenu.children('option[value="'+col+'"]');
+ if (option.length)
+ option.prop('disabled', false);
+ else
+ option = $('<option>').attr('value', col).html(colprop.label).appendTo(addmenu);
+ addmenu.show();
+ }
+ };
+
+ this.upload_contact_photo = function(form)
+ {
+ if (form && form.elements._photo.value) {
+ this.async_upload_form(form, 'upload-photo', function(e) {
+ rcmail.set_busy(false, null, rcmail.photo_upload_id);
+ });
+
+ // display upload indicator
+ this.photo_upload_id = this.set_busy(true, 'uploading');
+ }
+ };
+
+ this.replace_contact_photo = function(id)
+ {
+ var img_src = id == '-del-' ? this.env.photo_placeholder :
+ this.env.comm_path + '&_action=photo&_source=' + this.env.source + '&_cid=' + this.env.cid + '&_photo=' + id;
+
+ this.set_photo_actions(id);
+ $(this.gui_objects.contactphoto).children('img').attr('src', img_src);
+ };
+
+ this.photo_upload_end = function()
+ {
+ this.set_busy(false, null, this.photo_upload_id);
+ delete this.photo_upload_id;
+ };
+
+ this.set_photo_actions = function(id)
+ {
+ var n, buttons = this.buttons['upload-photo'];
+ for (n=0; buttons && n < buttons.length; n++)
+ $('#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto'));
+
+ $('#ff_photo').val(id);
+ this.enable_command('upload-photo', this.env.coltypes.photo ? true : false);
+ this.enable_command('delete-photo', this.env.coltypes.photo && id != '-del-');
+ };
+
+ // load advanced search page
+ this.advanced_search = function()
+ {
+ var add_url = '&_form=1', target = window;
+
+ if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
+ add_url += '&_framed=1';
+ target = window.frames[this.env.contentframe];
+ this.contact_list.clear_selection();
+ }
+
+ this.location_href(this.env.comm_path+'&_action=search'+add_url, target, true);
+
+ return true;
+ };
+
+ // unselect directory/group
+ this.unselect_directory = function()
+ {
+ this.select_folder('');
+ this.enable_command('search-delete', false);
+ };
+
+ // callback for creating a new saved search record
+ this.insert_saved_search = function(name, id)
+ {
+ this.reset_add_input();
+
+ var key = 'S'+id,
+ link = $('<a>').attr('href', '#')
+ .attr('rel', id)
+ .click(function() { return rcmail.command('listsearch', id, this); })
+ .html(name),
+ li = $('<li>').attr({id: 'rcmli' + this.html_identifier(key), 'class': 'contactsearch'})
+ .append(link),
+ prop = {name:name, id:id, li:li[0]};
+
+ this.add_saved_search_row(prop, li);
+ this.select_folder('S'+id);
+ this.enable_command('search-delete', true);
+ this.env.search_id = id;
+
+ this.triggerEvent('abook_search_insert', prop);
+ };
+
+ // add saved search row to the list, with sorting
+ this.add_saved_search_row = function(prop, li, reloc)
+ {
+ var row, sibling, name = prop.name.toUpperCase();
+
+ // When renaming groups, we need to remove it from DOM and insert it in the proper place
+ if (reloc) {
+ row = li.clone(true);
+ li.remove();
+ }
+ else
+ row = li;
+
+ $('li[class~="contactsearch"]', this.gui_objects.folderlist).each(function(i, elem) {
+ if (!sibling)
+ sibling = this.previousSibling;
+
+ if (name >= $(this).text().toUpperCase())
+ sibling = elem;
+ else
+ return false;
+ });
+
+ if (sibling)
+ row.insertAfter(sibling);
+ else
+ row.appendTo(this.gui_objects.folderlist);
+ };
+
+ // creates an input for saved search name
+ this.search_create = function()
+ {
+ this.add_input_row('contactsearch');
+ };
+
+ this.search_delete = function()
+ {
+ if (this.env.search_request) {
+ var lock = this.set_busy(true, 'savedsearchdeleting');
+ this.http_post('search-delete', '_sid='+urlencode(this.env.search_id), lock);
+ }
+ };
+
+ // callback from server upon search-delete command
+ this.remove_search_item = function(id)
+ {
+ var li, key = 'S'+id;
+ if ((li = this.get_folder_li(key))) {
+ this.triggerEvent('search_delete', { id:id, li:li });
+
+ li.parentNode.removeChild(li);
+ }
+
+ this.env.search_id = null;
+ this.env.search_request = null;
+ this.list_contacts_clear();
+ this.reset_qsearch();
+ this.enable_command('search-delete', 'search-create', false);
+ };
+
+ this.listsearch = function(id)
+ {
+ var folder, lock = this.set_busy(true, 'searching');
+
+ if (this.contact_list) {
+ this.list_contacts_clear();
+ }
+
+ this.reset_qsearch();
+ this.select_folder('S'+id);
+
+ // reset vars
+ this.env.current_page = 1;
+ this.http_request('search', '_sid='+urlencode(id), lock);
+ };
+
+
+ /*********************************************************/
+ /********* user settings methods *********/
+ /*********************************************************/
+