2014-02-13 22:57:48 +00:00
( function ( context , $ ) {
"use strict" ;
context . JK = context . JK || { } ;
// TODO: MUCH OF THIS CLASS IS REPEATED IN THE FOLLOWING FILES:
// createSession.js.erb
// accounts_profiles.js
context . JK . BandSetupScreen = function ( app ) {
2015-05-30 02:04:33 +00:00
var NONE _SPECIFIED = 'None specified'
2015-06-02 20:13:41 +00:00
var GENRE _STEP = 1
var SAMPLE _STEP = 3
var STEPS _COUNT = 5
var currentStep = 0
2015-05-30 02:04:33 +00:00
var ui = new context . JK . UIHelper ( JK . app )
2015-06-02 20:13:41 +00:00
var logger = context . JK . logger
var profileUtils = context . JK . ProfileUtils
var rest = context . JK . Rest ( )
var inviteMusiciansUtil = null
var invitationDialog = null
var autoComplete = null
var userNames = [ ]
var userIds = [ ]
var userPhotoUrls = [ ]
var selectedFriendIds = { }
var nilOptionStr = '<option value=""></option>'
var nilOptionText = 'n/a'
var bandId = ''
var friendInput = null
var bandType = null
var bandStatus = null
2015-06-16 22:55:55 +00:00
var concertCount = null
2015-05-31 14:53:28 +00:00
var $screen = $ ( "#band-setup" )
2015-05-31 22:35:09 +00:00
var $samples = $screen . find ( ".account-profile-samples" )
2015-05-30 02:04:33 +00:00
var $selectedInstruments = [ ]
2015-06-16 22:55:55 +00:00
var accountProfileSamples = new JK . AccountProfileSamples ( app , $screen , loadBandCallback , rest . updateBand )
accountProfileSamples . initialize ( )
2015-06-02 20:13:41 +00:00
2015-05-20 19:17:53 +00:00
function navBack ( ) {
2015-07-16 01:05:24 +00:00
var band = buildBand ( )
2015-05-20 19:17:53 +00:00
if ( currentStep > 0 ) {
2015-07-16 01:05:24 +00:00
saveBand ( band , function ( ) {
2015-05-20 19:17:53 +00:00
currentStep --
renderCurrentPage ( )
} )
}
}
2015-06-16 22:55:55 +00:00
2015-05-20 19:17:53 +00:00
function navCancel ( ) {
2015-06-16 22:55:55 +00:00
resetForm ( )
2015-05-20 19:17:53 +00:00
window . history . go ( - 1 )
return false
}
2015-06-16 22:55:55 +00:00
2015-05-20 19:17:53 +00:00
function navNext ( ) {
2015-07-16 01:05:24 +00:00
var band = buildBand ( )
if ( currentStep == GENRE _STEP ) {
band . genres = getSelectedGenres ( ) ;
band . validate _genres = true
} else {
band . validate _genres = false
}
2015-05-20 19:17:53 +00:00
if ( currentStep < STEPS _COUNT - 1 ) {
2015-07-16 01:05:24 +00:00
saveBand ( band , function ( band ) {
2015-05-20 19:17:53 +00:00
currentStep ++
renderCurrentPage ( )
} )
} else {
2015-07-16 01:05:24 +00:00
saveBand ( band , function ( band ) {
2015-05-20 19:17:53 +00:00
resetForm ( )
showProfile ( band . id ) ;
2015-06-16 22:55:55 +00:00
} )
2015-05-20 19:17:53 +00:00
}
}
2015-06-16 22:55:55 +00:00
function renderCurrentPage ( ) {
2015-05-31 14:53:28 +00:00
$screen . find ( $ ( ".band-step" ) ) . addClass ( "hidden" )
2015-05-20 19:17:53 +00:00
$ ( "#band-setup-step-" + currentStep ) . removeClass ( "hidden" )
2015-06-16 22:55:55 +00:00
if ( currentStep == 0 ) {
2015-05-20 19:17:53 +00:00
$ ( "#btn-band-setup-back" ) . addClass ( "hidden" )
2015-06-16 22:55:55 +00:00
$ ( "#btn-band-setup-next" ) . removeClass ( "hidden" ) . html ( "SAVE & NEXT" )
} else if ( currentStep < STEPS _COUNT - 1 ) {
2015-06-02 20:13:41 +00:00
// if(currentStep==SAMPLE_STEP) {
// accountProfileSamples.renderPlayer(band)
// }
2015-05-20 19:17:53 +00:00
$ ( "#btn-band-setup-back" ) . removeClass ( "hidden" )
2015-06-16 22:55:55 +00:00
$ ( "#btn-band-setup-next" ) . removeClass ( "hidden" ) . html ( "SAVE & NEXT" )
} else {
2015-05-20 19:17:53 +00:00
$ ( "#btn-band-setup-back" ) . removeClass ( "hidden" )
$ ( "#btn-band-setup-next" ) . removeClass ( "hidden" ) . html ( "SAVE & FINISH" )
2015-05-28 22:12:39 +00:00
}
renderOptionalControls ( )
}
2015-06-16 22:55:55 +00:00
function renderOptionalControls ( e ) {
2015-05-28 22:12:39 +00:00
if ( e ) { e . stopPropagation ( ) }
2015-06-16 22:55:55 +00:00
// Is new member selected?
2015-05-31 14:53:28 +00:00
if ( $screen . find ( $ ( 'input[name="add_new_members"]:checked' ) ) . val ( ) == "yes" ) {
$screen . find ( $ ( ".new-member-dependent" ) ) . removeClass ( "hidden" )
2015-05-28 22:12:39 +00:00
} else {
2015-05-31 14:53:28 +00:00
$screen . find ( $ ( ".new-member-dependent" ) ) . addClass ( "hidden" )
2015-05-28 22:12:39 +00:00
}
2015-06-16 22:55:55 +00:00
// Is paid gigs selected?
if ( $ ( 'input[name="paid_gigs"]:checked' ) . val ( ) == "yes" ) {
2015-05-31 14:53:28 +00:00
$screen . find ( $ ( ".paid-gigs-dependent" ) ) . removeClass ( "hidden" )
2015-05-28 22:12:39 +00:00
} else {
2015-05-31 14:53:28 +00:00
$screen . find ( $ ( ".paid-gigs-dependent" ) ) . addClass ( "hidden" )
2015-05-28 22:12:39 +00:00
}
return false ;
2015-05-20 19:17:53 +00:00
}
2014-02-13 22:57:48 +00:00
2015-06-16 22:55:55 +00:00
function isNewBand ( ) {
2015-05-23 18:00:22 +00:00
return bandId == null || typeof ( bandId ) == 'undefined' || bandId . length == 0 ;
2014-02-19 22:56:13 +00:00
}
function removeErrors ( ) {
$ ( '#band-setup-form .error-text' ) . remove ( )
$ ( '#band-setup-form .error' ) . removeClass ( "error" )
}
2014-02-13 22:57:48 +00:00
function resetForm ( ) {
2014-02-19 22:56:13 +00:00
removeErrors ( ) ;
2015-06-02 20:13:41 +00:00
accountProfileSamples . resetForm ( )
2014-02-19 22:56:13 +00:00
2014-02-13 22:57:48 +00:00
// name
$ ( "#band-name" ) . val ( '' ) ;
// country
$ ( "#band-country" ) . empty ( ) ;
$ ( "#band-country" ) . val ( '' ) ;
// region
$ ( "#band-region" ) . empty ( ) ;
$ ( "#band-region" ) . val ( '' ) ;
// city
$ ( "#band-city" ) . empty ( ) ;
$ ( "#band-city" ) . val ( '' ) ;
// description
$ ( "#band-biography" ) . val ( '' ) ;
2014-02-19 22:56:13 +00:00
// website
$ ( '#band-website' ) . val ( '' ) ;
2015-06-16 22:55:55 +00:00
2015-05-28 19:21:55 +00:00
$ ( "#new-member-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
$ ( "#paid-gigs-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
$ ( "#free-gigs-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
$ ( '#touring-option' ) . val ( 'no' )
2015-06-16 22:55:55 +00:00
2015-05-28 19:21:55 +00:00
$ ( "#play-commitment" ) . val ( '1' )
2015-07-15 15:04:45 +00:00
$screen . find ( "#hourly-rate" ) . val ( "0" )
$screen . find ( "#gig-minimum" ) . val ( "0" )
2015-06-16 22:55:55 +00:00
resetGenres ( ) ;
2015-05-30 02:04:33 +00:00
renderDesiredExperienceLabel ( [ ] )
2014-02-13 22:57:48 +00:00
2014-03-13 08:47:27 +00:00
$ ( friendInput )
2014-02-13 22:57:48 +00:00
. unbind ( 'blur' )
. attr ( "placeholder" , "Looking up friends..." )
. prop ( 'disabled' , true )
}
function resetGenres ( ) {
$ ( 'input[type=checkbox]:checked' , '#band-genres' ) . each ( function ( i ) {
$ ( this ) . removeAttr ( "checked" ) ;
} ) ;
var $tdGenres = $ ( "#tdBandGenres" ) ;
}
function getSelectedGenres ( ) {
var genres = [ ] ;
$ ( 'input[type=checkbox]:checked' , '#band-genres' ) . each ( function ( i ) {
var genre = $ ( this ) . val ( ) ;
genres . push ( genre ) ;
} ) ;
return genres ;
}
function validateGeneralInfo ( ) {
2014-02-19 22:56:13 +00:00
removeErrors ( ) ;
2014-02-13 22:57:48 +00:00
2014-02-19 22:56:13 +00:00
var band = buildBand ( ) ;
return rest . validateBand ( band ) ;
}
2014-02-13 22:57:48 +00:00
2014-02-19 22:56:13 +00:00
function renderErrors ( errors ) {
2015-05-31 22:35:09 +00:00
logger . debug ( "Band setup errors: " , errors )
2014-02-19 22:56:13 +00:00
var name = context . JK . format _errors ( "name" , errors ) ;
var country = context . JK . format _errors ( "country" , errors ) ;
var state = context . JK . format _errors ( "state" , errors ) ;
var city = context . JK . format _errors ( "city" , errors ) ;
var biography = context . JK . format _errors ( "biography" , errors ) ;
var website = context . JK . format _errors ( "website" , errors ) ;
2015-05-31 22:35:09 +00:00
var genres = context . JK . format _errors ( "genres" , errors ) ;
2014-02-19 22:56:13 +00:00
2015-05-31 22:35:09 +00:00
if ( name ) $ ( "#band-name" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( name ) ;
if ( country ) $ ( "#band-country" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( country ) ;
if ( state ) $ ( "#band-region" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( state ) ;
if ( city ) $ ( "#band-city" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( city ) ;
2014-02-19 22:56:13 +00:00
if ( biography ) $ ( "#band-biography" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( biography ) ;
2015-06-16 22:55:55 +00:00
if ( website ) $ ( "#band-website" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( website ) ;
if ( genres ) $ ( "#band-genres" ) . closest ( 'div.field' ) . addClass ( 'error' ) . end ( ) . after ( genres ) ;
2014-02-13 22:57:48 +00:00
}
2014-02-19 22:56:13 +00:00
function buildBand ( ) {
2015-05-30 02:04:33 +00:00
var band = { instruments : [ ] } ;
2015-05-28 22:12:39 +00:00
band . id = ( isNewBand ( ) ) ? null : bandId ;
2014-02-13 22:57:48 +00:00
band . name = $ ( "#band-name" ) . val ( ) ;
band . website = $ ( "#band-website" ) . val ( ) ;
band . biography = $ ( "#band-biography" ) . val ( ) ;
band . city = $ ( "#band-city" ) . val ( ) ;
band . state = $ ( "#band-region" ) . val ( ) ;
band . country = $ ( "#band-country" ) . val ( ) ;
2015-05-19 18:32:15 +00:00
2015-05-23 18:00:22 +00:00
band . band _type = bandType . val ( ) ;
band . band _status = bandStatus . val ( ) ;
band . concert _count = concertCount . val ( ) ;
2015-05-28 19:21:55 +00:00
band . add _new _members = $ ( 'input[name="add_new_members"]:checked' ) . val ( ) == "yes"
band . paid _gigs = $ ( 'input[name="paid_gigs"]:checked' ) . val ( ) == "yes"
band . free _gigs = $ ( 'input[name="free_gigs"]:checked' ) . val ( ) == "yes"
band . touring _option = $ ( '#touring-option' ) . val ( ) == "yes"
2015-06-16 22:55:55 +00:00
2015-07-15 15:04:45 +00:00
if ( $screen . find ( "#play-commitment" ) . length == 0 ) {
2015-07-16 01:05:24 +00:00
logger . error ( "MISSING PLAY COMMITMENT" )
2015-07-15 15:04:45 +00:00
}
band . play _commitment = $screen . find ( "#play-commitment" ) . val ( )
band . hourly _rate = profileUtils . normalizeMoneyForSubmit ( $screen . find ( "#hourly-rate" ) . val ( ) )
band . gig _minimum = profileUtils . normalizeMoneyForSubmit ( $ ( "#gig-minimum" ) . val ( ) )
2015-06-16 22:55:55 +00:00
2015-05-30 02:04:33 +00:00
$ . each ( $selectedInstruments , function ( index , instrument ) {
var h = { }
h . instrument _id = instrument . id
h . proficiency _level = instrument . level
2015-06-16 22:55:55 +00:00
band . instruments . push ( h )
2015-05-30 02:04:33 +00:00
} )
2015-06-03 21:34:37 +00:00
if ( ! isNewBand ( ) ) {
mergePerformanceSamples ( band )
}
2014-02-19 22:56:13 +00:00
return band ;
}
2015-06-03 21:34:37 +00:00
function mergePerformanceSamples ( band ) {
// Collect and merge data from this sub-widget:
var performanceSampleData = accountProfileSamples . buildPlayer ( )
band . website = performanceSampleData . website
band . online _presences = performanceSampleData . online _presences
band . performance _samples = performanceSampleData . performance _samples
// Change player id to that of band. Widget currently hardwires current user id:
if ( band . online _presences ) {
for ( var i = 0 ; i < band . online _presences . length ; ++ i ) {
band . online _presences [ i ] . player _id = band . id
}
}
// Change player id to that of band. Widget currently hardwires current user id:
if ( band . performance _samples ) {
for ( var i = 0 ; i < band . performance _samples . length ; ++ i ) {
band . performance _samples [ i ] . player _id = band . id
}
}
return band
}
2015-05-30 02:04:33 +00:00
function renderDesiredExperienceLabel ( selectedInstruments ) {
$selectedInstruments = selectedInstruments
var instrumentText = ""
$ . each ( $selectedInstruments , function ( index , instrument ) {
if ( instrumentText . length != 0 ) { instrumentText += ", " }
instrumentText += instrument . name
} )
$ ( "#desired-experience-label" ) . html ( ( $selectedInstruments && $selectedInstruments . length > 0 ) ? instrumentText : NONE _SPECIFIED )
}
2014-12-03 02:42:26 +00:00
function showProfile ( band _id ) {
context . location = "/client#/bandProfile/" + band _id ;
}
2015-06-17 20:05:19 +00:00
function saveInvitations ( response ) {
2015-05-20 19:17:53 +00:00
if ( 0 < $ ( '#selected-friends-band .invitation' ) . length ) {
createBandInvitations ( response . id , function ( ) {
showProfile ( response . id ) ;
} ) ;
}
}
2015-07-16 01:05:24 +00:00
function saveBand ( band , saveBandSuccessFn ) {
2015-06-16 22:55:55 +00:00
2015-05-20 19:17:53 +00:00
unbindNavButtons ( )
2015-07-16 01:05:24 +00:00
removeErrors ( )
2015-06-02 20:13:41 +00:00
2015-05-28 22:12:39 +00:00
var saveBandFn = ( isNewBand ( ) ) ? rest . createBand : rest . updateBand
2015-05-21 00:46:29 +00:00
saveBandFn ( band )
2015-06-16 22:55:55 +00:00
. done ( function ( response ) {
2015-06-02 20:13:41 +00:00
bandId = response . id
2015-06-17 20:05:19 +00:00
saveInvitations ( response )
2015-06-02 20:13:41 +00:00
if ( saveBandSuccessFn ) {
saveBandSuccessFn ( band )
}
2015-05-21 00:46:29 +00:00
} )
2015-06-16 22:55:55 +00:00
. fail ( function ( jqXHR ) {
2015-05-21 00:46:29 +00:00
if ( jqXHR . status == 422 ) {
renderErrors ( JSON . parse ( jqXHR . responseText ) )
} else {
2014-02-13 22:57:48 +00:00
app . notifyServerError ( jqXHR , "Unable to create band" )
2014-11-23 00:29:12 +00:00
}
2015-06-16 22:55:55 +00:00
} )
. always ( function ( jqXHR ) {
bindNavButtons ( )
} )
2014-02-13 22:57:48 +00:00
}
function createBandInvitations ( bandId , onComplete ) {
var callCount = 0 ;
var totalInvitations = 0 ;
2014-03-13 10:51:21 +00:00
$ ( '#selected-friends-band .invitation' ) . each ( function ( index , invitation ) {
2014-02-13 22:57:48 +00:00
callCount ++ ;
totalInvitations ++ ;
var userId = $ ( invitation ) . attr ( 'user-id' ) ;
rest . createBandInvitation ( bandId , userId )
. done ( function ( response ) {
callCount -- ;
} ) . fail ( app . ajaxError ) ;
} ) ;
function checker ( ) {
if ( callCount === 0 ) {
onComplete ( ) ;
} else {
context . setTimeout ( checker , 10 ) ;
2013-11-21 06:24:40 +00:00
}
2014-02-13 22:57:48 +00:00
}
checker ( ) ;
return totalInvitations ;
}
function beforeShow ( data ) {
2014-03-10 15:14:12 +00:00
inviteMusiciansUtil . clearSelections ( ) ;
2014-02-19 22:56:13 +00:00
bandId = data . id == 'new' ? '' : data . id ;
2015-05-20 19:17:53 +00:00
currentStep = 0
if ( data [ 'd' ] ) {
var stepNum = data [ 'd' ] . substring ( 4 )
if ( stepNum ) {
currentStep = stepNum
2015-06-16 22:55:55 +00:00
delete data [ 'd' ] ;
2015-05-20 19:17:53 +00:00
}
2015-06-16 22:55:55 +00:00
}
2015-05-29 03:39:32 +00:00
resetForm ( ) ;
2014-02-13 22:57:48 +00:00
}
function afterShow ( data ) {
2014-03-10 15:14:12 +00:00
inviteMusiciansUtil . loadFriends ( ) ;
2014-02-13 22:57:48 +00:00
2015-05-28 22:12:39 +00:00
if ( ! isNewBand ( ) ) {
2014-02-15 21:19:03 +00:00
$ ( "#band-change-photo" ) . html ( 'Upload band photo.' ) ;
2015-05-19 00:19:54 +00:00
$ ( '.band-photo' ) . removeClass ( "hidden" )
2015-06-16 22:55:55 +00:00
2014-02-13 22:57:48 +00:00
// retrieve and initialize band profile data points
2015-06-16 22:55:55 +00:00
loadBandDetails ( ) ;
2015-05-21 00:46:29 +00:00
} else {
2014-02-13 22:57:48 +00:00
loadGenres ( ) ;
2015-05-21 00:46:29 +00:00
// Load geo settings:
rest . getResolvedLocation ( ) . done ( function ( location ) {
loadCountries ( location . country , function ( ) {
loadRegions ( location . region , function ( ) {
loadCities ( location . city ) ;
2013-11-23 20:06:42 +00:00
} ) ;
2014-02-13 22:57:48 +00:00
} ) ;
2015-05-21 00:46:29 +00:00
} ) ;
2013-11-21 06:24:40 +00:00
2015-05-19 00:19:54 +00:00
$ ( '.band-photo' ) . addClass ( "hidden" )
2014-02-13 22:57:48 +00:00
}
2015-05-23 13:36:48 +00:00
renderCurrentPage ( )
2014-02-13 22:57:48 +00:00
}
2013-12-01 20:09:44 +00:00
2015-05-30 02:04:33 +00:00
function loadDesiredExperience ( ) {
}
2015-06-16 22:55:55 +00:00
2014-02-13 22:57:48 +00:00
function loadBandDetails ( ) {
rest . getBand ( bandId ) . done ( function ( band ) {
$ ( "#band-name" ) . val ( band . name ) ;
$ ( "#band-website" ) . val ( band . website ) ;
$ ( "#band-biography" ) . val ( band . biography ) ;
2013-11-23 20:06:42 +00:00
2015-05-23 18:00:22 +00:00
bandType . val ( band . band _type )
bandStatus . val ( band . band _status )
concertCount . val ( band . concert _count )
2015-06-16 22:55:55 +00:00
2015-05-28 19:21:55 +00:00
if ( band . add _new _members ) {
$ ( "#new-member-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
} else {
$ ( "#new-member-yes" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
}
if ( band . paid _gigs ) {
$ ( "#paid-gigs-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
} else {
$ ( "#paid-gigs-yes" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
}
2015-05-23 18:00:22 +00:00
2015-05-28 19:21:55 +00:00
if ( band . free _gigs ) {
$ ( "#free-gigs-no" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
} else {
$ ( "#free-gigs-yes" ) . iCheck ( 'check' ) . attr ( 'checked' , 'checked' )
}
$ ( '#touring-option' ) . val ( band . touring _option ? 'yes' : 'no' )
$ ( "#play-commitment" ) . val ( band . play _commitment )
2015-07-15 15:04:45 +00:00
$ ( "#hourly-rate" ) . val ( profileUtils . normalizeMoneyForDisplay ( band . hourly _rate ) )
$ ( "#gig-minimum" ) . val ( profileUtils . normalizeMoneyForDisplay ( band . gig _minimum ) )
2015-06-16 22:55:55 +00:00
2015-05-28 19:21:55 +00:00
// Initialize avatar
2014-02-13 22:57:48 +00:00
if ( band . photo _url ) {
$ ( "#band-avatar" ) . attr ( 'src' , band . photo _url ) ;
2013-11-21 06:24:40 +00:00
}
2014-02-13 22:57:48 +00:00
loadGenres ( band . genres ) ;
loadCountries ( band . country , function ( ) {
loadRegions ( band . state , function ( ) {
loadCities ( band . city ) ;
} ) ;
} ) ;
2015-05-28 22:12:39 +00:00
renderOptionalControls ( ) ;
2014-02-13 22:57:48 +00:00
2015-05-30 02:04:33 +00:00
$ . each ( band . instruments , function ( index , instrument ) {
var h = { }
h . id = instrument . instrument _id
h . level = instrument . proficiency _level
h . approve = true
$selectedInstruments . push ( h )
} )
renderDesiredExperienceLabel ( $selectedInstruments )
2015-06-16 22:55:55 +00:00
accountProfileSamples . renderPlayer ( band )
2015-06-02 20:13:41 +00:00
2014-02-13 22:57:48 +00:00
} ) ;
}
function loadGenres ( selectedGenres ) {
$ ( "#band-genres" ) . empty ( ) ;
rest . getGenres ( ) . done ( function ( genres ) {
$ . each ( genres , function ( index , genre ) {
var genreTemplate = $ ( '#template-band-setup-genres' ) . html ( ) ;
var selected = '' ;
if ( selectedGenres ) {
var genreMatch = $ . grep ( selectedGenres , function ( n , i ) {
return n . id === genre . id ;
2013-11-23 20:06:42 +00:00
} ) ;
2014-02-13 22:57:48 +00:00
if ( genreMatch . length > 0 ) {
selected = "checked" ;
2013-11-21 06:24:40 +00:00
}
2014-02-13 22:57:48 +00:00
}
var genreHtml = context . JK . fillTemplate ( genreTemplate , {
id : genre . id ,
description : genre . description ,
checked : selected
} ) ;
$ ( '#band-genres' ) . append ( genreHtml ) ;
} ) ;
} ) ;
}
function loadCountries ( initialCountry , onCountriesLoaded ) {
2014-03-18 03:20:41 +00:00
var countrySelect = $ ( "#band-country" ) ;
2014-02-13 22:57:48 +00:00
2014-03-18 03:20:41 +00:00
var nilOption = $ ( nilOptionStr ) ;
2014-02-13 22:57:48 +00:00
nilOption . text ( nilOptionText ) ;
2014-03-18 03:20:41 +00:00
countrySelect . append ( nilOption ) ;
2014-02-13 22:57:48 +00:00
2014-07-20 02:11:16 +00:00
rest . getCountries ( ) . done ( function ( response ) {
2014-03-18 03:20:41 +00:00
$ . each ( response [ "countriesx" ] , function ( index , countryx ) {
if ( ! countryx . countrycode ) return ;
var option = $ ( nilOptionStr ) ;
option . text ( countryx . countryname ) ;
option . attr ( "value" , countryx . countrycode ) ;
2014-02-13 22:57:48 +00:00
2014-03-18 03:20:41 +00:00
if ( initialCountry === countryx . countrycode ) {
2014-02-13 22:57:48 +00:00
option . attr ( "selected" , "selected" ) ;
}
2014-03-18 03:20:41 +00:00
countrySelect . append ( option ) ;
2014-02-13 22:57:48 +00:00
} ) ;
2014-03-18 03:20:41 +00:00
context . JK . dropdown ( countrySelect ) ;
2014-02-13 22:57:48 +00:00
if ( onCountriesLoaded ) {
onCountriesLoaded ( ) ;
2013-11-21 06:24:40 +00:00
}
2014-02-13 22:57:48 +00:00
} ) ;
}
function loadRegions ( initialRegion , onRegionsLoaded ) {
var $region = $ ( "#band-region" ) ;
var selectedCountry = $ ( "#band-country" ) . val ( ) ;
2015-07-18 19:26:50 +00:00
$region . empty ( ) ;
2014-03-18 03:20:41 +00:00
var nilOption = $ ( nilOptionStr ) ;
2014-02-13 22:57:48 +00:00
nilOption . text ( nilOptionText ) ;
$region . append ( nilOption ) ;
if ( selectedCountry ) {
rest . getRegions ( { 'country' : selectedCountry } ) . done ( function ( response ) {
2015-07-18 19:26:50 +00:00
$region . empty ( ) ;
var nilOption = $ ( nilOptionStr ) ;
nilOption . text ( nilOptionText ) ;
$region . append ( nilOption ) ;
2014-02-13 22:57:48 +00:00
$ . each ( response [ "regions" ] , function ( index , region ) {
if ( ! region ) return ;
2014-03-18 03:20:41 +00:00
var option = $ ( nilOptionStr ) ;
2014-06-25 14:49:33 +00:00
option . text ( region [ 'name' ] ) ;
option . attr ( "value" , region [ 'region' ] ) ;
2014-02-13 22:57:48 +00:00
2014-06-25 14:49:33 +00:00
if ( initialRegion === region [ 'region' ] ) {
2014-02-13 22:57:48 +00:00
option . attr ( "selected" , "selected" ) ;
2013-11-21 06:24:40 +00:00
}
2014-02-13 22:57:48 +00:00
$region . append ( option ) ;
} ) ;
2013-11-23 20:06:42 +00:00
2014-02-13 22:57:48 +00:00
context . JK . dropdown ( $region ) ;
2014-06-25 14:49:33 +00:00
if ( onRegionsLoaded ) {
onRegionsLoaded ( ) ;
}
} ) . error ( function ( err ) {
context . JK . dropdown ( $region ) ;
2014-02-13 22:57:48 +00:00
if ( onRegionsLoaded ) {
onRegionsLoaded ( ) ;
}
} ) ;
}
}
2013-12-01 06:25:01 +00:00
2014-02-13 22:57:48 +00:00
function loadCities ( initialCity ) {
var $city = $ ( "#band-city" ) ;
$city . empty ( ) ;
var selectedCountry = $ ( "#band-country" ) . val ( ) ;
var selectedRegion = $ ( "#band-region" ) . val ( ) ;
2013-12-01 06:25:01 +00:00
2014-03-18 03:20:41 +00:00
var nilOption = $ ( nilOptionStr ) ;
2014-02-13 22:57:48 +00:00
nilOption . text ( nilOptionText ) ;
$city . append ( nilOption ) ;
2014-06-25 14:49:33 +00:00
nilOption . attr ( 'selected' , 'selected' ) ;
2013-11-21 06:24:40 +00:00
2014-02-13 22:57:48 +00:00
if ( selectedCountry && selectedRegion ) {
rest . getCities ( { 'country' : selectedCountry , 'region' : selectedRegion } ) . done ( function ( response ) {
$ . each ( response [ "cities" ] , function ( index , city ) {
if ( ! city ) return ;
2014-03-18 03:20:41 +00:00
var option = $ ( nilOptionStr ) ;
2014-02-13 22:57:48 +00:00
option . text ( city ) ;
option . attr ( "value" , city ) ;
2013-11-21 06:24:40 +00:00
2014-02-13 22:57:48 +00:00
if ( initialCity === city ) {
option . attr ( "selected" , "selected" ) ;
}
2013-11-21 06:24:40 +00:00
2014-02-13 22:57:48 +00:00
$city . append ( option ) ;
} ) ;
context . JK . dropdown ( $city ) ;
2014-06-25 14:49:33 +00:00
} ) . error ( function ( err ) {
context . JK . dropdown ( $city ) ;
2014-02-13 22:57:48 +00:00
} ) ;
2014-06-25 14:49:33 +00:00
} else {
context . JK . dropdown ( $city ) ;
2014-02-13 22:57:48 +00:00
}
2015-06-16 22:55:55 +00:00
}
2014-02-13 22:57:48 +00:00
function addInvitation ( value , data ) {
if ( $ ( '#selected-band-invitees div[user-id=' + data + ']' ) . length === 0 ) {
var template = $ ( '#template-band-invitation' ) . html ( ) ;
var invitationHtml = context . JK . fillTemplate ( template , { userId : data , userName : value } ) ;
$ ( '#selected-band-invitees' ) . append ( invitationHtml ) ;
$ ( '#band-invitee-input' ) . select ( ) ;
selectedFriendIds [ data ] = true ;
2015-05-28 19:21:55 +00:00
} else {
2014-02-13 22:57:48 +00:00
$ ( '#band-invitee-input' ) . select ( ) ;
context . alert ( 'Invitation already exists for this musician.' ) ;
}
}
2014-02-15 21:19:03 +00:00
function navigateToBandPhoto ( evt ) {
evt . stopPropagation ( ) ;
2014-02-19 22:56:13 +00:00
context . location = '/client#/band/setup/photo/' + bandId ;
2014-02-15 21:19:03 +00:00
return false ;
}
2015-06-16 22:55:55 +00:00
2014-02-13 22:57:48 +00:00
function removeInvitation ( evt ) {
delete selectedFriendIds [ $ ( evt . currentTarget ) . parent ( ) . attr ( 'user-id' ) ] ;
$ ( evt . currentTarget ) . closest ( '.invitation' ) . remove ( ) ;
}
2015-06-16 22:55:55 +00:00
function bindNavButtons ( ) {
2015-05-20 19:17:53 +00:00
$ ( '#btn-band-setup-back' ) . on ( "click" , function ( e ) {
2015-06-16 22:55:55 +00:00
e . stopPropagation ( )
2015-05-20 19:17:53 +00:00
navBack ( )
return false
} )
2014-02-13 22:57:48 +00:00
2015-05-20 19:17:53 +00:00
$ ( '#btn-band-setup-cancel' ) . on ( "click" , function ( e ) {
2015-06-16 22:55:55 +00:00
e . stopPropagation ( )
2015-05-20 19:17:53 +00:00
navCancel ( )
return false
} )
2014-02-13 22:57:48 +00:00
2015-05-20 19:17:53 +00:00
$ ( '#btn-band-setup-next' ) . on ( "click" , function ( e ) {
2015-06-16 22:55:55 +00:00
e . stopPropagation ( )
2015-05-20 19:17:53 +00:00
navNext ( )
return false
} )
$ ( '#btn-band-setup-back' ) . removeClass ( "disabled" )
$ ( '#btn-band-setup-cancel' ) . removeClass ( "disabled" )
$ ( '#btn-band-setup-next' ) . removeClass ( "disabled" )
2015-05-19 00:19:54 +00:00
}
2015-05-20 19:17:53 +00:00
function unbindNavButtons ( ) {
2015-05-19 00:19:54 +00:00
$ ( '#btn-band-setup-back' ) . off ( "click" )
2015-05-20 19:17:53 +00:00
$ ( '#btn-band-setup-cancel' ) . off ( "click" )
$ ( '#btn-band-setup-next' ) . off ( "click" )
2015-06-16 22:55:55 +00:00
$ ( '#btn-band-setup-back' ) . addClass ( "disabled" )
$ ( '#btn-band-setup-cancel' ) . addClass ( "disabled" )
$ ( '#btn-band-setup-next' ) . addClass ( "disabled" )
2015-05-19 00:19:54 +00:00
}
function events ( ) {
$ ( '#selected-band-invitees' ) . on ( "click" , ".invitation a" , removeInvitation ) ;
2015-05-20 19:17:53 +00:00
bindNavButtons ( ) ;
2015-05-19 00:19:54 +00:00
// friend input focus
$ ( '#band-invitee-input' ) . focus ( function ( ) {
$ ( this ) . val ( '' ) ;
2015-06-16 22:55:55 +00:00
} ) ;
2014-02-13 22:57:48 +00:00
$ ( '#band-country' ) . on ( 'change' , function ( evt ) {
evt . stopPropagation ( ) ;
loadRegions ( ) ;
loadCities ( ) ;
return false ;
} ) ;
$ ( '#band-region' ) . on ( 'change' , function ( evt ) {
evt . stopPropagation ( ) ;
loadCities ( ) ;
return false ;
} ) ;
2014-02-15 21:19:03 +00:00
$ ( '#band-change-photo' ) . click ( navigateToBandPhoto ) ;
2015-05-19 00:19:54 +00:00
$ ( '#band-setup .band-avatar-profile' ) . click ( navigateToBandPhoto ) ;
2014-02-13 22:57:48 +00:00
$ ( 'div[layout-id="band/setup"] .btn-email-invitation' ) . click ( function ( ) {
invitationDialog . showEmailDialog ( ) ;
} ) ;
$ ( 'div[layout-id="band/setup"] .btn-gmail-invitation' ) . click ( function ( ) {
invitationDialog . showGoogleDialog ( ) ;
} ) ;
$ ( 'div[layout-id="band/setup"] .btn-facebook-invitation' ) . click ( function ( ) {
invitationDialog . showFacebookDialog ( ) ;
} ) ;
2015-05-28 22:12:39 +00:00
2015-05-30 02:04:33 +00:00
$ ( 'a#choose-desired-experience' ) . on ( "click" , chooseExperience )
2015-05-28 22:12:39 +00:00
$ ( '#band-setup' ) . on ( 'ifToggled' , 'input[type="radio"].dependent-master' , renderOptionalControls ) ;
2015-06-16 22:55:55 +00:00
2014-03-13 08:47:27 +00:00
$ ( friendInput ) . focus ( function ( ) { $ ( this ) . val ( '' ) ; } )
2014-02-13 22:57:48 +00:00
}
2015-06-16 22:55:55 +00:00
function chooseExperience ( e ) {
e . stopPropagation ( )
ui . launchInstrumentSelectorDialog ( "new member(s)" , $selectedInstruments , function ( selectedInstruments ) {
$selectedInstruments = selectedInstruments
2015-05-30 02:04:33 +00:00
renderDesiredExperienceLabel ( $selectedInstruments )
return false
} )
2015-06-16 22:55:55 +00:00
return false
2015-05-30 02:04:33 +00:00
}
2015-06-02 20:13:41 +00:00
function loadBandCallback ( ) {
2015-06-16 22:55:55 +00:00
return ( isNewBand ( ) ) ? { } : rest . getBand ( bandId )
2015-06-02 20:13:41 +00:00
}
2014-07-09 22:20:20 +00:00
function initialize ( invitationDialogInstance , friendSelectorDialog ) {
2015-05-31 22:35:09 +00:00
inviteMusiciansUtil = new JK . InviteMusiciansUtil ( app )
inviteMusiciansUtil . initialize ( friendSelectorDialog )
friendInput = inviteMusiciansUtil . inviteBandCreate ( '#band-setup-invite-musicians' , "<div class='left w70'>If your bandmates are already on JamKazam, start typing their names in the box below, or click the Choose Friends button to select them.</div>" )
invitationDialog = invitationDialogInstance
events ( )
2014-02-13 22:57:48 +00:00
var screenBindings = {
'beforeShow' : beforeShow ,
'afterShow' : afterShow
2015-05-31 22:35:09 +00:00
}
2014-02-13 22:57:48 +00:00
2015-05-23 18:00:22 +00:00
bandType = $ ( "#band-type" )
bandStatus = $ ( "#band-status" )
concertCount = $ ( "#concert-count" )
2015-06-16 22:55:55 +00:00
2015-05-31 22:35:09 +00:00
app . bindScreen ( 'band/setup' , screenBindings )
2015-05-27 18:11:12 +00:00
2015-06-03 22:44:17 +00:00
$screen . find ( 'input[type=radio]' ) . iCheck ( {
2015-05-31 14:53:28 +00:00
checkboxClass : 'icheckbox_minimal' ,
radioClass : 'iradio_minimal' ,
inheritClass : true
2015-05-31 22:35:09 +00:00
} )
2015-05-31 14:53:28 +00:00
2015-06-16 22:55:55 +00:00
profileUtils . initializeHelpBubbles ( )
2014-02-13 22:57:48 +00:00
}
this . initialize = initialize ;
this . afterShow = afterShow ;
return this ;
2015-06-16 22:55:55 +00:00
} ;
2014-02-13 22:57:48 +00:00
} ) ( window , jQuery ) ;