/** * Could (should) tidy this up to move the Quote/Invoice etc Specific * functionality into seperate files. * * Will do this at some point. Today I just need to hammer this out. * * Karl - 20/5/2011 */ $(function() { // var config defined in global.js loadLineItems(); var docID = $('#documentID').html(); $("#flashMessage").hide(); $("#lineItemDetails").hide(); $( "#addLineItemModal" ).dialog({ autoOpen: false, height: 900, width: 600, modal: true, buttons: { "Add Line Item": function() { $('#LineItemDescription').ckeditor(function() { this.updateElement(); this.destroy(); }); 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() { loadLineItems(); $( this ).dialog( "close" ); } } }); $( "#editLineItemModal" ).dialog({ autoOpen: false, height: 900, width: 600, modal: true, buttons: { "Edit Line Item": function() { $('#LineItemDescription').ckeditor(function() { this.updateElement(); this.destroy(); }); 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() { $('#LineItemDescription').ckeditor(function() { this.destroy(); }); loadLineItems(); } }); $( "#QuoteDetails" ).dialog({ autoOpen: false, height: 900, width: 600, modal: true, buttons: { "Edit Quote Details": function() { $('#QuoteCommercialComments').ckeditor(function() { this.updateElement(); this.destroy(); }); 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(); } }); $("#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(); }); $("#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); $( "#addLineItemModal" ).dialog('open'); }); return false; }); $(".editLineItem").live('click', function() { $('#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); $( "#editLineItemModal" ).dialog('open'); }); }); $("#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); //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(); }); }); $("#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'); }); }); $("#generateFirstPage").click(function() { if($(".firstPage").length == 0) { newPage(true); } $.get('/documents/generateFirstPage/'+docID, function(data) { $(".firstPage").val(data); savePages(); }); }); }); $('.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('