diff --git a/js/recurring_tickets_add_modal.js b/js/recurring_tickets_add_modal.js index 1d4d75a0..433fb5fe 100644 --- a/js/recurring_tickets_add_modal.js +++ b/js/recurring_tickets_add_modal.js @@ -3,14 +3,13 @@ const clientSelectDropdown = document.getElementById("changeClientSelect"); // Define client selector -// If the client selector is disabled, we must be on client_recurring_tickets.php instead. Trigger the contact list update. +// // If the client selector is disabled, we must be on client_recurring_tickets.php instead. Trigger the contact list update. if (clientSelectDropdown.disabled) { let client_id = $(clientSelectDropdown).find(':selected').val(); // Update the contacts dropdown list populateContactsDropdown(client_id); - } // Listener for client selection. Populate contact select when a client is selected diff --git a/js/recurring_tickets_edit_modal.js b/js/recurring_tickets_edit_modal.js index 2ce3e2c0..67966341 100644 --- a/js/recurring_tickets_edit_modal.js +++ b/js/recurring_tickets_edit_modal.js @@ -9,11 +9,11 @@ function populateRecurringTicketEditModal(client_id, ticket_id) { // If we get a response from post.php, parse it as JSON const response = JSON.parse(data); - // Access the ticket info, and all potential assets + // Access the ticket info, agents and all potential assets const contacts = response.contacts; const ticket = response.ticket[0]; - const assets = response.assets; const agents = response.agents; + const assets = response.assets; // Populate the scheduled ticket modal fields document.getElementById("editHeader").innerText = " Edit Recurring ticket: " + ticket.scheduled_ticket_subject; @@ -23,6 +23,28 @@ function populateRecurringTicketEditModal(client_id, ticket_id) { document.getElementById("editTicketNextRun").value = ticket.scheduled_ticket_next_run; tinyMCE.get('editTicketDetails').setContent(ticket.scheduled_ticket_details); + // Agent assignment dropdown + var agentDropdown = document.getElementById("editTicketAgent"); + + // Clear agent dropdown + var i, L = agentDropdown.options.length -1; + for(i = L; i >= 0; i--) { + agentDropdown.remove(i); + } + agentDropdown[agentDropdown.length] = new Option('- Agent -', '0'); + + + // Populate dropdown + agents.forEach(agent => { + if(parseInt(agent.user_id) == parseInt(ticket.scheduled_ticket_assigned_to)){ + // Selected agent + agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id, true, true); + } + else{ + agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id); + } + }); + // Contact dropdown var contactDropdown = document.getElementById("editTicketContact"); @@ -62,48 +84,28 @@ function populateRecurringTicketEditModal(client_id, ticket_id) { }); // Asset dropdown - var assetDropdown = document.getElementById("editTicketAssetId"); + if (assets && assets.length > 0) { + var assetDropdown = document.getElementById("editTicketAssetId"); - // Clear asset dropdown - var i, L = assetDropdown.options.length -1; - for(i = L; i >= 0; i--) { - assetDropdown.remove(i); + // Clear asset dropdown + var i, L = assetDropdown.options.length -1; + for(i = L; i >= 0; i--) { + assetDropdown.remove(i); + } + assetDropdown[assetDropdown.length] = new Option('- Asset -', '0'); + + // Populate dropdown + assets.forEach(asset => { + if(parseInt(asset.asset_id) == parseInt(ticket.scheduled_ticket_asset_id)){ + // Selected asset + assetDropdown[assetDropdown.length] = new Option(asset.asset_name, asset.asset_id, true, true); + } + else{ + assetDropdown[assetDropdown.length] = new Option(asset.asset_name, asset.asset_id); + } + }); } - assetDropdown[assetDropdown.length] = new Option('- Asset -', '0'); - // Populate dropdown - assets.forEach(asset => { - if(parseInt(asset.asset_id) == parseInt(ticket.scheduled_ticket_asset_id)){ - // Selected asset - assetDropdown[assetDropdown.length] = new Option(asset.asset_name, asset.asset_id, true, true); - } - else{ - assetDropdown[assetDropdown.length] = new Option(asset.asset_name, asset.asset_id); - } - }); - - - // Agent dropdown - var agentDropdown = document.getElementById("editTicketAgent"); - - // Clear agent dropdown - var i, L = agentDropdown.options.length -1; - for(i = L; i >= 0; i--) { - agentDropdown.remove(i); - } - agentDropdown[agentDropdown.length] = new Option('- Agent -', '0'); - - - // Populate dropdown - agents.forEach(agent => { - if(parseInt(agent.user_id) == parseInt(ticket.scheduled_ticket_assigned_to)){ - // Selected agent - agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id, true, true); - } - else{ - agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id); - } - }); } ); } diff --git a/recurring_ticket_add_modal.php b/recurring_ticket_add_modal.php index 56a289b7..16e24bdb 100644 --- a/recurring_ticket_add_modal.php +++ b/recurring_ticket_add_modal.php @@ -8,6 +8,10 @@