Changeset 4707 in subversion


Ignore:
Timestamp:
Apr 27, 2011 5:43:10 AM (2 years ago)
Author:
alec
Message:
  • Improve photo actions handling (set name of upload-photo, disable delete-photo according to photo existance), code cleanup
Location:
trunk/roundcubemail/program
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/js/app.js

    r4697 r4707  
    325325        } 
    326326 
    327         if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) { 
     327        if ((this.env.action == 'add' || this.env.action == 'edit') && this.gui_objects.editform) { 
    328328          this.enable_command('save', true); 
    329           this.enable_command('upload-photo', this.env.coltypes.photo ? true : false); 
    330           this.enable_command('delete-photo', this.env.coltypes.photo && this.env.action == 'edit'); 
    331  
    332           for (var col in this.env.coltypes) 
    333             this.init_edit_field(col, null); 
    334  
    335           $('.contactfieldgroup .row a.deletebutton').click(function(){ ref.delete_edit_field(this); return false }); 
    336  
    337           $('select.addfieldmenu').change(function(e){ 
    338             ref.insert_edit_field($(this).val(), $(this).attr('rel'), this); 
    339             this.selectedIndex = 0; 
    340           }); 
    341  
    342           $("input[type='text']:visible").first().focus(); 
     329          this.init_contact_form(); 
    343330        } 
    344331        else if (this.gui_objects.qsearchbox) { 
     
    357344        this.enable_command('preferences', 'identities', 'save', 'folders', true); 
    358345 
    359         if (this.env.action=='identities') { 
     346        if (this.env.action == 'identities') { 
    360347          this.enable_command('add', this.env.identities_level < 2); 
    361348        } 
    362         else if (this.env.action=='edit-identity' || this.env.action=='add-identity') { 
     349        else if (this.env.action == 'edit-identity' || this.env.action == 'add-identity') { 
    363350          this.enable_command('add', this.env.identities_level < 2); 
    364351          this.enable_command('save', 'delete', 'edit', 'toggle-editor', true); 
    365352        } 
    366         else if (this.env.action=='folders') { 
     353        else if (this.env.action == 'folders') { 
    367354          this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true); 
    368355        } 
     
    35993586    if (this.ksearch_pane) 
    36003587      this.ksearch_pane.hide(); 
    3601   }; 
     3588   }; 
    36023589 
    36033590 
     
    38393826 
    38403827    this.enable_command('export', (this.contact_list.rowcount > 0)); 
     3828  }; 
     3829 
     3830  this.init_contact_form = function() 
     3831  { 
     3832    var ref = this, col; 
     3833 
     3834    this.set_photo_actions($('#ff_photo').val()); 
     3835 
     3836    for (col in this.env.coltypes) 
     3837      this.init_edit_field(col, null); 
     3838 
     3839    $('.contactfieldgroup .row a.deletebutton').click(function() { 
     3840      ref.delete_edit_field(this); 
     3841      return false; 
     3842    }); 
     3843 
     3844    $('select.addfieldmenu').change(function(e) { 
     3845      ref.insert_edit_field($(this).val(), $(this).attr('rel'), this); 
     3846      this.selectedIndex = 0; 
     3847    }); 
     3848 
     3849    $("input[type='text']:visible").first().focus(); 
    38413850  }; 
    38423851 
     
    41374146    } 
    41384147  }; 
    4139    
     4148 
    41404149  this.replace_contact_photo = function(id) 
    41414150  { 
    4142     $('#ff_photo').val(id); 
    4143      
    4144     var buttons = this.buttons['upload-photo']; 
    4145     for (var n=0; n < buttons.length; n++) 
    4146       $('#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto')); 
    4147      
    41484151    var img_src = id == '-del-' ? this.env.photo_placeholder : 
    41494152      this.env.comm_path + '&_action=photo&_source=' + this.env.source + '&_cid=' + this.env.cid + '&_photo=' + id; 
     4153 
     4154    this.set_photo_actions(id); 
    41504155    $(this.gui_objects.contactphoto).children('img').attr('src', img_src); 
    4151      
    4152     this.enable_command('delete-photo', id != '-del-'); 
    4153   }; 
    4154    
     4156  }; 
     4157 
    41554158  this.photo_upload_end = function() 
    41564159  { 
    41574160    this.set_busy(false, null, this.photo_upload_id); 
    41584161    delete this.photo_upload_id; 
     4162  }; 
     4163 
     4164  this.set_photo_actions = function(id) 
     4165  { 
     4166    var n, buttons = this.buttons['upload-photo']; 
     4167    for (n=0; n < buttons.length; n++) 
     4168      $('#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto')); 
     4169 
     4170    $('#ff_photo').val(id); 
     4171    this.enable_command('upload-photo', this.env.coltypes.photo ? true : false); 
     4172    this.enable_command('delete-photo', this.env.coltypes.photo && id != '-del-'); 
    41594173  }; 
    41604174 
  • trunk/roundcubemail/program/steps/addressbook/func.inc

    r4575 r4707  
    558558{ 
    559559    global $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG; 
    560      
     560 
     561    if (!$CONTACT_COLTYPES['photo']) 
     562        return ''; 
     563 
    561564    if ($result = $CONTACTS->get_result()) 
    562565        $record = $result->first(); 
    563      
     566 
    564567    $photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/blank.gif'; 
     568    $RCMAIL->output->set_env('photo_placeholder', $photo_img); 
    565569    unset($attrib['placeholder']); 
    566      
    567     if ($CONTACT_COLTYPES['photo']) { 
    568         $RCMAIL->output->set_env('photo_placeholder', $photo_img); 
    569          
    570         if (strpos($record['photo'], 'http:') === 0) 
    571             $photo_img = $record['photo']; 
    572         else if ($record['photo']) 
    573             $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source'])); 
    574         $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => '')); 
    575         $content = html::div($attrib, $img); 
    576        
    577         if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') { 
    578             $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']); 
    579             $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo')); 
    580             $content .= $hidden->show(); 
    581         } 
    582   } 
    583    
    584   return $content; 
     570 
     571    if (strpos($record['photo'], 'http:') === 0) 
     572        $photo_img = $record['photo']; 
     573    else if ($record['photo']) 
     574        $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source'])); 
     575    else 
     576        $ff_value = '-del-'; // will disable delete-photo action 
     577 
     578    $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => '')); 
     579    $content = html::div($attrib, $img); 
     580 
     581    if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') { 
     582        $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']); 
     583        $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value)); 
     584        $content .= $hidden->show(); 
     585    } 
     586 
     587    return $content; 
    585588} 
    586589 
Note: See TracChangeset for help on using the changeset viewer.