2019-03-19 17:03:11 -07:00
|
|
|
define(['globalize', 'connectionManager', 'serverNotifications', 'require', 'loading', 'apphost', 'dom', 'recordingHelper', 'events', 'paper-icon-button-light', 'emby-button', 'css!./recordingfields', 'flexStyles'], function (globalize, connectionManager, serverNotifications, require, loading, appHost, dom, recordingHelper, events) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadData(parent, program, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (program.IsSeries) {
|
|
|
|
parent.querySelector('.recordSeriesContainer').classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
parent.querySelector('.recordSeriesContainer').classList.add('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (program.SeriesTimerId) {
|
|
|
|
parent.querySelector('.btnManageSeriesRecording').classList.remove('hide');
|
|
|
|
parent.querySelector('.seriesRecordingButton .recordingIcon').classList.add('recordingIcon-active');
|
2019-02-03 02:41:16 +09:00
|
|
|
parent.querySelector('.seriesRecordingButton .buttonText').innerHTML = globalize.translate('CancelSeries');
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
parent.querySelector('.btnManageSeriesRecording').classList.add('hide');
|
|
|
|
parent.querySelector('.seriesRecordingButton .recordingIcon').classList.remove('recordingIcon-active');
|
2019-02-03 02:41:16 +09:00
|
|
|
parent.querySelector('.seriesRecordingButton .buttonText').innerHTML = globalize.translate('RecordSeries');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (program.TimerId && program.Status !== 'Cancelled') {
|
|
|
|
parent.querySelector('.btnManageRecording').classList.remove('hide');
|
|
|
|
parent.querySelector('.singleRecordingButton .recordingIcon').classList.add('recordingIcon-active');
|
|
|
|
if (program.Status === 'InProgress') {
|
2019-02-03 02:41:16 +09:00
|
|
|
parent.querySelector('.singleRecordingButton .buttonText').innerHTML = globalize.translate('StopRecording');
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
2019-02-03 02:41:16 +09:00
|
|
|
parent.querySelector('.singleRecordingButton .buttonText').innerHTML = globalize.translate('DoNotRecord');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parent.querySelector('.btnManageRecording').classList.add('hide');
|
|
|
|
parent.querySelector('.singleRecordingButton .recordingIcon').classList.remove('recordingIcon-active');
|
2019-02-03 02:41:16 +09:00
|
|
|
parent.querySelector('.singleRecordingButton .buttonText').innerHTML = globalize.translate('Record');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetchData(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var options = instance.options;
|
|
|
|
var apiClient = connectionManager.getApiClient(options.serverId);
|
|
|
|
|
2019-04-25 01:25:19 -04:00
|
|
|
options.parent.querySelector('.recordingFields').classList.remove('hide');
|
2019-01-10 15:39:37 +03:00
|
|
|
return apiClient.getLiveTvProgram(options.programId, apiClient.getCurrentUserId()).then(function (program) {
|
|
|
|
instance.TimerId = program.TimerId;
|
|
|
|
instance.Status = program.Status;
|
|
|
|
instance.SeriesTimerId = program.SeriesTimerId;
|
|
|
|
loadData(options.parent, program, apiClient);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTimerChangedExternally(e, apiClient, data) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var options = this.options;
|
|
|
|
var refresh = false;
|
|
|
|
|
|
|
|
if (data.Id) {
|
|
|
|
if (this.TimerId === data.Id) {
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.ProgramId && options) {
|
|
|
|
if (options.programId === data.ProgramId) {
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSeriesTimerChangedExternally(e, apiClient, data) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var options = this.options;
|
|
|
|
var refresh = false;
|
|
|
|
|
|
|
|
if (data.Id) {
|
|
|
|
if (this.SeriesTimerId === data.Id) {
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.ProgramId && options) {
|
|
|
|
if (options.programId === data.ProgramId) {
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function RecordingEditor(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
this.options = options;
|
|
|
|
this.embed();
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var timerChangedHandler = onTimerChangedExternally.bind(this);
|
2019-01-10 15:39:37 +03:00
|
|
|
this.timerChangedHandler = timerChangedHandler;
|
|
|
|
|
|
|
|
events.on(serverNotifications, 'TimerCreated', timerChangedHandler);
|
|
|
|
events.on(serverNotifications, 'TimerCancelled', timerChangedHandler);
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var seriesTimerChangedHandler = onSeriesTimerChangedExternally.bind(this);
|
2019-01-10 15:39:37 +03:00
|
|
|
this.seriesTimerChangedHandler = seriesTimerChangedHandler;
|
|
|
|
|
|
|
|
events.on(serverNotifications, 'SeriesTimerCreated', seriesTimerChangedHandler);
|
|
|
|
events.on(serverNotifications, 'SeriesTimerCancelled', seriesTimerChangedHandler);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onManageRecordingClick(e) {
|
|
|
|
var options = this.options;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!this.TimerId || this.Status === 'Cancelled') {
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
require(['recordingEditor'], function (recordingEditor) {
|
|
|
|
recordingEditor.show(self.TimerId, options.serverId, {
|
|
|
|
enableCancel: false
|
|
|
|
}).then(function () {
|
|
|
|
self.changed = true;
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onManageSeriesRecordingClick(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var options = this.options;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!this.SeriesTimerId) {
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
require(['seriesRecordingEditor'], function (seriesRecordingEditor) {
|
|
|
|
|
|
|
|
seriesRecordingEditor.show(self.SeriesTimerId, options.serverId, {
|
|
|
|
|
|
|
|
enableCancel: false
|
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
self.changed = true;
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRecordChange(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
this.changed = true;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var options = this.options;
|
|
|
|
var apiClient = connectionManager.getApiClient(options.serverId);
|
|
|
|
|
|
|
|
var button = dom.parentWithTag(e.target, 'BUTTON');
|
|
|
|
var isChecked = !button.querySelector('i').classList.contains('recordingIcon-active');
|
|
|
|
|
|
|
|
var hasEnabledTimer = this.TimerId && this.Status !== 'Cancelled';
|
|
|
|
|
|
|
|
if (isChecked) {
|
|
|
|
if (!hasEnabledTimer) {
|
|
|
|
loading.show();
|
|
|
|
recordingHelper.createRecording(apiClient, options.programId, false).then(function () {
|
|
|
|
events.trigger(self, 'recordingchanged');
|
|
|
|
fetchData(self);
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hasEnabledTimer) {
|
|
|
|
loading.show();
|
|
|
|
recordingHelper.cancelTimer(apiClient, this.TimerId, true).then(function () {
|
|
|
|
events.trigger(self, 'recordingchanged');
|
|
|
|
fetchData(self);
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function sendToast(msg) {
|
2019-01-10 15:39:37 +03:00
|
|
|
require(['toast'], function (toast) {
|
|
|
|
toast(msg);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRecordSeriesChange(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
this.changed = true;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var options = this.options;
|
|
|
|
var apiClient = connectionManager.getApiClient(options.serverId);
|
|
|
|
|
|
|
|
var button = dom.parentWithTag(e.target, 'BUTTON');
|
|
|
|
var isChecked = !button.querySelector('i').classList.contains('recordingIcon-active');
|
|
|
|
|
|
|
|
if (isChecked) {
|
2019-05-24 19:30:24 +02:00
|
|
|
options.parent.querySelector('.recordSeriesContainer').classList.remove('hide');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!this.SeriesTimerId) {
|
|
|
|
var promise = this.TimerId ?
|
|
|
|
recordingHelper.changeRecordingToSeries(apiClient, this.TimerId, options.programId) :
|
|
|
|
recordingHelper.createRecording(apiClient, options.programId, true);
|
|
|
|
promise.then(function () {
|
|
|
|
fetchData(self);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this.SeriesTimerId) {
|
|
|
|
apiClient.cancelLiveTvSeriesTimer(this.SeriesTimerId).then(function () {
|
2019-02-03 02:41:16 +09:00
|
|
|
sendToast(globalize.translate('RecordingCancelled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
fetchData(self);
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
RecordingEditor.prototype.embed = function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var self = this;
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['text!./recordingfields.template.html'], function (template) {
|
|
|
|
var options = self.options;
|
|
|
|
var context = options.parent;
|
2019-02-08 07:50:23 +01:00
|
|
|
context.innerHTML = globalize.translateDocument(template, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
context.querySelector('.singleRecordingButton').addEventListener('click', onRecordChange.bind(self));
|
|
|
|
context.querySelector('.seriesRecordingButton').addEventListener('click', onRecordSeriesChange.bind(self));
|
|
|
|
context.querySelector('.btnManageRecording').addEventListener('click', onManageRecordingClick.bind(self));
|
|
|
|
context.querySelector('.btnManageSeriesRecording').addEventListener('click', onManageSeriesRecordingClick.bind(self));
|
|
|
|
|
|
|
|
fetchData(self).then(resolve);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
RecordingEditor.prototype.hasChanged = function () {
|
|
|
|
return this.changed;
|
|
|
|
};
|
|
|
|
|
|
|
|
RecordingEditor.prototype.refresh = function () {
|
|
|
|
fetchData(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
RecordingEditor.prototype.destroy = function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var timerChangedHandler = this.timerChangedHandler;
|
2019-01-10 15:39:37 +03:00
|
|
|
this.timerChangedHandler = null;
|
|
|
|
|
|
|
|
events.off(serverNotifications, 'TimerCreated', timerChangedHandler);
|
|
|
|
events.off(serverNotifications, 'TimerCancelled', timerChangedHandler);
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var seriesTimerChangedHandler = this.seriesTimerChangedHandler;
|
2019-01-10 15:39:37 +03:00
|
|
|
this.seriesTimerChangedHandler = null;
|
|
|
|
|
|
|
|
events.off(serverNotifications, 'SeriesTimerCreated', seriesTimerChangedHandler);
|
|
|
|
events.off(serverNotifications, 'SeriesTimerCancelled', seriesTimerChangedHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
return RecordingEditor;
|
2019-04-25 01:25:19 -04:00
|
|
|
});
|