remove form POST switch-email-forwarding

This commit is contained in:
Son NK 2020-04-25 15:26:07 +02:00
parent bbcd4fc355
commit fb9dc23529
2 changed files with 24 additions and 44 deletions

View file

@ -110,34 +110,31 @@
</span> </span>
</div> </div>
<div class="col text-right"> <div class="col text-right">
<form method="post"> <label class="custom-switch cursor"
<input type="hidden" name="form-name" value="switch-email-forwarding"> data-toggle="tooltip"
<input type="hidden" name="alias-id" value="{{ alias.id }}"> {% if alias.enabled %}
<label class="custom-switch cursor" title="Disable alias - you will stop receiving emails sent to this alias"
data-toggle="tooltip" {% else %}
{% if alias.enabled %} title="Enable alias - you will start receiving emails sent to this alias"
title="Disable alias - you will stop receiving emails sent to this alias" {% endif %}
{% else %}
title="Enable alias - you will start receiving emails sent to this alias"
{% endif %}
{% if loop.index ==1 %} {% if loop.index ==1 %}
data-intro="By turning off an alias, emails sent to this alias will <em>not</em> data-intro="By turning off an alias, emails sent to this alias will <em>not</em>
be forwarded to your inbox. <br><br> be forwarded to your inbox. <br><br>
This should be used with care as others might This should be used with care as others might
not be able to reach you after ... not be able to reach you after ...
" "
data-step="3" data-step="3"
{% endif %} {% endif %}
style="padding-left: 0px" style="padding-left: 0px"
> >
<input type="hidden" name="alias" class="alias" value="{{ alias.email }}"> <input type="checkbox" class="custom-switch-input"
<input type="checkbox" class="custom-switch-input" data-alias="{{ alias.id }}" data-alias="{{ alias.id }}"
{{ "checked" if alias.enabled else "" }}> data-alias-email="{{ alias.email }}"
{{ "checked" if alias.enabled else "" }}>
<span class="custom-switch-indicator"></span> <span class="custom-switch-indicator"></span>
</label> </label>
</form>
</div> </div>
</div> </div>
@ -412,7 +409,7 @@
$(".custom-switch-input").change(async function (e) { $(".custom-switch-input").change(async function (e) {
let aliasId = $(this).data("alias"); let aliasId = $(this).data("alias");
let alias = $(this).parent().find(".alias").val(); let alias = $(this).data("alias-email");
try { try {
let res = await fetch(`/api/aliases/${aliasId}/toggle`, { let res = await fetch(`/api/aliases/${aliasId}/toggle`, {

View file

@ -63,23 +63,6 @@ def index():
else: else:
flash(f"You need to upgrade your plan to create new alias.", "warning") flash(f"You need to upgrade your plan to create new alias.", "warning")
elif request.form.get("form-name") == "switch-email-forwarding":
alias_id = request.form.get("alias-id")
alias: Alias = Alias.get(alias_id)
LOG.d("switch email forwarding for %s", alias)
alias.enabled = not alias.enabled
if alias.enabled:
flash(f"Alias {alias.email} is enabled", "success")
else:
flash(f"Alias {alias.email} is disabled", "warning")
db.session.commit()
return redirect(
url_for("dashboard.index", highlight_alias_id=alias.id, query=query)
)
elif request.form.get("form-name") == "delete-email": elif request.form.get("form-name") == "delete-email":
alias_id = request.form.get("alias-id") alias_id = request.form.get("alias-id")
alias: Alias = Alias.get(alias_id) alias: Alias = Alias.get(alias_id)