Skip to content

Commit

Permalink
Convert smartmin haml templates
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Aug 18, 2023
1 parent 8063bc7 commit ac48494
Show file tree
Hide file tree
Showing 14 changed files with 732 additions and 0 deletions.
124 changes: 124 additions & 0 deletions templates/smartmin/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{% extends "base_admin_dashboard.html" %}
{% load smartmin %}
{% block pre-content %}
<h2 class="is-size-2 has-text-weight-bold">{{ title }}</h2>
{% endblock pre-content %}
{% block extra-script %}
{# placeholder form for posterizer href's.. href's with a posterize class will be converted to POSTs #}
<form method="post" id="posterizer">
{% csrf_token %}
</form>
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/jquery.url.js"></script>
<script type="text/javascript">
$("td.clickable").hover(function(){
this.style.cursor='pointer'
}, function(){});

$("td.clickable").click(function(){
document.location = $(this).children("a").attr("href");
});

$("a.posterize").click(function(event){
event.preventDefault();
event.stopPropagation();

var href = $(this).attr("href");
var url = $.url(href);

$("#posterizer").attr("action", url.attr("path"));

for (var key in url.param()){
$("#posterizer").append("<input type='hidden' name='" + key + "' value='" + url.param(key) + "'></input>");
}

$("#posterizer").submit();
});

function fetchPJAXContent(url, container, options) {

var type = 'GET';
var data = undefined;
if (options) {
if ('postData' in options) {
type = 'POST';
data = options['postData'];
}
}

var headers = { 'X-PJAX': true };
if (options && 'headers' in options) {
for (key in options['headers']) {
headers[key] = options['headers'][key];
}
}

$.ajax({
headers: headers,
type: type,
url: url,
data: data,
success: function(data, status, jqXHR) {
if ('followRedirects' in options && options['followRedirects'] == true) {
var redirect = jqXHR.getResponseHeader('REDIRECT');
if (redirect) {
window.document.location.href = redirect;
return;
}
}

var noPJAX = $(container).data('no-pjax');
if (options) {
if(!('forceReload' in options) || ('forceReload' in options && !options['forceReload'])) {
if (noPJAX || ('shouldIgnore' in options && options['shouldIgnore'](data))) {
if ('onIgnore' in options) {
options['onIgnore'](jqXHR);
}
return;
}
}
}
$(container).html(data);

if (options) {
if ('onSuccess' in options && options['onSuccess']) {
options['onSuccess']();
}
}
}
});
}
</script>
{# embed refresh script if refresh is active #}
{% if refresh %}
<script type="text/javascript">
function refresh(onSuccess, forceReload){
var url = "{{url_params|safe}}"
{% if page_obj %}
url += "page={{page_obj.number}}";
{% endif %}

if (url == '') {
url = '?';
}

url += '&ts=' + new Date().getTime();

fetchPJAXContent(url, '#pjax', {
forceReload: forceReload,
onSuccess: onSuccess,
onIgnore: function() {
scheduleRefresh();
}
});
}

function scheduleRefresh() {
window.setTimeout(refresh, {{ refresh }});
}

$(document).ready(function(){
scheduleRefresh();
});
</script>
{% endif %}
{% endblock extra-script %}
1 change: 1 addition & 0 deletions templates/smartmin/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "smartmin/form.html" %}
37 changes: 37 additions & 0 deletions templates/smartmin/delete_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "smartmin/base.html" %}
{% load smartmin i18n %}
{% block pre-content %}
{% endblock pre-content %}
{% block content %}
{% block pjax %}
<article class="message is-danger">
<div class="message-header">{% trans "Remove Item?" %}</div>
<div class="message-body">
<p>
{% blocktrans with object=object %}
Are you sure you want to remove <strong>{{ object }}</strong>?
{% endblocktrans %}
</p>
<div></div>
<p>{% trans "Once it is removed, it will be gone forever. There is no way to undo this operation." %}</p>
</div>
</article>
<form method="POST">
{% block delete_form %}
{% endblock delete_form %}
<div class="field smartmin-form-buttons is-horizontal">
<div class="field-label"></div>
<div class="field-body"></div>
<div class="field is-grouped">
<div class="control">
<a href="{{ cancel_url }}" class="button">{% trans "Cancel" %}</a>
{% csrf_token %}
</div>
<div class="control">
<button type="submit" class="button is-danger">{% trans "Remove" %}</button>
</div>
</div>
</div>
</form>
{% endblock pjax %}
{% endblock content %}
51 changes: 51 additions & 0 deletions templates/smartmin/field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% load smartmin ureport i18n %}
{% with form|field:field as form_field %}
{% getblock "before_field_" field %}
{% if form_field and form_field.is_hidden %}
{{ form_field }}
{% else %}
{% if form_field != None %}
<div class="{% if form_field.errors %}is-danger{% endif %} field is-horizontal">
<div class="field-label is-normal">
<label for="{{ field.name }}" class="label">{% get_label field %}</label>
</div>
<div class="field-body">
<div class="field is-expanded">
<div class="{% if form_field|is_multiple_checkbox %}multiple-checkbox{% endif %} control">
{% if form_field|is_checkbox %}
<label class="checkbox">{{ form_field }}</label>
{% elif form_field|is_input %}
{{ form_field|add_css:"input" }}
{% elif form_field|is_textarea %}
{{ form_field|add_css:"textarea" }}
{% elif form_field|is_select %}
<span class="{% if form_field|is_multiple_select %} is-multiple{% endif %} select">{{ form_field }}</span>
{% else %}
{{ form_field }}
{% endif %}
{% with view|field_help:field as help %}
{% if help %}<p class="help">{{ help }}</p>{% endif %}
{% endwith %}
{% if form_field.errors %}<p class="help is-danger">{{ form_field.errors }}</p>{% endif %}
</div>
</div>
</div>
</div>
{% else %}
<div class="field is-horizontal">
<div class="field-label is-normal">
<label for="{{ field.name }}" class="label">{% get_label field %}</label>
</div>
<div class="field-body">
<div class="field is-expanded">
<div class="control is-static">{% get_value_from_view field %}</div>
{% with view|field_help:field as help %}
{% if help %}<p class="help">{{ help }}</p>{% endif %}
{% endwith %}
</div>
</div>
</div>
{% endif %}
{% endif %}
{% getblock "after_field_" field %}
{% endwith %}
81 changes: 81 additions & 0 deletions templates/smartmin/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% extends "smartmin/base.html" %}
{% load smartmin i18n %}
{% block content %}
{% block pjax %}
<div class="columns" id="pjax">
<div class="{% block form-span %}is-12{% endblock %} column">
{% block pre-form %}
{% endblock pre-form %}
<form method="post"
enctype="multipart/form-data"
role="form"
class="smartmin-form">
{% block pre-form-errors %}
{% endblock pre-form-errors %}
{% if form.non_field_errors %}<div class="message is-danger form-errors">{{ form.non_field_errors }}</div>{% endif %}
{% block post-form-errors %}
{% endblock post-form-errors %}
{% block pre-fields %}
{% endblock pre-fields %}
{% block form-help %}
{% endblock form-help %}
{% block fields %}
<fieldset>
{% for field in fields %}
{% render_field field %}
{% endfor %}
{% block extra-fields %}
{% endblock extra-fields %}
</fieldset>
{% endblock fields %}
{% block post-fields %}
{% endblock post-fields %}
{% csrf_token %}
{% block form-buttons %}
<div class="field smartmin-form-buttons is-horizontal">
<div class="field-label"></div>
<div class="field-body">
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-primary">{{ submit_button_name }}</button>
</div>
<div class="control">
<a onclick="javascript:history.go(-1)" class="button">{% trans "Cancel" %}</a>
</div>
</div>
</div>
</div>
{% endblock form-buttons %}
</form>
{% block post-form %}
{% endblock post-form %}
</div>
{% block form-right %}
{% endblock form-right %}
</div>
{% endblock pjax %}
{% endblock content %}
{% block extra-script %}
{{ block.super }}
<script type="text/javascript">
$(document).ready(function() {
$('input[readonly]').prop('disabled', true);
});
</script>
{% if javascript_submit %}
<script type="text/javascript">
// attach a submit handler to the form
$("#smartmin_form").submit(function(event) {

// stop form from submitting normally
event.preventDefault();
event.stopPropagation();

// get some values from elements on the page:
var form = $(this);
var data = form.serialize();
{{ javascript_submit }}(form, data);
});
</script>
{% endif %}
{% endblock extra-script %}
Loading

0 comments on commit ac48494

Please sign in to comment.