1- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
1+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
22
33 function compileTemplate ( selector ) {
44 let template = document . querySelector ( selector ) ;
@@ -27,38 +27,38 @@ document.addEventListener('DOMContentLoaded', function() {
2727
2828 function showCategoryDropdown ( ) {
2929 axios
30- . get ( '/api/categories' )
31- . then ( function ( results ) {
32- let response = results . data ;
33- let data = response . data ;
34- let html = categoryListTemplateInstance ( {
35- categoryList : data
30+ . get ( '/api/categories' )
31+ . then ( function ( results ) {
32+ let response = results . data ;
33+ let data = response . data ;
34+ let html = categoryListTemplateInstance ( {
35+ categoryList : data
36+ } ) ;
37+ categoriesElem . innerHTML = html ;
3638 } ) ;
37- categoriesElem . innerHTML = html ;
38- } ) ;
3939 }
4040
4141 function showProducts ( ) {
4242 productService
43- . getProducts ( )
44- . then ( function ( results ) {
45- let response = results . data ;
46- let data = response . data ;
47- let html = productListTemplateInstance ( {
48- productList : data
43+ . getProducts ( )
44+ . then ( function ( results ) {
45+ let response = results . data ;
46+ let data = response . data ;
47+ let html = productListTemplateInstance ( {
48+ productList : data
49+ } ) ;
50+ let productTableHTML = html ;
51+ productsElem . innerHTML = productTableHTML ;
4952 } ) ;
50- let productTableHTML = html ;
51- productsElem . innerHTML = productTableHTML ;
52- } ) ;
5353 }
54-
54+
5555 function clearFields ( ) {
5656 productNameElem . value = '' ;
5757 categoryIdElem . value = '' ;
58- priceElem . value = '' ;
58+ priceElem . value = '' ;
5959 }
6060
61- productBtn . addEventListener ( 'click' , function ( ) {
61+ productBtn . addEventListener ( 'click' , function ( ) {
6262
6363 let description = productNameElem . value ;
6464 let category_id = categoryIdElem . value ;
@@ -82,18 +82,18 @@ document.addEventListener('DOMContentLoaded', function() {
8282 description,
8383 price
8484 } )
85- . then ( function ( ) {
86- showProducts ( ) ;
87- clearFields ( ) ;
88- } )
89- . catch ( function ( err ) {
90- alert ( err ) ;
91- } ) ;
85+ . then ( function ( ) {
86+ showProducts ( ) ;
87+ clearFields ( ) ;
88+ } )
89+ . catch ( function ( err ) {
90+ alert ( err ) ;
91+ } ) ;
9292 }
9393 else {
94- errorsElem . innerHTML = errorsTemplateInstance ( { errors} ) ;
94+ errorsElem . innerHTML = errorsTemplateInstance ( { errors } ) ;
9595 }
96-
96+
9797 } ) ;
9898
9999 showCategoryDropdown ( ) ;
@@ -107,7 +107,7 @@ function editProduct(id) {
107107}
108108
109109function ProductService ( ) {
110- function getProducts ( ) {
110+ function getProducts ( ) {
111111 return axios . get ( '/api/products' )
112112 }
113113
0 commit comments