2014-05-21 09:45:42 -07:00
|
|
|
|
(function ($, window, document) {
|
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
function renderViews(page, user, result) {
|
|
|
|
|
|
|
|
|
|
var folderHtml = '';
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
folderHtml += '<div data-role="controlgroup">';
|
|
|
|
|
folderHtml += result.Items.map(function (i) {
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var currentHtml = '';
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var id = 'chkGroupFolder' + i.Id;
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<label for="' + id + '">' + i.Name + '</label>';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var isChecked = user.Configuration.ExcludeFoldersFromGrouping.indexOf(i.Id) == -1;
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<input class="chkGroupFolder" data-folderid="' + i.Id + '" type="checkbox" id="' + id + '"' + checkedHtml + ' />';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
return currentHtml;
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
}).join('');
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
folderHtml += '</div>';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
$('.folderGroupList', page).html(folderHtml).trigger('create');
|
|
|
|
|
}
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
function renderChannels(page, user, result) {
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var folderHtml = '';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
folderHtml += '<div data-role="controlgroup">';
|
|
|
|
|
folderHtml += result.Items.map(function (i) {
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var currentHtml = '';
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var id = 'chkGroupChannel' + i.Id;
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<label for="' + id + '">' + i.Name + '</label>';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var isChecked = user.Configuration.DisplayChannelsWithinViews.indexOf(i.Id) != -1;
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
|
|
|
|
|
|
|
|
|
currentHtml += '<input class="chkGroupChannel" data-channelid="' + i.Id + '" type="checkbox" id="' + id + '"' + checkedHtml + ' />';
|
|
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
folderHtml += '</div>';
|
|
|
|
|
|
|
|
|
|
$('.channelGroupList', page).html(folderHtml).trigger('create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderViewOrder(page, user, result) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
html += '<ul data-role="listview" data-inset="true" data-mini="true">';
|
|
|
|
|
var index = 0;
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
html += result.Items.map(function (view) {
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var currentHtml = '';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<li data-mini="true" class="viewItem" data-viewid="' + view.Id + '">';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
if (index > 0) {
|
|
|
|
|
currentHtml += '<a href="#">' + view.Name + '</a>';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<a class="btnViewItemUp btnViewItemMove" href="#" data-icon="arrow-u">' + Globalize.translate('ButtonUp') + '</a>';
|
|
|
|
|
}
|
|
|
|
|
else if (result.Items.length > 1) {
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<a href="#">' + view.Name + '</a>';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += '<a class="btnViewItemDown btnViewItemMove" href="#" data-icon="arrow-d">' + Globalize.translate('ButtonDown') + '</a>';
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
currentHtml += view.Name;
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
}
|
|
|
|
|
html += '</li>';
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
index++;
|
|
|
|
|
return currentHtml;
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
html += '</ul>';
|
|
|
|
|
|
|
|
|
|
$('.viewOrderList', page).html(html).trigger('create');
|
|
|
|
|
}
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
function loadForm(page, user, hideMsg) {
|
|
|
|
|
|
|
|
|
|
$('#chkDisplayMissingEpisodes', page).checked(user.Configuration.DisplayMissingEpisodes || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkDisplayUnairedEpisodes', page).checked(user.Configuration.DisplayUnairedEpisodes || false).checkboxradio("refresh");
|
|
|
|
|
|
|
|
|
|
$('#chkGroupMoviesIntoCollections', page).checked(user.Configuration.GroupMoviesIntoBoxSets || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkDisplayCollectionView', page).checked(user.Configuration.DisplayCollectionsView || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkDisplayFolderView', page).checked(user.Configuration.DisplayFoldersView || false).checkboxradio("refresh");
|
|
|
|
|
|
|
|
|
|
var promise1 = ApiClient.getItems(user.Id, {
|
|
|
|
|
sortBy: "SortName"
|
2014-06-30 12:24:35 -07:00
|
|
|
|
});
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Channels", {
|
|
|
|
|
UserId: user.Id
|
|
|
|
|
}));
|
|
|
|
|
var promise3 = ApiClient.getUserViews(user.Id);
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2, promise3).done(function (r1, r2, r3) {
|
2014-06-30 12:24:35 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
renderViews(page, user, r1[0]);
|
|
|
|
|
renderChannels(page, user, r2[0]);
|
|
|
|
|
renderViewOrder(page, user, r3[0]);
|
|
|
|
|
|
|
|
|
|
if (hideMsg !== false) {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-21 09:45:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveUser(page, user) {
|
|
|
|
|
|
|
|
|
|
user.Configuration.DisplayMissingEpisodes = $('#chkDisplayMissingEpisodes', page).checked();
|
|
|
|
|
user.Configuration.DisplayUnairedEpisodes = $('#chkDisplayUnairedEpisodes', page).checked();
|
|
|
|
|
user.Configuration.GroupMoviesIntoBoxSets = $('#chkGroupMoviesIntoCollections', page).checked();
|
|
|
|
|
|
2014-06-30 19:29:27 -07:00
|
|
|
|
user.Configuration.DisplayCollectionsView = $('#chkDisplayCollectionView', page).checked();
|
2014-08-14 06:24:30 -07:00
|
|
|
|
user.Configuration.DisplayFoldersView = $('#chkDisplayFolderView', page).checked();
|
2014-06-30 19:29:27 -07:00
|
|
|
|
|
2014-06-04 19:32:40 -07:00
|
|
|
|
user.Configuration.ExcludeFoldersFromGrouping = $(".chkGroupFolder:not(:checked)", page).get().map(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
|
});
|
|
|
|
|
|
2014-06-30 12:24:35 -07:00
|
|
|
|
user.Configuration.DisplayChannelsWithinViews = $(".chkGroupChannel:checked", page).get().map(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-channelid');
|
|
|
|
|
});
|
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
user.Configuration.OrderedViews = $(".viewItem", page).get().map(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-viewid');
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
ApiClient.updateUser(user).done(function () {
|
2014-05-30 12:23:56 -07:00
|
|
|
|
Dashboard.alert(Globalize.translate('SettingsSaved'));
|
2014-08-18 18:42:53 -07:00
|
|
|
|
|
|
|
|
|
loadForm(page, user, false);
|
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSubmit() {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
|
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
ApiClient.getUser(userId).done(function (user) {
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
saveUser(page, user);
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', "#displayPreferencesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-08-18 18:42:53 -07:00
|
|
|
|
$('.viewOrderList', page).on('click', '.btnViewItemMove', function () {
|
|
|
|
|
|
|
|
|
|
var li = $(this).parents('.viewItem');
|
|
|
|
|
var ul = li.parents('ul');
|
|
|
|
|
|
|
|
|
|
if ($(this).hasClass('btnViewItemDown')) {
|
|
|
|
|
|
|
|
|
|
var next = li.next();
|
|
|
|
|
|
|
|
|
|
li.remove().insertAfter(next);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
var prev = li.prev();
|
|
|
|
|
|
|
|
|
|
li.remove().insertBefore(prev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.viewItem', ul).each(function () {
|
|
|
|
|
|
|
|
|
|
if ($(this).prev('.viewItem').length) {
|
|
|
|
|
$('.btnViewItemMove', this).addClass('btnViewItemUp').removeClass('btnViewItemDown').attr('data-icon', 'arrow-u').removeClass('ui-icon-arrow-d').addClass('ui-icon-arrow-u');
|
|
|
|
|
} else {
|
|
|
|
|
$('.btnViewItemMove', this).addClass('btnViewItemDown').removeClass('btnViewItemUp').attr('data-icon', 'arrow-d').removeClass('ui-icon-arrow-u').addClass('ui-icon-arrow-d');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ul.listview('destroy').listview({});
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
}).on('pageshow', "#displayPreferencesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
|
|
ApiClient.getUser(userId).done(function (user) {
|
|
|
|
|
|
|
|
|
|
loadForm(page, user);
|
|
|
|
|
|
|
|
|
|
});
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
}).on('pageshow', ".userPreferencesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
|
|
$('.lnkDisplayPreferences', page).attr('href', 'mypreferencesdisplay.html?userId=' + userId);
|
|
|
|
|
$('.lnkLanguagePreferences', page).attr('href', 'mypreferenceslanguages.html?userId=' + userId);
|
|
|
|
|
$('.lnkWebClientPreferences', page).attr('href', 'mypreferenceswebclient.html?userId=' + userId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.DisplayPreferencesPage = {
|
|
|
|
|
onSubmit: onSubmit
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(jQuery, window, document);
|