$(document).ready(function(){ $('.modal-change-type').change(function(e) { var $selectBox = $(e.currentTarget); var selectedChangeType = $selectBox.val(); var $modalityForm = $selectBox.closest('.modality-form'); $.ajax({ url: '/modalities/reasons.json', data: { modal_change_type: selectedChangeType }, success: function(json) { // console.log(json); var $reasonSelectBox = $modalityForm.find('.modality-reason-select'); $reasonSelectBox.html(''); for (var i = 0; i < json.length; i++) { var reasonId = json[i].id; var reasonDescription = json[i].description; var optionHtml = _.template("")({ id: reasonId, description: reasonDescription }); $reasonSelectBox.append(optionHtml); } }, error: function(json) { console.log("Modality Reasons failed to load"); console.log(json); } }); }); $('#modal-reason-code').click(function() { var $bigModal = $('
').attr('class','modal-show'); var $smallModal = $('
Renal Registry Reason for Change Codes
').attr('class','modal-window '); var $modalHolder = $(''); var $hdPdTable = $('
Haemodialysis to PD
RR CodeReason for Change
'); var $pdHdTable = $('
PD to Haemodialysis
RR CodeReason for Change
'); $bigModal.attr('id','big-modal').appendTo('div#modals-wrapper'); $smallModal.attr('id','small-modal').appendTo('div#big-modal'); $modalHolder.appendTo('div#small-modal'); $hdPdTable.appendTo('div#modal-holder'); $pdHdTable.appendTo('div#modal-holder'); $('.modal-close').click(function() { $('#big-modal').remove(); }); $.ajax({ url: '/modalities/reasons.json', data: { modal_change_type: "Modalities::HaemodialysisToPd" }, success: function(json) { // console.log(json); for (var i = 0; i < json.length; i++) { var reasonRrCode = json[i].rr_code; var reasonDescription = json[i].description; var trTdHtml = _.template("<%=rr_code%><%=description%>")({ rr_code: reasonRrCode, description: reasonDescription }); $('#hd-pd').append(trTdHtml); } }, error: function(json) { console.log("Modality Reasons failed to load"); console.log(json); } }); $.ajax({ url: '/modalities/reasons.json', data: { modal_change_type: "Modalities::PdToHaemodialysis" }, success: function(json) { // console.log(json); for (var i = 0; i < json.length; i++) { var reasonRrCode = json[i].rr_code; var reasonDescription = json[i].description; var trTdHtml = _.template("<%=rr_code%><%=description%>")({ rr_code: reasonRrCode, description: reasonDescription }); $('#pd-hd').append(trTdHtml); } }, error: function(json) { console.log("Modality Reasons failed to load"); console.log(json); } }); }); });