var profiles = [] // Save attempts to POST to /smtp/ function save(idx) { var profile = {} profile.name = $("#name").val() profile.interface_type = $("#interface_type").val() profile.from_address = $("#from").val() profile.host = $("#host").val() profile.username = $("#username").val() profile.password = $("#password").val() profile.ignore_cert_errors = $("#ignore_cert_errors").prop("checked") if (idx != -1) { profile.id = profiles[idx].id api.SMTPId.put(profile) .success(function(data) { successFlash("Profile edited successfully!") load() dismiss() }) } else { // Submit the profile api.SMTP.post(profile) .success(function(data) { successFlash("Profile added successfully!") load() dismiss() }) .error(function(data) { modalError(data.responseJSON.message) }) } } function dismiss() { $("#modal\\.flashes").empty() $("#name").val("") $("#from").val("") $("#host").val("") $("#username").val("") $("#password").val("") $("#modal").modal('hide') } function deleteProfile(idx) { if (confirm("Delete " + profiles[idx].name + "?")) { api.SMTPId.delete(profiles[idx].id) .success(function(data) { successFlash(data.message) load() }) } } function edit(idx) { $("#modalSubmit").unbind('click').click(function() { save(idx) }) var profile = {} if (idx != -1) { profile = profiles[idx] $("#name").val(profile.name) $("#interface_type").val(profile.interface_type) $("#from").val(profile.from_address) $("#host").val(profile.host) $("#username").val(profile.username) $("#password").val(profile.password) $("#ignore_cert_errors").prop("checked", profile.ignore_cert_errors) } } function copy(idx) { $("#modalSubmit").unbind('click').click(function() { save(-1) }) var profile = {} profile = profiles[idx] $("#name").val("Copy of " + profile.name) $("#interface_type").val(profile.interface_type) $("#from").val(profile.from_address) $("#host").val(profile.host) $("#username").val(profile.username) $("#password").val(profile.password) $("#ignore_cert_errors").prop("checked", profile.ignore_cert_errors) } function load() { $("#profileTable").hide() $("#emptyMessage").hide() $("#loading").show() api.SMTP.get() .success(function(ss) { profiles = ss $("#loading").hide() if (profiles.length > 0) { $("#profileTable").show() profileTable = $("#profileTable").DataTable({ destroy: true, columnDefs: [{ orderable: false, targets: "no-sort" }] }); profileTable.clear() $.each(profiles, function(i, profile) { profileTable.row.add([ profile.name, profile.interface_type, moment(profile.modified_date).format('MMMM Do YYYY, h:mm:ss a'), "