Localstorage crud

function addProduct()
{
productid = $(“#dlg_productid”).val();
productname = $(“#dlg_productname”).val();
itemnumber = $(“#dlg_itemnumber”).val();
quantity = $(“#dlg_quantity”).val();
addItem(productid, productname, itemnumber, quantity);
$(‘

Success! Successfully Product Added.

‘).insertBefore(‘#add_product_success_message’).delay(500).fadeOut();

}

 

/***Adding Item***********/
var addItem = function (id, name, itemnumber, quantity)
{
var oldItems = JSON.parse(localStorage.getItem(‘itemList’)) || [];

var newItem =
{
‘id’: id,
‘name’: name,
‘itemnumber’: itemnumber,
‘quantity’: quantity,
};

oldItems.push(newItem);
localStorage.setItem(‘itemList’, JSON.stringify(oldItems));

};

 

 

function showOrderList()
{

var oldItems = JSON.parse(localStorage.getItem(‘itemList’)) || [];
var ItemCount = oldItems.length;

$(‘#contributionList’).empty();
for (i = 0; i < ItemCount; i++)
{
var text = “‘”+i+”‘,'”+oldItems[i].name+”‘,'”+oldItems[i].quantity+”‘,'”+oldItems[i].itemnumer+”‘”;

$(‘#contributionList’).append(‘<li><a onclick=”orderDetails(‘+text+’)”><h3>’ + oldItems[i].name + ‘</h3> Quantity: ‘ + oldItems[i].quantity + ‘</a></li>’).listview(‘refresh’);
}
}

function orderDetails(rowid,product_name,product_quantity,itemnumber)
{
$(“#dlg_shoppingcartupdate_text”).html(product_name);
$(“#dlg_shoppingcartupdate_quantity”).val(product_quantity);
$(“#dlg_rowid”).val(rowid);
$(“#lnkDialog3”).click();
}
function deleteorderitem()
{
var rowid= $(“#dlg_rowid”).val();
rowid =parseInt(rowid);
var oldItems = JSON.parse(localStorage.getItem(‘itemList’)) || [];
var ItemCount = oldItems.length;

for (i = 0; i < ItemCount; i++)
{
if (i == rowid) {oldItems.splice(i,1); break;
}
}

localStorage.setItem(‘itemList’, JSON.stringify(oldItems));

showOrderList();

}

function updateProductquantity()
{
var rowid= $(“#dlg_rowid”).val();
var quantity =$(“#dlg_shoppingcartupdate_quantity”).val();
rowid =parseInt(rowid);

var oldItems = JSON.parse(localStorage.getItem(‘itemList’)) || [];
var ItemCount = oldItems.length;

for (i = 0; i < ItemCount; i++)
{
if (i == rowid)
{
oldItems[i].quantity=quantity; break;
}
}

localStorage.setItem(‘itemList’, JSON.stringify(oldItems));
showOrderList();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s