ClientForm.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _reactMaterialize = require("react-materialize");
  9. require("./ClientForm.css");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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); } }
  15. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  19. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  20. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  22. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  23. var Module = _modularityFront.default.Module;
  24. var ClientForm =
  25. /*#__PURE__*/
  26. function (_Modularity$Module) {
  27. _inherits(ClientForm, _Modularity$Module);
  28. function ClientForm(props) {
  29. var _this;
  30. _classCallCheck(this, ClientForm);
  31. _this = _possibleConstructorReturn(this, _getPrototypeOf(ClientForm).call(this, props));
  32. _this.state = {};
  33. _this.FormInputs.onUpdate(function (e) {
  34. return _this.updateState();
  35. });
  36. return _this;
  37. }
  38. _createClass(ClientForm, [{
  39. key: "componentDidMount",
  40. value: function componentDidMount() {
  41. _get(_getPrototypeOf(ClientForm.prototype), "componentDidMount", this).call(this); // must call
  42. this.updateState();
  43. }
  44. }, {
  45. key: "updateState",
  46. value: function updateState() {
  47. var _this2 = this;
  48. Object.keys(this.FormInputs.value).map(function (key, index) {
  49. _this2.setState(_defineProperty({}, key, _this2.FormInputs.value[key].value));
  50. });
  51. this.forceUpdate();
  52. }
  53. }, {
  54. key: "submitData",
  55. value: function submitData(e) {
  56. e.preventDefault();
  57. this.formData.set(this.state);
  58. }
  59. }, {
  60. key: "render",
  61. value: function render() {
  62. var _this3 = this;
  63. var data = Object.keys(this.FormInputs.value).map(function (key, index) {
  64. var input = _this3.FormInputs.value[key];
  65. return _react.default.createElement(_reactMaterialize.Row, null, _react.default.createElement(_reactMaterialize.Col, {
  66. s: 1
  67. }), _react.default.createElement(_reactMaterialize.Col, {
  68. className: "client_info",
  69. s: 2
  70. }, input.required ? _react.default.createElement("span", {
  71. className: "required"
  72. }, "*") : '', " ", key), _react.default.createElement(_reactMaterialize.Col, {
  73. s: 9
  74. }, _react.default.createElement("input", {
  75. onChange: function onChange(e) {
  76. return _this3.setState(_defineProperty({}, key, e.target.value));
  77. },
  78. key: index
  79. })));
  80. });
  81. return _react.default.createElement("div", null, _react.default.createElement("form", {
  82. className: "client_form"
  83. }, data), _get(_getPrototypeOf(ClientForm.prototype), "render", this).call(this));
  84. }
  85. }]);
  86. return ClientForm;
  87. }(_modularityFront.default.Module);
  88. ClientForm.EditPosition = "top-right";
  89. ClientForm.Inputs = {
  90. FormInputs: {
  91. type: Module.Types.Object,
  92. defaultValue: {}
  93. }
  94. };
  95. ClientForm.Outputs = {
  96. //
  97. formData: {}
  98. };
  99. ClientForm.Category = "sxoinas";
  100. var _default = ClientForm;
  101. exports.default = _default;