_new_profile_photo.haml 2.64 KB
Newer Older
danielgrippi's avatar
danielgrippi committed
1
-#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
2 3 4 5
-#   licensed under the Affero General Public License version 3 or later.  See
-#   the COPYRIGHT file.


6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
- content_for :head do
  :javascript
    function createUploader(){
     var uploader = new qq.FileUploaderBasic({
         element: document.getElementById('file-upload'),
         params: {'photo' : {'pending' : true, 'aspect_ids' : "all", 'set_profile_photo': true}},
         allowedExtensions: ['jpg', 'jpeg', 'png'],
         action: "#{photos_path}",
         button: document.getElementById('file-upload'),
         sizeLimit: 4194304,

         onProgress: function(id, fileName, loaded, total){
          var progress = Math.round(loaded / total * 100 );
           $('#fileInfo').text(fileName + ' ' + progress + '%');
         },

         messages: {
             typeError: "#{t('photos.new_photo.invalid_ext')}",
             sizeError: "#{t('photos.new_photo.size_error')}",
             emptyError: "#{t('photos.new_photo.empty')}"
         },

         onSubmit: function(id, fileName){
          $('#file-upload').addClass("loading");
          $("#profile_photo_upload").find(".avatar").addClass('loading');
          $("#file-upload-spinner").removeClass("hidden");
         },

         onComplete: function(id, fileName, responseJSON){
          $("#file-upload-spinner").addClass("hidden");
          $('#fileInfo').text(fileName + ' completed').fadeOut(2000);
          $('#file-upload').removeClass("loading");
38 39 40

          /* flash message prompt */
          var message = Diaspora.I18n.t("photo_uploader.looking_good");
41
          if(app.flashMessages) { app.flashMessages.success(message); }
42

43 44 45 46 47
          var id = responseJSON.data.photo.id;
          var url = responseJSON.data.photo.unprocessed_image.url;
          var oldPhoto = $('#photo_id');
          if(oldPhoto.length == 0) {
            $('#update_profile_form').prepend("<input type='hidden' value='" + id + "' id='photo_id' name='photo_id'/>");
48
          } else {
49 50 51 52 53
            oldPhoto.val(id);
          }

          $("#profile_photo_upload").find(".avatar").removeClass('loading');
          $("#profile_photo_upload").find(".avatar").attr("src",url);
danielgrippi's avatar
danielgrippi committed
54
          $(".avatar[data-person_id=#{current_user.person.id}]").attr("src",url);
55 56 57 58 59
         }
     });
    }
    window.onload = createUploader;

60
.profile-photo-upload#profile_photo_upload
Marcelo Briones's avatar
Marcelo Briones committed
61
  = owner_image_tag(:thumb_large)
62
  .small-horizontal-spacer
63
  .clearfix
64 65 66
    .text-center
      #file-upload.btn.btn-primary
        =t('.upload')
67 68 69

  = image_tag('mobile-spinner.gif', :class => 'hidden', :style => "z-index:-1", :id => 'file-upload-spinner')

70 71
  %p
    #fileInfo
72 73

  #publisher_photo_upload