Changeset 0be8bd1 in github


Ignore:
Timestamp:
Jun 26, 2012 5:49:47 AM (11 months ago)
Author:
Thomas Bruederli <thomas@…>
Branches:
master, HEAD
Children:
d901205
Parents:
7ab9c17
Message:

Enable drag & drop file upload for contact photos

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • program/js/app.js

    r2950ce4 r0be8bd1  
    47164716    if (form && form.elements._photo.value) { 
    47174717      this.async_upload_form(form, 'upload-photo', function(e) { 
    4718         rcmail.set_busy(false, null, rcmail.photo_upload_id); 
     4718        rcmail.set_busy(false, null, rcmail.file_upload_id); 
    47194719      }); 
    47204720 
    47214721      // display upload indicator 
    4722       this.photo_upload_id = this.set_busy(true, 'uploading'); 
     4722      this.file_upload_id = this.set_busy(true, 'uploading'); 
    47234723    } 
    47244724  }; 
     
    47354735  this.photo_upload_end = function() 
    47364736  { 
    4737     this.set_busy(false, null, this.photo_upload_id); 
    4738     delete this.photo_upload_id; 
     4737    this.set_busy(false, null, this.file_upload_id); 
     4738    delete this.file_upload_id; 
    47394739  }; 
    47404740 
     
    62556255    var files = e.target.files || e.dataTransfer.files, 
    62566256      formdata = window.FormData ? new FormData() : null, 
    6257       fieldname = this.env.filedrop.fieldname || '_file', 
     6257      fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'), 
    62586258      boundary = '------multipartformboundary' + (new Date).getTime(), 
    62596259      dashdash = '--', crlf = '\r\n', 
     
    62706270 
    62716271      // add to attachments list 
    6272       ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false }); 
     6272      if (!ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false })) 
     6273        ref.file_upload_id = ref.set_busy(true, 'uploading'); 
    62736274 
    62746275      // complete multipart content and post request 
     
    62786279        type: 'POST', 
    62796280        dataType: 'json', 
    6280         url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||'', _uploadid:ts, _remote:1 }), 
     6281        url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||ref.env.cid||'', _uploadid:ts, _remote:1 }), 
    62816282        contentType: formdata ? false : 'multipart/form-data; boundary=' + boundary, 
    62826283        processData: false, 
     
    62906291    // get contents of all dropped files 
    62916292    var last = this.env.filedrop.single ? 0 : files.length - 1; 
    6292     for (var i=0, f; i <= last && (f = files[i]); i++) { 
     6293    for (var j=0, i=0, f; j <= last && (f = files[i]); i++) { 
    62936294      if (!f.name) f.name = f.fileName; 
    62946295      if (!f.size) f.size = f.fileSize; 
     
    63076308      // do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+) 
    63086309      if (formdata) { 
    6309         formdata.append(fieldname + '[]', f); 
    6310         if (i == last) 
     6310        formdata.append(fieldname, f); 
     6311        if (j == last) 
    63116312          return submit_data(); 
    63126313      } 
     
    63166317 
    63176318        // closure to pass file properties to async callback function 
    6318         reader.onload = (function(file, i) { 
     6319        reader.onload = (function(file, j) { 
    63196320          return function(e) { 
    6320             multipart += 'Content-Disposition: form-data; name="' + fieldname + '[]"'; 
     6321            multipart += 'Content-Disposition: form-data; name="' + fieldname + '"'; 
    63216322            multipart += '; filename="' + (f.name_bin || file.name) + '"' + crlf; 
    63226323            multipart += 'Content-Length: ' + file.size + crlf; 
     
    63256326            multipart += dashdash + boundary + crlf; 
    63266327 
    6327             if (i == last)  // we're done, submit the data 
     6328            if (j == last)  // we're done, submit the data 
    63286329              return submit_data(); 
    63296330          } 
    6330         })(f,i); 
     6331        })(f,j); 
    63316332        reader.readAsBinaryString(f); 
    63326333      } 
    63336334      // Firefox 3 
    63346335      else if (f.getAsBinary) { 
    6335         multipart += 'Content-Disposition: form-data; name="' + fieldname + '[]"'; 
     6336        multipart += 'Content-Disposition: form-data; name="' + fieldname + '"'; 
    63366337        multipart += '; filename="' + (f.name_bin || f.name) + '"' + crlf; 
    63376338        multipart += 'Content-Length: ' + f.size + crlf; 
     
    63406341        multipart += dashdash + boundary +crlf; 
    63416342 
    6342         if (i == last) 
     6343        if (j == last) 
    63436344          return submit_data(); 
    63446345      } 
     6346 
     6347      j++; 
    63456348    } 
    63466349  }; 
  • program/steps/addressbook/edit.inc

    r041c93c r0be8bd1  
    263263 
    264264 
     265/** 
     266 * Register container as active area to drop photos onto 
     267 */ 
     268function rcmail_photo_drop_area($attrib) 
     269{ 
     270    global $OUTPUT; 
     271 
     272    if ($attrib['id']) { 
     273        $OUTPUT->add_gui_object('filedrop', $attrib['id']); 
     274        $OUTPUT->set_env('filedrop', array('action' => 'upload-photo', 'fieldname' => '_photo', 'single' => 1, 'filter' => '^image/.+')); 
     275    } 
     276} 
     277 
     278 
    265279$OUTPUT->add_handlers(array( 
    266280    'contactedithead' => 'rcmail_contact_edithead', 
     
    269283    'photouploadform' => 'rcmail_upload_photo_form', 
    270284    'sourceselector'  => 'rcmail_source_selector', 
     285    'filedroparea'    => 'rcmail_photo_drop_area', 
    271286)); 
    272287 
  • skins/larry/addressbook.css

    r0f3ae42 r0be8bd1  
    161161#contactpic img { 
    162162        width: 112px; 
     163        visibility: inherit; 
     164} 
     165 
     166#contactpic.droptarget { 
     167        background-image: url(images/filedrop.png); 
     168        background-position: center; 
     169        background-repeat: no-repeat; 
     170} 
     171 
     172#contactpic.droptarget.hover { 
     173        background-color: #d9ecf4; 
     174        box-shadow: 0 0 5px 2px rgba(71,135,177, 0.9); 
     175        -moz-box-shadow: 0 0 5px 2px rgba(71,135,177, 0.9); 
     176        -webkit-box-shadow: 0 0 5px 2px rgba(71,135,177, 0.9); 
     177        -o-box-shadow: 0 0 5px 2px rgba(71,135,177, 0.9); 
     178} 
     179 
     180#contactpic.droptarget.active img { 
     181        opacity: 0.15; 
     182} 
     183 
     184#contactpic.droptarget.hover img { 
     185        opacity: 0.05; 
    163186} 
    164187 
  • skins/larry/templates/contactedit.html

    r71e9efb r0be8bd1  
    2020                <roundcube:object name="contactphoto" id="contactpic" placeholder="/images/contactpic.png" /> 
    2121                <roundcube:if condition="env:photocol" /> 
     22                <roundcube:object name="fileDropArea" id="contactpic" /> 
    2223                <div class="formlinks"> 
    2324                        <roundcube:button command="upload-photo" id="uploadformlink" type="link" label="replacephoto" class="iconlink upload disabled" classAct="iconlink upload active" onclick="UI.show_uploadform();return false" condition="env:photocol" /><br/> 
Note: See TracChangeset for help on using the changeset viewer.