Removes hard coded links to /admin

The _editor_js.html page has been modified in order to get the urls to the
various views through the {% url %} tag and add them to the global window
variable. I believe that this is actually the best solution in our case
and I like it much better than the other available options.
This commit is contained in:
Serafeim Papastefanos 2014-02-12 11:03:47 +02:00
parent 594d7e03e3
commit b7158bb3fa
10 changed files with 17 additions and 10 deletions

View file

@ -41,9 +41,9 @@
if lastSelection.collapsed
# TODO: don't hard-code this, as it may be changed in urls.py
url = '/admin/choose-page/?allow_external_link=true&allow_email_link=true&prompt_for_link_text=true'
url = window.page_chooser+'?allow_external_link=true&allow_email_link=true&prompt_for_link_text=true'
else
url = '/admin/choose-page/?allow_external_link=true&allow_email_link=true'
url = window.page_chooser+'?allow_external_link=true&allow_email_link=true'
ModalWorkflow
url: url

View file

@ -4,8 +4,7 @@ function createPageChooser(id, pageType, openAtParentId) {
var input = $('#' + id);
$('.action-choose', chooserElement).click(function() {
var initialUrl = '/admin/choose-page/';
/* TODO: don't hard-code this URL, as it may be changed in urls.py */
var initialUrl = window.page_chooser;
if (openAtParentId) {
initialUrl += openAtParentId + '/';
}

View file

@ -29,6 +29,13 @@
<script src="{{ STATIC_URL }}wagtaildocs/js/document-chooser.js"></script>
<script src="{{ STATIC_URL }}wagtailsnippets/js/snippet-chooser.js"></script>
<script src="{{ STATIC_URL }}admin/js/urlify.js"></script>
<script type='text/javascript'>
window.document_chooser='{% url "wagtaildocs_chooser" %}';
window.image_chooser='{% url "wagtailimages_chooser" %}';
window.embeds_chooser='{% url "wagtailembeds_chooser" %}';
window.page_chooser='{% url "wagtailadmin_choose_page" %}';
window.snippet_chooser='{% url "wagtailsnippets_choose_generic" %}';
</script>
{% endcompress %}
<script>

View file

@ -5,7 +5,7 @@ function createDocumentChooser(id) {
$('.action-choose', chooserElement).click(function() {
ModalWorkflow({
'url': '/admin/documents/chooser/', /* TODO: don't hard-code this, as it may be changed in urls.py */
'url': window.document_chooser,
'responses': {
'documentChosen': function(docData) {
input.val(docData.id);

View file

@ -24,7 +24,7 @@
button.on "click", (event) ->
lastSelection = widget.options.editable.getSelection()
ModalWorkflow
url: '/admin/documents/chooser/' # TODO: don't hard-code this, as it may be changed in urls.py
url: window.document_chooser
responses:
documentChosen: (docData) ->
a = document.createElement('a')

View file

@ -25,7 +25,7 @@
lastSelection = widget.options.editable.getSelection()
insertionPoint = $(lastSelection.endContainer).parentsUntil('.richtext').last()
ModalWorkflow
url: '/admin/embeds/chooser/' # TODO: don't hard-code this, as it may be changed in urls.py
url: window.embeds_chooser
responses:
embedChosen: (embedData) ->
elem = $(embedData).get(0)

View file

@ -25,7 +25,7 @@
lastSelection = widget.options.editable.getSelection()
insertionPoint = $(lastSelection.endContainer).parentsUntil('.richtext').last()
ModalWorkflow
url: '/admin/images/chooser/?select_format=true' # TODO: don't hard-code this, as it may be changed in urls.py
url: window.image_chooser+'?select_format=true'
responses:
imageChosen: (imageData) ->
elem = $(imageData.html).get(0)

View file

@ -5,7 +5,7 @@ function createImageChooser(id) {
$('.action-choose', chooserElement).click(function() {
ModalWorkflow({
'url': '/admin/images/chooser/', /* TODO: don't hard-code this, as it may be changed in urls.py */
'url': window.image_chooser,
'responses': {
'imageChosen': function(imageData) {
input.val(imageData.id);

View file

@ -5,7 +5,7 @@ function createSnippetChooser(id, contentType) {
$('.action-choose', chooserElement).click(function() {
ModalWorkflow({
'url': '/admin/snippets/choose/' + contentType + '/', /* TODO: don't hard-code this, as it may be changed in urls.py */
'url': window.snippet_chooser + contentType + '/',
'responses': {
'snippetChosen': function(snippetData) {
input.val(snippetData.id);

View file

@ -5,6 +5,7 @@ urlpatterns = patterns(
'wagtail.wagtailsnippets.views',
url(r'^$', 'snippets.index', name='wagtailsnippets_index'),
url(r'^choose/$', 'chooser.choose', name='wagtailsnippets_choose_generic'),
url(r'^choose/(\w+)/(\w+)/$', 'chooser.choose', name='wagtailsnippets_choose'),
url(r'^choose/(\w+)/(\w+)/(\d+)/$', 'chooser.chosen', name='wagtailsnippets_chosen'),