Permalink
Browse files

Completed product search.

  • Loading branch information...
1 parent c37d527 commit cc52f9cf4b420dabdcca36a23f4da16cecc5ca49 @maxolasersquad committed Feb 22, 2014
Showing with 22 additions and 1 deletion.
  1. +20 −0 static/js/input.js
  2. +2 −1 templates/register/product_search.html
View
20 static/js/input.js
@@ -129,5 +129,25 @@ Orthosie.input = {
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;
}
}
View
3 templates/register/product_search.html
@@ -26,7 +26,7 @@
</thead>
<tbody>
{% for item in results %}
- <tr>
+ <tr onclick="Orthosie.input.select_item('{{ item.upc }}')">
<td>{{ item.upc }}</td>
<td>{{ item.name }}</td>
<td>{{ item.scalable }}</td>
@@ -35,3 +35,4 @@
{% endfor %}
</tbody>
</table>
+<button class="btn btn-danger" onclick="Orthosie.input.disable_product_search()">Cancel Search</button>

0 comments on commit cc52f9c

Please sign in to comment.