d2-ui
Version:
100 lines (84 loc) • 4.78 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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
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 PropTypes from 'prop-types';
import { config } from 'd2/lib/d2';
import Dialog from 'material-ui/Dialog/Dialog';
import { getTranslationFormFor } from './TranslationForm.component';
var TranslationDialog = function (_Component) {
_inherits(TranslationDialog, _Component);
function TranslationDialog(props, context) {
_classCallCheck(this, TranslationDialog);
var _this = _possibleConstructorReturn(this, (TranslationDialog.__proto__ || Object.getPrototypeOf(TranslationDialog)).call(this, props, context));
_this.i18n = context.d2.i18n;
_this.state = {
TranslationForm: getTranslationFormFor(_this.props.objectToTranslate)
};
_this.translationSaved = _this.translationSaved.bind(_this);
_this.translationError = _this.translationError.bind(_this);
_this.closeTranslationDialog = _this.closeTranslationDialog.bind(_this);
return _this;
}
_createClass(TranslationDialog, [{
key: 'render',
value: function render() {
return React.createElement(
Dialog,
_extends({
title: this.i18n.getTranslation('translation_dialog_title'),
autoDetectWindowHeight: true,
autoScrollBodyContent: true
}, this.props),
React.createElement(this.state.TranslationForm, {
onTranslationSaved: this.translationSaved,
onTranslationError: this.translationError,
onCancel: this.closeTranslationDialog,
fieldsToTranslate: this.props.fieldsToTranslate
})
);
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(newProps) {
if (newProps.objectToTranslate) {
this.setState({
TranslationForm: getTranslationFormFor(newProps.objectToTranslate)
});
}
}
}, {
key: 'closeTranslationDialog',
value: function closeTranslationDialog() {
this.props.onRequestClose();
}
}, {
key: 'translationSaved',
value: function translationSaved(args) {
this.props.onTranslationSaved(args);
this.closeTranslationDialog();
}
}, {
key: 'translationError',
value: function translationError(err) {
this.props.onTranslationError(err);
}
}]);
return TranslationDialog;
}(Component);
TranslationDialog.propTypes = {
objectToTranslate: PropTypes.shape({
id: PropTypes.string.isRequired
}).isRequired,
onTranslationSaved: PropTypes.func.isRequired,
onTranslationError: PropTypes.func.isRequired,
open: PropTypes.bool,
onRequestClose: PropTypes.func.isRequired,
fieldsToTranslate: PropTypes.array
};
TranslationDialog.contextTypes = {
d2: PropTypes.object
};
export default TranslationDialog;