From fe9e604d7064cfd2cf6bd8fd6d5f23a12873f0a1 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Mon, 13 Jul 2015 18:14:10 -0500 Subject: [PATCH] VRFS-3325 : Re-enable change to allow multiple of the widget for online presence and performance samples. --- .../javascripts/accounts_profile_samples.js | 98 +++++++++---------- web/app/views/clients/index.html.erb | 12 +-- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/web/app/assets/javascripts/accounts_profile_samples.js b/web/app/assets/javascripts/accounts_profile_samples.js index 882572141..7bac17952 100644 --- a/web/app/assets/javascripts/accounts_profile_samples.js +++ b/web/app/assets/javascripts/accounts_profile_samples.js @@ -4,9 +4,9 @@ context.JK = context.JK || {}; - // TODO: Add a target type, which can be band or user -- call the - // appropriate API methods. - context.JK.AccountProfileSamples = function(app) { + // Using loadFn & updateFn, this can be used to render online + // presences and performance samples for both users and bands: + context.JK.AccountProfileSamples = function(app, parent, loadFn, updateFn) { var $document = $(document) // used to initialize RecordingSourceValidator in site_validator.js.coffee @@ -20,8 +20,6 @@ var ui = new context.JK.UIHelper(JK.app); var target = {}; var profileUtils = context.JK.ProfileUtils; - var parent = $(".account-profile-samples") - var $screen = $('.profile-online-sample-controls', parent); // online presences var $website = $screen.find('.website'); @@ -60,8 +58,11 @@ } function afterShow(data) { - api.getUserProfile().done(function(targetPlayer) { - renderPlayer(targetPlayer) + $.when(loadFn()) + .done(function(targetPlayer) { + if (targetPlayer && targetPlayer.keys && targetPlayer.keys.length > 0) { + renderPlayer(targetPlayer) + } }) } @@ -146,29 +147,24 @@ if (samples && samples.length > 0) { $.each(samples, function(index, val) { - var source = { + recordingSources.push({ 'url': val.url, 'recording_id': val.service_id, 'recording_title': val.description - } - recordingSources.push(source); - buildNonJamKazamEntry($sampleList, type, source); + }); + + // TODO: this code is repeated in HTML file + 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 + '
'); + $sampleList.append('
X
'); }); } } } - function buildNonJamKazamEntry($sampleList, type, source) { - // TODO: this code is repeated in HTML file - var recordingIdAttr = ' data-recording-id="' + source.recording_id + '" '; - var recordingUrlAttr = ' data-recording-url="' + source.url + '" '; - var recordingTitleAttr = ' data-recording-title="' + source.recording_title + '"'; - var title = formatTitle(source.recording_title); - $sampleList.find(".empty").addClass("hidden") - $sampleList.append('
' + title + '
'); - $sampleList.append('
X
'); - } - function buildJamkazamEntry(recordingId, recordingName) { var title = formatTitle(recordingName); @@ -183,22 +179,25 @@ $btnAddJkRecording.click(function(evt) { evt.preventDefault(); - ui.launchRecordingSelectorDialog(jamkazamRecordingSources, function(selectedRecordings) { - $jamkazamSampleList.empty(); + // retrieve recordings and pass to modal dialog + api.getClaimedRecordings() + .done(function(response) { + ui.launchRecordingSelectorDialog(response, jamkazamRecordingSources, function(selectedRecordings) { + $jamkazamSampleList.empty(); - jamkazamRecordingSources = []; + jamkazamRecordingSources = []; - // update the list with the selected recordings - $.each(selectedRecordings, function(index, val) { - jamkazamRecordingSources.push({ - 'claimed_recording_id': val.id, - 'description': val.name + // update the list with the selected recordings + $.each(selectedRecordings, function(index, val) { + jamkazamRecordingSources.push({ + 'claimed_recording_id': val.id, + 'description': val.name + }); + + buildJamkazamEntry(val.id, val.name); + }); }); - - buildJamkazamEntry(val.id, val.name); }); - }); - return false; }); @@ -222,8 +221,8 @@ }) } - function enableSubmits() { - $btnSubmit.off("click").on("click", function(e) { + function enableSubmits() { + $btnSubmit.off("click").on("click", function(e) { e.stopPropagation(); handleUpdateProfile(); return false; @@ -288,7 +287,7 @@ disableSubmits() var player = buildPlayer() - api.updateUser({ + updateFn({ website: player.website, online_presences: player.online_presences, performance_samples: player.performance_samples @@ -317,13 +316,8 @@ addPerformanceSamples(ps, $soundCloudSampleList, performanceSampleTypes.SOUNDCLOUD.description); addPerformanceSamples(ps, $youTubeSampleList, performanceSampleTypes.YOUTUBE.description); - var website = $website.val() - if (website == '') { - website = null; - } - return { - website: website, + website: $website.val(), online_presences: op, performance_samples: ps } @@ -369,7 +363,7 @@ // refactor: function initializeValidators() { var initialized = false; - //$document.on('JAMKAZAM_READY', function(e, data) { + $document.on('JAMKAZAM_READY', function(e, data) { JK.JamServer.get$Server().on(JK.EVENTS.CONNECTION_UP, function() { if(initialized) { return; @@ -434,8 +428,8 @@ siteSuccessCallback($inputDiv, youTubeRecordingValidator, $youTubeSampleList, 'youtube'); } - function siteSuccessCallback($inputDiv, recordingSiteValidator, $sampleList, type) { - $sampleList.find(".empty").addClass("hidden") + function siteSuccessCallback($inputDiv, recordingSiteValidator, sampleList, type) { + sampleList.find(".empty").addClass("hidden") $inputDiv.removeClass('error'); $inputDiv.find('.error-text').remove(); @@ -443,7 +437,13 @@ if (recordingSources && recordingSources.length > 0) { var addedRecording = recordingSources[recordingSources.length-1]; - buildNonJamKazamEntry($sampleList, type, addedRecording); + // TODO: this code is repeated in elsewhere in this 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('
X
'); } $inputDiv.find('input').val(''); @@ -455,9 +455,9 @@ $inputDiv.append("Invalid URL").show(); } }); - //}); + }); + - } // end initializeValidators. diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index 5ed69e288..6b0d2201e 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -16,7 +16,7 @@ <%= render "searchResults" %> <%= render "faders" %> <%= render "vu_meters" %> - + <%= render "jamServer" %> <%= render "iconInstrumentSelect" %> <%= render "muteSelect" %> @@ -183,10 +183,10 @@ var jamtrackLicenseDialog = new JK.JamtrackLicenseDialog(JK.app); jamtrackLicenseDialog.initialize(); - + var jamtrackPaymentHistoryDialog = new JK.JamtrackPaymentHistoryDialog(JK.app); jamtrackPaymentHistoryDialog.initialize(); - + var audioProfileInvalidDialog = new JK.AudioProfileInvalidDialog(JK.app); audioProfileInvalidDialog.initialize(); @@ -240,8 +240,8 @@ var accountProfileInterests = new JK.AccountProfileInterests(JK.app); accountProfileInterests.initialize(); - var accountProfileSamples = new JK.AccountProfileSamples(JK.app) - accountProfileSamples.initialize(); + var accountProfileSamples = new JK.AccountProfileSamples(JK.app, $(".account-profile-samples"), api.getUserProfile, api.updateUser) + accountProfileSamples.initialize() var accountAudioProfile = new JK.AccountAudioProfile(JK.app); accountAudioProfile.initialize(); @@ -407,7 +407,7 @@ else { _initAfterConnect(false); } - + JK.bindHoverEvents(); })