Stepper.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 _Stepper = _interopRequireDefault(require("@material-ui/core/Stepper"));
  9. var _Step = _interopRequireDefault(require("@material-ui/core/Step"));
  10. var _StepLabel = _interopRequireDefault(require("@material-ui/core/StepLabel"));
  11. var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
  12. var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
  13. var _DictionaryService = _interopRequireDefault(require("../Services/DictionaryService"));
  14. require("./Stepper.css");
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. 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); }
  17. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18. 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); } }
  19. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  21. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  22. 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); }
  23. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  24. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  25. 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); }
  26. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  27. var Module = _modularityFront.default.Module;
  28. var StepperModule =
  29. /*#__PURE__*/
  30. function (_Modularity$Module) {
  31. _inherits(StepperModule, _Modularity$Module);
  32. function StepperModule(props) {
  33. var _this;
  34. _classCallCheck(this, StepperModule);
  35. _this = _possibleConstructorReturn(this, _getPrototypeOf(StepperModule).call(this, props));
  36. _this.state = {
  37. activeStep: 0
  38. };
  39. _this.checkUrl();
  40. _this.RoutingSystem.onRouteChange("StepperModule" + _this.getId(), function () {
  41. _this.checkUrl();
  42. });
  43. return _this;
  44. }
  45. _createClass(StepperModule, [{
  46. key: "checkUrl",
  47. value: function checkUrl() {
  48. var _this2 = this;
  49. var route = this.RoutingSystem.getRoute();
  50. var steps = this.props.steps;
  51. var flag = 0;
  52. steps.map(function (step, index) {
  53. if (route.url.endsWith(step.url)) {
  54. // window.history.replaceState({}, '',step.url);
  55. flag = 1;
  56. Promise.resolve(step.resolve && step.resolve()).then(function () {
  57. return _this2.setState({
  58. activeStep: index
  59. });
  60. });
  61. }
  62. });
  63. }
  64. }, {
  65. key: "handleNext",
  66. value: function handleNext() {
  67. var _this3 = this;
  68. if (this.props.lock) return;
  69. var steps = this.props.steps;
  70. var newStep = this.state.activeStep + 1;
  71. var nextStep = steps[newStep];
  72. Promise.resolve(nextStep.resolve && nextStep.resolve()).then(function () {
  73. _this3.CoreSystem.go(nextStep.url, {});
  74. _this3.setState(function (state) {
  75. return {
  76. activeStep: newStep
  77. };
  78. });
  79. }).then(function () {
  80. return Promise.resolve(nextStep.postResolve && nextStep.postResolve());
  81. }).then(function () {
  82. return _this3.props.onNext && _this3.props.onNext(newStep);
  83. });
  84. }
  85. }, {
  86. key: "handleBack",
  87. value: function handleBack() {
  88. var _this4 = this;
  89. if (this.props.lock) return;
  90. var steps = this.props.steps;
  91. var newStep = this.state.activeStep - 1;
  92. var prevStep = steps[newStep];
  93. Promise.resolve(prevStep.resolve && prevStep.resolve()).then(function () {
  94. _this4.CoreSystem.go(prevStep.url, {});
  95. _this4.setState(function (state) {
  96. return {
  97. activeStep: newStep
  98. };
  99. });
  100. }).then(function () {
  101. return Promise.resolve(prevStep.postResolve && prevStep.postResolve());
  102. }).then(function () {
  103. return _this4.props.onBack && _this4.props.onBack(_this4.state.activeStep - 1);
  104. });
  105. }
  106. }, {
  107. key: "handleReset",
  108. value: function handleReset() {
  109. if (this.props.lock) return;
  110. this.setState({
  111. activeStep: 0
  112. });
  113. }
  114. }, {
  115. key: "render",
  116. value: function render() {
  117. var _this5 = this;
  118. var steps = this.props.steps;
  119. var activeStep = this.state.activeStep;
  120. var step_text;
  121. var step = steps[activeStep];
  122. return _react.default.createElement("div", {
  123. className: "stepper_container"
  124. }, _react.default.createElement(_Stepper.default, {
  125. className: "row stepper",
  126. activeStep: activeStep,
  127. alternativeLabel: true
  128. }, steps.map(function (label) {
  129. return _react.default.createElement(_Step.default, {
  130. key: label.title
  131. }, _react.default.createElement(_StepLabel.default, null, label.title));
  132. })), _react.default.createElement("div", {
  133. className: "step_but"
  134. }, this.state.activeStep === steps.length ? _react.default.createElement("div", null, _react.default.createElement(_Typography.default, null, _DictionaryService.default.get("All steps completed")), _react.default.createElement(_Button.default, {
  135. onClick: function onClick() {
  136. return _this5.handleReset();
  137. },
  138. disabled: this.props.lock
  139. }, _DictionaryService.default.get("Reset"))) : _react.default.createElement("div", null, step.content, _react.default.createElement("div", null, _react.default.createElement(_Button.default, {
  140. disabled: activeStep === 0 || this.props.lock,
  141. onClick: function onClick() {
  142. return _this5.handleBack();
  143. },
  144. className: "prev_step_but"
  145. }, _DictionaryService.default.get("Back")), this.state.activeStep < steps.length - 1 && _react.default.createElement(_Button.default, {
  146. disabled: this.props.lock,
  147. variant: "contained",
  148. color: "primary",
  149. onClick: function onClick() {
  150. return _this5.handleNext();
  151. }
  152. }, step.button)))), _get(_getPrototypeOf(StepperModule.prototype), "render", this).call(this));
  153. }
  154. }]);
  155. return StepperModule;
  156. }(_modularityFront.default.Module);
  157. StepperModule.EditPosition = "center";
  158. StepperModule.Inputs = {
  159. Products: {
  160. type: Module.Types.Object
  161. },
  162. Token: {
  163. type: Module.Types.Text
  164. }
  165. };
  166. StepperModule.Outputs = {
  167. selectedProduct: {}
  168. };
  169. StepperModule.Category = "Sxoinas Packages";
  170. var _default = StepperModule;
  171. exports.default = _default;