You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.8 KiB
84 lines
1.8 KiB
import _ from 'lodash';
|
|
import $ from 'jquery';
|
|
import getMonitoringOptions from 'Utilities/Series/getMonitoringOptions';
|
|
import * as types from './actionTypes';
|
|
import { set } from './baseActions';
|
|
import { fetchArtist } from './artistActions';
|
|
|
|
const section = 'albumStudio';
|
|
|
|
const albumStudioActionHandlers = {
|
|
[types.SAVE_SEASON_PASS]: function(payload) {
|
|
return function(dispatch, getState) {
|
|
const {
|
|
artistIds,
|
|
monitored,
|
|
monitor
|
|
} = payload;
|
|
|
|
let monitoringOptions = null;
|
|
const series = [];
|
|
const allArtists = getState().series.items;
|
|
|
|
artistIds.forEach((id) => {
|
|
const s = _.find(allArtists, { id });
|
|
const seriesToUpdate = { id };
|
|
|
|
if (payload.hasOwnProperty('monitored')) {
|
|
seriesToUpdate.monitored = monitored;
|
|
}
|
|
|
|
if (monitor) {
|
|
const {
|
|
seasons,
|
|
options: seriesMonitoringOptions
|
|
} = getMonitoringOptions(_.cloneDeep(s.seasons), monitor);
|
|
|
|
if (!monitoringOptions) {
|
|
monitoringOptions = seriesMonitoringOptions;
|
|
}
|
|
|
|
seriesToUpdate.seasons = seasons;
|
|
}
|
|
|
|
series.push(seriesToUpdate);
|
|
});
|
|
|
|
dispatch(set({
|
|
section,
|
|
isSaving: true
|
|
}));
|
|
|
|
const promise = $.ajax({
|
|
url: '/albumStudio',
|
|
method: 'POST',
|
|
data: JSON.stringify({
|
|
series,
|
|
monitoringOptions
|
|
}),
|
|
dataType: 'json'
|
|
});
|
|
|
|
promise.done((data) => {
|
|
dispatch(fetchArtist());
|
|
|
|
dispatch(set({
|
|
section,
|
|
isSaving: false,
|
|
saveError: null
|
|
}));
|
|
});
|
|
|
|
promise.fail((xhr) => {
|
|
dispatch(set({
|
|
section,
|
|
isSaving: false,
|
|
saveError: xhr
|
|
}));
|
|
});
|
|
};
|
|
}
|
|
};
|
|
|
|
export default albumStudioActionHandlers;
|