2016-11-15 23:00:28 -07:00
|
|
|
|
define(['userSettingsBuilder', 'listViewStyle'], function (userSettingsBuilder) {
|
2016-10-22 22:11:46 -07:00
|
|
|
|
'use strict';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
function renderViews(page, user, result) {
|
|
|
|
|
|
|
|
|
|
var folderHtml = '';
|
|
|
|
|
|
2016-06-13 21:15:13 -07:00
|
|
|
|
folderHtml += '<div class="checkboxList">';
|
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;
|
|
|
|
|
|
2016-12-27 00:25:35 -07:00
|
|
|
|
var isChecked = user.Configuration.GroupedFolders.indexOf(i.Id) != -1;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
|
|
|
|
|
2016-06-13 21:15:13 -07:00
|
|
|
|
currentHtml += '<label>';
|
|
|
|
|
currentHtml += '<input type="checkbox" is="emby-checkbox" class="chkGroupFolder" data-folderid="' + i.Id + '" id="' + id + '"' + checkedHtml + '/>';
|
|
|
|
|
currentHtml += '<span>' + i.Name + '</span>';
|
|
|
|
|
currentHtml += '</label>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
folderHtml += '</div>';
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
page.querySelector('.folderGroupList').innerHTML = folderHtml;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderLatestItems(page, user, result) {
|
|
|
|
|
|
|
|
|
|
var folderHtml = '';
|
|
|
|
|
|
2016-06-13 21:15:13 -07:00
|
|
|
|
folderHtml += '<div class="checkboxList">';
|
2016-11-05 10:39:12 -07:00
|
|
|
|
var excludeViewTypes = ['playlists', 'livetv', 'boxsets', 'channels'];
|
|
|
|
|
var excludeItemTypes = ['Channel'];
|
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
folderHtml += result.Items.map(function (i) {
|
|
|
|
|
|
2016-11-05 10:39:12 -07:00
|
|
|
|
if (excludeViewTypes.indexOf(i.CollectionType || []) !== -1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// not implemented yet
|
|
|
|
|
if (excludeItemTypes.indexOf(i.Type) !== -1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
var currentHtml = '';
|
|
|
|
|
|
|
|
|
|
var id = 'chkIncludeInLatest' + i.Id;
|
|
|
|
|
|
|
|
|
|
var isChecked = user.Configuration.LatestItemsExcludes.indexOf(i.Id) == -1;
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
|
|
|
|
|
2016-06-13 21:15:13 -07:00
|
|
|
|
currentHtml += '<label>';
|
|
|
|
|
currentHtml += '<input type="checkbox" is="emby-checkbox" class="chkIncludeInLatest" data-folderid="' + i.Id + '" id="' + id + '"' + checkedHtml + '/>';
|
|
|
|
|
currentHtml += '<span>' + i.Name + '</span>';
|
|
|
|
|
currentHtml += '</label>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
folderHtml += '</div>';
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
page.querySelector('.latestItemsList').innerHTML = folderHtml;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderViewOrder(page, user, result) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
|
|
|
|
html += result.Items.map(function (view) {
|
|
|
|
|
|
|
|
|
|
var currentHtml = '';
|
|
|
|
|
|
2016-06-25 18:33:16 -07:00
|
|
|
|
currentHtml += '<div class="listItem viewItem" data-viewid="' + view.Id + '">';
|
2015-09-06 09:02:41 -07:00
|
|
|
|
|
2016-06-25 18:33:16 -07:00
|
|
|
|
currentHtml += '<button type="button" is="emby-button" class="fab mini autoSize" item-icon><i class="md-icon">folder_open</i></button>';
|
2015-09-06 09:02:41 -07:00
|
|
|
|
|
2016-06-25 18:33:16 -07:00
|
|
|
|
currentHtml += '<div class="listItemBody">';
|
2015-09-06 09:02:41 -07:00
|
|
|
|
|
|
|
|
|
currentHtml += '<div>';
|
|
|
|
|
currentHtml += view.Name;
|
|
|
|
|
currentHtml += '</div>';
|
|
|
|
|
|
2016-06-25 18:33:16 -07:00
|
|
|
|
currentHtml += '</div>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
|
2016-06-18 22:26:52 -07:00
|
|
|
|
currentHtml += '<button type="button" is="paper-icon-button-light" class="btnViewItemUp btnViewItemMove autoSize" title="' + Globalize.translate('ButtonUp') + '"><i class="md-icon">keyboard_arrow_up</i></button>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
else if (result.Items.length > 1) {
|
|
|
|
|
|
2016-06-18 22:26:52 -07:00
|
|
|
|
currentHtml += '<button type="button" is="paper-icon-button-light" class="btnViewItemDown btnViewItemMove autoSize" title="' + Globalize.translate('ButtonDown') + '"><i class="md-icon">keyboard_arrow_down</i></button>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-06-25 18:33:16 -07:00
|
|
|
|
currentHtml += '</div>';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
return currentHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
page.querySelector('.viewOrderList').innerHTML = html;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
function loadForm(page, user, userSettings) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2015-07-28 12:42:24 -07:00
|
|
|
|
page.querySelector('.chkHidePlayedFromLatest').checked = user.Configuration.HidePlayedInLatest || false;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
page.querySelector('#selectHomeSection1').value = userSettings.get('homesection0') || '';
|
|
|
|
|
page.querySelector('#selectHomeSection2').value = userSettings.get('homesection1') || '';
|
|
|
|
|
page.querySelector('#selectHomeSection3').value = userSettings.get('homesection2') || '';
|
|
|
|
|
page.querySelector('#selectHomeSection4').value = userSettings.get('homesection3') || '';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-02 13:53:50 -07:00
|
|
|
|
var promise1 = ApiClient.getUserViews({}, user.Id);
|
|
|
|
|
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Users/" + user.Id + "/GroupingOptions"));
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-02 13:53:50 -07:00
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-02 13:53:50 -07:00
|
|
|
|
renderViews(page, user, responses[1]);
|
2015-12-14 08:43:03 -07:00
|
|
|
|
renderLatestItems(page, user, responses[0]);
|
2016-11-02 13:53:50 -07:00
|
|
|
|
renderViewOrder(page, user, responses[0]);
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
function getCheckboxItems(selector, page, isChecked) {
|
|
|
|
|
|
|
|
|
|
var inputs = page.querySelectorAll(selector);
|
|
|
|
|
var list = [];
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = inputs.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
if (inputs[i].checked == isChecked) {
|
|
|
|
|
list.push(inputs[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 18:58:52 -07:00
|
|
|
|
function refreshGlobalUserSettings(userSettingsInstance) {
|
|
|
|
|
require(['userSettings'], function (userSettings) {
|
|
|
|
|
userSettings.importFrom(userSettingsInstance);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveUser(page, user, userSettingsInstance) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2015-07-28 12:42:24 -07:00
|
|
|
|
user.Configuration.HidePlayedInLatest = page.querySelector('.chkHidePlayedFromLatest').checked;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
user.Configuration.LatestItemsExcludes = getCheckboxItems(".chkIncludeInLatest", page, false).map(function (i) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
user.Configuration.GroupedFolders = getCheckboxItems(".chkGroupFolder", page, true).map(function (i) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
var viewItems = page.querySelectorAll('.viewItem');
|
|
|
|
|
var orderedViews = [];
|
|
|
|
|
for (var i = 0, length = viewItems.length; i < length; i++) {
|
|
|
|
|
orderedViews.push(viewItems[i].getAttribute('data-viewid'));
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
user.Configuration.OrderedViews = orderedViews;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-12-09 18:58:52 -07:00
|
|
|
|
userSettingsInstance.set('homesection0', page.querySelector('#selectHomeSection1').value);
|
|
|
|
|
userSettingsInstance.set('homesection1', page.querySelector('#selectHomeSection2').value);
|
|
|
|
|
userSettingsInstance.set('homesection2', page.querySelector('#selectHomeSection3').value);
|
|
|
|
|
userSettingsInstance.set('homesection3', page.querySelector('#selectHomeSection4').value);
|
|
|
|
|
|
|
|
|
|
if (user.Id === Dashboard.getCurrentUserId()) {
|
|
|
|
|
refreshGlobalUserSettings(userSettingsInstance);
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
return ApiClient.updateUserConfiguration(user.Id, user.Configuration);
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
function save(page, userId, userSettings) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2016-01-06 13:16:16 -07:00
|
|
|
|
if (!AppInfo.enableAutoSave) {
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getUser(userId).then(function (user) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
saveUser(page, user, userSettings).then(function () {
|
2016-01-06 13:16:16 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
if (!AppInfo.enableAutoSave) {
|
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast(Globalize.translate('SettingsSaved'));
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
}, function () {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2016-01-06 13:16:16 -07:00
|
|
|
|
});
|
2015-07-03 10:55:29 -07:00
|
|
|
|
});
|
2016-01-06 13:16:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
function parentWithClass(elem, className) {
|
2016-01-06 13:16:16 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
while (!elem.classList || !elem.classList.contains(className)) {
|
|
|
|
|
elem = elem.parentNode;
|
2016-01-06 13:16:16 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
if (!elem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
return elem;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
function getSibling(elem, type, className) {
|
|
|
|
|
|
|
|
|
|
var sibling = elem[type];
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
while (sibling != null) {
|
|
|
|
|
if (sibling.classList.contains(className)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
if (sibling != null) {
|
|
|
|
|
if (!sibling.classList.contains(className)) {
|
|
|
|
|
sibling = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
return sibling;
|
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
return function (view, params) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
var userId = params.userId || Dashboard.getCurrentUserId();
|
|
|
|
|
var userSettings = new userSettingsBuilder();
|
|
|
|
|
var userSettingsLoaded;
|
2016-07-11 12:25:27 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
function onSubmit(e) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
userSettings.setUserInfo(userId, ApiClient).then(function () {
|
|
|
|
|
|
|
|
|
|
save(view, userId, userSettings);
|
|
|
|
|
});
|
2016-06-20 17:47:37 -07:00
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
2016-11-15 23:00:28 -07:00
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
2016-06-20 17:47:37 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view.querySelector('.viewOrderList').addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
var target = parentWithClass(e.target, 'btnViewItemMove');
|
|
|
|
|
|
|
|
|
|
var li = parentWithClass(target, 'viewItem');
|
|
|
|
|
var ul = parentWithClass(li, 'paperList');
|
|
|
|
|
|
|
|
|
|
if (target.classList.contains('btnViewItemDown')) {
|
|
|
|
|
|
|
|
|
|
var next = li.nextSibling;
|
|
|
|
|
|
|
|
|
|
li.parentNode.removeChild(li);
|
|
|
|
|
next.parentNode.insertBefore(li, next.nextSibling);
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
var prev = li.previousSibling;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
li.parentNode.removeChild(li);
|
|
|
|
|
prev.parentNode.insertBefore(li, prev);
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
var viewItems = ul.querySelectorAll('.viewItem');
|
|
|
|
|
for (var i = 0, length = viewItems.length; i < length; i++) {
|
|
|
|
|
var viewItem = viewItems[i];
|
|
|
|
|
|
|
|
|
|
var btn = viewItem.querySelector('.btnViewItemMove');
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
var prevViewItem = getSibling(viewItem, 'previousSibling', 'viewItem');
|
2015-10-25 11:41:41 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
if (prevViewItem) {
|
2015-10-25 11:41:41 -07:00
|
|
|
|
|
|
|
|
|
btn.classList.add('btnViewItemUp');
|
|
|
|
|
btn.classList.remove('btnViewItemDown');
|
|
|
|
|
btn.icon = 'keyboard-arrow-up';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
} else {
|
2015-10-25 11:41:41 -07:00
|
|
|
|
|
|
|
|
|
btn.classList.remove('btnViewItemUp');
|
|
|
|
|
btn.classList.add('btnViewItemDown');
|
|
|
|
|
btn.icon = 'keyboard-arrow-down';
|
2015-07-03 10:55:29 -07:00
|
|
|
|
}
|
2016-06-20 17:47:37 -07:00
|
|
|
|
}
|
2015-07-03 10:55:29 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
view.querySelector('.homeScreenPreferencesForm').addEventListener('submit', onSubmit);
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-01-06 13:16:16 -07:00
|
|
|
|
if (AppInfo.enableAutoSave) {
|
2016-06-20 17:47:37 -07:00
|
|
|
|
view.querySelector('.btnSave').classList.add('hide');
|
2016-01-06 13:16:16 -07:00
|
|
|
|
} else {
|
2016-06-20 17:47:37 -07:00
|
|
|
|
view.querySelector('.btnSave').classList.remove('hide');
|
2016-01-06 13:16:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
view.addEventListener('viewshow', function () {
|
|
|
|
|
var page = this;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-07-11 12:25:27 -07:00
|
|
|
|
var userId = params.userId || Dashboard.getCurrentUserId();
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
ApiClient.getUser(userId).then(function (user) {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
userSettings.setUserInfo(userId, ApiClient).then(function () {
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
userSettingsLoaded = true;
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
2016-11-15 23:00:28 -07:00
|
|
|
|
loadForm(page, user, userSettings);
|
2016-06-20 17:47:37 -07:00
|
|
|
|
});
|
2015-07-03 10:55:29 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-20 17:47:37 -07:00
|
|
|
|
view.addEventListener('viewbeforehide', function () {
|
|
|
|
|
if (AppInfo.enableAutoSave) {
|
2016-11-15 23:00:28 -07:00
|
|
|
|
onSubmit();
|
2016-06-20 17:47:37 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|