VRFS-3335 : Conditional validation for hourly rate and daily minimum when editing profile.
* Use conditional validation on server side * Don’t always convert empty to 0 on client side * On view, manipulate visibility of dependent items through classes.
This commit is contained in:
parent
d8e712e85c
commit
d999978f84
|
|
@ -23,8 +23,8 @@ module JamRuby
|
|||
validate :validate_photo_info
|
||||
validate :require_at_least_one_genre, :unless => :skip_genre_validation
|
||||
validate :limit_max_genres
|
||||
validates_numericality_of :hourly_rate, greater_than:0, less_than:100000, :allow_nil => true
|
||||
validates_numericality_of :gig_minimum, greater_than:0, less_than:200000, :allow_nil => true
|
||||
validates_numericality_of :hourly_rate, greater_than:0, less_than:100000, :if => :paid_gigs
|
||||
validates_numericality_of :gig_minimum, greater_than:0, less_than:200000, :if => :paid_gigs
|
||||
|
||||
before_save :check_lat_lng
|
||||
before_save :check_website_url
|
||||
|
|
|
|||
|
|
@ -197,9 +197,9 @@ module JamRuby
|
|||
validates :last_jam_updated_reason, :inclusion => {:in => [nil, JAM_REASON_REGISTRATION, JAM_REASON_NETWORK_TEST, JAM_REASON_FTUE, JAM_REASON_JOIN, JAM_REASON_IMPORT, JAM_REASON_LOGIN] }
|
||||
|
||||
# stored in cents
|
||||
validates_numericality_of :paid_sessions_hourly_rate, greater_than:0, less_than:200000, :allow_nil => true
|
||||
validates_numericality_of :paid_sessions_hourly_rate, greater_than:0, less_than:200000, :if => :paid_sessions
|
||||
# stored in cents
|
||||
validates_numericality_of :paid_sessions_daily_rate, greater_than:0, less_than:5000000, :allow_nil => true
|
||||
validates_numericality_of :paid_sessions_daily_rate, greater_than:0, less_than:5000000, :if => :paid_sessions
|
||||
|
||||
# custom validators
|
||||
validate :validate_musician_instruments
|
||||
|
|
|
|||
|
|
@ -148,13 +148,15 @@
|
|||
// convert the value to cents
|
||||
$hourlyRate.val(profileUtils.normalizeMoneyForDisplay(userDetail.paid_sessions_hourly_rate));
|
||||
$dailyRate.val(profileUtils.normalizeMoneyForDisplay(userDetail.paid_sessions_daily_rate));
|
||||
|
||||
|
||||
$cowritingPurpose.val(userDetail.cowriting_purpose)
|
||||
context.JK.dropdown($cowritingPurpose)
|
||||
|
||||
renderOptionalControls()
|
||||
}
|
||||
|
||||
function bindGenreSelector(type, $btnSelect, $genreList) {
|
||||
$btnSelect.unbind('click').bind('click', function(e) {
|
||||
function bindGenreSelector(type, $btnSelect, $genreList) {
|
||||
$btnSelect.unbind('click').bind('click', function(e) {
|
||||
e.preventDefault()
|
||||
var genreText = $genreList.html()
|
||||
var genres = []
|
||||
|
|
@ -162,7 +164,7 @@
|
|||
genres = genreText.split(GENRE_LIST_DELIMITER)
|
||||
}
|
||||
|
||||
ui.launchGenreSelectorDialog(type, genres, function(selectedGenres) {
|
||||
ui.launchGenreSelectorDialog(type, genres, function(selectedGenres) {
|
||||
$genreList.html(selectedGenres && selectedGenres.length > 0 ? selectedGenres.join(GENRE_LIST_DELIMITER) : NONE_SPECIFIED)
|
||||
})
|
||||
|
||||
|
|
@ -194,7 +196,8 @@
|
|||
|
||||
context.JK.dropdown($virtualBandCommitment)
|
||||
context.JK.dropdown($traditionalBandCommitment)
|
||||
context.JK.dropdown($cowritingPurpose)
|
||||
context.JK.dropdown($cowritingPurpose)
|
||||
$screen.on('ifToggled', 'input[type="radio"].dependent-master', renderOptionalControls);
|
||||
}
|
||||
|
||||
function enableSubmits() {
|
||||
|
|
@ -219,6 +222,52 @@
|
|||
})
|
||||
}
|
||||
|
||||
function isChecked(val) {
|
||||
return (val && val != "false");
|
||||
}
|
||||
|
||||
function renderOptionalControls(e) {
|
||||
if(e){e.stopPropagation()}
|
||||
|
||||
|
||||
// Is virtual band selected?
|
||||
if (isChecked($screen.find($('input[name="virtual_band"]:checked')).val())) {
|
||||
$screen.find($(".virtual-band-dependent")).removeClass("hidden")
|
||||
} else {
|
||||
$screen.find($(".virtual-band-dependent")).addClass("hidden")
|
||||
}
|
||||
|
||||
// Is traditional band selected?
|
||||
if (isChecked($screen.find($('input[name="traditional_band"]:checked')).val())) {
|
||||
$screen.find($(".traditional-band-dependent")).removeClass("hidden")
|
||||
} else {
|
||||
$screen.find($(".traditional-band-dependent")).addClass("hidden")
|
||||
}
|
||||
|
||||
// Is paid sessions selected?
|
||||
if (isChecked($screen.find($('input[name="paid_sessions"]:checked')).val())) {
|
||||
$screen.find($(".paid-sessions-dependent")).removeClass("hidden")
|
||||
} else {
|
||||
$screen.find($(".paid-sessions-dependent")).addClass("hidden")
|
||||
}
|
||||
|
||||
// Is free sessions selected?
|
||||
if (isChecked($screen.find($('input[name="free_sessions"]:checked')).val())) {
|
||||
$screen.find($(".free-sessions-dependent")).removeClass("hidden")
|
||||
} else {
|
||||
$screen.find($(".free-sessions-dependent")).addClass("hidden")
|
||||
}
|
||||
|
||||
// Is cowriting selected?
|
||||
if (isChecked($screen.find($('input[name="cowriting"]:checked')).val())) {
|
||||
$screen.find($(".cowriting-dependent")).removeClass("hidden")
|
||||
} else {
|
||||
$screen.find($(".cowriting-dependent")).addClass("hidden")
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function navigateTo(targetLocation) {
|
||||
context.location = targetLocation
|
||||
}
|
||||
|
|
@ -285,7 +334,7 @@
|
|||
app.bindScreen('account/profile/interests', screenBindings)
|
||||
|
||||
events()
|
||||
|
||||
|
||||
$screen.find('.interest-options').iCheck({
|
||||
checkboxClass: 'icheckbox_minimal',
|
||||
radioClass: 'iradio_minimal',
|
||||
|
|
@ -294,11 +343,11 @@
|
|||
|
||||
profileUtils.initializeHelpBubbles($screen)
|
||||
}
|
||||
|
||||
|
||||
this.initialize = initialize
|
||||
this.beforeShow = beforeShow
|
||||
this.afterShow = afterShow
|
||||
this.afterShow = afterShow
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
})(window,jQuery)
|
||||
|
|
@ -99,6 +99,10 @@
|
|||
|
||||
// the server stores money in cents; display it as such
|
||||
profileUtils.normalizeMoneyForDisplay = function(serverValue) {
|
||||
if (!serverValue || serverValue==="") {
|
||||
// Blank value is valid:
|
||||
return ""
|
||||
}
|
||||
if(serverValue || serverValue == 0) {
|
||||
return (new Number(serverValue) / 100).toFixed(2)
|
||||
}
|
||||
|
|
@ -109,6 +113,10 @@
|
|||
|
||||
// the server stores money in cents; normalize it from what user entered
|
||||
profileUtils.normalizeMoneyForSubmit = function(clientValue) {
|
||||
if (!clientValue || clientValue==="") {
|
||||
// Blank value is valid:
|
||||
return ""
|
||||
}
|
||||
var money = new Number(clientValue);
|
||||
|
||||
if(!context._.isNaN(money)) {
|
||||
|
|
|
|||
|
|
@ -20,23 +20,24 @@
|
|||
<label>I would like to join a virtual band <a class="help" help-topic="profile-interests-virtual-band">[?]</a></label>
|
||||
<div class="yes-no-options">
|
||||
<div class="option">
|
||||
<input type="radio" name="virtual_band" id="virtual-band-yes" value="true" />
|
||||
<input type="radio" name="virtual_band" id="virtual-band-yes" class="dependent-master" value="true"/>
|
||||
<label for="virtual-band-yes">Yes</label>
|
||||
</div>
|
||||
<div class="option">
|
||||
<input type="radio" name="virtual_band" id="virtual-band-no" value="false" />
|
||||
<input type="radio" name="virtual_band" id="virtual-band-no" class="dependent-master" value="false" />
|
||||
<label for="virtual-band-no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="virtual-band-genres" class="left genres">
|
||||
|
||||
<div id="virtual-band-genres" class="left genres virtual-band-dependent hidden">
|
||||
<label>Desired Genre <a class="select-genre">select</a></label>
|
||||
<span class="genre-list"></span>
|
||||
</div>
|
||||
|
||||
<div class="field left play-commitment">
|
||||
<div class="field left play-commitment virtual-band-dependent hidden">
|
||||
<label>Play Commitment</label>
|
||||
<select id="virtual-band-commitment" name="virtual_band_commitment">
|
||||
<option value="1">infrequent</option>
|
||||
|
|
@ -46,6 +47,7 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="clearall"></div>
|
||||
|
||||
|
|
@ -54,22 +56,21 @@
|
|||
<label>I would like to join a traditional band <a class="help" help-topic="profile-interests-traditional-band">[?]</a></label>
|
||||
<div class="yes-no-options">
|
||||
<div class="option">
|
||||
<input type="radio" name="traditional_band" id="traditional-band-yes" value="true" />
|
||||
<input type="radio" name="traditional_band" id="traditional-band-yes" class="dependent-master" value="true" />
|
||||
<label for="traditional-band-yes">Yes</label>
|
||||
</div>
|
||||
<div class="option">
|
||||
<input type="radio" name="traditional_band" id="traditional-band-no" value="false" />
|
||||
<input type="radio" name="traditional_band" id="traditional-band-no" class="dependent-master" value="false" />
|
||||
<label for="traditional-band-no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="traditional-band-genres" class="left genres">
|
||||
<div id="traditional-band-genres" class="left genres traditional-band-dependent hidden">
|
||||
<label>Desired Genre <a class="select-genre">select</a></label>
|
||||
<span class="genre-list"></span>
|
||||
</div>
|
||||
|
||||
<div class="field left play-commitment">
|
||||
<div class="field left play-commitment traditional-band-dependent hidden">
|
||||
<label>Play Commitment</label>
|
||||
<select id="traditional-band-commitment" name="traditional_band_commitment">
|
||||
<option value="1">infrequent</option>
|
||||
|
|
@ -79,7 +80,7 @@
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<div class="field left">
|
||||
<div class="field left traditional-band-dependent hidden">
|
||||
<label>Touring Option</label>
|
||||
<select id="traditional-band-touring" name="touring">
|
||||
<option value='1'>Yes</option>
|
||||
|
|
@ -95,27 +96,27 @@
|
|||
<label>I am available to play in paid sessions <a class="help" help-topic="profile-interests-paid-sessions">[?]</a></label>
|
||||
<div class="yes-no-options">
|
||||
<div class="option">
|
||||
<input type="radio" name="paid_sessions" id="paid-sessions-yes" value="true" />
|
||||
<input type="radio" name="paid_sessions" id="paid-sessions-yes" class="dependent-master" value="true" />
|
||||
<label for="paid-sessions-yes">Yes</label>
|
||||
</div>
|
||||
<div class="option">
|
||||
<input type="radio" name="paid_sessions" id="paid-sessions-no" value="false" />
|
||||
<input type="radio" name="paid_sessions" id="paid-sessions-no" class="dependent-master" value="false" />
|
||||
<label for="paid-sessions-no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="paid-sessions-genres" class="genres">
|
||||
<div id="paid-sessions-genres" class="genres paid-sessions-dependent hidden">
|
||||
<label>Desired Genre <a class="select-genre">select</a></label>
|
||||
<span class="genre-list"></span>
|
||||
</div>
|
||||
|
||||
<div class="field left hourly-rate-holder">
|
||||
<div class="field left hourly-rate-holder paid-sessions-dependent hidden">
|
||||
<label>Hourly Rate:</label>
|
||||
<input type="text" class="rate" id="hourly-rate" name="paid_sessions_hourly_rate" />
|
||||
</div>
|
||||
|
||||
<div class="field left">
|
||||
<div class="field left paid-sessions-dependent hidden">
|
||||
<label>Daily Rate:</label>
|
||||
<input type="text" class="rate" id="daily-rate" name="paid_sessions_daily_rate" />
|
||||
</div>
|
||||
|
|
@ -128,17 +129,17 @@
|
|||
<label>I am available to play in free sessions <a class="help" help-topic="profile-interests-free-sessions">[?]</a></label>
|
||||
<div class="yes-no-options">
|
||||
<div class="option">
|
||||
<input type="radio" name="free_sessions" id="free-sessions-yes" value="true" />
|
||||
<input type="radio" name="free_sessions" id="free-sessions-yes" class="dependent-master" value="true" />
|
||||
<label for="free-sessions-yes">Yes</label>
|
||||
</div>
|
||||
<div class="option">
|
||||
<input type="radio" name="free_sessions" id="free-sessions-no" value="false" />
|
||||
<input type="radio" name="free_sessions" id="free-sessions-no" class="dependent-master" value="false" />
|
||||
<label for="free-sessions-no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="free-sessions-genres" class="left genres">
|
||||
<div id="free-sessions-genres" class="left genres free-sessions-dependent hidden">
|
||||
<label>Desired Genre <a class="select-genre">select</a></label>
|
||||
<span class="genre-list"></span>
|
||||
</div>
|
||||
|
|
@ -151,22 +152,22 @@
|
|||
<label>I would like to co-write with partner(s) <a class="help" help-topic="profile-interests-cowrite-partners">[?]</a></label>
|
||||
<div class="yes-no-options">
|
||||
<div class="option">
|
||||
<input type="radio" name="cowriting" id="cowriting-yes" value="true" />
|
||||
<input type="radio" name="cowriting" id="cowriting-yes" class="dependent-master" value="true" />
|
||||
<label for="cowriting-yes">Yes</label>
|
||||
</div>
|
||||
<div class="option">
|
||||
<input type="radio" name="cowriting" id="cowriting-no" value="false" />
|
||||
<input type="radio" name="cowriting" id="cowriting-no" class="dependent-master" value="false" />
|
||||
<label for="cowriting-no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="cowriting-genres" class="left genres">
|
||||
<div id="cowriting-genres" class="left genres cowriting-dependent hidden">
|
||||
<label>Desired Genre <a class="select-genre">select</a></label>
|
||||
<span class="genre-list"></span>
|
||||
</div>
|
||||
|
||||
<div class="field left purpose">
|
||||
<div class="field left purpose cowriting-dependent hidden">
|
||||
<label>Purpose</label>
|
||||
<select id="cowriting-purpose" name="cowriting_purpose">
|
||||
<option value='1'>just for fun</option>
|
||||
|
|
|
|||
Loading…
Reference in New Issue