diff --git a/main.lisp b/main.lisp index e89044d..da714a8 100644 --- a/main.lisp +++ b/main.lisp @@ -527,7 +527,7 @@ (defmacro standard-item-writeup (&key image full-images invoice-data) `(with-html-output (*standard-output* nil :indent t) - (:div :class "box" + (:div :class "box" :id "write-up-box" (:div :class "box-header" :id "box-picture" (:center (:img :id "input-picture" :src ,image :class "img-responsive" diff --git a/www/plugins/custom/ajax-item.js b/www/plugins/custom/ajax-item.js index 5d0c20a..e2ff611 100644 --- a/www/plugins/custom/ajax-item.js +++ b/www/plugins/custom/ajax-item.js @@ -1,39 +1,61 @@ -$(function() { var form = $('#new-item'); -$(form).submit(function(event) { event.preventDefault(); -var desc = document.getElementById('input-item-description').value; -var price = document.getElementById('input-item-price').value; -var qty = document.getElementById('input-item-qty').value; -var imageloc = document.getElementById('input-picture'); +$(function() { + var form = $('#new-item'); + $(form).submit(function(event) { + event.preventDefault(); + var desc = document.getElementById('input-item-description').value; + var price = document.getElementById('input-item-price').value; + var qty = document.getElementById('input-item-qty').value; + var imageloc = document.getElementById('input-picture'); -$.ajax({ -type: 'POST', -url: 'additem', -data: { -'input-item-qty' : qty , -'input-item-description' : desc , -'input-item-price' : price , -'image-data' : imageloc.name }, -success: function () { -var table = document.getElementById('itemlist'); -var row = table.insertRow(1); -var cell1 = row.insertCell(0); -var cell2 = row.insertCell(1); -var cell3 = row.insertCell(2); -var cell4 = row.insertCell(3); -cell1.innerHTML = desc; -cell2.innerHTML = price; -cell3.innerHTML = qty; -var newimg = $("#image-name"); + $.ajax({ + type: 'POST', + url: 'additem', + data: { + 'input-item-qty': qty, + 'input-item-description': desc, + 'input-item-price': price, + 'image-data': imageloc.name + }, + success: function() { + var table = document.getElementById('itemlist'); + var row = table.insertRow(1); + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + var cell3 = row.insertCell(2); + var cell4 = row.insertCell(3); + cell1.innerHTML = desc; + cell2.innerHTML = price; + cell3.innerHTML = qty; + var newimg = $("#image-name"); -if ($("#image-name").attr("value") == null) { -$("#input-picture").replaceWith("

All out of pictures

"); } -else { -$("#input-picture").replaceWith(""); -$("#input-picture").fadeOut(0); -$("#input-picture").fadeIn("slow"); -$('#modalImg').find('form').first().remove();} -}, -error: function() { -alert('error'); -} } ); }); }); + if ($("#image-name").attr("value") == null) { + $("#input-picture").replaceWith("

All out of pictures

"); + $("#write-up-box").fadeOut(0); + $("#write-up-box").attr("class", "box collapsed-box") + $("#write-up-box").fadeIn("slow"); + } else { + $("#input-picture").replaceWith(""); + $("#input-picture").fadeOut(0); + $("#input-picture").fadeIn("slow"); + $('#modalImg').find('form').first().remove(); + } + $("#new-item").trigger("reset"); + $("html").animate({scrollTop: 0}, "slow"); + $("#input-item-description").focus(); + + }, + error: function() { + alert('error'); + } + }); + }); +}); + +$(function () { + if ($("#input-picture").attr("src") == null) { + $("#input-picture").replaceWith("

Add more pictures to continue

"); + $("#write-up-box").attr("class", "box collapsed-box"); + } + +});