diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/index.html b/lnbits/extensions/diagonalley/templates/diagonalley/index.html index d1041b8..2dae3b0 100644 --- a/lnbits/extensions/diagonalley/templates/diagonalley/index.html +++ b/lnbits/extensions/diagonalley/templates/diagonalley/index.html @@ -64,6 +64,7 @@ {{ col.value }} + @@ -116,6 +117,8 @@ {{ col.value }} + + @@ -207,7 +210,7 @@ - + - Update Product + + Create Product + type="submit">Create Product + Cancel @@ -249,7 +257,7 @@ - + - Update Indexer + + Create Product + type="submit">Create Indexer + Cancel @@ -314,6 +327,7 @@ obj.date = Quasar.utils.date.formatDate(new Date(obj.time * 1000), 'YYYY-MM-DD HH:mm'); obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount); obj.wall = ['/diagonalley/', obj.id].join(''); + obj._data = _.clone(obj); return obj; } @@ -336,8 +350,10 @@ columns: [ {name: 'shopname', align: 'left', label: 'Shop', field: 'shopname'}, {name: 'indexeraddress', align: 'left', label: 'Address', field: 'indexeraddress'}, + {name: 'id', align: 'left', label: 'ID', field: 'id'}, {name: 'rating', align: 'left', label: 'Your Rating', field: 'rating'}, - {name: 'email', align: 'left', label: 'Your email', field: 'email'} + {name: 'email', align: 'left', label: 'Your email', field: 'email'}, + {name: 'online', align: 'left', label: 'Online', field: 'online'} ], pagination: { rowsPerPage: 10 @@ -400,8 +416,16 @@ }); }); }, - createIndexer: function () { + openIndexerUpdateDialog: function (linkId) { + var link = _.findWhere(this.indexers, {id: linkId}); + + this.indexerDialog.data = _.clone(link._data); + this.indexerDialog.show = true; + }, + sendIndexerFormData: function () { + if (this.indexerDialog.data.id){} + else{ var data = { shopname: this.indexerDialog.data.shopname, indexeraddress: this.indexerDialog.data.indexeraddress, @@ -410,11 +434,31 @@ shippingzone2: this.indexerDialog.data.shippingzone2.join(', '), zone2cost: this.indexerDialog.data.zone2cost, email: this.indexerDialog.data.email - }; - var self = this; - - console.log(data); + };} + if (this.indexerDialog.data.id) { + this.updateIndexer(this.indexerDialog.data); } + else { this.createIndexer(data); } + }, + updateIndexer: function (data) { + var self = this; + LNbits.api.request( + 'PUT', + '/diagonalley/api/v1/diagonalley/indexers' + data.id, + _.findWhere(this.g.user.wallets, {id: this.indexerDialog.data.wallet}).inkey, + _.pick(data, 'shopname', 'indexeraddress', 'shippingzone1', 'zone1cost', 'shippingzone2', 'zone2cost', 'email') + ).then(function (response) { + self.indexers = _.reject(self.indexers, function (obj) { return obj.id == data.id; }); + self.indexers.push(mapDiagonAlley(response.data)); + self.indexerDialog.show = false; + self.indexerDialog.data = {}; + data = {}; + }).catch(function (error) { + LNbits.utils.notifyApiError(error); + }); + }, + createIndexer: function (data) { + var self = this; LNbits.api.request( 'POST', '/diagonalley/api/v1/diagonalley/indexers', @@ -424,10 +468,12 @@ self.indexers.push(mapDiagonAlley(response.data)); self.indexerDialog.show = false; self.indexerDialog.data = {}; + data = {}; }).catch(function (error) { LNbits.utils.notifyApiError(error); }); }, + deleteIndexer: function (indexerId) { var self = this; var indexer = _.findWhere(this.indexers, {id: indexerId}); @@ -555,7 +601,17 @@ }); }, - createProduct: function () { + + + openProductUpdateDialog: function (linkId) { + var link = _.findWhere(this.products, {id: linkId}); + + this.productDialog.data = _.clone(link._data); + this.productDialog.show = true; + }, + sendProductFormData: function () { + if (this.productDialog.data.id){} + else{ var data = { product: this.productDialog.data.product, categories: this.productDialog.data.categories, @@ -563,9 +619,29 @@ image: this.productDialog.data.image, price: this.productDialog.data.price, quantity: this.productDialog.data.quantity - }; + };} + if (this.productDialog.data.id) { + this.updateProduct(this.productDialog.data); } + else { this.createProduct(data); } + }, + updateProduct: function (data) { + var self = this; + LNbits.api.request( + 'PUT', + '/diagonalley/api/v1/diagonalley/products' + data.id, + _.findWhere(this.g.user.wallets, {id: this.productDialog.data.wallet}).inkey, + _.pick(data, 'shopname', 'indexeraddress', 'shippingzone1', 'zone1cost', 'shippingzone2', 'zone2cost', 'email') + ).then(function (response) { + self.products = _.reject(self.products, function (obj) { return obj.id == data.id; }); + self.products.push(mapDiagonAlley(response.data)); + self.productDialog.show = false; + self.productDialog.data = {}; + }).catch(function (error) { + LNbits.utils.notifyApiError(error); + }); + }, + createProduct: function (data) { var self = this; - LNbits.api.request( 'POST', '/diagonalley/api/v1/diagonalley/products', @@ -579,6 +655,7 @@ LNbits.utils.notifyApiError(error); }); }, + deleteProduct: function (productId) { var self = this; var product = _.findWhere(this.products, {id: productId});