Fix #149 -- Add copying multiple tickets answers enhancement (#292)

* Added copying multiple tickets answers enhancement (#149)

* Copying of multiple tickets answers enhancement - review for #292 (#149)

* changed to button and removed unbinging

* Removed unused button id attribute - changes for PR #149

* Housekeeping
This commit is contained in:
Christopher Dambamuromo
2016-11-10 21:32:16 +00:00
committed by Raphael Michel
parent 2f0c7c0ebc
commit 79c65496b9
2 changed files with 49 additions and 1 deletions

View File

@@ -35,8 +35,50 @@ $(function () {
});
$("#ajaxerr").on("click", ".ajaxerr-close", ajaxErrDialog.hide);
// Copy answers
$(".js-copy-answers").click(function (e) {
e.preventDefault();
var idx = $(this).data('id');
bind_groups(idx);
});
});
function bind_groups(idx) {
var elements = $('*[data-idx="'+idx+'"] input, *[data-idx="'+idx+'"] select, *[data-idx="'+idx+'"] textarea');
var firstAnswers = $('*[data-idx="0"] input, *[data-idx="0"] select, *[data-idx="0"] textarea');
elements.each(function(index){
var input = $(this),
tagName = input.prop('tagName').toLowerCase(),
attributeType = input.attr('type');
switch (tagName) {
case "textarea":
input.val(firstAnswers.eq(index).val());
break;
case "select":
input.val(firstAnswers.eq(index).find(":selected").val()).change();
break;
case "input":
switch (attributeType) {
case "text":
case "number":
input.val(firstAnswers.eq(index).val());
break;
case "checkbox":
case "radio":
input.prop("checked", firstAnswers.eq(index).prop("checked"));
break;
default:
input.val(firstAnswers.eq(index).val());
}
break;
default:
input.val(firstAnswers.eq(index).val());
}
});
}
var waitingDialog = {
show: function (message) {
"use strict";