300 lines
8.9 KiB
JavaScript
300 lines
8.9 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.AccountProfileSamples = function(app) {
|
|
var $document = $(document);
|
|
var logger = context.JK.logger;
|
|
var EVENTS = context.JK.EVENTS;
|
|
var api = context.JK.Rest();
|
|
var ui = new context.JK.UIHelper(JK.app);
|
|
var user = {};
|
|
var profileUtils = context.JK.ProfileUtils;
|
|
|
|
var $screen = $('#account-profile-samples');
|
|
|
|
// online presences
|
|
var $website = $screen.find('#website');
|
|
var $soundCloudUsername = $screen.find('#soundcloud-username');
|
|
var $reverbNationUsername = $screen.find('#reverbnation-username');
|
|
var $bandCampUsername = $screen.find('#bandcamp-username');
|
|
var $fandalismUsername = $screen.find('#fandalism-username');
|
|
var $youTubeUsername = $screen.find('#youtube-username');
|
|
var $facebookUsername = $screen.find('#facebook-username');
|
|
var $twitterUsername = $screen.find('#twitter-username');
|
|
|
|
// performance samples
|
|
var $soundCloudRecordingUrl = $screen.find('#soundcloud-recording');
|
|
var $youTubeVideoUrl = $screen.find('#youtube-video');
|
|
|
|
var $jamkazamSampleList = $screen.find('.samples.jamkazam');
|
|
var $soundCloudSampleList = $screen.find('.samples.soundcloud');
|
|
var $youTubeSampleList = $screen.find('.samples.youtube');
|
|
|
|
// buttons
|
|
var $btnAddJkRecording = $screen.find('#btn-add-jk-recording');
|
|
var $btnAddSoundCloudRecording = $screen.find('#btn-add-soundcloud-recording');
|
|
var $btnAddYouTubeVideo = $screen.find('#btn-add-youtube-video');
|
|
|
|
var $btnCancel = $screen.find('#account-edit-profile-cancel');
|
|
var $btnBack = $screen.find('#account-edit-profile-back');
|
|
var $btnSubmit = $screen.find('#account-edit-profile-submit');
|
|
|
|
function beforeShow(data) {
|
|
}
|
|
|
|
function afterShow(data) {
|
|
$.when(api.getUserProfile())
|
|
.done(function(userDetail) {
|
|
renderPresence(userDetail);
|
|
renderSamples(userDetail);
|
|
});
|
|
}
|
|
|
|
function renderPresence(user) {
|
|
$website.val(user.website);
|
|
|
|
// SoundCloud
|
|
var presences = profileUtils.soundCloudPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$soundCloudUsername.val(presences[0].username);
|
|
}
|
|
|
|
// ReverbNation
|
|
presences = profileUtils.reverbNationPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$reverbNationUsername.val(presences[0].username);
|
|
}
|
|
|
|
// Bandcamp
|
|
presences = profileUtils.bandCampPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$bandCampUsername.val(presences[0].username);
|
|
}
|
|
|
|
// Fandalism
|
|
presences = profileUtils.fandalismPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$fandalismUsername.val(presences[0].username);
|
|
}
|
|
|
|
// YouTube
|
|
presences = profileUtils.youTubePresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$youTubeUsername.val(presences[0].username);
|
|
}
|
|
|
|
// Facebook
|
|
presences = profileUtils.facebookPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$facebookUsername.val(presences[0].username);
|
|
}
|
|
|
|
// Twitter
|
|
presences = profileUtils.twitterPresences(user.online_presences);
|
|
if (presences && presences.length > 0) {
|
|
$twitterUsername.val(presences[0].username);
|
|
}
|
|
}
|
|
|
|
function renderSamples(user) {
|
|
|
|
// JamKazam recordings
|
|
var samples = profileUtils.jamkazamSamples(user.performance_samples);
|
|
if (samples) {
|
|
$.each(samples, function(index, val) {
|
|
|
|
});
|
|
}
|
|
|
|
// SoundCloud recordings
|
|
samples = profileUtils.soundCloudSamples(user.performance_samples);
|
|
if (samples) {
|
|
$.each(samples, function(index, val) {
|
|
|
|
});
|
|
}
|
|
|
|
// YouTube videos
|
|
samples = profileUtils.youTubeSamples(user.performance_samples);
|
|
if (samples) {
|
|
$.each(samples, function(index, val) {
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
function events() {
|
|
|
|
$website.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate website
|
|
});
|
|
|
|
$soundCloudUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate SoundCloud username
|
|
});
|
|
|
|
$reverbNationUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate ReverbNation username
|
|
});
|
|
|
|
$bandCampUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate Bandcamp username
|
|
});
|
|
|
|
$fandalismUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate Fandalism username
|
|
});
|
|
|
|
$youTubeUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate YouTube username
|
|
});
|
|
|
|
$facebookUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate Facebook username
|
|
});
|
|
|
|
$twitterUsername.blur(function(evt) {
|
|
evt.preventDefault();
|
|
// TODO: validate Twitter username
|
|
});
|
|
|
|
|
|
// buttons
|
|
$btnAddJkRecording.click(function(evt) {
|
|
evt.preventDefault();
|
|
ui.launchRecordingSelectorDialog('', function(selectedRecordings) {
|
|
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
$btnAddSoundCloudRecording.click(function(evt) {
|
|
var url = $soundCloudRecordingUrl.val();
|
|
if (url.length > 0) {
|
|
if (extractSoundCloudUrlParts(url)) {
|
|
// add to list
|
|
}
|
|
}
|
|
});
|
|
|
|
$btnAddYouTubeVideo.click(function(evt) {
|
|
var url = $youTubeVideoUrl.val();
|
|
if (url.length) {
|
|
if (extractYouTubeUrlParts(url)) {
|
|
// add to list
|
|
}
|
|
}
|
|
});
|
|
|
|
$btnCancel.click(function(evt) {
|
|
evt.stopPropagation();
|
|
navigateTo('/client#/profile/' + context.JK.currentUserId);
|
|
return false;
|
|
});
|
|
|
|
$btnBack.click(function(evt) {
|
|
evt.stopPropagation();
|
|
navigateTo('/client#/account/profile/interests');
|
|
return false;
|
|
});
|
|
|
|
$btnSubmit.click(function(evt) {
|
|
$document.triggerHandler(EVENTS.USER_UPDATED, response);
|
|
|
|
handleUpdateProfile();
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function navigateTo(targetLocation) {
|
|
context.location = targetLocation;
|
|
}
|
|
|
|
function addOnlinePresence(presenceArray, username, type) {
|
|
if ($.trim($soundCloudUsername.val()).length > 0) {
|
|
presenceArray.push({
|
|
service_type: type,
|
|
username: username
|
|
});
|
|
}
|
|
}
|
|
|
|
function addPerformanceSamples(sampleArray, $samplesSelector, type) {
|
|
var sampleTable = $samplesSelector.find('table');
|
|
// loop over rows, extracting service id, description, and url
|
|
}
|
|
|
|
function handleUpdateProfile() {
|
|
|
|
// extract online presences
|
|
var op = [];
|
|
var presenceTypes = profileUtils.ONLINE_PRESENCE_TYPES;
|
|
addOnlinePresence(op, $soundCloudUsername.val(), presenceTypes.SOUNDCLOUD.description);
|
|
addOnlinePresence(op, $reverbNationUsername.val(), presenceTypes.REVERBNATION.description);
|
|
addOnlinePresence(op, $bandCampUsername.val(), presenceTypes.BANDCAMP.description);
|
|
addOnlinePresence(op, $fandalismUsername.val(), presenceTypes.FANDALISM.description);
|
|
addOnlinePresence(op, $youTubeUsername.val(), presenceTypes.YOUTUBE.description);
|
|
addOnlinePresence(op, $facebookUsername.val(), presenceTypes.FACEBOOK.description);
|
|
addOnlinePresence(op, $twitterUsername.val(), presenceTypes.TWITTER.description);
|
|
|
|
// extract performance samples
|
|
var ps = [];
|
|
var performanceSampleTypes = profileUtils.SAMPLE_TYPES;
|
|
addPerformanceSamples(ps, $jamkazamSampleList, performanceSampleTypes.JAMKAZAM);
|
|
addPerformanceSamples(ps, $soundCloudSampleList, performanceSampleTypes.SOUNDCLOUD);
|
|
addPerformanceSamples(ps, $youTubeSampleList, performanceSampleTypes.YOUTUBE);
|
|
|
|
// api.updateUser({
|
|
// website: $website.val(),
|
|
// online_presences: op,
|
|
// performance_samples: ps
|
|
// })
|
|
// .done(postUpdateProfileSuccess)
|
|
// .fail(postUpdateProfileFailure);
|
|
}
|
|
|
|
function postUpdateProfileSuccess(response) {
|
|
$document.triggerHandler(EVENTS.USER_UPDATED, response);
|
|
context.location = "/client#/profile/" + context.JK.currentUserId;
|
|
}
|
|
|
|
function postUpdateProfileFailure(xhr, textStatus, errorMessage) {
|
|
|
|
var errors = JSON.parse(xhr.responseText)
|
|
|
|
if(xhr.status == 422) {
|
|
|
|
}
|
|
else {
|
|
app.ajaxError(xhr, textStatus, errorMessage)
|
|
}
|
|
}
|
|
|
|
function initialize() {
|
|
var screenBindings = {
|
|
'beforeShow': beforeShow,
|
|
'afterShow': afterShow
|
|
};
|
|
|
|
app.bindScreen('account/profile/samples', screenBindings);
|
|
|
|
events();
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
this.beforeShow = beforeShow;
|
|
this.afterShow = afterShow;
|
|
return this;
|
|
};
|
|
|
|
})(window,jQuery); |