refactor: Remove inline javascript code in email_log.html.

All the inline javascript code present in email_log.html(which is
rendered when the user visits "/emails" in development mode) is
transferred to a new file: email_log.js in portico/ directory.

Fixes #11608.
This commit is contained in:
Abhinav Singh 2019-03-26 21:47:02 +05:30 committed by Tim Abbott
parent 69660da0e1
commit c27d927663
3 changed files with 46 additions and 38 deletions

View File

@ -0,0 +1,44 @@
$(function () {
// This code will be executed when the user visits /emails in
// development mode and email_log.html is rendered.
$('#toggle').change(function () {
if ($('.email-text').css('display') === 'none') {
$(".email-text").each(function () {
$(this).css("display", "block");
});
$(".email-html").each(function () {
$(this).css("display", "none");
});
} else {
$(".email-text").each(function () {
$(this).css("display", "none");
});
$(".email-html").each(function () {
$(this).css("display", "block");
});
}
});
$('input[type=radio][name=forward]').on('change', function () {
if ($(this).val() === "enabled") {
$("#forward_address_sections").show();
} else {
$("#forward_address_sections").hide();
}
});
$("#save_smptp_details").on("click", function () {
var address = $('input[name=forward]:checked').val() === "enabled" ? $("#address").val() : "";
var csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value');
var data = {forward_address: address, csrfmiddlewaretoken: csrf_token};
channel.post({
url: "/emails/",
data: data,
success: function () {
$("#smtp_form_status").show();
setTimeout(function () {
$("#smtp_form_status").hide();
}, 3000);
},
});
});
});

View File

@ -1,5 +1,6 @@
{% extends "zerver/base.html" %}
{% block content %}
{{ render_bundle('email-log') }}
<div class="container">
<div style="position: fixed">
<div class="alert">
@ -59,43 +60,5 @@
<button data-dismiss="modal">Close</button>
</div>
</div>
<script>
$('#toggle').change(function() {
if($('.email-text').css('display') == 'none') {
$(".email-text").each(function() {
$(this).css("display", "block");
});
$(".email-html").each(function() {
$(this).css("display", "none");
});
}
else {
$(".email-text").each(function() {
$(this).css("display", "none");
});
$(".email-html").each(function() {
$(this).css("display", "block");
});
}
});
$('input[type=radio][name=forward]').on('change', function() {
if ($(this).val() == "enabled") {
$("#forward_address_sections").show();
} else {
$("#forward_address_sections").hide();
}
});
$("#save_smptp_details").on("click", function() {
var address = $('input[name=forward]:checked').val() == "enabled" ? $("#address").val(): "";
var csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value');
var data = {"forward_address": address, "csrfmiddlewaretoken": csrf_token};
$.post("/emails/", data, function() {
$("#smtp_form_status").show();
setTimeout(function() {
$("#smtp_form_status").hide();
}, 3000);
});
});
</script>
</div>
{% endblock %}

View File

@ -83,6 +83,7 @@
"./static/js/portico/signup.js"
],
"dev-login": "./static/js/portico/dev-login.js",
"email-log": "./static/js/portico/email_log.js",
"stats": [
"./static/styles/stats.scss",
"./static/js/stats/stats.js",