mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migration of userdatabuttons to ES6 modules
This commit is contained in:
parent
e0b56a2e95
commit
03eff35a34
2 changed files with 166 additions and 160 deletions
|
@ -174,6 +174,7 @@
|
|||
"src/components/toast/toast.js",
|
||||
"src/components/tunerPicker.js",
|
||||
"src/components/upnextdialog/upnextdialog.js",
|
||||
"src/components/userdatabuttons/userdatabuttons.js",
|
||||
"src/components/viewContainer.js",
|
||||
"src/components/castSenderApi.js",
|
||||
"src/controllers/session/addServer/index.js",
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-button-light', 'material-icons', 'emby-button', 'css!./userdatabuttons'], function (connectionManager, globalize, dom, itemHelper) {
|
||||
'use strict';
|
||||
import connectionManager from 'connectionManager';
|
||||
import globalize from 'globalize';
|
||||
import dom from 'dom';
|
||||
import itemHelper from 'itemHelper';
|
||||
import 'paper-icon-button-light';
|
||||
import 'material-icons';
|
||||
import 'emby-button';
|
||||
import 'css!./userdatabuttons';
|
||||
|
||||
var userDataMethods = {
|
||||
const userDataMethods = {
|
||||
markPlayed: markPlayed,
|
||||
markDislike: markDislike,
|
||||
markLike: markLike,
|
||||
markFavorite: markFavorite
|
||||
};
|
||||
};
|
||||
|
||||
function getUserDataButtonHtml(method, itemId, serverId, buttonCssClass, iconCssClass, icon, tooltip, style) {
|
||||
function getUserDataButtonHtml(method, itemId, serverId, buttonCssClass, iconCssClass, icon, tooltip, style) {
|
||||
if (style === 'fab-mini') {
|
||||
style = 'fab';
|
||||
buttonCssClass = buttonCssClass ? (buttonCssClass + ' mini') : 'mini';
|
||||
}
|
||||
|
||||
var is = style === 'fab' ? 'emby-button' : 'paper-icon-button-light';
|
||||
var className = style === 'fab' ? 'autoSize fab' : 'autoSize';
|
||||
const is = style === 'fab' ? 'emby-button' : 'paper-icon-button-light';
|
||||
let className = style === 'fab' ? 'autoSize fab' : 'autoSize';
|
||||
|
||||
if (buttonCssClass) {
|
||||
className += ' ' + buttonCssClass;
|
||||
|
@ -30,21 +36,21 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
iconCssClass += 'material-icons';
|
||||
|
||||
return '<button title="' + tooltip + '" data-itemid="' + itemId + '" data-serverid="' + serverId + '" is="' + is + '" data-method="' + method + '" class="' + className + '"><span class="' + iconCssClass + ' ' + icon + '"></span></button>';
|
||||
}
|
||||
}
|
||||
|
||||
function onContainerClick(e) {
|
||||
var btnUserData = dom.parentWithClass(e.target, 'btnUserData');
|
||||
function onContainerClick(e) {
|
||||
const btnUserData = dom.parentWithClass(e.target, 'btnUserData');
|
||||
|
||||
if (!btnUserData) {
|
||||
return;
|
||||
}
|
||||
|
||||
var method = btnUserData.getAttribute('data-method');
|
||||
const method = btnUserData.getAttribute('data-method');
|
||||
userDataMethods[method](btnUserData);
|
||||
}
|
||||
}
|
||||
|
||||
function fill(options) {
|
||||
var html = getIconsHtml(options);
|
||||
function fill(options) {
|
||||
const html = getIconsHtml(options);
|
||||
|
||||
if (options.fillMode === 'insertAdjacent') {
|
||||
options.element.insertAdjacentHTML(options.insertLocation || 'beforeend', html);
|
||||
|
@ -59,44 +65,44 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
dom.addEventListener(options.element, 'click', onContainerClick, {
|
||||
passive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function destroy(options) {
|
||||
function destroy(options) {
|
||||
options.element.innerHTML = '';
|
||||
|
||||
dom.removeEventListener(options.element, 'click', onContainerClick, {
|
||||
passive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getIconsHtml(options) {
|
||||
var item = options.item;
|
||||
var includePlayed = options.includePlayed;
|
||||
var cssClass = options.cssClass;
|
||||
var style = options.style;
|
||||
function getIconsHtml(options) {
|
||||
const item = options.item;
|
||||
const includePlayed = options.includePlayed;
|
||||
const cssClass = options.cssClass;
|
||||
const style = options.style;
|
||||
|
||||
var html = '';
|
||||
let html = '';
|
||||
|
||||
var userData = item.UserData || {};
|
||||
const userData = item.UserData || {};
|
||||
|
||||
var itemId = item.Id;
|
||||
const itemId = item.Id;
|
||||
|
||||
if (itemHelper.isLocalItem(item)) {
|
||||
return html;
|
||||
}
|
||||
|
||||
var btnCssClass = 'btnUserData';
|
||||
let btnCssClass = 'btnUserData';
|
||||
|
||||
if (cssClass) {
|
||||
btnCssClass += ' ' + cssClass;
|
||||
}
|
||||
|
||||
var iconCssClass = options.iconCssClass;
|
||||
const iconCssClass = options.iconCssClass;
|
||||
|
||||
var serverId = item.ServerId;
|
||||
const serverId = item.ServerId;
|
||||
|
||||
if (includePlayed !== false) {
|
||||
var tooltipPlayed = globalize.translate('MarkPlayed');
|
||||
const tooltipPlayed = globalize.translate('MarkPlayed');
|
||||
|
||||
if (itemHelper.canMarkPlayed(item)) {
|
||||
if (userData.Played) {
|
||||
|
@ -107,7 +113,7 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
}
|
||||
}
|
||||
|
||||
var tooltipFavorite = globalize.translate('Favorite');
|
||||
const tooltipFavorite = globalize.translate('Favorite');
|
||||
if (userData.IsFavorite) {
|
||||
html += getUserDataButtonHtml('markFavorite', itemId, serverId, btnCssClass + ' btnUserData btnUserDataOn', iconCssClass, 'favorite', tooltipFavorite, style);
|
||||
} else {
|
||||
|
@ -115,13 +121,13 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
function markFavorite(link) {
|
||||
var id = link.getAttribute('data-itemid');
|
||||
var serverId = link.getAttribute('data-serverid');
|
||||
function markFavorite(link) {
|
||||
const id = link.getAttribute('data-itemid');
|
||||
const serverId = link.getAttribute('data-serverid');
|
||||
|
||||
var markAsFavorite = !link.classList.contains('btnUserDataOn');
|
||||
const markAsFavorite = !link.classList.contains('btnUserDataOn');
|
||||
|
||||
favorite(id, serverId, markAsFavorite);
|
||||
|
||||
|
@ -130,11 +136,11 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
} else {
|
||||
link.classList.remove('btnUserDataOn');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function markLike(link) {
|
||||
var id = link.getAttribute('data-itemid');
|
||||
var serverId = link.getAttribute('data-serverid');
|
||||
function markLike(link) {
|
||||
const id = link.getAttribute('data-itemid');
|
||||
const serverId = link.getAttribute('data-serverid');
|
||||
|
||||
if (!link.classList.contains('btnUserDataOn')) {
|
||||
likes(id, serverId, true);
|
||||
|
@ -147,11 +153,11 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
}
|
||||
|
||||
link.parentNode.querySelector('.btnDislike').classList.remove('btnUserDataOn');
|
||||
}
|
||||
}
|
||||
|
||||
function markDislike(link) {
|
||||
var id = link.getAttribute('data-itemid');
|
||||
var serverId = link.getAttribute('data-serverid');
|
||||
function markDislike(link) {
|
||||
const id = link.getAttribute('data-itemid');
|
||||
const serverId = link.getAttribute('data-serverid');
|
||||
|
||||
if (!link.classList.contains('btnUserDataOn')) {
|
||||
likes(id, serverId, false);
|
||||
|
@ -164,11 +170,11 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
}
|
||||
|
||||
link.parentNode.querySelector('.btnLike').classList.remove('btnUserDataOn');
|
||||
}
|
||||
}
|
||||
|
||||
function markPlayed(link) {
|
||||
var id = link.getAttribute('data-itemid');
|
||||
var serverId = link.getAttribute('data-serverid');
|
||||
function markPlayed(link) {
|
||||
const id = link.getAttribute('data-itemid');
|
||||
const serverId = link.getAttribute('data-serverid');
|
||||
|
||||
if (!link.classList.contains('btnUserDataOn')) {
|
||||
played(id, serverId, true);
|
||||
|
@ -179,36 +185,35 @@ define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-butto
|
|||
|
||||
link.classList.remove('btnUserDataOn');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function likes(id, serverId, isLiked) {
|
||||
var apiClient = connectionManager.getApiClient(serverId);
|
||||
function likes(id, serverId, isLiked) {
|
||||
const apiClient = connectionManager.getApiClient(serverId);
|
||||
return apiClient.updateUserItemRating(apiClient.getCurrentUserId(), id, isLiked);
|
||||
}
|
||||
}
|
||||
|
||||
function played(id, serverId, isPlayed) {
|
||||
var apiClient = connectionManager.getApiClient(serverId);
|
||||
function played(id, serverId, isPlayed) {
|
||||
const apiClient = connectionManager.getApiClient(serverId);
|
||||
|
||||
var method = isPlayed ? 'markPlayed' : 'markUnplayed';
|
||||
const method = isPlayed ? 'markPlayed' : 'markUnplayed';
|
||||
|
||||
return apiClient[method](apiClient.getCurrentUserId(), id, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
function favorite(id, serverId, isFavorite) {
|
||||
var apiClient = connectionManager.getApiClient(serverId);
|
||||
function favorite(id, serverId, isFavorite) {
|
||||
const apiClient = connectionManager.getApiClient(serverId);
|
||||
|
||||
return apiClient.updateFavoriteStatus(apiClient.getCurrentUserId(), id, isFavorite);
|
||||
}
|
||||
}
|
||||
|
||||
function clearLike(id, serverId) {
|
||||
var apiClient = connectionManager.getApiClient(serverId);
|
||||
function clearLike(id, serverId) {
|
||||
const apiClient = connectionManager.getApiClient(serverId);
|
||||
|
||||
return apiClient.clearUserItemRating(apiClient.getCurrentUserId(), id);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
export default {
|
||||
fill: fill,
|
||||
destroy: destroy,
|
||||
getIconsHtml: getIconsHtml
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue