2019-03-19 17:03:11 -07:00
|
|
|
define(['globalize', 'loading', 'connectionManager'], function (globalize, loading, connectionManager) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-28 23:08:27 +01:00
|
|
|
loading = loading.default || loading;
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function changeRecordingToSeries(apiClient, timerId, programId, confirmTimerCancellation) {
|
2019-01-10 15:39:37 +03:00
|
|
|
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();
|
2019-02-03 02:41:16 +09:00
|
|
|
sendToast(globalize.translate('SeriesRecordingScheduled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2019-03-19 17:03:11 -07:00
|
|
|
// cancel
|
2019-01-10 15:39:37 +03:00
|
|
|
if (confirmTimerCancellation) {
|
|
|
|
return cancelTimerWithConfirmation(timerId, apiClient.serverId());
|
|
|
|
}
|
|
|
|
|
|
|
|
return cancelTimer(apiClient.serverId(), timerId, true);
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelTimerWithConfirmation(timerId, serverId) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['confirm'], function (confirm) {
|
2020-06-18 22:41:43 +03:00
|
|
|
confirm.default({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
2019-09-06 02:02:58 -07:00
|
|
|
primary: 'delete',
|
2019-02-03 02:41:16 +09:00
|
|
|
confirmText: globalize.translate('HeaderCancelRecording'),
|
|
|
|
cancelText: globalize.translate('HeaderKeepRecording')
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
cancelTimer(apiClient, timerId, true).then(resolve, reject);
|
|
|
|
}, reject);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelSeriesTimerWithConfirmation(timerId, serverId) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['confirm'], function (confirm) {
|
2020-06-18 22:41:43 +03:00
|
|
|
confirm.default({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
2019-09-06 02:02:58 -07:00
|
|
|
primary: 'delete',
|
2019-02-03 02:41:16 +09:00
|
|
|
confirmText: globalize.translate('HeaderCancelSeries'),
|
|
|
|
cancelText: globalize.translate('HeaderKeepSeries')
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
apiClient.cancelLiveTvSeriesTimer(timerId).then(function () {
|
|
|
|
require(['toast'], function (toast) {
|
2019-02-03 02:41:16 +09:00
|
|
|
toast(globalize.translate('SeriesCancelled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
resolve();
|
|
|
|
}, reject);
|
|
|
|
}, reject);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelTimer(apiClient, timerId, hideLoading) {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.show();
|
|
|
|
return apiClient.cancelLiveTvTimer(timerId).then(function () {
|
|
|
|
if (hideLoading !== false) {
|
|
|
|
loading.hide();
|
2019-02-03 02:41:16 +09:00
|
|
|
sendToast(globalize.translate('RecordingCancelled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function createRecording(apiClient, programId, isSeries) {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.show();
|
|
|
|
return apiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (item) {
|
|
|
|
var promise = isSeries ?
|
|
|
|
apiClient.createLiveTvSeriesTimer(item) :
|
|
|
|
apiClient.createLiveTvTimer(item);
|
|
|
|
|
|
|
|
return promise.then(function () {
|
|
|
|
loading.hide();
|
2019-02-03 02:41:16 +09:00
|
|
|
sendToast(globalize.translate('RecordingScheduled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
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 showMultiCancellationPrompt(serverId, programId, timerId, timerStatus, seriesTimerId) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['dialog'], function (dialog) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var items = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
items.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('HeaderKeepRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'cancel',
|
|
|
|
type: 'submit'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (timerStatus === 'InProgress') {
|
|
|
|
items.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('HeaderStopRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'canceltimer',
|
|
|
|
type: 'cancel'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
items.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('HeaderCancelRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'canceltimer',
|
|
|
|
type: 'cancel'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
items.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('HeaderCancelSeries'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'cancelseriestimer',
|
|
|
|
type: 'cancel'
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog({
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
text: globalize.translate('MessageConfirmRecordingCancellation'),
|
2018-10-23 01:05:09 +03:00
|
|
|
buttons: items
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(function (result) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (result === 'canceltimer') {
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
cancelTimer(apiClient, timerId, true).then(resolve, reject);
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (result === 'cancelseriestimer') {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.show();
|
|
|
|
|
|
|
|
apiClient.cancelLiveTvSeriesTimer(seriesTimerId).then(function () {
|
|
|
|
require(['toast'], function (toast) {
|
2019-02-03 02:41:16 +09:00
|
|
|
toast(globalize.translate('SeriesCancelled'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
resolve();
|
|
|
|
}, reject);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}, reject);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleRecording(serverId, programId, timerId, timerStatus, seriesTimerId) {
|
2019-03-19 17:03:11 -07:00
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
var 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
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
return {
|
|
|
|
cancelTimer: cancelTimer,
|
|
|
|
createRecording: createRecording,
|
|
|
|
changeRecordingToSeries: changeRecordingToSeries,
|
|
|
|
toggleRecording: toggleRecording,
|
|
|
|
cancelTimerWithConfirmation: cancelTimerWithConfirmation,
|
|
|
|
cancelSeriesTimerWithConfirmation: cancelSeriesTimerWithConfirmation
|
2019-01-10 15:39:37 +03:00
|
|
|
};
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|