shoppingcart.xhtml
4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:reader="http://java.sun.com/jsf/composite/cditools/reader" xmlns:p="http://primefaces.org/ui">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form id="shoppingcartform">
<h:panelGrid columns="2" style="width:100%;" columnClasses="shopProductbuttons,topalign">
<h:panelGroup>
<div id="shopItems">
<ui:repeat value="#{productShopView.shoppingcart}" var="cart">
<h:commandLink styleClass="shopItem" action="#{productShopView.addOne}">
<f:ajax render="@form" />
<div>
#{cart.product.name}<br />
<h:outputText value="#{cart.product.price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</div>
</h:commandLink>
</ui:repeat>
</div>
</h:panelGroup>
<h:panelGroup>
<reader:codefield selectaction="#{productShopView.readCode}" selectvalue="#{i18n['shop.readBarcode']}" />
<br />
<p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.count']}" />
</f:facet>
<p:inplace>
<h:outputText value="#{prods.count}" size="4">
<f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
</h:outputText>
</p:inplace>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.product']}" />
</f:facet>
<h:outputText value="#{prods.getProduct().name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.price']}" />
</f:facet>
<h:outputText value="#{prods.getProduct().price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.actions']}" />
</f:facet>
<p:commandButton action="#{productShopView.removeBought()}" update="@form" onerror="location.reload(true);" value="Poista" />
</p:column>
</p:dataTable>
<div style="font-weight: bold;">
<h:outputText value="#{i18n['shop.cartPrice']}" />
<h:outputText id="shoptotal" value="#{productShopView.cartPrice}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
<br />
<h:outputLabel value="#{i18n['shop.currentBalance']}" />
<h:outputText id="currentbalance" value="#{productShopView.accountCredits}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
<br />
<h:outputLabel value="#{i18n['shop.transactionTotal']}" />
<h:outputText id="transactiontotal" value="#{productShopView.transactionTotal}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</div>
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['shop.toAccountValue']}" />
<h:inputText styleClass="inputval" size="5" value="#{productShopView.cash}">
<f:ajax render="@form" event="valueChange" listener="#{productShopView.cashChanged}" />
</h:inputText>
</h:panelGrid>
<p:commandButton update="@form" onerror="location.reload(true);" action="#{productShopView.buyByCredit()}" value="#{i18n['shop.buyByCredit']}" />
<h:panelGrid columns="2" style="background-color: #{productShopView.balanceAfterTransaction lt 0?'lightcoral':'lightgreen'}">
<h:outputLabel value="#{i18n['shop.afterBalance']}" />
<h:outputText value="#{productShopView.balanceAfterTransaction}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:panelGrid>
<p:commandButton ajax="false" action="#{productShopView.commitShoppingCart()}" value="#{i18n['shop.buy']}" />
</h:panelGroup>
</h:panelGrid>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
</h:form>
<script>
var blipSnd = new Audio(
"#{request.contextPath}/resources/media/blip.mp3")
$(function() {
$("#shoppingcartform\\:barcode").focus();
});
function blip() {
blipSnd.play();
}
function calc() {
$("#returnval").val(
$("#inputval").val()
- $(".inputval").text().replace(",", "."));
}
function barcodeReadEvent(data) {
if (data.status == "success") {
$("[id$=shoppingcartform\\:barcode]").focus();
}
}
</script>
</composite:implementation>
</html>