chap2->Creating templates->The header template
parent
61c3776031
commit
4b8c3312f0
|
@ -26,7 +26,24 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- templates -->
|
<!-- templates -->
|
||||||
<script type="text/html" id="header"></script>
|
<script type="text/html" id="header">
|
||||||
|
<h1>Catalog</h1>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="btn btn-primary btn-sm"
|
||||||
|
data-toggle="modal"
|
||||||
|
data-target="#addToCatalogModal"
|
||||||
|
>
|
||||||
|
Add New Product
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn btn-primary btn-sm"
|
||||||
|
data-bind="click: showCartDetails, css:{ disabled: cart().length < 1}"
|
||||||
|
>
|
||||||
|
Show Cart Details
|
||||||
|
</button>
|
||||||
|
<hr />
|
||||||
|
</script>
|
||||||
<script type="text/html" id="catalog"></script>
|
<script type="text/html" id="catalog"></script>
|
||||||
<script type="text/html" id="add-to-catalog-modal"></script>
|
<script type="text/html" id="add-to-catalog-modal"></script>
|
||||||
<script type="text/html" id="cart-widget"></script>
|
<script type="text/html" id="cart-widget"></script>
|
||||||
|
|
|
@ -40,12 +40,23 @@ var vm = (function () {
|
||||||
});
|
});
|
||||||
return filtered;
|
return filtered;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var cart = ko.observableArray([]);
|
||||||
|
var showCartDetails = function () {
|
||||||
|
if (cart().length > 0) {
|
||||||
|
$("#cartContainer").removeClass("hidden");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// first chapter
|
||||||
searchTerm: searchTerm,
|
searchTerm: searchTerm,
|
||||||
catalog: filteredCatalog,
|
catalog: filteredCatalog,
|
||||||
newProduct: newProduct,
|
newProduct: newProduct,
|
||||||
addProduct: addProduct,
|
addProduct: addProduct,
|
||||||
|
// second chapter
|
||||||
|
cart: cart,
|
||||||
|
showCartDetails: showCartDetails
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
ko.applyBindings(vm);
|
ko.applyBindings(vm);
|
||||||
|
|
Loading…
Reference in New Issue