-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* global $ django */ | ||
(function (init) { | ||
document.addEventListener('DOMContentLoaded', init, false) | ||
document.addEventListener('a4.embed.ready', init, false) | ||
})(function () { | ||
// Dynamically add subforms to a formset. | ||
var $formsets = $('.js-formset') | ||
var PLACEHOLDER = /__prefix__/g | ||
var dynamicFormSets = [] | ||
|
||
var DynamicFormSet = function ($formset) { | ||
this.$formset = $formset | ||
this.$formTemplate = this.$formset.find('.js-form-template') | ||
this.prefix = this.$formset.data('prefix') | ||
this.$totalInput = this.$formset.find('#id_' + this.prefix + '-TOTAL_FORMS') | ||
this.total = parseInt(this.$totalInput.val()) | ||
this.maxNum = parseInt(this.$formset.find('#id_' + this.prefix + '-MAX_NUM_FORMS').val()) | ||
|
||
this.$formset.on('click', '.js-add-form', this.addForm.bind(this)) | ||
} | ||
|
||
DynamicFormSet.prototype.addForm = function () { | ||
if (this.total < this.maxNum) { | ||
this.total += 1 | ||
this.$totalInput.val(this.total) | ||
var newForm = getNewForm(this.$formTemplate, this.total - 1) | ||
$(newForm).insertBefore(this.$formTemplate) | ||
} else { | ||
var text = django.gettext('Maximum number of upload documents reached.') | ||
$('#error-max-num-forms').html('<ul class="errorlist"><li>' + text + '</li></ul>') | ||
} | ||
} | ||
|
||
function getNewForm ($formTemplate, id) { | ||
return $formTemplate.html().replace(PLACEHOLDER, id) | ||
} | ||
|
||
$formsets.each(function (i) { | ||
dynamicFormSets.push( | ||
new DynamicFormSet($formsets.eq(i)) | ||
) | ||
}) | ||
}) |
41 changes: 41 additions & 0 deletions
41
euth/communitydebate/templates/euth_communitydebate/includes/inline_fileupload_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% load widget_tweaks i18n thumbnail base_tags form_tags %} | ||
|
||
<div class="card card-body"> | ||
{% for field in form.visible_fields %} | ||
{% if field.name == 'title' or field.name == 'document' %} | ||
<div class="form-group {% if field.errors %} has-error{% endif %}"> | ||
<label> | ||
{{ field.label }} | ||
</label> | ||
|
||
{% if field.errors %} | ||
{{ field|add_class:"form-control form-error" }} | ||
{% else %} | ||
{{ field|add_class:"form-control"}} | ||
{% endif %} | ||
{{ field.errors }} | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% if form.instance.id %} | ||
<div class="row"> | ||
<div class="col-sm-12 col-md-6"> | ||
<div class="form-group {% if form.DELETE.errors %} has-error{% endif %}"> | ||
<label> | ||
{{ form.DELETE.label }} | ||
</label> | ||
{% if form.DELETE.errors %} | ||
{{ form.DELETE|add_class:"form-control form-error" }} | ||
{% else %} | ||
{{ form.DELETE }} | ||
{% endif %} | ||
{{ form.DELETE.errors }} | ||
</div> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% for hidden in form.hidden_fields %} | ||
{{ hidden }} | ||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters