jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/guide/guide-settings.js

172 lines
5.6 KiB
JavaScript
Raw Normal View History

2016-09-29 23:50:06 -07:00
define(['dialogHelper', 'globalize', 'userSettings', 'layoutManager', 'connectionManager', 'require', 'loading', 'scrollHelper', 'emby-checkbox', 'emby-radio', 'css!./../formdialog', 'material-icons'], function (dialogHelper, globalize, userSettings, layoutManager, connectionManager, require, loading, scrollHelper) {
2016-10-12 11:23:09 -07:00
'use strict';
2016-09-05 22:02:05 -07:00
2016-12-11 22:41:24 -07:00
function saveCategories(context, options) {
var categories = [];
var chkCategorys = context.querySelectorAll('.chkCategory');
for (var i = 0, length = chkCategorys.length; i < length; i++) {
var type = chkCategorys[i].getAttribute('data-type');
if (chkCategorys[i].checked) {
categories.push(type);
}
}
if (categories.length >= 4) {
categories.push('series');
}
// differentiate between none and all
categories.push('all');
options.categories = categories;
}
function loadCategories(context, options) {
var selectedCategories = options.categories || [];
var chkCategorys = context.querySelectorAll('.chkCategory');
for (var i = 0, length = chkCategorys.length; i < length; i++) {
var type = chkCategorys[i].getAttribute('data-type');
chkCategorys[i].checked = !selectedCategories.length || selectedCategories.indexOf(type) !== -1;
}
}
2016-09-05 22:02:05 -07:00
function save(context) {
2016-09-29 23:50:06 -07:00
var i, length;
2016-09-05 22:02:05 -07:00
var chkIndicators = context.querySelectorAll('.chkIndicator');
2016-09-29 23:50:06 -07:00
for (i = 0, length = chkIndicators.length; i < length; i++) {
2016-09-05 22:02:05 -07:00
var type = chkIndicators[i].getAttribute('data-type');
userSettings.set('guide-indicator-' + type, chkIndicators[i].checked);
}
2016-09-27 22:11:41 -07:00
userSettings.set('guide-colorcodedbackgrounds', context.querySelector('.chkColorCodedBackgrounds').checked);
2016-09-29 23:50:06 -07:00
userSettings.set('livetv-favoritechannelsattop', context.querySelector('.chkFavoriteChannelsAtTop').checked);
var sortBys = context.querySelectorAll('.chkSortOrder');
for (i = 0, length = sortBys.length; i < length; i++) {
if (sortBys[i].checked) {
userSettings.set('livetv-channelorder', sortBys[i].value);
break;
}
}
2016-09-05 22:02:05 -07:00
}
function load(context) {
2016-09-29 23:50:06 -07:00
var i, length;
2016-09-05 22:02:05 -07:00
var chkIndicators = context.querySelectorAll('.chkIndicator');
2016-09-29 23:50:06 -07:00
for (i = 0, length = chkIndicators.length; i < length; i++) {
2016-09-05 22:02:05 -07:00
var type = chkIndicators[i].getAttribute('data-type');
2016-09-07 23:15:44 -07:00
2016-10-12 11:23:09 -07:00
if (chkIndicators[i].getAttribute('data-default') === 'true') {
chkIndicators[i].checked = userSettings.get('guide-indicator-' + type) !== 'false';
2016-09-07 23:15:44 -07:00
} else {
2016-10-12 11:23:09 -07:00
chkIndicators[i].checked = userSettings.get('guide-indicator-' + type) === 'true';
2016-09-07 23:15:44 -07:00
}
2016-09-05 22:02:05 -07:00
}
2016-09-27 22:11:41 -07:00
2016-10-12 11:23:09 -07:00
context.querySelector('.chkColorCodedBackgrounds').checked = userSettings.get('guide-colorcodedbackgrounds') === 'true';
context.querySelector('.chkFavoriteChannelsAtTop').checked = userSettings.get('livetv-favoritechannelsattop') !== 'false';
2016-09-29 23:50:06 -07:00
2016-10-14 09:22:04 -07:00
var sortByValue = userSettings.get('livetv-channelorder') || 'Number';
2016-09-29 23:50:06 -07:00
var sortBys = context.querySelectorAll('.chkSortOrder');
for (i = 0, length = sortBys.length; i < length; i++) {
2016-10-12 11:23:09 -07:00
sortBys[i].checked = sortBys[i].value === sortByValue;
2016-09-29 23:50:06 -07:00
}
}
function onSortByChange() {
var newValue = this.value;
if (this.checked) {
2016-10-12 11:23:09 -07:00
var changed = options.query.SortBy !== newValue;
2016-09-29 23:50:06 -07:00
options.query.SortBy = newValue.replace('_', ',');
options.query.StartIndex = 0;
if (options.callback && changed) {
options.callback();
}
}
2016-09-05 22:02:05 -07:00
}
2016-12-11 22:41:24 -07:00
function showEditor(options) {
2016-09-05 22:02:05 -07:00
return new Promise(function (resolve, reject) {
var settingsChanged = false;
require(['text!./guide-settings.template.html'], function (template) {
var dialogOptions = {
removeOnClose: true,
scrollY: false
};
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
2016-09-05 22:02:05 -07:00
} else {
dialogOptions.size = 'small';
}
var dlg = dialogHelper.createDialog(dialogOptions);
dlg.classList.add('formDialog');
var html = '';
html += globalize.translateDocument(template, 'sharedcomponents');
dlg.innerHTML = html;
dlg.addEventListener('change', function () {
settingsChanged = true;
});
dlg.addEventListener('close', function () {
if (layoutManager.tv) {
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
}
save(dlg);
2016-12-11 22:41:24 -07:00
saveCategories(dlg, options);
2016-09-05 22:02:05 -07:00
if (settingsChanged) {
resolve();
} else {
reject();
}
});
2016-09-07 00:08:20 -07:00
dlg.querySelector('.btnCancel').addEventListener('click', function () {
dialogHelper.close(dlg);
});
2016-09-05 22:02:05 -07:00
if (layoutManager.tv) {
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
}
load(dlg);
2016-12-11 22:41:24 -07:00
loadCategories(dlg, options);
2016-09-05 22:02:05 -07:00
dialogHelper.open(dlg);
});
});
}
return {
show: showEditor
};
});