2020-05-04 12:44:12 +02:00
|
|
|
define(['jQuery', 'datetime', 'loading', 'libraryMenu', 'globalize', 'listViewStyle', 'paper-icon-button-light'], function ($, datetime, loading, libraryMenu, globalize) {
|
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function populateRatings(allParentalRatings, page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var html = '';
|
2018-10-23 01:05:09 +03:00
|
|
|
html += "<option value=''></option>";
|
2019-11-06 13:43:39 +03:00
|
|
|
var i;
|
|
|
|
var length;
|
|
|
|
var rating;
|
|
|
|
var ratings = [];
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
for (i = 0, length = allParentalRatings.length; i < length; i++) {
|
|
|
|
if (rating = allParentalRatings[i], ratings.length) {
|
|
|
|
var lastRating = ratings[ratings.length - 1];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (lastRating.Value === rating.Value) {
|
2020-05-04 12:44:12 +02:00
|
|
|
lastRating.Name += '/' + rating.Name;
|
2019-11-06 13:43:39 +03:00
|
|
|
continue;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
ratings.push({
|
|
|
|
Name: rating.Name,
|
|
|
|
Value: rating.Value
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, length = ratings.length; i < length; i++) {
|
|
|
|
rating = ratings[i];
|
2020-05-04 12:44:12 +02:00
|
|
|
html += "<option value='" + rating.Value + "'>" + rating.Name + '</option>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#selectMaxParentalRating', page).html(html);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadUnratedItems(page, user) {
|
|
|
|
var items = [{
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockBooks'),
|
|
|
|
value: 'Book'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockChannelContent'),
|
|
|
|
value: 'ChannelContent'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockLiveTvChannels'),
|
|
|
|
value: 'LiveTvChannel'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockMovies'),
|
|
|
|
value: 'Movie'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockMusic'),
|
|
|
|
value: 'Music'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockTrailers'),
|
|
|
|
value: 'Trailer'
|
2019-11-06 13:43:39 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('OptionBlockTvShows'),
|
|
|
|
value: 'Series'
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2020-05-04 12:44:12 +02:00
|
|
|
var html = '';
|
|
|
|
html += '<h3 class="checkboxListLabel">' + globalize.translate('HeaderBlockItemsWithNoRating') + '</h3>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="checkboxList paperList checkboxList-paperList">';
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
for (var i = 0, length = items.length; i < length; i++) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var item = items[i];
|
2020-05-04 12:44:12 +02:00
|
|
|
var checkedAttribute = -1 != user.Policy.BlockUnratedItems.indexOf(item.value) ? ' checked="checked"' : '';
|
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkUnratedItem" data-itemtype="' + item.value + '" type="checkbox"' + checkedAttribute + '><span>' + item.name + '</span></label>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
$('.blockUnratedItems', page).html(html).trigger('create');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadUser(page, user, allParentalRatings) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.username').innerHTML = user.Name;
|
2019-11-06 13:43:39 +03:00
|
|
|
libraryMenu.setTitle(user.Name);
|
|
|
|
loadUnratedItems(page, user);
|
|
|
|
loadBlockedTags(page, user.Policy.BlockedTags);
|
|
|
|
populateRatings(allParentalRatings, page);
|
2020-05-04 12:44:12 +02:00
|
|
|
var ratingValue = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (user.Policy.MaxParentalRating) {
|
2018-10-23 01:05:09 +03:00
|
|
|
for (var i = 0, length = allParentalRatings.length; i < length; i++) {
|
|
|
|
var rating = allParentalRatings[i];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (user.Policy.MaxParentalRating >= rating.Value) {
|
|
|
|
ratingValue = rating.Value;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#selectMaxParentalRating', page).val(ratingValue);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (user.Policy.IsAdministrator) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.accessScheduleSection', page).hide();
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.accessScheduleSection', page).show();
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
renderAccessSchedule(page, user.Policy.AccessSchedules || []);
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadBlockedTags(page, tags) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var html = tags.map(function (h) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var li = '<div class="listItem">';
|
2019-11-06 13:43:39 +03:00
|
|
|
li += '<div class="listItemBody">';
|
|
|
|
li += '<h3 class="listItemBodyText">';
|
|
|
|
li += h;
|
2020-05-04 12:44:12 +02:00
|
|
|
li += '</h3>';
|
|
|
|
li += '</div>';
|
2020-04-26 02:37:28 +03:00
|
|
|
li += '<button type="button" is="paper-icon-button-light" class="blockedTag btnDeleteTag listItemButton" data-tag="' + h + '"><span class="material-icons delete"></span></button>';
|
2020-05-04 12:44:12 +02:00
|
|
|
return li += '</div>';
|
|
|
|
}).join('');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (html) {
|
2020-05-04 12:44:12 +02:00
|
|
|
html = '<div class="paperList">' + html + '</div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
var elem = $('.blockedTags', page).html(html).trigger('create');
|
|
|
|
$('.btnDeleteTag', elem).on('click', function () {
|
|
|
|
var tag = this.getAttribute('data-tag');
|
2019-11-06 13:43:39 +03:00
|
|
|
var newTags = tags.filter(function (t) {
|
|
|
|
return t != tag;
|
|
|
|
});
|
|
|
|
loadBlockedTags(page, newTags);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteAccessSchedule(page, schedules, index) {
|
2019-11-06 13:43:39 +03:00
|
|
|
schedules.splice(index, 1);
|
|
|
|
renderAccessSchedule(page, schedules);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderAccessSchedule(page, schedules) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var html = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
var index = 0;
|
|
|
|
html += schedules.map(function (a) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var itemHtml = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
itemHtml += '<div class="liSchedule listItem" data-day="' + a.DayOfWeek + '" data-start="' + a.StartHour + '" data-end="' + a.EndHour + '">';
|
|
|
|
itemHtml += '<div class="listItemBody two-line">';
|
|
|
|
itemHtml += '<h3 class="listItemBodyText">';
|
2020-05-04 12:44:12 +02:00
|
|
|
itemHtml += globalize.translate('Option' + a.DayOfWeek);
|
|
|
|
itemHtml += '</h3>';
|
|
|
|
itemHtml += '<div class="listItemBodyText secondary">' + getDisplayTime(a.StartHour) + ' - ' + getDisplayTime(a.EndHour) + '</div>';
|
|
|
|
itemHtml += '</div>';
|
2020-04-26 02:37:28 +03:00
|
|
|
itemHtml += '<button type="button" is="paper-icon-button-light" class="btnDelete listItemButton" data-index="' + index + '"><span class="material-icons delete"></span></button>';
|
2020-05-04 12:44:12 +02:00
|
|
|
itemHtml += '</div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
index++;
|
|
|
|
return itemHtml;
|
2020-05-04 12:44:12 +02:00
|
|
|
}).join('');
|
|
|
|
var accessScheduleList = page.querySelector('.accessScheduleList');
|
2019-11-06 13:43:39 +03:00
|
|
|
accessScheduleList.innerHTML = html;
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.btnDelete', accessScheduleList).on('click', function () {
|
|
|
|
deleteAccessSchedule(page, schedules, parseInt(this.getAttribute('data-index')));
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveComplete(page) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.hide();
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
require(['toast'], function (toast) {
|
|
|
|
toast(globalize.translate('SettingsSaved'));
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveUser(user, page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.MaxParentalRating = $('#selectMaxParentalRating', page).val() || null;
|
|
|
|
user.Policy.BlockUnratedItems = $('.chkUnratedItem', page).get().filter(function (i) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return i.checked;
|
|
|
|
}).map(function (i) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return i.getAttribute('data-itemtype');
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
user.Policy.AccessSchedules = getSchedulesFromPage(page);
|
|
|
|
user.Policy.BlockedTags = getBlockedTagsFromPage(page);
|
|
|
|
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
|
|
|
|
onSaveComplete(page);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDisplayTime(hours) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var minutes = 0;
|
|
|
|
var pct = hours % 1;
|
|
|
|
|
|
|
|
if (pct) {
|
|
|
|
minutes = parseInt(60 * pct);
|
|
|
|
}
|
|
|
|
|
|
|
|
return datetime.getDisplayTime(new Date(2000, 1, 1, hours, minutes, 0, 0));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showSchedulePopup(page, schedule, index) {
|
2019-11-06 13:43:39 +03:00
|
|
|
schedule = schedule || {};
|
|
|
|
|
2020-05-17 01:06:28 +09:00
|
|
|
require(['components/accessSchedule/accessSchedule'], function (accessschedule) {
|
2018-10-23 01:05:09 +03:00
|
|
|
accessschedule.show({
|
|
|
|
schedule: schedule
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (updatedSchedule) {
|
|
|
|
var schedules = getSchedulesFromPage(page);
|
|
|
|
|
|
|
|
if (-1 == index) {
|
|
|
|
index = schedules.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedules[index] = updatedSchedule;
|
|
|
|
renderAccessSchedule(page, schedules);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSchedulesFromPage(page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return $('.liSchedule', page).map(function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
return {
|
2020-05-04 12:44:12 +02:00
|
|
|
DayOfWeek: this.getAttribute('data-day'),
|
|
|
|
StartHour: this.getAttribute('data-start'),
|
|
|
|
EndHour: this.getAttribute('data-end')
|
2019-11-06 13:43:39 +03:00
|
|
|
};
|
|
|
|
}).get();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBlockedTagsFromPage(page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return $('.blockedTag', page).map(function () {
|
|
|
|
return this.getAttribute('data-tag');
|
2019-11-06 13:43:39 +03:00
|
|
|
}).get();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showBlockedTagPopup(page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
require(['prompt'], function (prompt) {
|
2018-10-23 01:05:09 +03:00
|
|
|
prompt({
|
2020-05-04 12:44:12 +02:00
|
|
|
label: globalize.translate('LabelTag')
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (value) {
|
|
|
|
var tags = getBlockedTagsFromPage(page);
|
|
|
|
|
|
|
|
if (-1 == tags.indexOf(value)) {
|
|
|
|
tags.push(value);
|
|
|
|
loadBlockedTags(page, tags);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
window.UserParentalControlPage = {
|
2019-11-06 13:43:39 +03:00
|
|
|
onSubmit: function () {
|
2020-05-04 12:44:12 +02:00
|
|
|
var page = $(this).parents('.page');
|
2018-10-23 01:05:09 +03:00
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
var userId = getParameterByName('userId');
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getUser(userId).then(function (result) {
|
|
|
|
saveUser(result, page);
|
|
|
|
});
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
};
|
2020-05-04 12:44:12 +02:00
|
|
|
$(document).on('pageinit', '#userParentalControlPage', function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.btnAddSchedule', page).on('click', function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
showSchedulePopup(page, {}, -1);
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.btnAddBlockedTag', page).on('click', function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
showBlockedTagPopup(page);
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.userParentalControlForm').off('submit', UserParentalControlPage.onSubmit).on('submit', UserParentalControlPage.onSubmit);
|
|
|
|
}).on('pageshow', '#userParentalControlPage', function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
var userId = getParameterByName('userId');
|
2019-11-06 13:43:39 +03:00
|
|
|
var promise1 = ApiClient.getUser(userId);
|
|
|
|
var promise2 = ApiClient.getParentalRatings();
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
|
|
|
loadUser(page, responses[0], responses[1]);
|
|
|
|
});
|
|
|
|
});
|
2019-01-27 22:10:07 +01:00
|
|
|
});
|