Created
September 17, 2017 09:14
-
-
Save CeramicTitan/6352ea2e15569b2a78ab5938a1b7673e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add additional text boxes | |
$(document).ready(function() { | |
//Set popovers | |
$('[data-toggle="tooltip"]').tooltip(); | |
//Additional field code | |
var max_fields = 10; //maximum input boxes allowed | |
var wrapper = $(".modal-body"); //Fields wrapper | |
var add_button = $("#addNewProduct"); //Add button ID | |
var x = 1; //initlal text box count | |
$(add_button).click(function(e) { //on add input button click | |
e.preventDefault(); | |
if (x < max_fields) { //max input box allowed | |
$(wrapper).append( | |
'<div class="row"><div class="col-md-6"><label class="form-control-label" for="inputProductName">Product Name</label><input id="inputProductName"' + | |
'data-bind=\'value: productName' + | |
x + | |
'\' class="form-control" type="text" name="productName"/></div><div class="col-md-6 move-left"><label class="form-control-label" for="inputAmountSold">Amount Sold</label><input id="inputAmountSold" class="form-control" type="number" name="amountSold" value="0" /></div></div >'); //add input box | |
x++; //text box increment | |
} | |
}); | |
}); | |
function SalesModel() { | |
var self = this; | |
//Getting data | |
self.salesRecords = ko.observableArray(); | |
$.getJSON("api/salesdata", | |
function(data) { | |
self.salesRecords(data); | |
}); | |
//Posting data | |
self.sales_id = ko.observable(); | |
self.product_name = ko.observable(); | |
self.amount_sold = ko.observable(); | |
self.date_sold = ko.observable(null); | |
self.time_sold = ko.observable(null); | |
self.addNewReport = function (id) { | |
alert(self.sales_id()) | |
return; | |
var mapping = { | |
'ignore': ["salesRecords"] | |
} | |
var json = ko.mapping.toJSON(self, mapping); | |
$.ajax({ | |
url: "http://localhost:63251/api/salesdata", | |
type: "POST", | |
data: json, | |
contentType: "application/json; charset=utf-8", | |
async: false, | |
success: function (result) { | |
if (result.url) { | |
location.href = result.url; | |
} | |
} | |
}); | |
}; | |
buildArray = function() { | |
var names = $('.modal-body input[type="text"]'); | |
var amounts = $('.modal-body input[type="number"]'); | |
if (names.length > 1) { | |
for (count = 0; count < names.length; ++count) { | |
//TODO: row per product | |
} | |
} else { | |
$.getJSON("api/salesdata", | |
function (data) { | |
self.addNewReport(data.length+1); | |
}); | |
} | |
} | |
} | |
ko.applyBindings(new SalesModel()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment