jellyfish-web/src/components/recordingcreator/recordingbutton.js

116 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-03-19 17:03:11 -07:00
define(['globalize', 'connectionManager', 'require', 'loading', 'apphost', 'dom', 'recordingHelper', 'events', 'paper-icon-button-light', 'emby-button', 'css!./recordingfields'], function (globalize, connectionManager, require, loading, appHost, dom, recordingHelper, events) {
'use strict';
2018-10-23 01:05:09 +03:00
function onRecordingButtonClick(e) {
2018-10-23 01:05:09 +03:00
var item = this.item;
2018-10-23 01:05:09 +03:00
if (item) {
var serverId = item.ServerId;
var programId = item.Id;
var timerId = item.TimerId;
var timerStatus = item.Status;
var seriesTimerId = item.SeriesTimerId;
var instance = this;
recordingHelper.toggleRecording(serverId, programId, timerId, timerStatus, seriesTimerId).then(function () {
instance.refresh(serverId, programId);
});
2018-10-23 01:05:09 +03:00
}
}
function RecordingButton(options) {
this.options = options;
if (options.item) {
this.refreshItem(options.item);
} else if (options.itemId && options.serverId) {
this.refresh(options.itemId, options.serverId);
}
2018-10-23 01:05:09 +03:00
var button = options.button;
button.querySelector('i').innerHTML = '';
2018-10-23 01:05:09 +03:00
var clickFn = onRecordingButtonClick.bind(this);
this.clickFn = clickFn;
dom.addEventListener(button, 'click', clickFn, {
passive: true
});
2018-10-23 01:05:09 +03:00
}
function getIndicatorIcon(item) {
2018-10-23 01:05:09 +03:00
var status;
if (item.Type === 'SeriesTimer') {
return '';
}
else if (item.TimerId || item.SeriesTimerId) {
status = item.Status || 'Cancelled';
}
else if (item.Type === 'Timer') {
status = item.Status;
}
2018-10-23 01:05:09 +03:00
else {
return '';
}
if (item.SeriesTimerId) {
if (status !== 'Cancelled') {
return '';
}
2018-10-23 01:05:09 +03:00
}
return '';
2018-10-23 01:05:09 +03:00
}
RecordingButton.prototype.refresh = function (serverId, itemId) {
var apiClient = connectionManager.getApiClient(serverId);
var self = this;
apiClient.getItem(apiClient.getCurrentUserId(), itemId).then(function (item) {
self.refreshItem(item);
});
};
RecordingButton.prototype.refreshItem = function (item) {
var options = this.options;
var button = options.button;
this.item = item;
button.querySelector('i').innerHTML = getIndicatorIcon(item);
if (item.TimerId && (item.Status || 'Cancelled') !== 'Cancelled') {
button.classList.add('recordingIcon-active');
} else {
button.classList.remove('recordingIcon-active');
}
};
RecordingButton.prototype.destroy = function () {
2018-10-23 01:05:09 +03:00
var options = this.options;
2018-10-23 01:05:09 +03:00
if (options) {
var button = options.button;
var clickFn = this.clickFn;
if (clickFn) {
dom.removeEventListener(button, 'click', clickFn, {
passive: true
});
}
}
this.options = null;
this.item = null;
};
return RecordingButton;
2018-10-23 01:05:09 +03:00
});