diff --git a/ruby/lib/jam_ruby/models/performance_sample.rb b/ruby/lib/jam_ruby/models/performance_sample.rb
index db02b26c1..703ebe2e0 100644
--- a/ruby/lib/jam_ruby/models/performance_sample.rb
+++ b/ruby/lib/jam_ruby/models/performance_sample.rb
@@ -3,7 +3,7 @@ module JamRuby
PERMISSION_MSG = "You do not have permission to perform this operation."
- attr_accessible :user_id, :service_type, :claimed_recording_id, :service_id, :url
+ attr_accessible :user_id, :service_type, :claimed_recording_id, :service_id, :url, :description
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording", :foreign_key => "claimed_recording_id"
@@ -50,7 +50,8 @@ module JamRuby
:service_type => options[:service_type],
:claimed_recording_id => options[:claimed_recording_id],
:service_id => options[:service_id],
- :url => options[:url]
+ :url => options[:url],
+ :description => options[:description]
})
ps.save! if save
diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb
index 6a8da6870..cb9df691c 100644
--- a/ruby/lib/jam_ruby/models/user.rb
+++ b/ruby/lib/jam_ruby/models/user.rb
@@ -669,8 +669,8 @@ module JamRuby
end
online_presences.each do |op|
- op = OnlinePresence.create(self, online_presences, false)
- self.online_presences << op
+ new_presence = OnlinePresence.create(self, op, false)
+ self.online_presences << new_presence
end
end
@@ -680,8 +680,8 @@ module JamRuby
end
performance_samples.each do |ps|
- ps = PerformanceSample.create(self, performance_samples, false)
- self.performance_samples << ps
+ new_sample = PerformanceSample.create(self, ps, false)
+ self.performance_samples << new_sample
end
end
diff --git a/web/app/assets/javascripts/accounts_profile_samples.js b/web/app/assets/javascripts/accounts_profile_samples.js
index e884d3549..26867b7bf 100644
--- a/web/app/assets/javascripts/accounts_profile_samples.js
+++ b/web/app/assets/javascripts/accounts_profile_samples.js
@@ -5,6 +5,12 @@
context.JK = context.JK || {};
context.JK.AccountProfileSamples = function(app) {
var $document = $(document);
+
+ // used to initialize RecordingSourceValidator in site_validator.js.coffee
+ window.jamkazamRecordingSources = [];
+ window.soundCloudRecordingSources = [];
+ window.youTubeRecordingSources = [];
+
var logger = context.JK.logger;
var EVENTS = context.JK.EVENTS;
var api = context.JK.Rest();
@@ -25,9 +31,9 @@
var $twitterUsername = $screen.find('#twitter-username');
// performance samples
- var $jamkazamSampleList = $screen.find('.samples.jamkazam');
- var $soundCloudSampleList = $screen.find('.samples.soundcloud');
- var $youTubeSampleList = $screen.find('.samples.youtube');
+ var $jamkazamSampleList = $screen.find('.samples.jamkazam').find('.sample-list');
+ var $soundCloudSampleList = $screen.find('.samples.soundcloud').find('.sample-list');
+ var $youTubeSampleList = $screen.find('.samples.youtube').find('.sample-list');
// buttons
var $btnAddJkRecording = $screen.find('#btn-add-jk-recording');
@@ -43,6 +49,7 @@
.done(function(userDetail) {
renderPresence(userDetail);
renderSamples(userDetail);
+ $document.triggerHandler('INIT_SITE_VALIDATORS');
});
}
@@ -93,30 +100,48 @@
}
function renderSamples(user) {
-
// JamKazam recordings
var samples = profileUtils.jamkazamSamples(user.performance_samples);
- if (samples && samples.length > 0) {
- $.each(samples, function(index, val) {
-
- });
- }
+ loadSamples(samples, 'jamkazam', $jamkazamSampleList, window.jamkazamRecordingSources);
// SoundCloud recordings
samples = profileUtils.soundCloudSamples(user.performance_samples);
- if (samples && samples.length > 0) {
- $.each(samples, function(index, val) {
-
- });
- }
+ loadSamples(samples, 'soundcloud', $soundCloudSampleList, window.soundCloudRecordingSources);
// YouTube videos
samples = profileUtils.youTubeSamples(user.performance_samples);
- if (samples && samples.length > 0) {
- $.each(samples, function(index, val) {
-
- });
+ loadSamples(samples, 'youtube', $youTubeSampleList, window.youTubeRecordingSources);
+ }
+
+ function loadSamples(samples, type, $sampleList, recordingSources) {
+ if (type === 'jamkazam') {
+
}
+ else {
+ if (samples && samples.length > 0) {
+ $.each(samples, function(index, val) {
+
+ recordingSources.push({
+ 'url': val.url,
+ 'recording_id': val.service_id,
+ 'recording_title': val.description
+ });
+
+ var recordingIdAttr = ' data-recording-id="' + val.service_id + '" ';
+ var recordingUrlAttr = ' data-recording-url="' + val.url + '" ';
+ var recordingTitleAttr = ' data-recording-title="' + val.description + '"';
+ var title = formatTitle(val.description);
+ $sampleList.append('
' + title + '
');
+
+ var onclick = "onclick=removeRow(\'" + val.service_id + "\',\'" + type + "\');";
+ $sampleList.append('X
');
+ });
+ }
+ }
+ }
+
+ function formatTitle(title) {
+ return title && title.length > 30 ? title.substring(0, 30) + "..." : title;
}
function events() {
@@ -163,15 +188,42 @@
function addOnlinePresence(presenceArray, username, type) {
if ($.trim(username).length > 0) {
presenceArray.push({
- service_type: type,
- username: username
+ 'user_id': context.JK.currentUserId,
+ 'service_type': type,
+ 'username': username
});
}
}
function addPerformanceSamples(sampleArray, $samplesSelector, type) {
- var sampleTable = $samplesSelector.find('table');
+ var rows = $samplesSelector.find('.recording-row');
+
// loop over rows, extracting service id, description, and url
+ rows.each(function(index) {
+ var id = $(this).attr('data-recording-id');
+ var url = $(this).attr('data-recording-url');
+ var title = $(this).attr('data-recording-title');
+
+ if (type === 'jamkazam') {
+ sampleArray.push({
+ 'user_id': context.JK.currentUserId,
+ 'service_type': type,
+ 'claimed_recording_id': id,
+ 'url': url,
+ 'description': title
+ });
+ }
+
+ else {
+ sampleArray.push({
+ 'user_id': context.JK.currentUserId,
+ 'service_type': type,
+ 'service_id': id,
+ 'url': url,
+ 'description': title
+ });
+ }
+ });
}
function handleUpdateProfile() {
@@ -194,6 +246,9 @@
addPerformanceSamples(ps, $soundCloudSampleList, performanceSampleTypes.SOUNDCLOUD.description);
addPerformanceSamples(ps, $youTubeSampleList, performanceSampleTypes.YOUTUBE.description);
+ logger.debug('online_presences = %o', op);
+ logger.debug('performance_samples = %o', ps);
+
api.updateUser({
website: $website.val(),
online_presences: op,
diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js
index 916c6a8b4..9d9adb0e9 100644
--- a/web/app/assets/javascripts/profile.js
+++ b/web/app/assets/javascripts/profile.js
@@ -561,19 +561,23 @@
}
$.each(jamkazamSamples, function(index, sample) {
- $jamkazamSamples.append("" + sample.claimed_recording.name + "
");
+ $jamkazamSamples.append("" + formatTitle(sample.claimed_recording.name) + "
");
});
$.each(soundCloudSamples, function(index, sample) {
- $soundCloudSamples.append("" + sample.description + "
");
+ $soundCloudSamples.append("" + formatTitle(sample.description) + "
");
});
$.each(youTubeSamples, function(index, sample) {
- $youTubeSamples.append("" + sample.description + "
");
+ $youTubeSamples.append("" + formatTitle(sample.description) + "
");
});
}
}
+ function formatTitle(title) {
+ return title && title.length > 30 ? title.substring(0, 30) + "..." : title;
+ }
+
function renderOnlinePresence() {
// online presences
var onlinePresences = user.online_presences;
diff --git a/web/app/views/clients/_account_profile_samples.html.erb b/web/app/views/clients/_account_profile_samples.html.erb
index 6af344f03..ec3d776d6 100644
--- a/web/app/views/clients/_account_profile_samples.html.erb
+++ b/web/app/views/clients/_account_profile_samples.html.erb
@@ -144,6 +144,11 @@
}
var initialized = false;
+ $(document).on('INIT_SITE_VALIDATORS', function(e, data) {
+ window.soundCloudRecordingValidator.init(window.soundCloudRecordingSources);
+ window.youTubeRecordingValidator.init(window.youTubeRecordingSources);
+ });
+
$(document).on('JAMKAZAM_READY', function(e, data) {
window.JK.JamServer.get$Server().on(window.JK.EVENTS.CONNECTION_UP, function() {
if(initialized) {
@@ -159,34 +164,32 @@
setTimeout(function() {
window.urlValidator = new JK.SiteValidator('url', userNameSuccessCallback, userNameFailCallback);
- urlValidator.init();
+ window.urlValidator.init();
window.soundCloudValidator = new JK.SiteValidator('soundcloud', userNameSuccessCallback, userNameFailCallback);
- soundCloudValidator.init();
+ window.soundCloudValidator.init();
window.reverbNationValidator = new JK.SiteValidator('reverbnation', userNameSuccessCallback, userNameFailCallback);
- reverbNationValidator.init();
+ window.reverbNationValidator.init();
window.bandCampValidator = new JK.SiteValidator('bandcamp', userNameSuccessCallback, userNameFailCallback);
- bandCampValidator.init();
+ window.bandCampValidator.init();
window.fandalismValidator = new JK.SiteValidator('fandalism', userNameSuccessCallback, userNameFailCallback);
- fandalismValidator.init();
+ window.fandalismValidator.init();
window.youTubeValidator = new JK.SiteValidator('youtube', userNameSuccessCallback, userNameFailCallback);
- youTubeValidator.init();
+ window.youTubeValidator.init();
window.facebookValidator = new JK.SiteValidator('facebook', userNameSuccessCallback, userNameFailCallback);
- facebookValidator.init();
+ window.facebookValidator.init();
window.twitterValidator = new JK.SiteValidator('twitter', userNameSuccessCallback, userNameFailCallback);
- twitterValidator.init();
+ window.twitterValidator.init();
window.soundCloudRecordingValidator = new JK.RecordingSourceValidator('rec_soundcloud', soundCloudSuccessCallback, siteFailCallback);
- soundCloudRecordingValidator.init();
window.youTubeRecordingValidator = new JK.RecordingSourceValidator('rec_youtube', youTubeSuccessCallback, siteFailCallback);
- youTubeRecordingValidator.init();
}, 1);
function userNameSuccessCallback($inputDiv) {
@@ -214,16 +217,17 @@
var recordingSources = recordingSiteValidator.recordingSources();
if (recordingSources && recordingSources.length > 0) {
- console.log('recordingSources=%o', recordingSources);
var $sampleList = $sampleList.find('.sample-list');
var addedRecording = recordingSources[recordingSources.length-1];
+
+ // TODO: this code is repeated in JS file
var recordingIdAttr = ' data-recording-id="' + addedRecording.recording_id + '" ';
var recordingUrlAttr = ' data-recording-url="' + addedRecording.url + '" ';
var recordingTitleAttr = ' data-recording-title="' + addedRecording.recording_title + '"';
var title = formatTitle(addedRecording.recording_title);
- $sampleList.append('' + title + '
');
+ $sampleList.append('' + title + '
');
- var onclick = "onclick=removeRow(" + addedRecording.recording_id + ",\'" + type + "\');";
+ var onclick = "onclick=removeRow(\'" + addedRecording.recording_id + "\',\'" + type + "\');";
$sampleList.append('X
');
}
@@ -231,7 +235,7 @@
}
function formatTitle(title) {
- return title && title.length > 30 ? title.substring(0, 30) : title;
+ return title && title.length > 30 ? title.substring(0, 30) + "..." : title;
}
function siteFailCallback($inputDiv) {