From 3bfa7d77cea7f2b22a0bd7fea6a9507fa3d40561 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Tue, 3 Dec 2019 21:07:19 +0300 Subject: [PATCH] deleted excesses data --- dist/public/css/style.css | 3 +++ dist/public/js/bundle.js | 8 ++++---- dist/views/product.pug | 4 ++-- src/js/components/items.component.js | 22 +++++++++++----------- src/js/modals/cart.modal.js | 6 +++--- src/js/modals/pay.modal.js | 4 ++-- src/js/templates/items.template.js | 8 ++++---- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/dist/public/css/style.css b/dist/public/css/style.css index cb6712d..42f99e8 100644 --- a/dist/public/css/style.css +++ b/dist/public/css/style.css @@ -447,6 +447,9 @@ footer .container { display: flex; align-items: center; } +.list-date { + margin-left: 8px; +} .list-title { padding-left: 7px; diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index 0a2dd12..de1edc9 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -3942,7 +3942,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"ItemsComponent\", function() { return ItemsComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/js/core/component.js\");\n/* harmony import */ var _services_api_service__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../services/api.service */ \"./src/js/services/api.service.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\n/* harmony import */ var _templates_items_template__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../templates/items.template */ \"./src/js/templates/items.template.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\n\n\nvar ItemsComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(ItemsComponent, _Component);\n\n function ItemsComponent(id, _ref) {\n var _this;\n\n var loader = _ref.loader;\n\n _classCallCheck(this, ItemsComponent);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(ItemsComponent).call(this, id));\n _this.loader = loader;\n _this.$el ? _this.roster = _this.$el.querySelector('#roster') : false;\n\n if (localStorage.getItem('cart')) {\n _this.cart = JSON.parse(localStorage.getItem('cart'));\n } else {\n _this.cart = [];\n }\n\n return _this;\n }\n\n _createClass(ItemsComponent, [{\n key: \"init\",\n value: function init() {\n var fData, categories, html;\n return regeneratorRuntime.async(function init$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n if (!this.$el) {\n _context.next = 14;\n break;\n }\n\n localStorage.setItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n this.$el.addEventListener('click', addItem.bind(this));\n\n if (localStorage.getItem('category')) {\n _context.next = 14;\n break;\n }\n\n _context.next = 6;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItems());\n\n case 6:\n fData = _context.sent;\n _context.next = 9;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getCategories());\n\n case 9:\n categories = _context.sent;\n html = Object(_templates_items_template__WEBPACK_IMPORTED_MODULE_3__[\"renderItems\"])(categories, fData);\n this.insertItems(html);\n this.btnColor();\n this.loader.hide();\n\n case 14:\n case \"end\":\n return _context.stop();\n }\n }\n }, null, this);\n }\n }, {\n key: \"onHide\",\n value: function onHide() {\n this.$el.querySelector('#roster').innerHTML = '';\n this.loader.hide();\n }\n }, {\n key: \"onShow\",\n value: function onShow() {\n this.$el.querySelector('#roster').innerHTML = '';\n this.loader.show();\n }\n }, {\n key: \"btnColor\",\n value: function btnColor() {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n // Окраска кнопок айтемов которые находятся в корзине\n var obj = JSON.parse(localStorage.getItem('cart'));\n obj.forEach(function (item) {\n if (_this2.$el.querySelector(\"#addItem[data-id=\\\"\".concat(item.id, \"\\\"]\"))) {\n _this2.$el.querySelector(\"#addItem[data-id=\\\"\".concat(item.id, \"\\\"]\")).classList.add('orange');\n\n _this2.$el.querySelector(\"#addItem[data-id=\\\"\".concat(item.id, \"\\\"] i\")).innerHTML = 'close';\n }\n });\n }\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(html) {\n this.roster.insertAdjacentHTML('afterbegin', html);\n this.btnColor();\n }\n }]);\n\n return ItemsComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\nfunction addItem(e) {\n if (e.target.localName === 'button' && e.target.id === 'addItem') {\n var target = e.target;\n var item = {\n id: e.target.dataset.id,\n title: e.target.dataset.title,\n count: e.target.dataset.count,\n price: e.target.dataset.price\n };\n renderObj(item, this, target);\n } else if (e.target.localName === 'i') {\n var _target = e.target.parentNode;\n var _item = {\n id: e.target.parentNode.dataset.id,\n title: e.target.parentNode.dataset.title,\n count: e.target.parentNode.dataset.count,\n price: e.target.parentNode.dataset.price\n };\n renderObj(_item, this, _target);\n }\n}\n\nfunction renderObj(obj, context, target) {\n if (context.cart.length > 0) {\n var insterted = false;\n var index; // Проверка на существующий айтем в корзине\n\n context.cart.forEach(function (item, i) {\n if (item.id === obj.id) {\n insterted = true;\n index = i;\n }\n });\n\n if (insterted === false) {\n context.cart.push(obj);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.add('orange');\n target.querySelector('i').innerHTML = 'close';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n } else {\n context.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.remove('orange');\n target.querySelector('i').innerHTML = 'shopping_cart';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n }\n } else {\n context.cart.push(obj);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.add('orange');\n target.querySelector('i').innerHTML = 'close';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n }\n}\n\n;\n\n//# sourceURL=webpack:///./src/js/components/items.component.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"ItemsComponent\", function() { return ItemsComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/js/core/component.js\");\n/* harmony import */ var _services_api_service__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../services/api.service */ \"./src/js/services/api.service.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\n/* harmony import */ var _templates_items_template__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../templates/items.template */ \"./src/js/templates/items.template.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\n\n\nvar ItemsComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(ItemsComponent, _Component);\n\n function ItemsComponent(id, _ref) {\n var _this;\n\n var loader = _ref.loader;\n\n _classCallCheck(this, ItemsComponent);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(ItemsComponent).call(this, id));\n _this.loader = loader;\n _this.$el ? _this.roster = _this.$el.querySelector('#roster') : false;\n\n if (localStorage.getItem('cart')) {\n _this.cart = JSON.parse(localStorage.getItem('cart'));\n } else {\n _this.cart = [];\n }\n\n return _this;\n }\n\n _createClass(ItemsComponent, [{\n key: \"init\",\n value: function init() {\n var fData, categories, html;\n return regeneratorRuntime.async(function init$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n if (!this.$el) {\n _context.next = 14;\n break;\n }\n\n localStorage.setItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n this.$el.addEventListener('click', addItem.bind(this));\n\n if (localStorage.getItem('category')) {\n _context.next = 14;\n break;\n }\n\n _context.next = 6;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItems());\n\n case 6:\n fData = _context.sent;\n _context.next = 9;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getCategories());\n\n case 9:\n categories = _context.sent;\n html = Object(_templates_items_template__WEBPACK_IMPORTED_MODULE_3__[\"renderItems\"])(categories, fData);\n this.insertItems(html);\n this.btnColor();\n this.loader.hide();\n\n case 14:\n case \"end\":\n return _context.stop();\n }\n }\n }, null, this);\n }\n }, {\n key: \"onHide\",\n value: function onHide() {\n this.$el.querySelector('#roster').innerHTML = '';\n this.loader.hide();\n }\n }, {\n key: \"onShow\",\n value: function onShow() {\n this.$el.querySelector('#roster').innerHTML = '';\n this.loader.show();\n }\n }, {\n key: \"btnColor\",\n value: function btnColor() {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n // Окраска кнопок айтемов которые находятся в корзине\n var obj = JSON.parse(localStorage.getItem('cart'));\n obj.forEach(function (item) {\n if (_this2.$el.querySelector(\"#rosterButtons[data-id=\\\"\".concat(item.id, \"\\\"] #addItem\"))) {\n _this2.$el.querySelector(\"#rosterButtons[data-id=\\\"\".concat(item.id, \"\\\"] #addItem\")).classList.add('orange');\n\n _this2.$el.querySelector(\"#rosterButtons[data-id=\\\"\".concat(item.id, \"\\\"] #addItem i\")).innerHTML = 'close';\n }\n });\n }\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(html) {\n this.roster.insertAdjacentHTML('afterbegin', html);\n this.btnColor();\n }\n }]);\n\n return ItemsComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\nfunction addItem(e) {\n if (e.target.localName === 'button' && e.target.id === 'addItem') {\n var target = e.target;\n var item = {\n id: e.target.parentNode.dataset.id,\n title: e.target.parentNode.dataset.title,\n count: e.target.parentNode.dataset.count,\n price: e.target.parentNode.dataset.price\n };\n renderObj(item, this, target);\n } else if (e.target.localName === 'i') {\n var _target = e.target.parentNode;\n var _item = {\n id: e.target.parentNode.parentNode.dataset.id,\n title: e.target.parentNode.parentNode.dataset.title,\n count: e.target.parentNode.parentNode.dataset.count,\n price: e.target.parentNode.parentNode.dataset.price\n };\n renderObj(_item, this, _target);\n }\n}\n\nfunction renderObj(obj, context, target) {\n if (context.cart.length > 0) {\n var insterted = false;\n var index; // Проверка на существующий айтем в корзине\n\n context.cart.forEach(function (item, i) {\n if (item.id === obj.id) {\n insterted = true;\n index = i;\n }\n });\n\n if (insterted === false) {\n context.cart.push(obj);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.add('orange');\n target.querySelector('i').innerHTML = 'close';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n } else {\n context.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.remove('orange');\n target.querySelector('i').innerHTML = 'shopping_cart';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n }\n } else {\n context.cart.push(obj);\n localStorage.setItem('cart', JSON.stringify(context.cart));\n target.classList.add('orange');\n target.querySelector('i').innerHTML = 'close';\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_2__[\"insertCount\"])('counter', context.cart);\n }\n}\n\n;\n\n//# sourceURL=webpack:///./src/js/components/items.component.js?"); /***/ }), @@ -4002,7 +4002,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _com /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#purchaseInfo').classList.add('hide');\n } else {\n this.$el.querySelector('#purchaseInfo').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n } else {\n list.innerHTML = '

Вы не добавили ни один товар

';\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n this.defaultBtnColor(id);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay(e) {\n e.preventDefault();\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info:', payInfo);\n }\n }, {\n key: \"defaultBtnColor\",\n value: function defaultBtnColor(id) {\n if (this.items.roster) {\n if (this.items.roster.querySelector(\"#addItem[data-id=\\\"\".concat(id, \"\\\"]\"))) {\n this.items.roster.querySelector(\"#addItem[data-id=\\\"\".concat(id, \"\\\"]\")).classList.remove('orange');\n this.items.roster.querySelector(\"#addItem[data-id=\\\"\".concat(id, \"\\\"] i\")).innerHTML = 'shopping_cart';\n }\n }\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/cart.modal.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#purchaseInfo').classList.add('hide');\n } else {\n this.$el.querySelector('#purchaseInfo').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n } else {\n list.innerHTML = '

Вы не добавили ни один товар

';\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n this.defaultBtnColor(id);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay(e) {\n e.preventDefault();\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info:', payInfo);\n }\n }, {\n key: \"defaultBtnColor\",\n value: function defaultBtnColor(id) {\n if (this.items.roster) {\n if (this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\"))) {\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\")).classList.remove('orange');\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem i\")).innerHTML = 'shopping_cart';\n }\n }\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/cart.modal.js?"); /***/ }), @@ -4014,7 +4014,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"PayModal\", function() { return PayModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\nvar PayModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(PayModal, _Modal);\n\n function PayModal(id, open, close) {\n var _this;\n\n _classCallCheck(this, PayModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(PayModal).call(this, id, open, close));\n\n if (_this.open != null) {\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n }\n\n return _this;\n }\n\n _createClass(PayModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.$el.querySelector('#purchaseInfo').onsubmit = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler(e) {\n var _this2 = this;\n\n if (e.target.id === 'payOpen') {\n var targetInfo = e.target.dataset;\n this.$el.querySelector('.title-field #title').value = targetInfo.title;\n this.show();\n\n this.$el.querySelector('#purchaseInfo').onsubmit = function (e) {\n _this2.makePay(e, targetInfo);\n };\n } else {\n this.hide();\n }\n }\n }, {\n key: \"makePay\",\n value: function makePay(e, info) {\n e.preventDefault();\n var payInfo = {\n item: [{\n id: info.id,\n title: info.title\n }],\n totalPrice: parseFloat(info.price)\n };\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info: ', payInfo);\n }\n }]);\n\n return PayModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/pay.modal.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"PayModal\", function() { return PayModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\nfunction _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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\nvar PayModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(PayModal, _Modal);\n\n function PayModal(id, open, close) {\n var _this;\n\n _classCallCheck(this, PayModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(PayModal).call(this, id, open, close));\n\n if (_this.open != null) {\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n }\n\n return _this;\n }\n\n _createClass(PayModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.$el.querySelector('#purchaseInfo').onsubmit = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler(e) {\n var _this2 = this;\n\n if (e.target.id === 'payOpen') {\n var targetInfo = e.target.parentNode.dataset;\n this.$el.querySelector('.title-field #title').value = targetInfo.title;\n this.show();\n\n this.$el.querySelector('#purchaseInfo').onsubmit = function (e) {\n _this2.makePay(e, targetInfo);\n };\n } else {\n this.hide();\n }\n }\n }, {\n key: \"makePay\",\n value: function makePay(e, info) {\n e.preventDefault();\n var payInfo = {\n items: [{\n id: info.id,\n title: info.title\n }],\n totalPrice: parseFloat(info.price)\n };\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info: ', payInfo);\n }\n }]);\n\n return PayModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/pay.modal.js?"); /***/ }), @@ -4050,7 +4050,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var arrayCategories = categories;\n var arrayItems = items;\n var html = '';\n arrayCategories.forEach(function (category) {\n html += \"
\\n

\".concat(category.title, \"

\\n
\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(diffDates(new Date(), new Date(item.date)), \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\");\n }\n });\n });\n return html;\n}\n\nfunction diffDates(firstDate, secondDate) {\n var diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000));\n\n if (diff <= 0) {\n return 'добавлено сегодня';\n }\n\n return diff + ' дней назад';\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var arrayCategories = categories;\n var arrayItems = items;\n var html = '';\n arrayCategories.forEach(function (category) {\n html += \"
\\n

\".concat(category.title, \"

\\n
\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(diffDates(new Date(), new Date(item.date)), \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\");\n }\n });\n });\n return html;\n}\n\nfunction diffDates(firstDate, secondDate) {\n var diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000));\n\n if (diff <= 0) {\n return 'добавлено сегодня';\n }\n\n return diff + ' дней назад';\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?"); /***/ }), diff --git a/dist/views/product.pug b/dist/views/product.pug index 7262bb2..7fe1520 100644 --- a/dist/views/product.pug +++ b/dist/views/product.pug @@ -26,9 +26,9 @@ main.main-section small(style="font-size: 12px") Дата добавления: #{date.toLocaleDateString()} .product-info .product-info__left - #pay-js.product-left__pay + #pay-js.product-left__pay(data-id=id data-title=title data-count=count data-price=price) img(src='../img/service-icons/'+image alt='#') - button#payOpen.waves-effect.waves-light.btn(data-id=id data-title=title data-date=date data-count=count data-price=price) Купить + button#payOpen.waves-effect.waves-light.btn Купить .product-info__cost .product-info__count span #{count} шт diff --git a/src/js/components/items.component.js b/src/js/components/items.component.js index cf5a6fb..b4dc9a8 100644 --- a/src/js/components/items.component.js +++ b/src/js/components/items.component.js @@ -46,9 +46,9 @@ export class ItemsComponent extends Component { const obj = JSON.parse(localStorage.getItem('cart')); obj.forEach(item => { - if (this.$el.querySelector(`#addItem[data-id="${item.id}"]`)) { - this.$el.querySelector(`#addItem[data-id="${item.id}"]`).classList.add('orange'); - this.$el.querySelector(`#addItem[data-id="${item.id}"] i`).innerHTML = 'close'; + if (this.$el.querySelector(`#rosterButtons[data-id="${item.id}"] #addItem`)) { + this.$el.querySelector(`#rosterButtons[data-id="${item.id}"] #addItem`).classList.add('orange'); + this.$el.querySelector(`#rosterButtons[data-id="${item.id}"] #addItem i`).innerHTML = 'close'; } }); } @@ -65,19 +65,19 @@ function addItem(e) { if (e.target.localName === 'button' && e.target.id === 'addItem') { const target = e.target; const item = { - id: e.target.dataset.id, - title: e.target.dataset.title, - count: e.target.dataset.count, - price: e.target.dataset.price + id: e.target.parentNode.dataset.id, + title: e.target.parentNode.dataset.title, + count: e.target.parentNode.dataset.count, + price: e.target.parentNode.dataset.price } renderObj(item, this, target); } else if (e.target.localName === 'i') { const target = e.target.parentNode; const item = { - id: e.target.parentNode.dataset.id, - title: e.target.parentNode.dataset.title, - count: e.target.parentNode.dataset.count, - price: e.target.parentNode.dataset.price + id: e.target.parentNode.parentNode.dataset.id, + title: e.target.parentNode.parentNode.dataset.title, + count: e.target.parentNode.parentNode.dataset.count, + price: e.target.parentNode.parentNode.dataset.price } renderObj(item, this, target); } diff --git a/src/js/modals/cart.modal.js b/src/js/modals/cart.modal.js index a84cba4..d9178e0 100644 --- a/src/js/modals/cart.modal.js +++ b/src/js/modals/cart.modal.js @@ -84,9 +84,9 @@ export class CartModal extends Modal { defaultBtnColor(id) { if (this.items.roster) { - if (this.items.roster.querySelector(`#addItem[data-id="${id}"]`)) { - this.items.roster.querySelector(`#addItem[data-id="${id}"]`).classList.remove('orange'); - this.items.roster.querySelector(`#addItem[data-id="${id}"] i`).innerHTML = 'shopping_cart'; + if (this.items.roster.querySelector(`#rosterButtons[data-id="${id}"] #addItem`)) { + this.items.roster.querySelector(`#rosterButtons[data-id="${id}"] #addItem`).classList.remove('orange'); + this.items.roster.querySelector(`#rosterButtons[data-id="${id}"] #addItem i`).innerHTML = 'shopping_cart'; } } } diff --git a/src/js/modals/pay.modal.js b/src/js/modals/pay.modal.js index 700e768..104854c 100644 --- a/src/js/modals/pay.modal.js +++ b/src/js/modals/pay.modal.js @@ -15,7 +15,7 @@ export class PayModal extends Modal { openHandler(e) { if (e.target.id === 'payOpen') { - const targetInfo = e.target.dataset; + const targetInfo = e.target.parentNode.dataset; this.$el.querySelector('.title-field #title').value = targetInfo.title; this.show(); @@ -31,7 +31,7 @@ export class PayModal extends Modal { e.preventDefault(); const payInfo = { - item: [{ + items: [{ id: info.id, title: info.title }], diff --git a/src/js/templates/items.template.js b/src/js/templates/items.template.js index 534fa8e..6187b68 100644 --- a/src/js/templates/items.template.js +++ b/src/js/templates/items.template.js @@ -11,7 +11,7 @@ export function renderItems(categories, items) { arrayItems.forEach(item => { if (item.category.toLowerCase() === category.title.toLowerCase()) { html += ` -
+
# @@ -33,9 +33,9 @@ export function renderItems(categories, items) {
${item.price.toFixed(2)}₽
-
- - +