#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" 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('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>
<form id="editUserProfileForm">
<ul data-role="listview" class="ulForm">
@ -22,14 +22,7 @@
</li>
<li id="fldMaxParentalRating" style="display: none;">
<label for="selectMaxParentalRating">Max parental rating:</label>
<select name="selectMaxParentalRating" id="selectMaxParentalRating">
<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>
<select name="selectMaxParentalRating" id="selectMaxParentalRating"></select>
</li>
<li id="fldIsAdmin" style="display: none;">
<input type="checkbox" id="chkIsAdmin" name="chkIsAdmin" />
@ -67,4 +60,4 @@
</script>
</div>
</body>
</html>
</html>

View File

@ -22,17 +22,39 @@
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>";
}
$('#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) {
@ -47,10 +69,29 @@
$('#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) {
populateLanguages($('#selectAudioLanguage', page), allCultures);
populateLanguages($('#selectSubtitleLanguage', page), allCultures);
@ -135,7 +176,7 @@
$(document).on('pagebeforeshow', "#editUserPage", function () {
var page = this;
var userId = getParameterByName("userId");
if (userId) {
@ -179,11 +220,13 @@
var promise2 = Dashboard.getCurrentUser();
var parentalRatingsPromise = ApiClient.getParentalRatings();
var allCulturesPromise = ApiClient.getCultures();
$.when(promise1, promise2).done(function (response1, response2) {
loadUser(page, response1[0] || response1, response2[0], allCulturesPromise);
loadUser(page, response1[0] || response1, response2[0], parentalRatingsPromise, allCulturesPromise);
});