mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #1649 from Camc314/migrate-to-ES6-40
Migration of notification and notifications to ES6 modules
This commit is contained in:
commit
a6cd54b661
3 changed files with 167 additions and 166 deletions
|
@ -193,6 +193,8 @@
|
||||||
"src/controllers/dashboard/metadataImages.js",
|
"src/controllers/dashboard/metadataImages.js",
|
||||||
"src/controllers/dashboard/metadatanfo.js",
|
"src/controllers/dashboard/metadatanfo.js",
|
||||||
"src/controllers/dashboard/networking.js",
|
"src/controllers/dashboard/networking.js",
|
||||||
|
"src/controllers/dashboard/notifications/notification.js",
|
||||||
|
"src/controllers/dashboard/notifications/notifications.js",
|
||||||
"src/controllers/dashboard/playback.js",
|
"src/controllers/dashboard/playback.js",
|
||||||
"src/controllers/dashboard/plugins/repositories/index.js",
|
"src/controllers/dashboard/plugins/repositories/index.js",
|
||||||
"src/controllers/dashboard/scheduledtasks/scheduledtask.js",
|
"src/controllers/dashboard/scheduledtasks/scheduledtask.js",
|
||||||
|
|
|
@ -1,119 +1,118 @@
|
||||||
define(['jQuery', 'emby-checkbox'], function ($) {
|
import $ from 'jQuery';
|
||||||
'use strict';
|
import 'emby-checkbox';
|
||||||
|
|
||||||
function fillItems(elem, items, cssClass, idPrefix, currentList, isEnabledList) {
|
function fillItems(elem, items, cssClass, idPrefix, currentList, isEnabledList) {
|
||||||
var html = '<div class="checkboxList paperList" style="padding: .5em 1em;">';
|
let html = '<div class="checkboxList paperList" style="padding: .5em 1em;">';
|
||||||
html += items.map(function (u) {
|
html += items.map(function (u) {
|
||||||
var isChecked = isEnabledList ? currentList.indexOf(u.Id) != -1 : currentList.indexOf(u.Id) == -1;
|
const isChecked = isEnabledList ? currentList.indexOf(u.Id) != -1 : currentList.indexOf(u.Id) == -1;
|
||||||
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
const checkedHtml = isChecked ? ' checked="checked"' : '';
|
||||||
return '<label><input is="emby-checkbox" class="' + cssClass + '" type="checkbox" data-itemid="' + u.Id + '"' + checkedHtml + '/><span>' + u.Name + '</span></label>';
|
return '<label><input is="emby-checkbox" class="' + cssClass + '" type="checkbox" data-itemid="' + u.Id + '"' + checkedHtml + '/><span>' + u.Name + '</span></label>';
|
||||||
}).join('');
|
}).join('');
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
elem.html(html).trigger('create');
|
elem.html(html).trigger('create');
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload(page) {
|
function reload(page) {
|
||||||
var type = getParameterByName('type');
|
const type = getParameterByName('type');
|
||||||
var promise1 = ApiClient.getUsers();
|
const promise1 = ApiClient.getUsers();
|
||||||
var promise2 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
const promise2 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
||||||
var promise3 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Types'));
|
const promise3 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Types'));
|
||||||
var promise4 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Services'));
|
const promise4 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Services'));
|
||||||
Promise.all([promise1, promise2, promise3, promise4]).then(function (responses) {
|
Promise.all([promise1, promise2, promise3, promise4]).then(function (responses) {
|
||||||
var users = responses[0];
|
const users = responses[0];
|
||||||
var notificationOptions = responses[1];
|
const notificationOptions = responses[1];
|
||||||
var types = responses[2];
|
const types = responses[2];
|
||||||
var services = responses[3];
|
const services = responses[3];
|
||||||
var notificationConfig = notificationOptions.Options.filter(function (n) {
|
let notificationConfig = notificationOptions.Options.filter(function (n) {
|
||||||
return n.Type == type;
|
return n.Type == type;
|
||||||
})[0];
|
})[0];
|
||||||
var typeInfo = types.filter(function (n) {
|
const typeInfo = types.filter(function (n) {
|
||||||
return n.Type == type;
|
return n.Type == type;
|
||||||
})[0] || {};
|
})[0] || {};
|
||||||
|
|
||||||
if (typeInfo.IsBasedOnUserEvent) {
|
if (typeInfo.IsBasedOnUserEvent) {
|
||||||
$('.monitorUsers', page).show();
|
$('.monitorUsers', page).show();
|
||||||
} else {
|
} else {
|
||||||
$('.monitorUsers', page).hide();
|
$('.monitorUsers', page).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.notificationType', page).html(typeInfo.Name || 'Unknown Notification');
|
$('.notificationType', page).html(typeInfo.Name || 'Unknown Notification');
|
||||||
|
|
||||||
if (!notificationConfig) {
|
if (!notificationConfig) {
|
||||||
notificationConfig = {
|
notificationConfig = {
|
||||||
DisabledMonitorUsers: [],
|
DisabledMonitorUsers: [],
|
||||||
SendToUsers: [],
|
SendToUsers: [],
|
||||||
DisabledServices: [],
|
DisabledServices: [],
|
||||||
SendToUserMode: 'Admins'
|
SendToUserMode: 'Admins'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fillItems($('.monitorUsersList', page), users, 'chkMonitor', 'chkMonitor', notificationConfig.DisabledMonitorUsers);
|
fillItems($('.monitorUsersList', page), users, 'chkMonitor', 'chkMonitor', notificationConfig.DisabledMonitorUsers);
|
||||||
fillItems($('.sendToUsersList', page), users, 'chkSendTo', 'chkSendTo', notificationConfig.SendToUsers, true);
|
fillItems($('.sendToUsersList', page), users, 'chkSendTo', 'chkSendTo', notificationConfig.SendToUsers, true);
|
||||||
fillItems($('.servicesList', page), services, 'chkService', 'chkService', notificationConfig.DisabledServices);
|
fillItems($('.servicesList', page), services, 'chkService', 'chkService', notificationConfig.DisabledServices);
|
||||||
$('#chkEnabled', page).prop('checked', notificationConfig.Enabled || false);
|
$('#chkEnabled', page).prop('checked', notificationConfig.Enabled || false);
|
||||||
$('#selectUsers', page).val(notificationConfig.SendToUserMode).trigger('change');
|
$('#selectUsers', page).val(notificationConfig.SendToUserMode).trigger('change');
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function save(page) {
|
|
||||||
var type = getParameterByName('type');
|
|
||||||
var promise1 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
|
||||||
// TODO: Check if this promise is really needed, as it's unused.
|
|
||||||
var promise2 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Types'));
|
|
||||||
Promise.all([promise1, promise2]).then(function (responses) {
|
|
||||||
var notificationOptions = responses[0];
|
|
||||||
var notificationConfig = notificationOptions.Options.filter(function (n) {
|
|
||||||
return n.Type == type;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (!notificationConfig) {
|
|
||||||
notificationConfig = {
|
|
||||||
Type: type
|
|
||||||
};
|
|
||||||
notificationOptions.Options.push(notificationConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
notificationConfig.Enabled = $('#chkEnabled', page).is(':checked');
|
|
||||||
notificationConfig.SendToUserMode = $('#selectUsers', page).val();
|
|
||||||
notificationConfig.DisabledMonitorUsers = $('.chkMonitor', page).get().filter(function (c) {
|
|
||||||
return !c.checked;
|
|
||||||
}).map(function (c) {
|
|
||||||
return c.getAttribute('data-itemid');
|
|
||||||
});
|
|
||||||
notificationConfig.SendToUsers = $('.chkSendTo', page).get().filter(function (c) {
|
|
||||||
return c.checked;
|
|
||||||
}).map(function (c) {
|
|
||||||
return c.getAttribute('data-itemid');
|
|
||||||
});
|
|
||||||
notificationConfig.DisabledServices = $('.chkService', page).get().filter(function (c) {
|
|
||||||
return !c.checked;
|
|
||||||
}).map(function (c) {
|
|
||||||
return c.getAttribute('data-itemid');
|
|
||||||
});
|
|
||||||
ApiClient.updateNamedConfiguration(notificationsConfigurationKey, notificationOptions).then(function (r) {
|
|
||||||
Dashboard.processServerConfigurationUpdateResult();
|
|
||||||
Dashboard.navigate('notificationsettings.html');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSubmit() {
|
|
||||||
save($(this).parents('.page'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var notificationsConfigurationKey = 'notifications';
|
|
||||||
$(document).on('pageinit', '#notificationSettingPage', function () {
|
|
||||||
var page = this;
|
|
||||||
$('#selectUsers', page).on('change', function () {
|
|
||||||
if (this.value == 'Custom') {
|
|
||||||
$('.selectCustomUsers', page).show();
|
|
||||||
} else {
|
|
||||||
$('.selectCustomUsers', page).hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('.notificationSettingForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
||||||
}).on('pageshow', '#notificationSettingPage', function () {
|
|
||||||
reload(this);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(page) {
|
||||||
|
const type = getParameterByName('type');
|
||||||
|
const promise1 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
||||||
|
// TODO: Check if this promise is really needed, as it's unused.
|
||||||
|
const promise2 = ApiClient.getJSON(ApiClient.getUrl('Notifications/Types'));
|
||||||
|
Promise.all([promise1, promise2]).then(function (responses) {
|
||||||
|
const notificationOptions = responses[0];
|
||||||
|
let notificationConfig = notificationOptions.Options.filter(function (n) {
|
||||||
|
return n.Type == type;
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
if (!notificationConfig) {
|
||||||
|
notificationConfig = {
|
||||||
|
Type: type
|
||||||
|
};
|
||||||
|
notificationOptions.Options.push(notificationConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationConfig.Enabled = $('#chkEnabled', page).is(':checked');
|
||||||
|
notificationConfig.SendToUserMode = $('#selectUsers', page).val();
|
||||||
|
notificationConfig.DisabledMonitorUsers = $('.chkMonitor', page).get().filter(function (c) {
|
||||||
|
return !c.checked;
|
||||||
|
}).map(function (c) {
|
||||||
|
return c.getAttribute('data-itemid');
|
||||||
|
});
|
||||||
|
notificationConfig.SendToUsers = $('.chkSendTo', page).get().filter(function (c) {
|
||||||
|
return c.checked;
|
||||||
|
}).map(function (c) {
|
||||||
|
return c.getAttribute('data-itemid');
|
||||||
|
});
|
||||||
|
notificationConfig.DisabledServices = $('.chkService', page).get().filter(function (c) {
|
||||||
|
return !c.checked;
|
||||||
|
}).map(function (c) {
|
||||||
|
return c.getAttribute('data-itemid');
|
||||||
|
});
|
||||||
|
ApiClient.updateNamedConfiguration(notificationsConfigurationKey, notificationOptions).then(function (r) {
|
||||||
|
Dashboard.processServerConfigurationUpdateResult();
|
||||||
|
Dashboard.navigate('notificationsettings.html');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSubmit() {
|
||||||
|
save($(this).parents('.page'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const notificationsConfigurationKey = 'notifications';
|
||||||
|
$(document).on('pageinit', '#notificationSettingPage', function () {
|
||||||
|
const page = this;
|
||||||
|
$('#selectUsers', page).on('change', function () {
|
||||||
|
if (this.value == 'Custom') {
|
||||||
|
$('.selectCustomUsers', page).show();
|
||||||
|
} else {
|
||||||
|
$('.selectCustomUsers', page).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('.notificationSettingForm').off('submit', onSubmit).on('submit', onSubmit);
|
||||||
|
}).on('pageshow', '#notificationSettingPage', function () {
|
||||||
|
reload(this);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,62 +1,62 @@
|
||||||
define(['loading', 'libraryMenu', 'globalize', 'listViewStyle', 'emby-button'], function(loading, libraryMenu, globalize) {
|
import loading from 'loading';
|
||||||
'use strict';
|
import libraryMenu from 'libraryMenu';
|
||||||
|
import globalize from 'globalize';
|
||||||
|
import 'listViewStyle';
|
||||||
|
import 'emby-button';
|
||||||
|
|
||||||
loading = loading.default || loading;
|
function reload(page) {
|
||||||
|
loading.show();
|
||||||
function reload(page) {
|
ApiClient.getJSON(ApiClient.getUrl('Notifications/Types')).then(function (list) {
|
||||||
loading.show();
|
let html = '';
|
||||||
ApiClient.getJSON(ApiClient.getUrl('Notifications/Types')).then(function(list) {
|
let lastCategory = '';
|
||||||
var html = '';
|
let showHelp = true;
|
||||||
var lastCategory = '';
|
html += list.map(function (notification) {
|
||||||
var showHelp = true;
|
let itemHtml = '';
|
||||||
html += list.map(function(notification) {
|
if (notification.Category !== lastCategory) {
|
||||||
var itemHtml = '';
|
lastCategory = notification.Category;
|
||||||
if (notification.Category !== lastCategory) {
|
if (lastCategory) {
|
||||||
lastCategory = notification.Category;
|
itemHtml += '</div>';
|
||||||
if (lastCategory) {
|
|
||||||
itemHtml += '</div>';
|
|
||||||
itemHtml += '</div>';
|
|
||||||
}
|
|
||||||
itemHtml += '<div class="verticalSection verticalSection-extrabottompadding">';
|
|
||||||
itemHtml += '<div class="sectionTitleContainer" style="margin-bottom:1em;">';
|
|
||||||
itemHtml += '<h2 class="sectionTitle">';
|
|
||||||
itemHtml += notification.Category;
|
|
||||||
itemHtml += '</h2>';
|
|
||||||
if (showHelp) {
|
|
||||||
showHelp = false;
|
|
||||||
itemHtml += '<a is="emby-linkbutton" class="raised button-alt headerHelpButton" target="_blank" href="https://docs.jellyfin.org/general/server/notifications.html">';
|
|
||||||
itemHtml += globalize.translate('Help');
|
|
||||||
itemHtml += '</a>';
|
|
||||||
}
|
|
||||||
itemHtml += '</div>';
|
itemHtml += '</div>';
|
||||||
itemHtml += '<div class="paperList">';
|
|
||||||
}
|
}
|
||||||
itemHtml += '<a class="listItem listItem-border" is="emby-linkbutton" data-ripple="false" href="notificationsetting.html?type=' + notification.Type + '">';
|
itemHtml += '<div class="verticalSection verticalSection-extrabottompadding">';
|
||||||
if (notification.Enabled) {
|
itemHtml += '<div class="sectionTitleContainer" style="margin-bottom:1em;">';
|
||||||
itemHtml += '<span class="listItemIcon material-icons notifications_active"></span>';
|
itemHtml += '<h2 class="sectionTitle">';
|
||||||
} else {
|
itemHtml += notification.Category;
|
||||||
itemHtml += '<span class="listItemIcon material-icons notifications_off" style="background-color:#999;"></span>';
|
itemHtml += '</h2>';
|
||||||
|
if (showHelp) {
|
||||||
|
showHelp = false;
|
||||||
|
itemHtml += '<a is="emby-linkbutton" class="raised button-alt headerHelpButton" target="_blank" href="https://docs.jellyfin.org/general/server/notifications.html">';
|
||||||
|
itemHtml += globalize.translate('Help');
|
||||||
|
itemHtml += '</a>';
|
||||||
}
|
}
|
||||||
itemHtml += '<div class="listItemBody">';
|
|
||||||
itemHtml += '<div class="listItemBodyText">' + notification.Name + '</div>';
|
|
||||||
itemHtml += '</div>';
|
itemHtml += '</div>';
|
||||||
itemHtml += '<button type="button" is="paper-icon-button-light"><span class="material-icons mode_edit"></span></button>';
|
itemHtml += '<div class="paperList">';
|
||||||
itemHtml += '</a>';
|
|
||||||
return itemHtml;
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
if (list.length) {
|
|
||||||
html += '</div>';
|
|
||||||
html += '</div>';
|
|
||||||
}
|
}
|
||||||
page.querySelector('.notificationList').innerHTML = html;
|
itemHtml += '<a class="listItem listItem-border" is="emby-linkbutton" data-ripple="false" href="notificationsetting.html?type=' + notification.Type + '">';
|
||||||
loading.hide();
|
if (notification.Enabled) {
|
||||||
});
|
itemHtml += '<span class="listItemIcon material-icons notifications_active"></span>';
|
||||||
}
|
} else {
|
||||||
|
itemHtml += '<span class="listItemIcon material-icons notifications_off" style="background-color:#999;"></span>';
|
||||||
|
}
|
||||||
|
itemHtml += '<div class="listItemBody">';
|
||||||
|
itemHtml += '<div class="listItemBodyText">' + notification.Name + '</div>';
|
||||||
|
itemHtml += '</div>';
|
||||||
|
itemHtml += '<button type="button" is="paper-icon-button-light"><span class="material-icons mode_edit"></span></button>';
|
||||||
|
itemHtml += '</a>';
|
||||||
|
return itemHtml;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
return function(view, params) {
|
if (list.length) {
|
||||||
view.addEventListener('viewshow', function() {
|
html += '</div>';
|
||||||
reload(view);
|
html += '</div>';
|
||||||
});
|
}
|
||||||
};
|
page.querySelector('.notificationList').innerHTML = html;
|
||||||
});
|
loading.hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function (view, params) {
|
||||||
|
view.addEventListener('viewshow', function () {
|
||||||
|
reload(view);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue