Commit ad233d58 authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

update

parent 9fbd2a99
...@@ -42,8 +42,8 @@ class Product_l2a(models.Model): ...@@ -42,8 +42,8 @@ class Product_l2a(models.Model):
class CartProduct(models.Model): class CartProduct(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
aggreg_date = models.DateTimeField(auto_now=True) ## date of product aggregation
uuid = models.CharField(max_length=50) uuid = models.CharField(max_length=50)
aggreg_date = models.DateTimeField(auto_now=True) ## date of product aggregation
info = models.TextField(null=True) info = models.TextField(null=True)
purchased = models.NullBooleanField() purchased = models.NullBooleanField()
......
...@@ -14,8 +14,8 @@ var polygonList; ...@@ -14,8 +14,8 @@ var polygonList;
var makeRequest = function (value) { var makeRequest = function (value) {
var pol_element = document.getElementById('polygon-list'); var pol_element = document.getElementById('polygon-list');
// petición de municipios a base de datos // city request to DB
// variable req_url en map.html // variable req_url in map.html
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : req_url, url : req_url,
...@@ -112,6 +112,7 @@ $("#id_polygon").on('keyup', function (e) { ...@@ -112,6 +112,7 @@ $("#id_polygon").on('keyup', function (e) {
}); });
// this function cleans list of available products
function erase_product_list_globe() { function erase_product_list_globe() {
prevfeature = null; prevfeature = null;
var pol_element = document.getElementById('product-list-globe'); var pol_element = document.getElementById('product-list-globe');
...@@ -121,6 +122,7 @@ function erase_product_list_globe() { ...@@ -121,6 +122,7 @@ function erase_product_list_globe() {
} }
// this function cleans list of available products by ID
function erase_product_list_globe_by_id(element_id) { function erase_product_list_globe_by_id(element_id) {
var $div_element = $('div#' + element_id + "-div"); var $div_element = $('div#' + element_id + "-div");
var $li_element = $('li#' + element_id + "-li"); var $li_element = $('li#' + element_id + "-li");
...@@ -129,6 +131,15 @@ function erase_product_list_globe_by_id(element_id) { ...@@ -129,6 +131,15 @@ function erase_product_list_globe_by_id(element_id) {
} }
// this function cleans list of products in cart
function erase_product_list_cart() {
var item_element = document.getElementById('product-list-cart');
while (item_element.firstChild) {
item_element.removeChild(item_element.firstChild);
}
}
var prevfeature = null; var prevfeature = null;
function drawApiResponse(element) { function drawApiResponse(element) {
var list_globe = document.getElementById('product-list-globe').children; var list_globe = document.getElementById('product-list-globe').children;
...@@ -217,7 +228,7 @@ $(document).ready(function () { ...@@ -217,7 +228,7 @@ $(document).ready(function () {
var pol_element = document.getElementById('polygon-list'); var pol_element = document.getElementById('polygon-list');
var typingTimer; var typingTimer;
var typingInterval = 800; //milliseconds var typingInterval = 800; //milliseconds
var productListGlobe = []; var productListGlobe = [];
var cartProductList = []; // this array represent DB where products will be stored var cartProductList = []; // this array represent DB where products will be stored
var productsToObtain = []; var productsToObtain = [];
...@@ -251,8 +262,8 @@ $(document).ready(function () { ...@@ -251,8 +262,8 @@ $(document).ready(function () {
erase_product_list_globe(); erase_product_list_globe();
var submit_data = $('#product-form').serialize(); var submit_data = $('#product-form').serialize();
// petición de producto a base de datos // product request to DB
// variable prod_req_url en map.html // variable prod_req_url in map.html
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : prod_req_url, url : prod_req_url,
...@@ -269,7 +280,8 @@ $(document).ready(function () { ...@@ -269,7 +280,8 @@ $(document).ready(function () {
console.log("DEFS: ahora crea producto"); console.log("DEFS: ahora crea producto");
data.catalog.forEach(function (data) { data.catalog.forEach(function (data) {
// petición de imagen a webservice // image request to webservice
// variable img_req_url in map.html
$.ajax({ $.ajax({
type : "GET", type : "GET",
url : img_req_url, url : img_req_url,
...@@ -316,7 +328,7 @@ $(document).ready(function () { ...@@ -316,7 +328,7 @@ $(document).ready(function () {
}); });
// agrega producto al carrito // adds product to cart
$('#product-to-cart-form').submit(function (event) { $('#product-to-cart-form').submit(function (event) {
event.preventDefault(); event.preventDefault();
var ul_element = document.getElementById('product-list-globe'); var ul_element = document.getElementById('product-list-globe');
...@@ -352,8 +364,8 @@ $(document).ready(function () { ...@@ -352,8 +364,8 @@ $(document).ready(function () {
}); });
if (cartProductList.length > 0) { if (cartProductList.length > 0) {
// request para guardado de producto en carrito // request for saving product in cart DB
// variable prod_cart_url en map.html // variable prod_cart_url in map.html
$.ajax({ $.ajax({
type : 'POST', type : 'POST',
url : prod_cart_url, url : prod_cart_url,
...@@ -364,26 +376,15 @@ $(document).ready(function () { ...@@ -364,26 +376,15 @@ $(document).ready(function () {
success: function () { success: function () {
cartProductList = []; cartProductList = [];
productUUIDListCart.push.apply(productUUIDListCart, productsToObtain); productUUIDListCart.push.apply(productUUIDListCart, productsToObtain);
// PRODUCT_COUNTER += 1; // this variable counts the number of products in shopping cart
// PRODUCT_COUNTER_STR = PRODUCT_COUNTER.toString();
// var temp_1 = document.querySelector('#product_cart_1');
// var prod_id = temp_1.content.querySelectorAll('ul')[1].id + "-" + PRODUCT_COUNTER_STR;
// // filling template
// temp_1.content.querySelector('span').textContent = "Product " + PRODUCT_COUNTER_STR;
// temp_1.content.querySelectorAll('ul')[1].id = prod_id;
// var clone_1 = document.importNode(temp_1.content, true);
// document.querySelector('#product-list-cart').appendChild(clone_1);
if (!IS_PRODUCT_CONTAINER) { if (!IS_PRODUCT_CONTAINER) {
// building product container
createProductContainer(); createProductContainer();
IS_PRODUCT_CONTAINER = true; IS_PRODUCT_CONTAINER = true; // this flag is set to false when products are purchased
} }
// TODO : return IS_PRODUCT_CONTAINER to 'false' in some point
// request a DB para mostrar los productos en el carrito // request to DB for showing the products in cart
// variable prod_from_cartDB_url en map.html // variable prod_from_cartDB_url in map.html
$.ajax({ $.ajax({
type : 'POST', type : 'POST',
url : prod_from_cartDB_url, url : prod_from_cartDB_url,
...@@ -409,7 +410,6 @@ $(document).ready(function () { ...@@ -409,7 +410,6 @@ $(document).ready(function () {
var clone_2 = document.importNode(temp_2.content, true); var clone_2 = document.importNode(temp_2.content, true);
document.querySelector('#product-list-cart-items').appendChild(clone_2); document.querySelector('#product-list-cart-items').appendChild(clone_2);
// document.querySelector('#' + prod_id).appendChild(clone_2);
}); });
} }
}); });
...@@ -425,7 +425,7 @@ $(document).ready(function () { ...@@ -425,7 +425,7 @@ $(document).ready(function () {
}); });
//compra de producto(s) que está(n) en el carrito // purchasing products in cart
$('#purchased-product-form').submit(function (event) { $('#purchased-product-form').submit(function (event) {
event.preventDefault(); event.preventDefault();
var ul_element = document.getElementById('product-list-cart'); var ul_element = document.getElementById('product-list-cart');
...@@ -441,6 +441,7 @@ $(document).ready(function () { ...@@ -441,6 +441,7 @@ $(document).ready(function () {
}); });
// L1C product download request // L1C product download request
// variable purch_prod_url in map.html
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : purch_prod_url, url : purch_prod_url,
...@@ -450,6 +451,10 @@ $(document).ready(function () { ...@@ -450,6 +451,10 @@ $(document).ready(function () {
}, },
dataType : 'json' dataType : 'json'
}); });
erase_product_list_cart();
IS_PRODUCT_CONTAINER = false;
productUUIDListCart = [];
} else { } else {
mssgModal({ mssgModal({
title : "No products available!", title : "No products available!",
...@@ -457,6 +462,4 @@ $(document).ready(function () { ...@@ -457,6 +462,4 @@ $(document).ready(function () {
}); });
} }
}); });
// TODO: Clean productUUIDListCart array after purchased is done
}); });
...@@ -217,6 +217,7 @@ def purchaseProduct(request): ...@@ -217,6 +217,7 @@ def purchaseProduct(request):
return HttpResponse(status=204) return HttpResponse(status=204)
## TODO: Implement a webservice in server for downloading those non-existing L1C products. ## ## TODO: Implement a webservice in server for downloading those non-existing L1C products. ##
## TODO: Add product L1C to Cart DB after product download. ##
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def L2ASCL_data(request): def L2ASCL_data(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment