cmc-sales/php/app/webroot/js/addLineItem.js

157 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

/*
* addLineItem.js
*
* Brings up a jQuery modal form dialog for adding a line item to a quote/job/invoice
*
* Also does the date picker on the commercial details. Might change the commercial details so they're all javacript sexy too.
*
*
*/
$(function() {
fetchTable();
var quoteID = $("#QuoteId").serialize();
$(".nocosting").hide();
$(".blankItem").hide();
2010-05-30 22:54:44 -07:00
$(".fromProductDB").hide();
$("#addLineItem-form").dialog({
autoOpen: false,
2010-02-18 21:38:43 -08:00
height: 800,
width: 800,
modal: true,
buttons: {
'Add Product': function() {
$.post("/line_items/ajaxSave", $("#LineItemAddForm").serialize(), function(data) {
fetchTable();
2010-05-30 22:54:44 -07:00
$('#mydebug').html(data);
}
);
$("#LineItemAddForm").resetForm();
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function() {
}
});
$('#addLineItem')
.button()
.click(function() {
2010-02-18 21:38:43 -08:00
$('#addLineItem-form2').hide();
$('#addLineItem-form').dialog('open');
});
2010-02-18 21:38:43 -08:00
$('#generatePDF')
.button()
.click(function() {
$.post("/quotes/ajaxpdf",quoteID, function(data) {
2010-05-30 22:54:44 -07:00
$('#mydebug').html(data);
});
});
2010-02-18 21:38:43 -08:00
$("#LineItemPrincipleId").change(getPrincipleProducts);
$('#QuoteDateIssuedDisplay').datepicker({
showButtonPanel: true,
dateFormat: 'DD d MM yy',
altFormat: 'yy-mm-dd',
altField: '#QuoteDateIssued'
});
2010-05-30 22:54:44 -07:00
$('#addBlankItem').button().click(function () {
$("#LineItemPrincipleId").hide();
$(".blankItem").show();
$(".nocosting").show();
return false;
2010-05-30 22:54:44 -07:00
});
2010-05-30 22:54:44 -07:00
$('#LineItemFromDB').change(function () {
if(this.value == 'No') {
$(".blankItem").show();
$(".nocosting").show();
$(".fromProductDB").hide();
}
else {
$(".fromProductDB").show();
$(".blankItem").hide();
$(".nocosting").hide();
}
});
2010-02-18 21:38:43 -08:00
});
/**
* Updates the productBox div with a Select Box of the products.
2010-02-18 21:38:43 -08:00
*
* puts the output in a div called productBox
*/
function getPrincipleProducts() {
$.post("/products/getPrincipleProducts", $("#LineItemPrincipleId").serialize(), function(data) {
$('#productBox').html(data);
$("#LineItemProductId").change(getProductOptions);
2010-02-18 21:38:43 -08:00
});
2010-02-18 21:38:43 -08:00
}
/*
* Ajax Request to get the Product Options (if any) for the Product selected
*/
function getProductOptions() {
$.post("/products/getProductOptions", $("#LineItemProductId").serialize(), function(optionData) {
$("#productOptionsBox").html(optionData);
});
$(".nocosting").show();
}
/*
* Fetch the most recent table of Line Items. This allows calculation to be done in PHP rather than JS.
*/
function fetchTable() {
$.post("/lineItems/viewTable", $("#LineItemQuoteId").serialize(), function (itemTable) {
$("#productTable").html(itemTable);
});
}