jellyfin-web/dashboard-ui/scripts/mypreferenceshome.js

290 lines
9.5 KiB
JavaScript
Raw Normal View History

2015-07-03 10:55:29 -07:00
(function ($, window, document) {
function renderViews(page, user, result) {
var folderHtml = '';
2015-08-18 10:54:29 -07:00
folderHtml += '<div class="paperCheckboxList">';
2015-09-15 11:09:44 -07:00
folderHtml += result.map(function (i) {
2015-07-03 10:55:29 -07:00
var currentHtml = '';
var id = 'chkGroupFolder' + i.Id;
var isChecked = (user.Configuration.ExcludeFoldersFromGrouping != null && user.Configuration.ExcludeFoldersFromGrouping.indexOf(i.Id) == -1) ||
user.Configuration.GroupedFolders.indexOf(i.Id) != -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
2015-08-18 10:54:29 -07:00
currentHtml += '<paper-checkbox class="chkGroupFolder" data-folderid="' + i.Id + '" id="' + id + '"' + checkedHtml + '>' + i.Name + '</paper-checkbox>';
2015-07-03 10:55:29 -07:00
return currentHtml;
}).join('');
folderHtml += '</div>';
$('.folderGroupList', page).html(folderHtml).trigger('create');
}
function renderViewStyles(page, user, result) {
var folderHtml = '';
2015-08-18 10:54:29 -07:00
folderHtml += '<div class="paperCheckboxList">';
2015-07-03 10:55:29 -07:00
folderHtml += result.map(function (i) {
var currentHtml = '';
var id = 'chkPlainFolder' + i.Id;
var isChecked = user.Configuration.PlainFolderViews.indexOf(i.Id) == -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
2015-08-18 10:54:29 -07:00
currentHtml += '<paper-checkbox class="chkPlainFolder" data-folderid="' + i.Id + '" id="' + id + '"' + checkedHtml + '>' + i.Name + '</paper-checkbox>';
2015-07-03 10:55:29 -07:00
return currentHtml;
}).join('');
folderHtml += '</div>';
$('.viewStylesList', page).html(folderHtml).trigger('create');
if (result.length) {
$('.viewStylesSection', page).show();
} else {
$('.viewStylesSection', page).hide();
}
}
function renderLatestItems(page, user, result) {
var folderHtml = '';
2015-08-18 10:54:29 -07:00
folderHtml += '<div class="paperCheckboxList">';
2015-07-03 10:55:29 -07:00
folderHtml += result.Items.map(function (i) {
var currentHtml = '';
var id = 'chkIncludeInLatest' + i.Id;
var isChecked = user.Configuration.LatestItemsExcludes.indexOf(i.Id) == -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
2015-08-18 10:54:29 -07:00
currentHtml += '<paper-checkbox class="chkIncludeInLatest" data-folderid="' + i.Id + '" id="' + id + '"' + checkedHtml + '>' + i.Name + '</paper-checkbox>';
2015-07-03 10:55:29 -07:00
return currentHtml;
}).join('');
folderHtml += '</div>';
$('.latestItemsList', page).html(folderHtml).trigger('create');
}
function renderViewOrder(page, user, result) {
var html = '';
var index = 0;
html += result.Items.map(function (view) {
var currentHtml = '';
2015-09-06 09:02:41 -07:00
currentHtml += '<paper-icon-item class="viewItem" data-viewid="' + view.Id + '">';
currentHtml += '<paper-fab class="listAvatar" style="background-color:#444;" icon="folder-open" item-icon></paper-fab>';
currentHtml += '<paper-item-body>';
currentHtml += '<div>';
currentHtml += view.Name;
currentHtml += '</div>';
currentHtml += '</paper-item-body>';
2015-07-03 10:55:29 -07:00
if (index > 0) {
2015-09-06 09:02:41 -07:00
currentHtml += '<paper-icon-button icon="keyboard-arrow-up" class="btnViewItemUp btnViewItemMove" title="' + Globalize.translate('ButtonUp') + '"></paper-icon-button>';
2015-07-03 10:55:29 -07:00
}
else if (result.Items.length > 1) {
2015-09-06 09:02:41 -07:00
currentHtml += '<paper-icon-button icon="keyboard-arrow-down" class="btnViewItemDown btnViewItemMove" title="' + Globalize.translate('ButtonDown') + '"></paper-icon-button>';
2015-07-03 10:55:29 -07:00
}
2015-09-06 09:02:41 -07:00
currentHtml += '</paper-icon-item>';
2015-07-03 10:55:29 -07:00
index++;
return currentHtml;
}).join('');
$('.viewOrderList', page).html(html).trigger('create');
}
function loadForm(page, user, displayPreferences) {
2015-07-28 12:42:24 -07:00
page.querySelector('.chkDisplayCollectionView').checked = user.Configuration.DisplayCollectionsView || false;
page.querySelector('.chkHidePlayedFromLatest').checked = user.Configuration.HidePlayedInLatest || false;
2015-08-14 12:14:54 -07:00
page.querySelector('.chkDisplayChannelsInline').checked = user.Configuration.DisplayChannelsInline || false;
2015-07-03 10:55:29 -07:00
2015-09-03 10:01:51 -07:00
$('#selectHomeSection1', page).val(displayPreferences.CustomPrefs.home0 || '');
$('#selectHomeSection2', page).val(displayPreferences.CustomPrefs.home1 || '');
$('#selectHomeSection3', page).val(displayPreferences.CustomPrefs.home2 || '');
$('#selectHomeSection4', page).val(displayPreferences.CustomPrefs.home3 || '');
2015-07-03 10:55:29 -07:00
var promise1 = ApiClient.getItems(user.Id, {
sortBy: "SortName"
});
2015-08-14 12:14:54 -07:00
var promise2 = ApiClient.getUserViews({}, user.Id);
var promise3 = ApiClient.getJSON(ApiClient.getUrl("Users/" + user.Id + "/SpecialViewOptions"));
2015-09-15 11:09:44 -07:00
var promise4 = ApiClient.getJSON(ApiClient.getUrl("Users/" + user.Id + "/GroupingOptions"));
2015-07-03 10:55:29 -07:00
2015-09-15 11:09:44 -07:00
$.when(promise1, promise2, promise3, promise4).done(function (r1, r2, r3, r4) {
2015-07-03 10:55:29 -07:00
2015-09-15 11:09:44 -07:00
renderViews(page, user, r4[0]);
2015-07-03 10:55:29 -07:00
renderLatestItems(page, user, r1[0]);
2015-08-14 12:14:54 -07:00
renderViewOrder(page, user, r2[0]);
renderViewStyles(page, user, r3[0]);
2015-07-03 10:55:29 -07:00
Dashboard.hideLoadingMsg();
});
}
function saveUser(page, user, displayPreferences) {
2015-07-28 12:42:24 -07:00
user.Configuration.DisplayCollectionsView = page.querySelector('.chkDisplayCollectionView').checked;
user.Configuration.HidePlayedInLatest = page.querySelector('.chkHidePlayedFromLatest').checked;
2015-07-03 10:55:29 -07:00
2015-08-14 12:14:54 -07:00
user.Configuration.DisplayChannelsInline = page.querySelector('.chkDisplayChannelsInline').checked;
2015-08-19 04:56:03 -07:00
user.Configuration.LatestItemsExcludes = $(".chkIncludeInLatest", page).get().filter(function (i) {
return !i.checked;
}).map(function (i) {
2015-07-03 10:55:29 -07:00
return i.getAttribute('data-folderid');
});
user.Configuration.ExcludeFoldersFromGrouping = null;
2015-08-19 04:56:03 -07:00
user.Configuration.GroupedFolders = $(".chkGroupFolder", page).get().filter(function(i) {
return i.checked;
}).map(function (i) {
2015-07-03 10:55:29 -07:00
return i.getAttribute('data-folderid');
});
2015-08-19 04:56:03 -07:00
user.Configuration.PlainFolderViews = $(".chkPlainFolder", page).get().filter(function (i) {
return !i.checked;
}).map(function (i) {
2015-07-03 10:55:29 -07:00
return i.getAttribute('data-folderid');
});
user.Configuration.OrderedViews = $(".viewItem", page).get().map(function (i) {
return i.getAttribute('data-viewid');
});
displayPreferences.CustomPrefs.home0 = $('#selectHomeSection1', page).val();
displayPreferences.CustomPrefs.home1 = $('#selectHomeSection2', page).val();
displayPreferences.CustomPrefs.home2 = $('#selectHomeSection3', page).val();
displayPreferences.CustomPrefs.home3 = $('#selectHomeSection4', page).val();
2015-07-30 07:34:46 -07:00
ApiClient.updateDisplayPreferences('home', displayPreferences, user.Id, AppSettings.displayPreferencesKey()).done(function () {
2015-07-03 10:55:29 -07:00
ApiClient.updateUserConfiguration(user.Id, user.Configuration).done(function () {
Dashboard.alert(Globalize.translate('SettingsSaved'));
loadForm(page, user, displayPreferences);
});
});
}
function onSubmit() {
2015-07-28 12:42:24 -07:00
var page = $(this).parents('.page')[0];
2015-07-03 10:55:29 -07:00
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (displayPreferences) {
saveUser(page, user, displayPreferences);
});
});
// Disable default form submission
return false;
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#homeScreenPreferencesPage", function () {
2015-07-03 10:55:29 -07:00
var page = this;
$('.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({});
});
$('.homeScreenPreferencesForm').off('submit', onSubmit).on('submit', onSubmit);
}).on('pageshowready', "#homeScreenPreferencesPage", function () {
var page = this;
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (result) {
loadForm(page, user, result);
});
});
});
})(jQuery, window, document);