#182 - Eliminate duplicates in the selection list for max rating in user screen

This commit is contained in:
Luke Pulverenti 2013-04-22 12:04:54 -04:00
parent 6e0c8a0fee
commit f88ed16bf0
2 changed files with 54 additions and 18 deletions

View File

@ -12,7 +12,7 @@
<a href="#" data-role="button" class="ui-btn-active">Profile</a> <a href="#" data-role="button" class="ui-btn-active">Profile</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('userimage.html', true);">Image</a> <a href="#" data-role="button" onclick="Dashboard.navigate('userimage.html', true);">Image</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('updatepassword.html', true);">Password</a> <a href="#" data-role="button" onclick="Dashboard.navigate('updatepassword.html', true);">Password</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('library.html', true);" class="lnkMediaLibrary" style="display: none;">Media Library</a> <a href="#" data-role="button" onclick="Dashboard.navigate('library.html', true);" class="lnkMediaLibrary" style="display:none;">Media Library</a>
</div> </div>
<form id="editUserProfileForm"> <form id="editUserProfileForm">
<ul data-role="listview" class="ulForm"> <ul data-role="listview" class="ulForm">
@ -22,14 +22,7 @@
</li> </li>
<li id="fldMaxParentalRating" style="display: none;"> <li id="fldMaxParentalRating" style="display: none;">
<label for="selectMaxParentalRating">Max parental rating:</label> <label for="selectMaxParentalRating">Max parental rating:</label>
<select name="selectMaxParentalRating" id="selectMaxParentalRating"> <select name="selectMaxParentalRating" id="selectMaxParentalRating"></select>
<option value="">None</option>
<option value="G">G</option>
<option value="PG">PG</option>
<option value="PG-13">PG-13</option>
<option value="R">R</option>
<option value="NC-17">NC-17</option>
</select>
</li> </li>
<li id="fldIsAdmin" style="display: none;"> <li id="fldIsAdmin" style="display: none;">
<input type="checkbox" id="chkIsAdmin" name="chkIsAdmin" /> <input type="checkbox" id="chkIsAdmin" name="chkIsAdmin" />

View File

@ -22,9 +22,31 @@
html += "<option value=''>None</option>"; html += "<option value=''>None</option>";
for (var i = 0, length = allParentalRatings.length; i < length; i++) { var ratings = [];
var i, length, rating;
var rating = allParentalRatings[i]; for (i = 0, length = allParentalRatings.length; i < length; i++) {
rating = allParentalRatings[i];
if (ratings.length) {
var lastRating = ratings[ratings.length - 1];
if (lastRating.Value === rating.Value) {
lastRating.Name += "/" + rating.Name;
continue;
}
}
ratings.push({ Name: rating.Name, Value: rating.Value });
}
for (i = 0, length = ratings.length; i < length; i++) {
rating = ratings[i];
html += "<option value='" + rating.Value + "'>" + rating.Name + "</option>"; html += "<option value='" + rating.Value + "'>" + rating.Name + "</option>";
} }
@ -32,7 +54,7 @@
$('#selectMaxParentalRating', page).html(html).selectmenu("refresh"); $('#selectMaxParentalRating', page).html(html).selectmenu("refresh");
} }
function loadUser(page, user, loggedInUser, allCulturesPromise) { function loadUser(page, user, loggedInUser, parentalRatingsPromise, allCulturesPromise) {
if (!loggedInUser.Configuration.IsAdministrator || user.Id == loggedInUser.Id) { if (!loggedInUser.Configuration.IsAdministrator || user.Id == loggedInUser.Id) {
@ -47,7 +69,26 @@
$('#txtUserName', page).val(user.Name); $('#txtUserName', page).val(user.Name);
$('#selectMaxParentalRating', page).val(user.Configuration.MaxParentalRating).selectmenu("refresh"); parentalRatingsPromise.done(function (allParentalRatings) {
populateRatings(allParentalRatings, page);
var ratingValue = "";
if (user.Configuration.MaxParentalRating) {
for (var i = 0, length = allParentalRatings.length; i < length; i++) {
var rating = allParentalRatings[i];
if (user.Configuration.MaxParentalRating >= rating.Value) {
ratingValue = rating.Value;
}
}
}
$('#selectMaxParentalRating', page).val(ratingValue).selectmenu("refresh");
});
allCulturesPromise.done(function (allCultures) { allCulturesPromise.done(function (allCultures) {
@ -179,11 +220,13 @@
var promise2 = Dashboard.getCurrentUser(); var promise2 = Dashboard.getCurrentUser();
var parentalRatingsPromise = ApiClient.getParentalRatings();
var allCulturesPromise = ApiClient.getCultures(); var allCulturesPromise = ApiClient.getCultures();
$.when(promise1, promise2).done(function (response1, response2) { $.when(promise1, promise2).done(function (response1, response2) {
loadUser(page, response1[0] || response1, response2[0], allCulturesPromise); loadUser(page, response1[0] || response1, response2[0], parentalRatingsPromise, allCulturesPromise);
}); });