$(document).ready(function () { getListCodeTemplate(); CKEDITOR.replace('pdf_text'); $('#pdf_template_selected').val($('#pdf_template').val()); $('#pdf_template').on('change',function () { if( $('#pdf_template_selected').val()!=''){ var zgoda = confirm("Czy na pewno chcesz zmienić szablon pdf? Zmiany w aktualnym szablonie będą utracone."); if(!zgoda){ return; } } $('#pdf_template_selected').val($('#pdf_template').val()); getFilledCodeTemplate(); getAditionalFieldsTemplate(); }); $("#refresh").on('click',pdfRefresh); $("#preview_pdf").on('click',getPDFpreview); }); function getPDFpreview(){ window.open("Agreement.pdf"); } function getAditionalFieldsTemplate() { var id = $('#pdf_template').val(); $.ajax({ type: "POST", url: "index.php?module=EcmAgreements&action=dbpost&to_pdf=1", dataType: "json", async: false, data: { job: "getCodeTemplate", id: id, }, success: function (data) { $("#aditionalFields").find('tr').remove(); $.each(data.aditional_fields, function (key,value){ $("#aditionalFields").append(""+ value.value0+ ":"); }); } }); } function pdfRefresh(){ var zgoda = confirm("Czy na pewno chcesz odświeżyć treść pdf? Nie będzie można tego cofnąć."); if(!zgoda){ return; } getFilledCodeTemplate(); } function getFilledCodeTemplate() { var id_template = $('#pdf_template').val(); var inputs = $('input, textarea, select').not(':input[type=button], :input[type=submit], :input[type=reset]'); var fill_data = {}; $.each(inputs, function (indeks,value){ var jqval = $(value); if(jqval.val()!=''){ fill_data[jqval.attr('name')] = jqval.val(); } }); var tmp = null; $.ajax({ type: "POST", url: "index.php?module=EcmAgreements&action=dbpost&to_pdf=1", dataType: "html", data: { job: "getFilledCodeTemplate", id: id_template, data: fill_data, }, success: function (data) { CKEDITOR.instances['pdf_text'].setData(data); } }); } function getListCodeTemplate() { var selected = $("#pdf_template_selected").val(); $('#pdf_template').find('option').remove(); $.ajax({ type: "POST", url: "index.php?module=EcmAgreements&action=dbpost&to_pdf=1", dataType: "json", data: { job: "getListCodeTemplate", }, success: function(data) { $("#pdf_template").append(''); $.each(data, function(key, value) { console.debug("key " + key); console.debug("selected " + selected); if (key == selected) { $("#pdf_template").append(''); } else { $("#pdf_template").append(''); } $("#pdf_template").val(selected); }); } }); }