Skip to content

Commit

Permalink
Added requireJS to inventory.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxolasersquad committed Mar 29, 2014
1 parent d53fef3 commit 222e933
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 59 deletions.
115 changes: 68 additions & 47 deletions static/js/inventory.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
// 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.inventory = {

edit_vendor: function(upc) {
require(['jquery'], function($) {

$('.vendor-name').each(function() {
$(this).click(function() {
edit_vendor($(this).data('upc'));
});
});

$('.inventory-name').each(function() {
$(this).click(function() {
edit_name($(this).data('upc'));
});
});

$('.inventory-price').each(function() {
$(this).click(function() {
edit_price($(this).data('upc'));
});
});

$('.inventory-scalable').each(function() {
$(this).click(function() {
toggle_scalable($(this).data('upc'));
});
});

$('.inventory-taxable').each(function() {
$(this).click(function() {
toggle_taxable($(this).data('upc'));
});

$('.new-inventory').each(function() {
$(this).blur(function() {
new_inventory();
});
}); });

function edit_vendor(upc) {
if ($('#' + upc + '_vendor > input').length == 0) {
$('#' + upc + '_vendor').html("<input type='text' id='" + upc + "_vendor_edit' class='inventory_vendor_edit' value='" + $('#' + upc + '_vendor').html() + "' onblur='Orthosie.inventory.save_vendor(\"" + upc + "\")' >");
$('#' + upc + '_vendor_edit').focus();
$('#' + upc + '_vendor').html("<input type='text' id='" + upc + "_vendor_edit' class='inventory_vendor_edit' value='" + $('#' + upc + '_vendor').html() + "'>");
$('#' + upc + '_vendor_edit').focus().blur(function() {
save_vendor(upc);
});
}
},
}

save_vendor: function(upc) {
function save_vendor(upc) {
new_vendor = $('#' + upc + '_vendor_edit').val();
post_args = {
upc: upc,
Expand All @@ -49,16 +65,18 @@ Orthosie.inventory = {
}
});

},
}

edit_name: function(upc) {
function edit_name(upc) {
if ($('#' + upc + '_name > input').length == 0) {
$('#' + upc + '_name').html("<input type='text' id='" + upc + "_name_edit' class='inventory_name_edit' value='" + $('#' + upc + '_name').html() + "' onblur='Orthosie.inventory.save_name(\"" + upc + "\")' >");
$('#' + upc + '_name_edit').focus();
$('#' + upc + '_name').html("<input type='text' id='" + upc + "_name_edit' class='inventory_name_edit' value='" + $('#' + upc + '_name').html() + "'>");
$('#' + upc + '_name_edit').focus().blur(function() {
save_name(upc);
});
}
},
}

save_name: function(upc) {
function save_name(upc) {
new_name = $('#' + upc + '_name_edit').val();
post_args = {
upc: upc,
Expand All @@ -79,16 +97,18 @@ Orthosie.inventory = {
}
});

},
}

edit_price: function(upc) {
function edit_price(upc) {
if ($('#' + upc + '_price > input').length == 0) {
$('#' + upc + '_price').html("<input type='number' id='" + upc + "_price_edit' class='inventory_price_edit' value='" + $('#' + upc + '_price').html() + "' onblur='Orthosie.inventory.save_price(\"" + upc + "\")' >");
$('#' + upc + '_price_edit').focus();
$('#' + upc + '_price').html("<input type='number' id='" + upc + "_price_edit' class='inventory_price_edit' value='" + $('#' + upc + '_price').html() + "'>");
$('#' + upc + '_price_edit').focus().blur(function() {
save_price(upc);
});
}
},
}

save_price: function(upc) {
function save_price(upc) {
new_price = $('#' + upc + '_price_edit').val();

post_args = {
Expand All @@ -110,9 +130,9 @@ Orthosie.inventory = {
}
});

},
}

toggle_taxable: function(upc) {
function toggle_taxable(upc) {
var taxable;
if ($('#' + upc + '_taxable').html() == 'Taxable') {
taxable = false;
Expand Down Expand Up @@ -145,9 +165,9 @@ Orthosie.inventory = {
}
});

},
}

toggle_scalable: function(upc) {
function toggle_scalable(upc) {
var scalable;
if ($('#' + upc + '_scalable').html() == 'Scalable') {
scalable = false;
Expand Down Expand Up @@ -180,9 +200,9 @@ Orthosie.inventory = {
}
});

},
}

new_inventory: function() {
function new_inventory() {
if ($('#input_upc > input').val() == '' || $('#input_vendor > input').val() == '' || $('#input_name > input').val() == '' || $('#input_price > input').val() == '') {
console.log('Fail');
return
Expand Down Expand Up @@ -232,4 +252,5 @@ Orthosie.inventory = {
}
});
}
}

});
23 changes: 11 additions & 12 deletions templates/inventory/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
You should have received a copy of the GNU General Public License
along with Orthosie. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}

<!DOCTYPE html>
<html>
<head>
<title>Orthosie Inventory Management</title>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script data-main="/static/js/inventory.js" src="/static/js/require.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/css/font-awesome.css">
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<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/inventory.css' />
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/inventory.js"></script>
<meta charset="UTF-8" />
<meta charset="UTF-8"/>
</head>
<body>
<form id="csrf_token">
Expand All @@ -40,26 +39,26 @@
{% for inventory in inventory_items %}
<tr id="{{ inventory.upc }}" class="inventory_row">
<td id="{{ inventory.upc }}_upc" class="inventory_upc form-control-static">{{ inventory.upc }}</td>
<td id="{{ inventory.upc }}_vendor_name" class="inventory_vendor_name form-control-static"><span id="{{ inventory.upc }}_vendor" onclick="Orthosie.inventory.edit_vendor('{{ inventory.upc }}');">{{ inventory.vendor.name }}</span> <span id="{{ inventory.upc }}_name" onclick="Orthosie.inventory.edit_name('{{ inventory.upc }}');">{{ inventory.name }}</span></td>
<td id="{{ inventory.upc }}_price" class="inventory_price form-control-static" onclick="Orthosie.inventory.edit_price('{{ inventory.upc }}');">{{ inventory.price }}</td>
<td id="{{ inventory.upc }}_scalable" class="inventory_scalable" onclick="Orthosie.inventory.toggle_scalable('{{ inventory.upc }}');">{{ inventory.scalable|yesno:"Scalable, Non-Scalable," }}</td>
<td id="{{ inventory.upc }}_taxable" class="inventory_taxable" onclick="Orthosie.inventory.toggle_taxable('{{ inventory.upc }}');">{{ inventory.taxable|yesno:"Taxable, Non-Taxable," }}</td>
<td id="{{ inventory.upc }}_vendor_name" class="inventory_vendor_name form-control-static"><span id="{{ inventory.upc }}_vendor" class="vendor-name" data-upc="{{ inventory.upc }}">{{ inventory.vendor.name }}</span> <span id="{{ inventory.upc }}_name" class="inventory-name" data-upc="{{ inventory.upc }}">{{ inventory.name }}</span></td>
<td id="{{ inventory.upc }}_price" class="inventory_price inventory-price form-control-static" data-upc="{{ inventory.upc }}">{{ inventory.price }}</td>
<td id="{{ inventory.upc }}_scalable" class="inventory_scalable inventory-scalable" data-upc="{{ inventory.upc }}">{{ inventory.scalable|yesno:"Scalable, Non-Scalable," }}</td>
<td id="{{ inventory.upc }}_taxable" class="inventory_taxable inventory-taxable" data-upc="{{ inventory.upc }}">{{ inventory.taxable|yesno:"Taxable, Non-Taxable," }}</td>
</tr>
{% endfor %}
<tr>
<td id="input_upc" class="inventory_upc">
<input class="form-control" type="text" required pattern="\d+" placeholder="upc" onblur="Orthosie.inventory.new_inventory();" />
<input class="form-control new-inventory" type="text" required pattern="\d+" placeholder="upc"/>
</td>
<td id="input_vendor_name" class="inventory_vendor_name form-inline">
<span id="input_vendor">
<input class="form-control" type="text" required placeholder="Vendor" onblur="Orthosie.inventory.new_inventory();" />
<input class="form-control new-inventory" type="text" required placeholder="Vendor"/>
</span>
<span id="input_name">
<input class="form-control" type="text" required placeholder="Name" onblur="Orthosie.inventory.new_inventory();" />
<input class="form-control new-inventory" type="text" required placeholder="Name"/>
</span>
</td>
<td id="input_price" class="inventory_price">
<input class="form-control" type="number" required placeholder="Price" step="0.01" min="0" onblur="Orthosie.inventory.new_inventory();" />
<input class="form-control new-inventory" type="number" required placeholder="Price" step="0.01" min="0"/>
</td>
<td id="input_scalable" class="inventory_scalable">Non-Scalable</td>
<td id="input_taxable" class="inventory_taxable">Taxable</td>
Expand Down

0 comments on commit 222e933

Please sign in to comment.