@bigfishtv/cockpit
Version:
99 lines (81 loc) • 4 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _dec, _class;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React, { Component } from 'react';
import { withFormValue } from '@bigfishtv/react-forms';
import { connect } from 'react-redux';
import MainContent from '../container/MainContent';
import Bulkhead from '../page/Bulkhead';
import Button from '../button/Button';
import Panel from '../container/panel/Panel';
import Breadcrumb from '../breadcrumb/Breadcrumb';
import EditForm from '../form/EditForm';
import RedirectEditFieldset from './RedirectEditFieldset';
import { notifySuccess, notifyFailure } from '../../actions/notifications';
/**
* Redirect edit page template
*/
var RedirectEdit = (_dec = connect(), _dec(_class = function (_Component) {
_inherits(RedirectEdit, _Component);
function RedirectEdit() {
var _temp, _this, _ret;
_classCallCheck(this, RedirectEdit);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.handleSubmitSuccess = function (data) {
_this.props.dispatch(notifySuccess('The redirect has been saved.'));
history.replaceState(null, null, '/tank/redirects/edit/' + data.id);
}, _this.handleSubmitError = function () {
_this.props.dispatch(notifyFailure('The redirect could not be saved.'));
}, _temp), _possibleConstructorReturn(_this, _ret);
}
RedirectEdit.prototype.getSubmitUrl = function getSubmitUrl(data) {
if (data.id) {
return '/tank/redirects/edit/' + data.id + '.json';
} else {
return '/tank/redirects/add.json';
}
};
RedirectEdit.prototype.render = function render() {
return React.createElement(
MainContent,
null,
React.createElement(
EditForm,
_extends({}, this.props, {
submitUrl: this.getSubmitUrl,
onSubmitSuccess: this.handleSubmitSuccess,
onSubmitError: this.handleSubmitError,
Header: withFormValue(function (props) {
return React.createElement(Bulkhead, {
title: props.formValue.value.id ? 'Edit Redirect' : 'New Redirect',
Toolbar: function Toolbar(props) {
return React.createElement(Button, { type: 'submit', text: 'Save', style: 'secondary', size: 'large' });
}
});
}) }),
React.createElement(RedirectEditMainPanel, null)
)
);
};
return RedirectEdit;
}(Component)) || _class);
export { RedirectEdit as default };
var RedirectEditMainPanel = withFormValue(function (props) {
return React.createElement(
Breadcrumb,
{ title: 'Redirects', url: '/tank/redirects' },
React.createElement(
Breadcrumb,
{ title: props.formValue.value.id ? 'Edit' : 'New' },
React.createElement(
Panel,
{ title: 'Properties', uncontrolled: true },
React.createElement(RedirectEditFieldset, props)
)
)
);
});