- Improve photo actions handling (set name of upload-photo, disable delete-photo according to photo existance), code cleanup

release-0.6
alecpl 14 years ago
parent 5852db96d7
commit e505519d1a

@ -326,20 +326,7 @@ function rcube_webmail()
if ((this.env.action == 'add' || this.env.action == 'edit') && this.gui_objects.editform) {
this.enable_command('save', true);
this.enable_command('upload-photo', this.env.coltypes.photo ? true : false);
this.enable_command('delete-photo', this.env.coltypes.photo && this.env.action == 'edit');
for (var col in this.env.coltypes)
this.init_edit_field(col, null);
$('.contactfieldgroup .row a.deletebutton').click(function(){ ref.delete_edit_field(this); return false });
$('select.addfieldmenu').change(function(e){
ref.insert_edit_field($(this).val(), $(this).attr('rel'), this);
this.selectedIndex = 0;
});
$("input[type='text']:visible").first().focus();
this.init_contact_form();
}
else if (this.gui_objects.qsearchbox) {
this.enable_command('search', 'reset-search', 'moveto', true);
@ -3840,6 +3827,28 @@ function rcube_webmail()
this.enable_command('export', (this.contact_list.rowcount > 0));
};
this.init_contact_form = function()
{
var ref = this, col;
this.set_photo_actions($('#ff_photo').val());
for (col in this.env.coltypes)
this.init_edit_field(col, null);
$('.contactfieldgroup .row a.deletebutton').click(function() {
ref.delete_edit_field(this);
return false;
});
$('select.addfieldmenu').change(function(e) {
ref.insert_edit_field($(this).val(), $(this).attr('rel'), this);
this.selectedIndex = 0;
});
$("input[type='text']:visible").first().focus();
};
this.group_create = function()
{
if (!this.gui_objects.folderlist || !this.env.address_sources[this.env.source].groups)
@ -4139,17 +4148,11 @@ function rcube_webmail()
this.replace_contact_photo = function(id)
{
$('#ff_photo').val(id);
var buttons = this.buttons['upload-photo'];
for (var n=0; n < buttons.length; n++)
$('#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto'));
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.gui_objects.contactphoto).children('img').attr('src', img_src);
this.enable_command('delete-photo', id != '-del-');
this.set_photo_actions(id);
$(this.gui_objects.contactphoto).children('img').attr('src', img_src);
};
this.photo_upload_end = function()
@ -4158,6 +4161,17 @@ function rcube_webmail()
delete this.photo_upload_id;
};
this.set_photo_actions = function(id)
{
var n, buttons = this.buttons['upload-photo'];
for (n=0; 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-');
};
/*********************************************************/
/********* user settings methods *********/

@ -558,28 +558,31 @@ function rcmail_contact_photo($attrib)
{
global $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG;
if (!$CONTACT_COLTYPES['photo'])
return '';
if ($result = $CONTACTS->get_result())
$record = $result->first();
$photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/blank.gif';
unset($attrib['placeholder']);
if ($CONTACT_COLTYPES['photo']) {
$RCMAIL->output->set_env('photo_placeholder', $photo_img);
unset($attrib['placeholder']);
if (strpos($record['photo'], 'http:') === 0)
$photo_img = $record['photo'];
else if ($record['photo'])
$photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source']));
else
$ff_value = '-del-'; // will disable delete-photo action
$img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => ''));
$content = html::div($attrib, $img);
if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') {
$RCMAIL->output->add_gui_object('contactphoto', $attrib['id']);
$hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo'));
$hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value));
$content .= $hidden->show();
}
}
return $content;
}

Loading…
Cancel
Save