Skip to content
Browse files

Moved over (probably) all of the javascript logic on the register to …

…requireJS
  • Loading branch information...
1 parent cfee7a2 commit 336965e8470e5d20c4169d0ff7a41d33e4714989 @maxolasersquad committed Mar 28, 2014
View
5 static/css/register.css
@@ -65,12 +65,11 @@
}
#numpad_enter {
- font-size: 2.5em;
- width: 80%;
+ font-size: 2.5em !important;
cursor: pointer;
}
-.numpad_number {
+.numpad_sm {
font-size: 3em;
cursor: pointer;
}
View
182 static/js/input.js
@@ -1,182 +0,0 @@
-// Copyright 2013 Jack David Baucum
-//
-// This file is part of Orthosie.
-//
-// Orthosie is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Orthosie is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Orthosie. If not, see <http://www.gnu.org/licenses/>.
-
-if (Orthosie === undefined) {
- var Orthosie = {};
-}
-
-Orthosie.input = {
- input_mode: 'upc',
-
- append: function(key) {
- $('#register_input').append(key);
- },
-
- backspace: function() {
- $('#register_input').html($('#register_input').html().substring(0, $('#register_input').html().length - 1));
- },
-
- submit: function() {
- switch (Orthosie.input.input_mode) {
- case 'upc':
- post_args = {
- upc: $('#register_input').html(),
- quantity: 1
- };
- post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
- $.ajax({
- url: '/register/process_upc/',
- data: post_args,
- type: 'POST',
- dataType: 'json',
- success: function(data, status) {
- if (data.success) {
- if ($('#transactions').data('status') == 'end') {
- $('#transactions>table>tbody').html('');
- $('#transactions').data('status', 'ring');
- }
- $('#transactions>table').append('<tr id="line-' + data.id + '"><td>' + data.vendor + ' ' + data.name + '</td><td>' + data.quantity + ' @ $' + data.price + '</td><td><i class="fa fa-times text-danger void-line" onclick="Orthosie.input.void_line(' + data.id + ')"></i></td></tr>');
- $('#sub_total_value').html('$' + data.subtotal);
- $('#tax_total_value').html('$' + data.taxtotal);
- $('#paid_total_value').html('$' + data.paidtotal);
- $('#total_value').html('$' + data.total);
- $('#transactions').scrollTop($("#transactions")[0].scrollHeight);
- }
- else {
- alert(data.error);
- }
- },
- error: function(xhr, text, error) {
- alert('There was an error processing the request.');
- }
- });
- break;
- case 'tender':
- post_args = {
- tender: $('#register_input').html(),
- quantity: 1
- };
- post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
- $.ajax({
- url: '/register/tender_transaction/',
- data: post_args,
- type: 'POST',
- dataType: 'json',
- success: function(data, status) {
- if (data.total <= 0) {
- $('#transactions').data('status', 'end');
- }
- $('#sub_total_value').html('$' + data.subtotal);
- $('#tax_total_value').html('$' + data.taxtotal);
- $('#paid_total_value').html('$' + data.paidtotal);
- $('#total_value').html('$' + data.total);
- },
- error: function(xhr, text, error) {
- alert('There was an error processing the request.')
- }
- });
- break;
- case 'product-search':
- Orthosie.input.product_search($('#register_input').html());
- break;
- }
- $('#register_input').html('');
- },
- set_inputtype: function(type) {
- var Type = $('#ringtype-' + type + ' > a').html();
- var header = $('#ringtype > button');
- var selected = $('#ringtype-' + type);
- var foo = $('#ringtype-' + header.attr('data-ringtype'));
-
- $(header.children()[0]).html(Type);
- selected.css('display', 'none');
- foo.css('display', 'list-item');
- header.attr('data-ringtype', type);
- Orthosie.input.input_mode = type;
- },
- end_shift: function() {
- $.ajax({
- url: '/register/end_shift/',
- dataType: 'json',
- success: function(data, status) {
- $('#confirm_endshift > div').modal('hide');
- },
- error: function(xhr, text, error) {
- alert('An error was encountered while trying to end the shift.')
- }
- });
- },
- product_search: function(search) {
- $('#product_search').load('/register/product_search/?search=' + search + '&csrfmiddlewaretoken=' + $('#csrf_token>input').attr('value'), function() {
- $('#transactions').addClass('hidden');
- $('#product_search').removeClass('hidden');
- });
- },
- disable_product_search: function() {
- $('#product_search').addClass('hidden');
- $('#transactions').removeClass('hidden');
- },
- select_item: function(item) {
- Orthosie.input.set_inputtype('upc');
- $('#register_input').html(item + Orthosie.input.get_upc_check_digit(item));
- Orthosie.input.disable_product_search();
- },
- get_upc_check_digit: function(upc) {
- var check_digit = 0;
- var odd_pos = true;
- for (var i=0;i < upc.length;i++) {
- if (odd_pos) {
- check_digit += parseInt(upc.charAt(i)) * 3;
- }
- else {
- check_digit += parseInt(upc.charAt(i));
- }
- odd_pos = !odd_pos;
- }
- check_digit = (10 - check_digit % 10) % 10;
- return check_digit;
- },
- void_line: function(id) {
- post_args = {
- id: id
- };
- post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
- $.ajax({
- url: '/register/cancel_line/',
- data: post_args,
- type: 'POST',
- dataType: 'json',
- success: function(data, status) {
- $('#line-' + id).addClass('danger');
- $('#line-' + id + ' td:nth-child(3)').html('')
- Orthosie.input.update_totals();
- }
- });
- },
- update_totals: function() {
- $.ajax({
- url: '/register/transaction_total',
- dataType: 'json',
- success: function(data) {
- $('#sub_total_value').html('$' + data.subtotal);
- $('#tax_total_value').html('$' + data.taxtotal);
- $('#paid_total_value').html('$' + data.paidtotal);
- $('#total_value').html('$' + data.total);
- }
- })
- }
-}
View
227 static/js/register.js
@@ -1,3 +1,228 @@
require(['jquery'], function($) {
- console.log($);
+
+ var input_mode = 'upc';
+
+ document.ready = function () {
+ $('#transactions').scrollTop($("#transactions")[0].scrollHeight);
+ };
+ document.onkeypress = function(e) {
+ if (e.keyCode == 13) {
+ submit();
+ }
+ else if (e.keyCode == 32 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || (e.keyCode >= 48 && e.keyCode <= 57)) {
+ append(String.fromCharCode(e.keyCode));
+ }
+ }
+ document.onkeydown = function(e) {
+ if (e.keyCode == 8) {
+ backspace();
+ }
+ }
+
+ $('.numpad_key').each(function() {
+ $(this).click(function() {
+ if (!isNaN($(this).data('key'))) {
+ append($(this).data('key'));
+ }
+ else {
+ switch ($(this).data('key')) {
+ case 'back':
+ backspace();
+ break;
+ case 'enter':
+ submit();
+ break;
+ }
+ }
+ })
+ });
+
+ $('.void-line').each(function() {
+ $(this).click(function() {
+ void_line($(this).data('id'));
+ });
+ });
+
+ $('.ringtype').each(function() {
+ $(this).click(function() {
+ set_inputtype($(this).children('a').data('input-type'));
+ });
+ });
+
+ $('#confirm-end-shift').click(function() {
+ end_shift();
+ });
+
+ function backspace() {
+ $('#register_input').html($('#register_input').html().substring(0, $('#register_input').html().length - 1));
+ };
+
+ function append(key) {
+ $('#register_input').append(key);
+ };
+
+ function submit() {
+ switch (input_mode) {
+ case 'upc':
+ post_args = {
+ upc: $('#register_input').html(),
+ quantity: 1
+ };
+ post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
+ $.ajax({
+ url: '/register/process_upc/',
+ data: post_args,
+ type: 'POST',
+ dataType: 'json',
+ success: function(data, status) {
+ if (data.success) {
+ if ($('#transactions').data('status') == 'end') {
+ $('#transactions>table>tbody').html('');
+ $('#transactions').data('status', 'ring');
+ }
+ $('#transactions>table').append('<tr id="line-' + data.id + '"><td>' + data.vendor + ' ' + data.name + '</td><td>' + data.quantity + ' @ $' + data.price + '</td><td><i class="fa fa-times text-danger void-line"></i></td></tr>').click(function() {void_line(data.id)});
+ update_totals();
+ $('#transactions').scrollTop($("#transactions")[0].scrollHeight);
+ }
+ else {
+ alert(data.error);
+ }
+ },
+ error: function(xhr, text, error) {
+ alert('There was an error processing the request.');
+ }
+ });
+ break;
+ case 'tender':
+ post_args = {
+ tender: $('#register_input').html(),
+ quantity: 1
+ };
+ post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
+ $.ajax({
+ url: '/register/tender_transaction/',
+ data: post_args,
+ type: 'POST',
+ dataType: 'json',
+ success: function(data, status) {
+ if (data.total <= 0) {
+ $('#transactions').data('status', 'end');
+ }
+ $('#sub_total_value').html('$' + data.subtotal);
+ $('#tax_total_value').html('$' + data.taxtotal);
+ $('#paid_total_value').html('$' + data.paidtotal);
+ $('#total_value').html('$' + data.total);
+ },
+ error: function(xhr, text, error) {
+ alert('There was an error processing the request.')
+ }
+ });
+ break;
+ case 'product-search':
+ product_search($('#register_input').html());
+ break;
+ }
+ $('#register_input').html('');
+ }
+
+ function product_search(search) {
+ $('#product_search').load('/register/product_search/?search=' + search + '&csrfmiddlewaretoken=' + $('#csrf_token>input').attr('value'), function() {
+ $('#transactions').addClass('hidden');
+ $('#product_search').removeClass('hidden');
+ $('.search-result').each(function() {
+ $(this).click(function() {
+ select_item($(this).data('upc'));
+ });
+ });
+ $('#cancel-search').click(function() {
+ disable_product_search();
+ });
+ });
+ };
+
+ function void_line(id) {
+ post_args = {
+ id: id
+ };
+ post_args[$('#csrf_token>input').attr('name')] = $('#csrf_token>input').attr('value');
+ $.ajax({
+ url: '/register/cancel_line/',
+ data: post_args,
+ type: 'POST',
+ dataType: 'json',
+ success: function(data, status) {
+ $('#line-' + id).addClass('danger');
+ $('#line-' + id + ' td:nth-child(3)').html('')
+ update_totals();
+ }
+ });
+ };
+
+ function update_totals() {
+ $.ajax({
+ url: '/register/transaction_total',
+ dataType: 'json',
+ success: function(data) {
+ $('#sub_total_value').html('$' + data.subtotal);
+ $('#tax_total_value').html('$' + data.taxtotal);
+ $('#paid_total_value').html('$' + data.paidtotal);
+ $('#total_value').html('$' + data.total);
+ }
+ })
+ }
+
+ function set_inputtype(type) {
+ var Type = $('#ringtype-' + type + ' > a').html();
+ var header = $('#ringtype > button');
+ var selected = $('#ringtype-' + type);
+ var foo = $('#ringtype-' + header.attr('data-ringtype'));
+
+ $(header.children()[0]).html(Type);
+ selected.css('display', 'none');
+ foo.css('display', 'list-item');
+ header.attr('data-ringtype', type);
+ input_mode = type;
+ }
+
+ function end_shift() {
+ $.ajax({
+ url: '/register/end_shift/',
+ dataType: 'json',
+ success: function(data, status) {
+ $('#confirm_endshift > div').modal('hide');
+ },
+ error: function(xhr, text, error) {
+ alert('An error was encountered while trying to end the shift.')
+ }
+ });
+ }
+
+ function select_item(item) {
+ set_inputtype('upc');
+ $('#register_input').html(item.toString() + get_upc_check_digit(item));
+ disable_product_search();
+ }
+
+ function get_upc_check_digit(upc) {
+ upc = upc.toString();
+ var check_digit = 0;
+ var odd_pos = true;
+ for (var i=0;i < upc.length;i++) {
+ if (odd_pos) {
+ check_digit += parseInt(upc.charAt(i)) * 3;
+ }
+ else {
+ check_digit += parseInt(upc.charAt(i));
+ }
+ odd_pos = !odd_pos;
+ }
+ check_digit = (10 - check_digit % 10) % 10;
+ return check_digit;
+ }
+
+ function disable_product_search() {
+ $('#product_search').addClass('hidden');
+ $('#transactions').removeClass('hidden');
+ }
+
});
View
6 templates/register/confirm_endshift.html
@@ -24,13 +24,11 @@
<h4 id="end-shift-title" class="modal-title">Confirm</h4>
</div>
<div class="modal-body">
- <p>
- Are you sure you wish to end the shift?
- </p>
+ <p>Are you sure you wish to end the shift?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Dismiss</button>
- <button type="button" class="btn btn-warning" onclick="Orthosie.input.end_shift();">Confirm</button>
+ <button type="button" class="btn btn-warning" id="confirm-end-shift">Confirm</button>
</div>
</div>
</div>
View
19 templates/register/index.html
@@ -28,28 +28,9 @@
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
<script src="/static/js/bootstrap.min.js"></script>
<link rel='stylesheet' type='text/css' href='/static/css/register.css' />
- <script type="text/javascript" src="/static/js/input.js"></script>
<meta charset="UTF-8">
</head>
<body>
- <script type="text/javascript">
- document.ready = function () {
- $('#transactions').scrollTop($("#transactions")[0].scrollHeight);
- };
- document.onkeypress = function(e) {
- if (e.keyCode == 13) {
- Orthosie.input.submit();
- }
- else if (e.keyCode == 32 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || (e.keyCode >= 48 && e.keyCode <= 57)) {
- Orthosie.input.append(String.fromCharCode(e.keyCode));
- }
- }
- document.onkeydown = function(e) {
- if (e.keyCode == 8) {
- Orthosie.input.backspace();
- }
- }
- </script>
<div id="input">
{% include "register/input.html" %}
</div>
View
8 templates/register/input.html
@@ -20,10 +20,10 @@
<div id='ringtype' class='input-group-btn'>
<button type='button' class='btn btn-success dropdown-toggle' data-toggle='dropdown' data-ringtype='upc'><span>UPC</span> <span class='caret'></span></button>
<ul class='dropdown-menu'>
- <li id='ringtype-upc'><a href='#' onclick="Orthosie.input.set_inputtype('upc');">UPC</a></li>
- <li id='ringtype-tender'><a href='#' onclick="Orthosie.input.set_inputtype('tender');">Tender</a></li>
- <li id='ringtype-product-search'><a href='#' onclick="Orthosie.input.set_inputtype('product-search');">Product Search</a></li>
- <li id='ringtype-endshift' data-toggle='modal' data-target='#confirm_endshift > div'><a href='#' onclick="Orthosie.input.set_inputtype('endshift');">End Shift</a></li>
+ <li id='ringtype-upc' class='ringtype'><a href='#' data-input-type='upc'>UPC</a></li>
+ <li id='ringtype-tender' class='ringtype'><a href='#' data-input-type='tender'>Tender</a></li>
+ <li id='ringtype-product-search' class='ringtype'><a href='#' data-input-type='product-search'>Product Search</a></li>
+ <li id='ringtype-endshift' class='ringtype' data-toggle='modal' data-target='#confirm_endshift > div'><a href='#' data-input-type='endshift'>End Shift</a></li>
</ul>
</div>
<span id='register_input' class='form-control'></span>
View
46 templates/register/numpad.html
@@ -18,28 +18,30 @@
{% endcomment %}
<div id='numpad'>
- <div id='numpad_numbers'>
- <div id='first_row' class='btn-group col-xs-12'>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(7);'>7</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(8);'>8</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(9);'>9</button>
+ <div id='numpad_keys'>
+ <div class="row">
+ <div id='first_row' class='btn-group col-xs-12'>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="7">7</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="8">8</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="9">9</button>
+ </div>
+ <div id='second_row' class='btn-group col-xs-12'>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="4">4</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="5">5</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="6">6</button>
+ </div>
+ <div id='third_row' class='btn-group col-xs-12'>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="1">1</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="2">2</button>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="3">3</button>
+ </div>
+ <div id='fourth_row' class='btn-group col-xs-12'>
+ <button class='btn btn-primary btn-lg numpad_key numpad_sm col-xs-4' data-key="0">0</button>
+ <button class='btn btn-warning btn-lg numpad_key numpad_sm col-xs-8' data-key="back">Back</button>
+ </div>
+ <div id='numpad_enter' class='btn-group col-xs-12'>
+ <button class='btn btn-success btn-lg numpad_key col-xs-12 ' data-key="enter">Enter</button>
+ </div>
</div>
- <div id='second_row' class='btn-group col-xs-12'>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(4);'>4</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(5);'>5</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(6);'>6</button>
- </div>
- <div id='third_row' class='btn-group col-xs-12'>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(1);'>1</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(2);'>2</button>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(3);'>3</button>
- </div>
- <div id='fourth_row' class='btn-group col-xs-12'>
- <button class='btn btn-primary btn-lg numpad_number col-xs-4' onclick='Orthosie.input.append(0);'>0</button>
- <button class='btn btn-warning btn-lg numpad_number col-xs-8' onclick='Orthosie.input.backspace();'>Back</button>
- </div>
- </div>
- <div id='numpad_enter' class='col-xs-12'>
- <button class='btn btn-success btn-lg col-xs-12' onclick='Orthosie.input.submit();'>Enter</button>
</div>
</div>
View
4 templates/register/product_search.html
@@ -26,7 +26,7 @@
</thead>
<tbody>
{% for item in results %}
- <tr onclick="Orthosie.input.select_item('{{ item.upc }}')">
+ <tr class="search-result" data-upc="{{ item.upc }}">
<td>{{ item.upc }}</td>
<td>{{ item.vendor.name}} {{ item.name }}</td>
<td>{{ item.scalable }}</td>
@@ -35,4 +35,4 @@
{% endfor %}
</tbody>
</table>
-<button class="btn btn-danger" onclick="Orthosie.input.disable_product_search()">Cancel Search</button>
+<button class="btn btn-danger" id="cancel-search">Cancel Search</button>
View
2 templates/register/transactions.html
@@ -24,7 +24,7 @@
<td>{{ line_item.quantity }} @ ${{ line_item.price }}</td>
<td>
{% if line_item.status == 'ACTIVE' %}
- <i class="fa fa-times text-danger void-line" onclick="Orthosie.input.void_line({{ line_item.id }})"></i>
+ <i class="fa fa-times text-danger void-line" data-id="{{ line_item.id }}"></i>
{% endif %}
</td>
</tr>

0 comments on commit 336965e

Please sign in to comment.
Something went wrong with that request. Please try again.