/**
* Could (should) tidy this up to move the Quote/Invoice etc Specific
* functionality into seperate files.
*
*
* Karl - 20/5/2011
*/
$(function() {
// var config defined in global.js
loadLineItems();
var docID = $('#documentID').html();
<<<<<<< HEAD
$("#flashMessage").hide();
$("#lineItemDetails").hide();
$( "#addLineItemModal" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Add Line Item": function() {
$('#LineItemDescription').ckeditor(function() {
this.updateElement();
});
=======
$("#flashMessage").hide();
$("#lineItemDetails").hide();
$( "#addLineItemModal" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Add Line Item": function() {
$('#LineItemDescription').ckeditor(function() {
this.updateElement();
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea');
<<<<<<< HEAD
var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea');
$.post('/line_items/ajax_add', thisLineItemInputs, function(data) {
if(data == 'SUCCESS') {
loadLineItems();
$( "#addLineItemModal" ).dialog('close');
}
else {
alert("Line Item could not be saved")
$('#LineItemDescription').ckeditor(config);
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
loadLineItems();
}
});
$( "#editLineItemModal" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Line Item": function() {
$('#LineItemDescription').ckeditor(function() {
this.updateElement();
});
var thisLineItemInputs = $('#LineItemEditForm').find('input,select,textarea');
$.post('/line_items/ajax_edit', thisLineItemInputs, function(data) {
if(data == 'SUCCESS') {
$( "#editLineItemModal" ).dialog('close');
}
else {
alert("Line Item could not be saved")
$('#LineItemDescription').ckeditor(config);
}
});
},
Cancel: function() {
$( "#editLineItemModal" ).dialog('close');
}
},
close: function() {
loadLineItems();
}
});
=======
$.post('/line_items/ajax_add', thisLineItemInputs, function(data) {
if(data == 'SUCCESS') {
loadLineItems();
$( "#addLineItemModal" ).dialog('close');
}
else {
alert("Line Item could not be saved")
$('#LineItemDescription').ckeditor(config);
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
loadLineItems();
}
});
$( "#editLineItemModal" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Line Item": function() {
$('#LineItemDescription').ckeditor(function() {
this.updateElement();
});
var thisLineItemInputs = $('#LineItemEditForm').find('input,select,textarea');
$.post('/line_items/ajax_edit', thisLineItemInputs, function(data) {
if(data == 'SUCCESS') {
$( "#editLineItemModal" ).dialog('close');
}
else {
alert("Line Item could not be saved")
$('#LineItemDescription').ckeditor(config);
}
});
},
Cancel: function() {
$( "#editLineItemModal" ).dialog('close');
}
},
close: function() {
loadLineItems();
}
});
$( "#QuoteDetails" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Quote Details": function() {
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$( "#QuoteDetails" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Quote Details": function() {
<<<<<<< HEAD
=======
$('#QuoteCommercialComments').ckeditor(function() {
this.updateElement();
this.destroy();
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$('#QuoteCommercialComments').ckeditor(function() {
this.updateElement();
this.destroy();
});
<<<<<<< HEAD
var quoteInputs = $('#QuoteEditForm').find('input,select,textarea');
$.post('/quotes/ajax_edit', quoteInputs, function(data) {
$( "#QuoteDetails" ).dialog('close');
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
loadLineItems();
}
});
=======
var quoteInputs = $('#QuoteEditForm').find('input,select,textarea');
$.post('/quotes/ajax_edit', quoteInputs, function(data) {
$( "#QuoteDetails" ).dialog('close');
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
loadLineItems();
}
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$( "#addJobConfirmation" ).dialog({
autoOpen: false,
height: 400,
width: 400,
modal: true,
buttons: {
"Create New Job and Order Acknowledgement": function() {
<<<<<<< HEAD
$( "#addJobConfirmation" ).dialog({
autoOpen: false,
height: 400,
width: 400,
modal: true,
buttons: {
"Create New Job and Order Acknowledgement": function() {
var documentID = $("#documentID").html();
=======
var documentID = $("#documentID").html();
//window.location.href = "/documents/convert_to_oa/"+documentID;
//var newOAform = $('#DocumentConvertToOaForm').find('input');
var newOAform = $('#DocumentConvertToOaForm');
newOAform.submit();
>>>>>>> b15eee9619754852ad75ae598103249c33343064
//window.location.href = "/documents/convert_to_oa/"+documentID;
//var newOAform = $('#DocumentConvertToOaForm').find('input');
var newOAform = $('#DocumentConvertToOaForm');
newOAform.submit();
<<<<<<< HEAD
/*$.post('/documents/convert_to_oa', newOAform, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Invoice Saved Successfully");
}
else {
$("#flashMessage").html("Unable to Save Invoice");
}
$("#flashMessage").show();
loadLineItems();
});
*/
=======
/*$.post('/documents/convert_to_oa', newOAform, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Invoice Saved Successfully");
}
else {
$("#flashMessage").html("Unable to Save Invoice");
}
$("#flashMessage").show();
loadLineItems();
});
*/
},
Cancel: function() {
$( this ).dialog( "close" );
>>>>>>> b15eee9619754852ad75ae598103249c33343064
}
},
close: function() {
}
});
<<<<<<< HEAD
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
$("#pageContentFactory").hide();
=======
$("#pageContentFactory").hide();
//Add a new Page Element.
$("#addPage").button().click(function(event) {
event.preventDefault();
newPage(false);
return false;
});
//Open the LineItem dialog
$(".addLineItem").button().click(function() {
$('#LineItemDescription').ckeditor(function() {
this.destroy();
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
//Add a new Page Element.
$("#addPage").button().click(function(event) {
event.preventDefault();
<<<<<<< HEAD
newPage(false);
return false;
});
//Open the LineItem dialog
$(".addLineItem").button().click(function() {
$('#LineItemDescription').ckeditor(function() {
this.destroy();
});
=======
$("#editLineItemModal").empty();
var nextItemNo = $(".lineItem").length;
nextItemNo++;
$.get('/line_items/add/'+docID, function(data) {
$("#addLineItemModal").html(data);
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$("#LineItemItemNumber").val(nextItemNo); //Auto fill in the next Item No
<<<<<<< HEAD
$("#editLineItemModal").empty();
var nextItemNo = $(".lineItem").length;
nextItemNo++;
$.get('/line_items/add/'+docID, function(data) {
$("#addLineItemModal").html(data);
$("#LineItemItemNumber").val(nextItemNo); //Auto fill in the next Item No
=======
$("#productDetails").hide();
$('#LineItemDescription').ckeditor(config);
showHideTextPrices();
$( "#addLineItemModal" ).dialog('open');
});
return false;
});
$(".editLineItem").live('click', function() {
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$("#productDetails").hide();
<<<<<<< HEAD
$('#LineItemDescription').ckeditor(config);
showHideTextPrices();
$( "#addLineItemModal" ).dialog('open');
=======
$('#LineItemDescription').ckeditor(function() {
this.destroy();
});
$("#addLineItemModal").empty();
var thisLineItemID = $(this).parent('td').attr('id');
$.get('/line_items/edit/'+thisLineItemID, function(data) {
$("#editLineItemModal").html(data);
$("#productDetails").hide();
$('#LineItemDescription').ckeditor(config);
showHideTextPrices();
$( "#editLineItemModal" ).dialog('open');
>>>>>>> b15eee9619754852ad75ae598103249c33343064
});
});
<<<<<<< HEAD
return false;
});
$(".editLineItem").live('click', function() {
$('#LineItemDescription').ckeditor(function() {
this.destroy();
=======
$("#principleSelect").live('change',function() {
var principleID = getSelectedID('#principleSelect');
$("#productDetails").hide();
$.get('/documents/getProducts/'+principleID, function(data) {
$('#productsDiv').html(data);
>>>>>>> b15eee9619754852ad75ae598103249c33343064
});
});
$("#productSelect").live('change',function() {
var productID = getSelectedID('#productSelect');
<<<<<<< HEAD
$("#addLineItemModal").empty();
var thisLineItemID = $(this).parent('td').attr('id');
$.get('/line_items/edit/'+thisLineItemID, function(data) {
$("#editLineItemModal").html(data);
$("#productDetails").hide();
$('#LineItemDescription').ckeditor(config);
showHideTextPrices();
$( "#editLineItemModal" ).dialog('open');
=======
$.get('/documents/getProductDetails/'+productID, function(data) {
$("#lineItemDetails").show();
$("#LineItemProductId").val(data.id);
$("#LineItemTitle").val(data.title);
>>>>>>> b15eee9619754852ad75ae598103249c33343064
var descText = '';
if(data.item_code) {
descText = descText + '
Item Code: ' + data.item_code;
}
if(data.item_description) {
descText = descText + '
Item Description: ' + data.item_description + '
';
}
descText = descText + data.description;
$("#LineItemDescription").val(descText);
}, "json");
});
// Initialize the editor.
// Callback function can be passed and executed after full instance creation.
$('.page').ckeditor(config);
$("#LineItemHasTextPrices").live('change', function() {
showHideTextPrices();
});
//Remove this Page
$(".removePage").live('click',function() {
$('.page').ckeditor(function() {
this.destroy();
});
});
$(this).parents(".docPage").remove();
$('.page').ckeditor(config);
});
$("#savePages").click(function() {
savePages();
<<<<<<< HEAD
$("#principleSelect").live('change',function() {
var principleID = getSelectedID('#principleSelect');
$("#productDetails").hide();
$.get('/documents/getProducts/'+principleID, function(data) {
$('#productsDiv').html(data);
});
});
$("#productSelect").live('change',function() {
var productID = getSelectedID('#productSelect');
$.get('/documents/getProductDetails/'+productID, function(data) {
$("#lineItemDetails").show();
$("#LineItemProductId").val(data.id);
$("#LineItemTitle").val(data.title);
$("#LineItemDescription").val(data.description);
}, "json");
});
// Initialize the editor.
// Callback function can be passed and executed after full instance creation.
$('.page').ckeditor(config);
$("#LineItemHasTextPrices").live('change', function() {
showHideTextPrices();
});
//Remove this Page
$(".removePage").live('click',function() {
$('.page').ckeditor(function() {
this.destroy();
});
$(this).parents(".docPage").remove();
$('.page').ckeditor(config);
});
$("#savePages").click(function() {
savePages();
});
$(".quickpricing").live('change', function() {
calculateQuickPrices();
});
$('.removeLineItem').live('click', function() {
var thisLineItemID = $(this).parent('td').attr('id');
$.post('/line_items/ajax_delete/'+thisLineItemID, function(data) {
loadLineItems();
});
});
=======
});
$(".quickpricing").live('change', function() {
calculateQuickPrices();
});
$('.removeLineItem').live('click', function() {
var thisLineItemID = $(this).parent('td').attr('id');
$.post('/line_items/ajax_delete/'+thisLineItemID, function(data) {
loadLineItems();
});
});
$("#editQuoteDetails").click(function() {
var quoteID = $("#quoteID").html();
$('#QuoteCommercialComments').ckeditor(function() {
this.destroy();
});
$.get('/quotes/edit/'+quoteID, function(data) {
$("#QuoteDetails").html(data);
$('#QuoteCommercialComments').ckeditor(config);
$("#QuoteDetails").dialog('open');
});
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$("#editQuoteDetails").click(function() {
var quoteID = $("#quoteID").html();
<<<<<<< HEAD
$('#QuoteCommercialComments').ckeditor(function() {
this.destroy();
});
$.get('/quotes/edit/'+quoteID, function(data) {
=======
$("#generateFirstPage").click(function() {
if($(".firstPage").length == 0) {
newPage(true);
}
$.get('/documents/generateFirstPage/'+docID, function(data) {
$(".firstPage").val(data);
savePages();
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
$("#QuoteDetails").html(data);
<<<<<<< HEAD
$('#QuoteCommercialComments').ckeditor(config);
$("#QuoteDetails").dialog('open');
});
});
$("#generateFirstPage").click(function() {
=======
});
>>>>>>> b15eee9619754852ad75ae598103249c33343064
if($(".firstPage").length == 0) {
newPage(true);
}
$.get('/documents/generateFirstPage/'+docID, function(data) {
$(".firstPage").val(data);
savePages();
});
<<<<<<< HEAD
});
//Invoice View
$('#shippingDetails').ckeditor(config);
$("#DocumentBillTo").ckeditor(config);
$("#DocumentShipTo").ckeditor(config);
$("#saveInvoiceButton").click(function() {
updateTextFields(); //Update the CKEditor instances.
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
$.post('/documents/ajax_edit', invoiceDetails, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Invoice Saved Successfully");
}
else {
$("#flashMessage").html("Unable to Save Invoice");
}
$("#flashMessage").show();
=======
//Invoice View
$('#shippingDetails').ckeditor(config);
$("#DocumentBillTo").ckeditor(config);
$("#DocumentShipTo").ckeditor(config);
$("#saveInvoiceButton").click(function() {
updateTextFields(); //Update the CKEditor instances.
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
$.post('/documents/ajax_edit', invoiceDetails, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Invoice Saved Successfully");
}
else {
$("#flashMessage").html("Unable to Save Invoice");
}
$("#flashMessage").show();
>>>>>>> b15eee9619754852ad75ae598103249c33343064
loadLineItems();
});
});
//OA View.
$("#saveOAButton").click(function() {
updateTextFields(); //Update the CKEditor instances.
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
$.post('/documents/ajax_edit', invoiceDetails, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Order Acknowledgement Saved Successfully");
}
else {
$("#flashMessage").html("Unable to Save Order Acknowledgement");
}
$("#flashMessage").show();
loadLineItems();
});
});
$("#createJobAndOA").click(function() {
$("#addJobConfirmation").dialog('open');
});
});
$('.generateCommercialComments').live('click', function(event) {
event.preventDefault();
var deliveryTime = $("#QuoteDeliveryTime").val();
var deliveryTF = $("#QuoteDeliveryTimeFrame").val();
var paymentTerms = $("#QuotePaymentTerms").val();
var daysValid = $("#QuoteDaysValid").val();
var deliveryPoint = $("#QuoteDeliveryPoint").val();
var exchangeRate = $("#QuoteExchangeRate").val();
var customsDuty = $("#QuoteCustomsDuty").val();
deliveryTime = deliveryTime.toUpperCase();
paymentTerms = paymentTerms.toUpperCase();
deliveryPoint = deliveryPoint.toUpperCase();
var commComments = $("#commCommentsInitialString").clone();
var commList = commComments.find('ol');
commList.append('