Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <title>Carrito de la compra</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- <link href="div.css" rel="stylesheet" type="text/css"/>
- <script src="forge-sha256.min.js" type="text/javascript"></script>
- <style>
- #teveo, #fueraForm{
- visibility: hidden;
- }
- input{
- margin: 0 20px 0 9px;
- }
- form{
- margin: 20px 0 20px 0;
- }
- #elh2{
- display: inline-block;
- }
- #logout{
- margin: 0 0 12px 15px;
- }
- img{
- width: 350px !important;
- height: 260px !important;
- }
- th{
- width: 320px;
- padding: 10px 10px 10px 10px;
- }
- table{
- margin: 30px 0 30px 0 ;
- background-color: lightgrey;
- }
- tr{
- padding: 30px 0 30px 0;
- }
- input.form-control.text-center{
- margin: 0 0 0 0;
- height: 22px;
- }
- b{
- background-color: rgba(53, 132, 20, 0.71) !important;
- }
- .row{
- margin-top: 50px;
- margin-bottom: 15px;
- }
- </style>
- <body>
- <div class="container">
- <div class="col-lg-12">
- <div class="page-header">
- <h1>Venta de CDs</h1>
- </div>
- <div id="adios"></div>
- <!-- FORMULARIO LOGIN-->
- <form id="fueraForm" class="form-inline">
- <div class="form-group">
- <label for="user">User:</label>
- <input type="text" class="form-control" id="user" name="user" placeholder="Usuario...">
- </div>
- <div class="form-group">
- <label for="pass">Password:</label>
- <input type="password" class="form-control" id="pass" name="pass" placeholder="Password...">
- </div>
- <button id="loguear" type="submit" class="btn btn-primary">Logueate</button>
- </form>
- <div id="hash"></div>
- <div id="errores"></div>
- <div id="teveo" class="container" style="margin-top:50px;">
- <span id="elh2"></span>
- <button id="logout" type="submit" class="btn btn-primary">Logout</button>
- <div class="row">
- <!-------------------------art1---------------------->
- <div class="col-xs-12 col-sm-6 col-md-3">
- <div class="col-item">
- <div class="post-img-content">
- <img id="img1" class="img-responsive" alt="a" />
- <span class="post-title">
- <b>Stock: </b>
- <b id="stock1"></b><br>
- </span>
- </div>
- <div class="info">
- <div class="row">
- <div class="price col-md-6">
- <h5 id="nombre1"></h5>
- <h5 class="price-text-color">Precio: </h5>
- <h5 id="precio1" class="price-text-color"></h5>
- <h5 id="sinstock1"></h5>
- </div>
- </div>
- <div class="separator clear-left">
- <p class="btn-add">
- <i class="fa fa-shopping-cart"></i><button id="boton1">Add to cart</button></p>
- <p class="btn-details">
- <input type="number" id="inp1" class="form-control text-center" value="1"></p>
- </div>
- <div class="clearfix">
- </div>
- </div>
- </div>
- </div>
- <!--------------------------art2------------------------->
- <div class="col-xs-12 col-sm-6 col-md-3">
- <div class="col-item">
- <div class="post-img-content">
- <img id="img2" class="img-responsive" alt="a" />
- <span class="post-title">
- <b>Stock: </b>
- <b id="stock2"></b><br>
- </span>
- </div>
- <div class="info">
- <div class="row">
- <div class="price col-md-6">
- <h5 id="nombre2"></h5>
- <h5 class="price-text-color">Precio: </h5>
- <h5 id="precio2" class="price-text-color"></h5>
- <h5 id="sinstock2"></h5>
- </div>
- </div>
- <div class="separator clear-left">
- <p class="btn-add">
- <i class="fa fa-shopping-cart"></i><button id="boton2">Add to cart</button></p>
- <p class="btn-details">
- <input type="number" id="inp2" class="form-control text-center" value="1"></p>
- </div>
- <div class="clearfix">
- </div>
- </div>
- </div>
- </div>
- <!-------------------------art3------------------------->
- <div class="col-xs-12 col-sm-6 col-md-3">
- <div class="col-item">
- <div class="post-img-content">
- <img id="img3" class="img-responsive" alt="a" />
- <span class="post-title">
- <b>Stock: </b>
- <b id="stock3"></b><br>
- </span>
- </div>
- <div class="info">
- <div class="row">
- <div class="price col-md-6">
- <h5 id="nombre3"></h5>
- <h5 class="price-text-color">Precio: </h5>
- <h5 id="precio3" class="price-text-color"></h5>
- <h5 id="sinstock3"></h5>
- </div>
- </div>
- <div class="separator clear-left">
- <p class="btn-add">
- <i class="fa fa-shopping-cart"></i><button id="boton3">Add to cart</button></p>
- <p class="btn-details">
- <input type="number" id="inp3" class="form-control text-center" value="1"></p>
- </div>
- <div class="clearfix">
- </div>
- </div>
- </div>
- </div>
- <!--------------------------art4------------------------>
- <div class="col-xs-12 col-sm-6 col-md-3">
- <div class="col-item">
- <div class="post-img-content">
- <img id="img4" class="img-responsive" alt="a" />
- <span class="post-title">
- <b>Stock: </b>
- <b id="stock4"></b><br>
- </span>
- </div>
- <div class="info">
- <div class="row">
- <div class="price col-md-6">
- <h5 id="nombre4"></h5>
- <h5 class="price-text-color">Precio: </h5>
- <h5 id="precio4" class="price-text-color"></h5>
- <h5 id="sinstock4"></h5>
- </div>
- </div>
- <div class="separator clear-left">
- <p class="btn-add">
- <i class="fa fa-shopping-cart"></i><button id="boton4">Add to cart</button></p>
- <p class="btn-details">
- <input type="number" id="inp4" class="form-control text-center" value="1"></p>
- </div>
- <div class="clearfix">
- </div>
- </div>
- </div>
- </div>
- </div>
- <table class="table table-striped table-hover table-bordered">
- <tbody>
- <tr>
- <th>CD</th>
- <th>Cantidad</th>
- <th>Precio</th>
- <th>Precio Total</th>
- </tr>
- <tr>
- <td id="cart1">
- <!--<button type="button" class="btn btn-default btn-xs">
- <span class="glyphicon glyphicon-remove"></span>
- </button>-->
- </td>
- <td id="qty1"></td>
- <td id="price1"></td>
- <td id="price_sub1"></td>
- </tr>
- <tr>
- <td id="cart2"></td>
- <td id="qty2"></td>
- <td id="price2"></td>
- <td id="price_sub2"></td>
- </tr>
- <tr>
- <td id="cart3"></td>
- <td id="qty3"></td>
- <td id="price3"></td>
- <td id="price_sub3"></td>
- </tr>
- <tr>
- <td id="cart4"></td>
- <td id="qty4"></td>
- <td id="price4"></td>
- <td id="price_sub4"></td>
- </tr>
- <tr>
- <th colspan="3"><span class="pull-right">Total</span></th>
- <th id="total"></th>
- </tr>
- <tr>
- <td>
- <a href="#" class="btn btn-primary" data-dismiss="modal" id="vaciarCarr">Vaciar carrito</a>
- <div id="errVaciar"></div>
- </td>
- <td colspan="3"><a href="javascript:void(0)" id="checkout" class="pull-right btn btn-success">Checkout</a></td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <script>
- function inicio() {
- $("#pass").keyup(manejoTecla);
- }
- function manejoTecla() {
- pass = $("#pass").val();
- epass = forge_sha256(pass);
- $("#hash").empty().append(epass);
- }
- $(document).ready(function () {
- $("#pass").keyup(function () {
- $("#hash").empty().append(forge_sha256($("#pass").val()));
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=usuario&op=check',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- //si existe una sesion, se esconde el formulario de login.
- if (data.user != null) {
- visualizarSesion();
- $("#elh2").empty().append("<h2>Bienvenido: " + data.user + "!</h2>");
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).append(data[i].nombre);
- $("#precio" + (i + 1)).append(data[i].precio);
- $("#stock" + (i + 1)).append(data[i].existencias);
- $("#img" + (i + 1)).attr("src", data[i].url);
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#cart" + (i + 1)).empty().html(data[i].nombre);
- $("#qty" + (i + 1)).empty().append(data[i].existencias);
- $("#price" + (i + 1)).empty().append(data[i].precio);
- $("#price_sub" + (i + 1)).empty().append((data[i].existencias) * (data[i].precio));
- }
- }
- });
- } else {
- visualizarLogin();
- }
- },
- error: function () {
- $("#errores").html("<p>Error.</p>");
- }
- });
- $("#loguear").click(function () {
- event.preventDefault();
- nomUser = $("#user").val();
- //nomPass = $("#pass").val();
- nomPass = forge_sha256($("#pass").val());
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=usuario&op=login&user=' + nomUser + '&pass=' + nomPass,
- type: 'POST',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 200) {
- visualizarSesion();
- $("#elh2").empty().append("<h2>Bienvenido: " + data.user + "!</h2>");
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=app&op=inicializar',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 200) {
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#cart" + (i + 1)).empty().html(data[i].nombre);
- $("#qty" + (i + 1)).empty().append(data[i].existencias);
- $("#price" + (i + 1)).empty().append(data[i].precio);
- $("#price_sub" + (i + 1)).empty().append((data[i].existencias) * (data[i].precio));
- }
- }
- });
- }
- }
- });
- } else {
- $("#errores").html('<p>Error, revise la contrasenya</p>');
- }
- },
- error: function () {
- $("#errores").html("<p>Error.</p>");
- }
- });
- });
- $("#logout").click(function () {
- event.preventDefault();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=usuario&op=logout',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 200) {
- visualizarLogin();
- $("#adios").html("<h3>Has sido desconectado correctamente</h3>");
- }
- },
- error: function () {
- $("#errores").html("<p>Error.</p>");
- }
- });
- });
- //----------------------- BOTONERA -----------------------------------------
- //-----------------------BOTON 1 -----------------------------------------
- $("#boton1").click(function () {
- event.preventDefault();
- cant = $("#inp1").val();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=add&id=1&cantidad=' + cant,
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 500) {
- $("sinstock1").empty().html(data.message);
- } else {
- $("#cart1").empty().html(data[0].nombre);
- $("#qty1").empty().html(data[0].existencias);
- $("#price1").empty().html(data[0].precio);
- $("#price_sub1").empty().html((data[0].existencias) * (data[0].precio));
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- });
- //-----------------------BOTON 2 -----------------------------------------
- $("#boton2").click(function () {
- event.preventDefault();
- cant = $("#inp2").val();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=add&id=2&cantidad=' + cant,
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 500) {
- $("sinstock2").empty().html(data.message);
- } else {
- $("#cart2").empty().html(data[1].nombre);
- $("#qty2").empty().html(data[1].existencias);
- $("#price2").empty().html(data[1].precio);
- $("#price_sub2").empty().html((data[1].existencias) * (data[1].precio));
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- });
- //-----------------------BOTON 3 -----------------------------------------
- $("#boton3").click(function () {
- event.preventDefault();
- cant = $("#inp3").val();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=add&id=3&cantidad=' + cant,
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 500) {
- $("sinstock3").empty().html(data.message);
- } else {
- $("#cart3").empty().html(data[2].nombre);
- $("#qty3").empty().html(data[2].existencias);
- $("#price3").empty().html(data[2].precio);
- $("#price_sub3").empty().html((data[2].existencias) * (data[2].precio));
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- });
- //-----------------------BOTON 4 -----------------------------------------
- $("#boton4").click(function () {
- event.preventDefault();
- cant = $("#inp4").val();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=add&id=4&cantidad=' + cant,
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 500) {
- $("sinstock4").empty().html(data.message);
- } else {
- $("#cart4").empty().html(data[3].nombre);
- $("#qty4").empty().html(data[3].existencias);
- $("#price4").empty().html(data[3].precio);
- $("#price_sub4").empty().html((data[3].existencias) * (data[3].precio));
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- });
- //--------------------------- VACIAR CARRITO ---------------
- $("#vaciarCarr").click(function () {
- event.preventDefault();
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=carrito&op=clean',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- if (data.status == 200) {
- for (i = 1; i <= 4; i++) {
- $("#cart" + i).empty();
- $("#qty" + i).empty();
- $("#price" + i).empty();
- $("#price_sub" + i).empty();
- }
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- } else {
- $("#errVaciar").html("<b>" + data.message + "</b>");
- }
- }
- });
- $.ajax({
- url: 'http://localhost:8084/mavenCarrito/session?ob=almacen&op=list',
- type: 'GET',
- xhrFields: {
- withCredentials: true
- },
- datatype: 'json',
- success: function (data) {
- for (i = 0; i < data.length; i++) {
- $("#nombre" + (i + 1)).empty().append(data[i].nombre);
- $("#precio" + (i + 1)).empty().append(data[i].precio);
- $("#stock" + (i + 1)).empty().append(data[i].existencias);
- $("#img" + (i + 1)).empty().attr("src", data[i].url);
- }
- }
- });
- });
- function visualizarSesion() {
- $("#fueraForm").css("display", "none");
- $("#fueraForm").css("visibility", "hidden");
- $("#teveo").css("visibility", "visible");
- $("#errores").empty();
- $("#adios").empty();
- }
- function visualizarLogin() {
- $("#fueraForm").css("display", "block");
- $("#fueraForm").css("visibility", "visible");
- $("#teveo").css("visibility", "hidden");
- $("#elh2").empty();
- $("#errores").empty();
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement