2020-08-05 11:48:31 +01:00
|
|
|
import globalize from 'globalize';
|
|
|
|
import loading from 'loading';
|
|
|
|
|
|
|
|
/*eslint prefer-const: "error"*/
|
|
|
|
|
|
|
|
function changeRecordingToSeries(apiClient, timerId, programId, confirmTimerCancellation) {
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
return apiClient.getItem(apiClient.getCurrentUserId(), programId).then(function (item) {
|
|
|
|
if (item.IsSeries) {
|
|
|
|
// create series
|
|
|
|
return apiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (timerDefaults) {
|
|
|
|
return apiClient.createLiveTvSeriesTimer(timerDefaults).then(function () {
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('SeriesRecordingScheduled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// cancel
|
|
|
|
if (confirmTimerCancellation) {
|
|
|
|
return cancelTimerWithConfirmation(timerId, apiClient.serverId());
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
return cancelTimer(apiClient.serverId(), timerId, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
function cancelTimerWithConfirmation(timerId, serverId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
import('confirm').then(({ default: confirm }) => {
|
|
|
|
confirm.default({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
|
|
|
primary: 'delete',
|
|
|
|
confirmText: globalize.translate('HeaderCancelRecording'),
|
|
|
|
cancelText: globalize.translate('HeaderKeepRecording')
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(serverId);
|
2020-08-05 11:48:31 +01:00
|
|
|
cancelTimer(apiClient, timerId, true).then(resolve, reject);
|
|
|
|
}, reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelSeriesTimerWithConfirmation(timerId, serverId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
import('confirm').then(({ default: confirm }) => {
|
|
|
|
confirm.default({
|
|
|
|
|
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
|
|
|
primary: 'delete',
|
|
|
|
confirmText: globalize.translate('HeaderCancelSeries'),
|
|
|
|
cancelText: globalize.translate('HeaderKeepSeries')
|
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
|
|
|
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(serverId);
|
2020-08-05 11:48:31 +01:00
|
|
|
apiClient.cancelLiveTvSeriesTimer(timerId).then(function () {
|
|
|
|
import('toast').then(({default: toast}) => {
|
|
|
|
toast(globalize.translate('SeriesCancelled'));
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
loading.hide();
|
|
|
|
resolve();
|
2019-01-10 15:39:37 +03:00
|
|
|
}, reject);
|
2020-08-05 11:48:31 +01:00
|
|
|
}, reject);
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelTimer(apiClient, timerId, hideLoading) {
|
|
|
|
loading.show();
|
|
|
|
return apiClient.cancelLiveTvTimer(timerId).then(function () {
|
|
|
|
if (hideLoading !== false) {
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('RecordingCancelled'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRecording(apiClient, programId, isSeries) {
|
|
|
|
loading.show();
|
|
|
|
return apiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (item) {
|
|
|
|
const promise = isSeries ?
|
|
|
|
apiClient.createLiveTvSeriesTimer(item) :
|
|
|
|
apiClient.createLiveTvTimer(item);
|
|
|
|
|
|
|
|
return promise.then(function () {
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('RecordingScheduled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendToast(msg) {
|
|
|
|
import('toast').then(({ default: toast }) => {
|
|
|
|
toast(msg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showMultiCancellationPrompt(serverId, programId, timerId, timerStatus, seriesTimerId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
import('dialog').then(({ default: dialog }) => {
|
|
|
|
const items = [];
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
name: globalize.translate('HeaderKeepRecording'),
|
|
|
|
id: 'cancel',
|
|
|
|
type: 'submit'
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
if (timerStatus === 'InProgress') {
|
2019-01-10 15:39:37 +03:00
|
|
|
items.push({
|
2020-08-05 11:48:31 +01:00
|
|
|
name: globalize.translate('HeaderStopRecording'),
|
|
|
|
id: 'canceltimer',
|
|
|
|
type: 'cancel'
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
} else {
|
2018-10-23 01:05:09 +03:00
|
|
|
items.push({
|
2020-08-05 11:48:31 +01:00
|
|
|
name: globalize.translate('HeaderCancelRecording'),
|
|
|
|
id: 'canceltimer',
|
2019-01-10 15:39:37 +03:00
|
|
|
type: 'cancel'
|
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
items.push({
|
|
|
|
name: globalize.translate('HeaderCancelSeries'),
|
|
|
|
id: 'cancelseriestimer',
|
|
|
|
type: 'cancel'
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
dialog({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
|
|
|
buttons: items
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
}).then(function (result) {
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(serverId);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
if (result === 'canceltimer') {
|
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
cancelTimer(apiClient, timerId, true).then(resolve, reject);
|
|
|
|
} else if (result === 'cancelseriestimer') {
|
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
apiClient.cancelLiveTvSeriesTimer(seriesTimerId).then(function () {
|
|
|
|
import('toast').then(({ default: toast }) => {
|
|
|
|
toast(globalize.translate('SeriesCancelled'));
|
|
|
|
});
|
|
|
|
|
|
|
|
loading.hide();
|
2019-01-10 15:39:37 +03:00
|
|
|
resolve();
|
2020-08-05 11:48:31 +01:00
|
|
|
}, reject);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}, reject);
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-08-05 11:48:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleRecording(serverId, programId, timerId, timerStatus, seriesTimerId) {
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(serverId);
|
2020-08-05 11:48:31 +01:00
|
|
|
const hasTimer = timerId && timerStatus !== 'Cancelled';
|
|
|
|
if (seriesTimerId && hasTimer) {
|
|
|
|
// cancel
|
|
|
|
return showMultiCancellationPrompt(serverId, programId, timerId, timerStatus, seriesTimerId);
|
|
|
|
} else if (hasTimer && programId) {
|
|
|
|
// change to series recording, if possible
|
|
|
|
// otherwise cancel individual recording
|
|
|
|
return changeRecordingToSeries(apiClient, timerId, programId, true);
|
|
|
|
} else if (programId) {
|
|
|
|
// schedule recording
|
|
|
|
return createRecording(apiClient, programId);
|
|
|
|
} else {
|
|
|
|
return Promise.reject();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-08-05 11:48:31 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-05 11:48:31 +01:00
|
|
|
export default {
|
|
|
|
cancelTimer: cancelTimer,
|
|
|
|
createRecording: createRecording,
|
|
|
|
changeRecordingToSeries: changeRecordingToSeries,
|
|
|
|
toggleRecording: toggleRecording,
|
|
|
|
cancelTimerWithConfirmation: cancelTimerWithConfirmation,
|
|
|
|
cancelSeriesTimerWithConfirmation: cancelSeriesTimerWithConfirmation
|
|
|
|
};
|
2019-01-10 15:39:37 +03:00
|
|
|
|