Skip to content

Commit

Permalink
Merge pull request #60 from SEL-Columbia/cards
Browse files Browse the repository at this point in the history
write card button disabled/enabled for vendors/customers
  • Loading branch information
jmbott authored Jul 19, 2017
2 parents cfc813a + be4934e commit ac77558
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import populateCardInfoTable from './populate_card_info.js';

(function(){

const input = document.getElementById('card-value');
const inputs = document.getElementsByClassName('card-value');

console.log('new input', inputs)

let conn = new SockJS(http_protocol + '://' + window.location.host + '/cardconn');
let received_info;
Expand All @@ -21,14 +23,19 @@ import populateCardInfoTable from './populate_card_info.js';
};

conn.onmessage = function(e) {
console.log('Received: ' + JSON.stringify(e.data['received_info']));
console.log('Received!: ' + JSON.stringify(e.data));
received_info = e.data['received_info'];
card_read_error = e.data['card_read_error'];
console.log('its different part 1', e.data['device_active']);

if (e.data['device_active']!==device_active) {
device_active = e.data['device_active'];
if (e.data['device_active']) input.disabled = false;
else input.disabled = true;
console.log('its different', device_active);
console.log(inputs);
[].forEach.call(inputs, function(input){
if (e.data['device_active']) input.disabled = false;
else input.disabled = true;
});
populateCardInfoTable(received_info, card_read_error);
};
};
Expand Down
16 changes: 8 additions & 8 deletions minigrid/templates/minigrid_customers.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
<p>User ID: {{ customer.customer_user_id }}</p>
<form action="/minigrids/{{ minigrid.minigrid_id }}/customers" method="POST">
{% module xsrf_form_html() %}
<input type="hidden" name="action" value="write" />
<input type="hidden" name="customer_id" value="{{ customer.customer_id }}" />
{% if device_active %}
<input type="submit" value="Write ID card" />
{% else %}
<input type="submit" value="Write ID card" title="Touch card to reader" disabled/>
{% end %}
<input type="hidden" name="action" value="write" />
<input type="hidden" name="customer_id" value="{{ customer.customer_id }}" />
{% if device_active %}
<input class="card-value" type="submit" value="Write ID card" />
{% else %}
<input class="card-value" type="submit" value="Write ID card" title="Touch card to reader" disabled/>
{% end %}
</form>
<form action="/minigrids/{{ minigrid.minigrid_id }}/customers" method="POST">
{% module xsrf_form_html() %}
Expand Down Expand Up @@ -62,5 +62,5 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
<script>
var http_protocol = '{{ http_protocol }}';
</script>
<script type="text/javascript" src="{{ static_url('dist/read_card.bundle.js') }}"></script>
<script type="text/javascript" src="{{ static_url('dist/write_card.bundle.js') }}"></script>
{% end %}
6 changes: 3 additions & 3 deletions minigrid/templates/minigrid_vendors.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
<input type="hidden" name="action" value="write" />
<input type="hidden" name="vendor_id" value="{{ vendor.vendor_id }}" />
{% if device_active %}
<input type="submit" value="Write ID card" />
<input class="card-value" type="submit" value="Write ID card" />
{% else %}
<input type="submit" value="Write ID card" title="Touch card to reader" disabled/>
<input class="card-value" type="submit" value="Write ID card" title="Touch card to reader" disabled/>
{% end %}
</form>
<form action="/minigrids/{{ minigrid.minigrid_id }}/vendors" method="POST">
Expand Down Expand Up @@ -63,5 +63,5 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
<script>
var http_protocol = '{{ http_protocol }}';
</script>
<script type="text/javascript" src="{{ static_url('dist/read_card.bundle.js') }}"></script>
<script type="text/javascript" src="{{ static_url('dist/write_card.bundle.js') }}"></script>
{% end %}
6 changes: 3 additions & 3 deletions minigrid/templates/minigrid_write_credit.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
{% module xsrf_form_html() %}
<label>Card value : <input type="number" step="1" min="0" name="credit_value" required /></label><br>
{% if device_active %}
<input id="card-value" type="submit" value="Write credit card" />
<input class="card-value" type="submit" value="Write credit card" />
{% else %}
<input id="card-value" type="submit" value="Write credit card" title="Touch card to reader" disabled/>
<input class="card-value" type="submit" value="Write credit card" title="Touch card to reader" disabled/>
{% end %}
</form>
</div>
Expand All @@ -36,6 +36,6 @@ <h1>Minigrid Name: {{ minigrid.minigrid_name }}</h1>
var http_protocol = '{{ http_protocol }}';
</script>

<script type="text/javascript" src="{{ static_url('dist/write_credit.bundle.js') }}"></script>
<script type="text/javascript" src="{{ static_url('dist/write_card.bundle.js') }}"></script>

{% end %}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const webpack = require('webpack');

module.exports = {
entry: {
write_credit: path.resolve(__dirname, 'minigrid/static/src/js/minigrid_write_credit.js'),
write_card: path.resolve(__dirname, 'minigrid/static/src/js/minigrid_write_card.js'),
read_card: path.resolve(__dirname, 'minigrid/static/src/js/read_card.js'),
tariffs: path.resolve(__dirname, 'minigrid/static/src/js/tariffs.js')
},
Expand Down

0 comments on commit ac77558

Please sign in to comment.