Commit e96f0534 authored by Ryan Herbert's avatar Ryan Herbert

form_builder decrement index on delete

parent 69241cb2
......@@ -172,6 +172,16 @@ PatientFormBuilder.prototype.build = function(index) {
return div;
};
PatientFormBuilder.prototype.createCloseButton = function() {
var self = this;
var close = Object.getPrototypeOf(PatientFormBuilder.prototype).createCloseButton.call(this);
$(close).click(function() {
var button = document.getElementById('patient_button');
button.dataset.index --;
});
return close;
};
function RunFormBuilder() {
SetFormBuilder.call(this);
this.type = 'run';
......@@ -194,6 +204,16 @@ RunFormBuilder.prototype.build = function(index) {
return div;
};
RunFormBuilder.prototype.createCloseButton = function() {
var self = this;
var close = Object.getPrototypeOf(RunFormBuilder.prototype).createCloseButton.call(this);
$(close).click(function() {
var button = document.getElementById('run_button');
button.dataset.index--;
});
return close;
};
function GenericFormBuilder() {
SetFormBuilder.call(this);
this.type = 'generic';
......@@ -212,6 +232,16 @@ GenericFormBuilder.prototype.build = function(index) {
return div;
}
GenericFormBuilder.prototype.createCloseButton = function() {
var self = this;
var close = Object.getPrototypeOf(GenericFormBuilder.prototype).createCloseButton.call(this);
$(close).click(function() {
var button = document.getElementById('generic_button');
button.dataset.index--;
});
return close;
};
function FileFormBuilder(group_ids, source, num_files) {
FormBuilder.call(this);
this.group_ids = group_ids;
......@@ -344,3 +374,13 @@ FileFormBuilder.prototype.build_jstree = function() {
tree_par.appendChild(tree);
return d;
}
FileFormBuilder.prototype.createCloseButton = function() {
var self = this;
var close = Object.getPrototypeOf(FileFormBuilder.prototype).createCloseButton.call(this);
$(close).click(function() {
var button = document.getElementById('file_button');
button.dataset.index--;
});
return close;
}
......@@ -66,6 +66,7 @@
</div>
<span class="button"
onclick="add_file('fieldset_container', this.dataset.index++, {{=group_ids}})"
id="file_button"
data-index="{{=len(files)}}">add file</span>
<div class="clear"></div>
<input type="submit" value="Soumettre" class="btn">
......
......@@ -20,12 +20,15 @@
</div>
<span class="button"
onclick="document.getElementById('fieldset_container').appendChild(new PatientFormBuilder().build(this.dataset.index++));"
id="patient_button"
data-index="{{=len(sets[defs.SET_TYPE_PATIENT])}}">add patient</span>
<span class="button"
onclick="document.getElementById('fieldset_container').appendChild(new RunFormBuilder().build(this.dataset.index++));"
id="run_button"
data-index="{{=len(sets[defs.SET_TYPE_RUN])}}">add run</span>
<span class="button"
onclick="document.getElementById('fieldset_container').appendChild(new GenericFormBuilder().build(this.dataset.index++));"
id="generic_button"
data-index="{{=len(sets[defs.SET_TYPE_GENERIC])}}">add set</span>
<div class="clear"></div>
<input type="submit" value="save" class="btn"></td>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment