jQuery(document).ready(function($) { $('#email_send_to').dynamicRows({template: '#email_send_to_table_row', allow_empty: true}); // Show/hide multiple "Send to" inputs and single "Send to" input and populate hidden "type" field. $('#mediatypeid') .on('change', function() { var mediatypes_by_type = , mediatypeid = $(this).val(); if (mediatypes_by_type[mediatypeid] == ) { $('#mediatype_send_to').hide(); $('#mediatype_email_send_to').show(); } else { $('#mediatype_send_to').show(); $('#mediatype_email_send_to').hide(); } $('.focusable', $(this)).toggleClass('red', $(`li[value="${mediatypeid}"]`, $(this)).hasClass('red')); }) .trigger("change"); overlays_stack.end().centerDialog(); }); /** * Send media form data to server for validation before adding them to user media tab. * * @param {Overlay} overlay */ function validateMedia(overlay) { var $form = overlay.$dialogue.find('form'); $form.trimValues(['#period', '#sendto', 'input[name^="sendto_emails"]']); overlay.setLoading(); overlay.xhr = jQuery.ajax({ url: $form.attr('action'), data: $form.serialize(), success: function(ret) { overlay.$dialogue.find('.msg-bad, .msg-good').remove(); if ('error' in ret) { const message_box = makeMessageBox('bad', ret.error.messages, ret.error.title); message_box.insertBefore($form); overlay.unsetLoading(); } else { add_media(ret.dstfrm, ret.media, ret.mediatypeid, ret.sendto, ret.period, ret.active, ret.severity); } }, dataType: 'json', type: 'post' }); }