-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Redirects: allow update #9593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirects: allow update #9593
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,33 @@ | |
|
||
{% load i18n %} | ||
|
||
{% block title %}{% trans "Edit Redirects" %}{% endblock %} | ||
{% block title %}{% trans "Redirect" %}{% endblock %} | ||
|
||
{% block project-redirects-active %}active{% endblock %} | ||
{% block project_edit_content_header %}{% trans "Redirects" %}{% endblock %} | ||
|
||
{% block extra_scripts %} | ||
<script type="text/javascript"> | ||
|
||
var update_outcome = function(ev) { | ||
var update_outcome = function() { | ||
$('#id_from_url').parent().hide() | ||
$('#id_to_url').parent().hide() | ||
$('#dynamic-redirect').hide() | ||
|
||
let redirect_type = $('#id_redirect_type').val(); | ||
if (redirect_type == 'prefix') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().hide() | ||
} | ||
else if (redirect_type == 'page') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().show() | ||
} | ||
else if (redirect_type == 'exact') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().show() | ||
} | ||
|
||
var field_from_url = $('#id_from_url'); | ||
field_to_url = $('#id_to_url'); | ||
option = $('#id_redirect_type').val(); | ||
|
@@ -39,31 +57,11 @@ | |
}; | ||
|
||
$(document).ready(function() { | ||
$('#id_from_url').parent().hide() | ||
$('#id_to_url').parent().hide() | ||
$('#dynamic-redirect').hide() | ||
|
||
update_outcome(); | ||
$('#id_redirect_type').bind('change', function(ev) { | ||
$('#id_from_url').val(''); | ||
$('#id_to_url').val(''); | ||
$('#id_from_url').parent().hide() | ||
$('#id_to_url').parent().hide() | ||
|
||
if (this.value == 'prefix') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().hide() | ||
} | ||
else if (this.value == 'page') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().show() | ||
} | ||
else if (this.value == 'exact') { | ||
$('#id_from_url').parent().show() | ||
$('#id_to_url').parent().show() | ||
} | ||
Comment on lines
-42
to
-63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved this logic to be inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't fully check this Javascript code, but looks good! |
||
update_outcome(ev); | ||
}); | ||
$('#id_from_url, #id_to_url').keyup(update_outcome); | ||
update_outcome(); | ||
}); | ||
$('#id_from_url, #id_to_url').keyup(update_outcome); | ||
}); | ||
|
||
</script> | ||
|
@@ -76,44 +74,18 @@ | |
{% endblocktrans %} | ||
</p> | ||
|
||
{% if redirects|length > 0 %} | ||
<h3>{% trans "Redirects" %}</h3> | ||
<div class="module"> | ||
<div class="module-list"> | ||
<div class="module-list-wrapper"> | ||
<ul> | ||
{% for redirect in redirects %} | ||
<li class="module-item"> | ||
<div> | ||
{{ redirect.get_redirect_type_display }} | ||
</div> | ||
{% if redirect.get_from_to_url_display %} | ||
<div> | ||
{{ redirect.get_from_to_url_display }} | ||
</div> | ||
{% endif %} | ||
<ul class="module-item-menu"> | ||
<li> | ||
<form method="post" action="{% url "projects_redirects_delete" project.slug %}"> | ||
{% csrf_token %} | ||
<input type="hidden" name="id_pk" value="{{ redirect.pk }}" /> | ||
<input type="submit" value="{% trans "Remove" %}"> | ||
</form> | ||
</li> | ||
</ul> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
|
||
<form method="post" action=".">{% csrf_token %} | ||
{{ form.as_p }} | ||
<div id="dynamic-redirect" class="empty"></div> | ||
<p> | ||
<input style="display: inline;" type="submit" value="{% trans "Add" %}"> | ||
</p> | ||
<input type="submit" value="{% trans "Save" %}"> | ||
</form> | ||
|
||
{% if redirect %} | ||
humitos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<form | ||
method="post" | ||
action="{% url 'projects_redirects_delete' project_slug=project.slug redirect_pk=redirect.pk %}"> | ||
{% csrf_token %} | ||
<input type="submit" value="{% trans "Delete" %}"> | ||
</form> | ||
{% endif %} | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{% extends "projects/project_edit_base.html" %} | ||
|
||
{% load i18n %} | ||
|
||
{% block title %}{% trans "Redirects" %}{% endblock %} | ||
|
||
{% block project-redirects-active %}active{% endblock %} | ||
{% block project_edit_content_header %}{% trans "Redirects" %}{% endblock %} | ||
|
||
{% block project_edit_content %} | ||
<p class="help_text"> | ||
{% blocktrans trimmed with docs_url='https://docs.readthedocs.io/page/user-defined-redirects.html' %} | ||
Add redirects for your project. This allows you to fix links to old pages that are 404ing. <a href="{{ docs_url }}">Learn more</a>. | ||
{% endblocktrans %} | ||
</p> | ||
|
||
<div class="button-bar"> | ||
<ul> | ||
<li> | ||
<a class="button" | ||
href="{% url 'projects_redirects_create' project_slug=project.slug %}"> | ||
{% trans "Add Redirect" %} | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="module"> | ||
<div class="module-list"> | ||
<div class="module-list-wrapper"> | ||
<ul> | ||
{% for redirect in redirects %} | ||
<li class="module-item"> | ||
<div> | ||
{{ redirect.get_redirect_type_display }} | ||
</div> | ||
{% if redirect.get_from_to_url_display %} | ||
<div> | ||
{{ redirect.get_from_to_url_display }} | ||
</div> | ||
{% endif %} | ||
<ul class="module-item-menu"> | ||
<li> | ||
<a href="{% url 'projects_redirects_edit' project_slug=project.slug redirect_pk=redirect.pk %}"> | ||
{% trans "Edit" %} | ||
</a> | ||
</li> | ||
</ul> | ||
</li> | ||
{% empty %} | ||
<li class="module-item"> | ||
<p class="quiet"> | ||
{% trans "No redirects found." %} | ||
</p> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were doing this override to allow passing the project, but by using the trick of listing the project field and always using the project we pass to form this isn't needed anymore.