Fork me on GitHub

Opening a Dialog

view code

Opening a static Dialog

The layout of the Dialog is fully described by the referenced HTML template: either the default "#dialog_generic" of a specific one.

You can fully customize the rendering with CSS; the default styles are provided by static/frontend_forms/css/frontend_forms.css

dialog1 = new Dialog({
    dialog_selector: '#dialog_generic',
    html: '<h1>Static content goes here ...</h1>',
    width: '600px',
    min_height: '200px',
    title: '<i class="fa fa-calculator"></i> Select an object ...',
    footer_text: 'testing dialog ...',
    enable_trace: true
});

dialog1.open()
/static/images/static_dialog.png

A simple static Dialog

Opening a dynamic Dialog

In most cases, you will rather produce the dialog content dynamically.

To obtain that, just add an "url" option to the Djalog constructor, and it will be automatically used to obtain the Dialog content from the server via an Ajax call.

dialog1 = new Dialog({
    ...
    url: "/samples/simple-content",
    ...

Sometimes it is convenient to reuse the very same single view to render either a modal dialog, or a standalone HTML page.

This can be easily accomplished providing:

  • an "inner" template which renders the content
  • an "outer" container template which renders the full page, then includes the "inner" template
  • in the view, detect the call context and render one or another
def simple_content2(request):

    # Either render only the modal content, or a full standalone page
    if request.is_ajax():
        template_name = 'frontend/includes/simple_content2_inner.html'
    else:
        template_name = 'frontend/includes/simple_content2.html'

    return render(request, template_name, {
    })

here, the "inner" template provides the content:

<div class="row">
    <div class="col-sm-4">
        <p>Repellat molestiae et, animi nobis ex fuga ea, eius cupiditate nam earum deleniti nostrum consequatur quidem quisquam, et nisi reiciendis voluptatibus magni itaque dolores maxime facilis in aliquid. Nisi necessitatibus sapiente nesciunt blanditiis molestias accusantium fuga optio voluptates? Beatae odit autem fugit ut at optio voluptatum modi eos praesentium, laboriosam quo aspernatur molestiae labore optio expedita dolores. Ipsum esse quasi maiores impedit ex libero molestias, est culpa nulla earum nisi non dolore assumenda rerum a, illum possimus fuga ut eligendi dicta, quisquam saepe repellat, voluptatem natus modi voluptas expedita nam dolor saepe illo.</p>
    </div>
    <div class="col-sm-4">
        <p>Omnis facere consequatur nobis pariatur esse eveniet repellendus perferendis, eius cupiditate nostrum earum, voluptas maiores impedit quis. Id corrupti repudiandae eligendi at, fuga dolorum voluptates vel ratione nihil quia odio natus aut, cupiditate incidunt repellat odit blanditiis praesentium nobis autem dignissimos consequatur esse magnam. Enim facilis corporis nesciunt rerum temporibus magni natus quibusdam praesentium, ducimus nihil eius non impedit nisi esse quia nostrum, omnis molestiae temporibus deserunt voluptatum repellat blanditiis tempore veritatis ullam? Exercitationem necessitatibus eligendi voluptate natus libero dolorem maxime hic reiciendis doloribus.</p>
    </div>
    <div class="col-sm-4">
        <p>Fuga unde libero eligendi voluptatibus incidunt, qui sed itaque assumenda dicta rem fugit similique?</p>
    </div>
</div>

while the "outer" one renders the full page:

{% extends "base.html" %}
{% load static staticfiles i18n %}

{% block content %}
{% include 'frontend/includes/simple_content2_inner.html' %}
{% endblock content %}