diff --git a/ruby/lib/jam_ruby/models/band.rb b/ruby/lib/jam_ruby/models/band.rb index 56161d067..640f6c2a0 100644 --- a/ruby/lib/jam_ruby/models/band.rb +++ b/ruby/lib/jam_ruby/models/band.rb @@ -1,12 +1,16 @@ module JamRuby class Band < ActiveRecord::Base - attr_accessible :name, :website, :biography, :city, :state, :country + attr_accessible :name, :website, :biography, :city, :state, + :country, :original_fpfile_photo, :cropped_fpfile_photo, + :cropped_s3_path_photo, :crop_selection_photo, :photo_url attr_accessor :updating_photo self.primary_key = 'id' + before_save :stringify_photo_info , :if => :updating_photo + validate :validate_photo_info validates :biography, no_profanity: true # musicians @@ -59,6 +63,14 @@ module JamRuby loc end + def validate_photo_info + if updating_photo + # we want to mak sure that original_fpfile and cropped_fpfile seems like real fpfile info objects (i.e, json objects from filepicker.io) + errors.add(:original_fpfile_photo, ValidationMessages::INVALID_FPFILE) if self.original_fpfile_photo.nil? || self.original_fpfile_photo["key"].nil? || self.original_fpfile_photo["url"].nil? + errors.add(:cropped_fpfile_photo, ValidationMessages::INVALID_FPFILE) if self.cropped_fpfile_photo.nil? || self.cropped_fpfile_photo["key"].nil? || self.cropped_fpfile_photo["url"].nil? + end + end + def add_member(user_id, admin) BandMusician.create(:band_id => self.id, :user_id => user_id, :admin => admin) end @@ -241,5 +253,15 @@ module JamRuby end end end + + def stringify_photo_info + # fpfile comes in as a hash, which is a easy-to-use and validate form. However, we store it as a VARCHAR, + # so we need t oconvert it to JSON before storing it (otherwise it gets serialized as a ruby object) + # later, when serving this data out to the REST API, we currently just leave it as a string and make a JSON capable + # client parse it, because it's very rare when it's needed at all + self.original_fpfile_photo = original_fpfile_photo.to_json if !original_fpfile_photo.nil? + self.cropped_fpfile_photo = cropped_fpfile_photo.to_json if !cropped_fpfile_photo.nil? + self.crop_selection_photo = crop_selection_photo.to_json if !crop_selection_photo.nil? + end end end diff --git a/web/app/assets/javascripts/accounts_profile_avatar.js b/web/app/assets/javascripts/accounts_profile_avatar.js index 460a6ab8b..81336953e 100644 --- a/web/app/assets/javascripts/accounts_profile_avatar.js +++ b/web/app/assets/javascripts/accounts_profile_avatar.js @@ -7,7 +7,6 @@ var self = this; var logger = context.JK.logger; var rest = context.JK.Rest(); - var userId; var user = {}; var tmpUploadPath = null; var userDetail = null; @@ -18,8 +17,6 @@ var userDropdown; function beforeShow(data) { - logger.debug("data.id=" + data.id); - userId = data.id; } diff --git a/web/app/assets/javascripts/band_setup.js b/web/app/assets/javascripts/band_setup.js index eb1d30316..5752a35e4 100644 --- a/web/app/assets/javascripts/band_setup.js +++ b/web/app/assets/javascripts/band_setup.js @@ -229,7 +229,8 @@ userNames = []; userIds = []; userPhotoUrls = []; - bandId = "1158c8b6-4c92-47dc-82bf-1e390c4f9b2c";// $("#hdn-band-id").val(); + //bandId = "1158c8b6-4c92-47dc-82bf-1e390c4f9b2c"; + bandId = $("#hdn-band-id").val(); resetForm(); } @@ -271,6 +272,10 @@ $("#band-website").val(band.website); $("#band-biography").val(band.biography); + if (band.photo_url) { + $("#band-avatar").attr('src', band.photo_url); + } + loadGenres(band.genres); loadCountries(band.country, function() { diff --git a/web/app/assets/javascripts/band_setup_photo.js b/web/app/assets/javascripts/band_setup_photo.js index af00f42c0..f5775cee5 100644 --- a/web/app/assets/javascripts/band_setup_photo.js +++ b/web/app/assets/javascripts/band_setup_photo.js @@ -60,9 +60,9 @@ function events() { // wire up main panel clicks $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-upload', function(evt) { evt.stopPropagation(); handleFilePick(); return false; } ); - $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-delete', function(evt) { evt.stopPropagation(); handleDeletePhoto(); return false; } ); + $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-delete', function(evt) { evt.stopPropagation(); handleDeleteBandPhoto(); return false; } ); $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-cancel', function(evt) { evt.stopPropagation(); navToEditProfile(); return false; } ); - $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-submit', function(evt) { evt.stopPropagation(); handleUpdatePhoto(); return false; } ); + $('#band-setup-photo-content-scroller').on('click', '#band-setup-photo-submit', function(evt) { evt.stopPropagation(); handleUpdateBandPhoto(); return false; } ); //$('#band-setup-photo-content-scroller').on('change', 'input[type=filepicker-dragdrop]', function(evt) { evt.stopPropagation(); afterImageUpload(evt.originalEvent.fpfile); return false; } ); } diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index f36dfddc4..f0ad75ebc 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -211,6 +211,12 @@ var cropped_fpfile = options['cropped_fpfile']; var crop_selection = options['crop_selection']; + logger.debug(JSON.stringify({ + original_fpfile : original_fpfile, + cropped_fpfile : cropped_fpfile, + crop_selection : crop_selection + })); + var url = "/api/users/" + id + "/avatar"; return $.ajax({ type: "POST", @@ -259,6 +265,12 @@ var cropped_fpfile = options['cropped_fpfile']; var crop_selection = options['crop_selection']; + logger.debug(JSON.stringify({ + original_fpfile : original_fpfile, + cropped_fpfile : cropped_fpfile, + crop_selection : crop_selection + })); + var url = "/api/bands/" + id + "/photo"; return $.ajax({ type: "POST", diff --git a/web/app/views/clients/_session.html.erb b/web/app/views/clients/_session.html.erb index eda192a6b..4c71c8349 100644 --- a/web/app/views/clients/_session.html.erb +++ b/web/app/views/clients/_session.html.erb @@ -5,7 +5,6 @@ <%= image_tag "shared/icon_session.png", {:height => 19, :width => 19} %>

session

- <%= render "screen_navigation" %>