-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.html
221 lines (188 loc) · 7.08 KB
/
Main.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{{ block content }}
<div class="alert alert-secondary otree-timer-custom">Time left:<br><b class="otree-timer__time-left">0:00</b></div>
<section id="waiting" class="bg-light border rounded p-3 m-3">
<p>Waiting for other players to arrive</p>
<ot-pulse></ot-pulse>
</section>
<section id="endowment" class="ot-fade bg-light border rounded p-3 m-3" hidden>
<p>The endowment is <b>{{C.ENDOWMENT}}</b></p>
</section>
{{ if player.role == C.PROPOSER_ROLE }}
<section ot-stage="1" class="ot-fade bg-light border rounded p-3 m-3">
<h4>Proposal</h4>
<input ot-input type="range" name="proposal" min="0" max="{{C.ENDOWMENT}}" step="1" class="form-range" ot-stage="1">
<div class="w-100 d-flex justify-content-between">
<p class="text-center">You share:<br><b ot-text="vars.proposed">...</b></p>
<p class="text-center">You leave:<br><b ot-text="vars.remained">...</b></p>
</div>
<button ot-click-input type="button" name="propose" class="btn btn-primary d-block m-auto" disabled>Submit</button>
</section>
<section ot-stage="2" class="ot-fade bg-light border rounded p-3 m-3">
<div id="deciding-wait">
<p>Wait while your partner is deciding</p>
<ot-pulse></ot-pulse>
</div>
<div id="deciding-done">
<p id="decision-ACCEPT">Your partner has accepted your proposal.</p>
<p id="decision-REJECT">Your partner has rejected your proposal.</p>
</div>
</section>
<section ot-stage="3" class="ot-fade bg-light border rounded p-3 m-3">
<p>Your bonus: <b ot-text="vars.bonus.Proposer"></b></p>
<p>Your partner's bonus: <b ot-text="vars.bonus.Receiver"></b></p>
<button ot-click-input type="button" name="complete" class="btn btn-primary m-3" ot-stage="3">Complete</button>
</section>
{{ endif }}
{{ if player.role == C.RECEIVER_ROLE }}
<section ot-stage="1" class="ot-fade bg-light border rounded p-3 m-3">
<h4>Proposal</h4>
<div id="proposing-wait">
<p>Wait while your partner is deciding</p>
<ot-pulse></ot-pulse>
</div>
<div id="proposing-done">
<p>Your partner shared: <b ot-text="vars.proposal"></b></p>
</div>
</section>
<section ot-stage="2" class="ot-fade bg-light border rounded p-3 m-3">
<h4>Decision</h4>
<div class="d-flex m-3">
<div class="form-check form-check-inline">
<input ot-input type="radio" id="accept" name="decision" value="ACCEPT" class="form-check-input" ot-stage="2">
<label for="accept" class="form-check-label">Accept</label>
</div>
<div class="form-check form-check-inline">
<input ot-input type="radio" id="reject" name="decision" value="REJECT" class="form-check-input" ot-stage="2">
<label for="reject" class="form-check-label">Reject</label>
</div>
</div>
<button ot-click-input type="button" name="decide" class="btn btn-primary d-block m-auto" disabled>Submit</button>
</section>
<section ot-stage="3" class="ot-fade bg-light border rounded p-3 m-3" hidden>
<p>Your bonus: <b ot-text="vars.bonus.Receiver"></b></p>
<p>Your partner's bonus: <b ot-text="vars.bonus.Proposer"></b></p>
<button ot-click-input type="button" name="complete" class="btn btn-primary m-3" ot-stage="3">Complete</button>
</section>
{{ endif }}
{{ endblock }}
{{ block styles }}
<link rel="stylesheet" href="{{ static 'otree-front-ext.css' }}">
<link rel="stylesheet" href="{{ static 'ot-pulse.css' }}">
<style>
.otree-timer {
display: none;
}
.otree-timer-custom {
display: block;
position: absolute;
right: 1rem;
top: 1rem;
}
/* unhide passed stages */
[ot-stage].passed[hidden] {
display: block !important;
opacity: 1.0;
}
/* outline active stage */
[ot-stage].active {
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15);
}
</style>
{{ endblock }}
{{ block scripts }}
<script src="{{ static 'otree-front-2.0.b2.js' }}"></script>
<script src="{{ static 'otree-front-ext.js' }}"></script>
<script src="{{ static 'otree-front-live.js' }}"></script>
<script src="{{ static 'ot-pulse.js' }}"></script>
<script src="{{ static 'ot-stage.js' }}"></script>
<script>
"use strict";
const ENDOWMENT = js_vars.C.ENDOWMENT;
const ROLE = js_vars.role;
onLoad(startPage);
onLive('game', updateGame); // on page load and after each step
onInput('proposal', inputProposal);
onInput('propose', sendProposal);
onInput('decision', inputDecision);
onInput('decide', sendDecision);
onInput('complete', completeGame);
function startPage() {
vars.stage = null;
vars.proposal = null;
vars.decision = null;
vars.proposed = 50;
vars.remained = 50;
sendLive('start');
}
/* generic game state update */
function updateGame(data) {
console.debug("state=", data);
vars.stage = data.stage;
if (data.stage == 'STARTING') {
return;
} else {
ot.hideDisplay("waiting");
ot.showDisplay("endowment");
}
vars.proposal = data.proposal;
vars.decision = data.decision;
vars.bonus = data.bonus;
if (ROLE == "Proposer") switch (vars.stage) {
case 'PROPOSING':
switchStage(1); // this enables inputs as well
ot.beginTimeMeasurement();
break;
case 'DECIDING':
switchStage(2);
switchDisplays("deciding-wait");
break;
case 'COMPLETED':
switchDisplays("deciding-done");
switchStage(3);
switchDisplays(`decision-${vars.decision}`);
break;
}
if (ROLE == "Receiver") switch (vars.stage) {
case 'PROPOSING':
switchStage(1);
switchDisplays("proposing-wait");
break;
case 'DECIDING':
switchDisplays("proposing-done");
switchStage(2); // this enables inputs as well
ot.beginTimeMeasurement();
break;
case 'COMPLETED':
switchStage(3);
break;
}
}
function inputProposal(value) {
vars.proposal = value;
vars.proposed = value;
vars.remained = ENDOWMENT - value;
ot.enableInput('propose');
}
function sendProposal() {
ot.disableInputs();
sendLive("proposal", {
time: ot.getTimeMeasurement(),
proposal: vars.proposal
});
}
function inputDecision(value) {
vars.decision = value;
ot.enableInput('decide');
}
function sendDecision() {
ot.disableInputs();
sendLive('decision', {
time: ot.getTimeMeasurement(),
decision: vars.decision
});
}
function completeGame() {
ot.completePage();
}
</script>
{{ endblock }}