Skip to content

Commit

Permalink
Fixed issue #11320: When clicking "Insert new answer option" Two new …
Browse files Browse the repository at this point in the history
…rows are added to the answers table

Fixed issue #11139: Subquestion: add error, more than 1 subquestion will be added
  • Loading branch information
LouisGac committed Jun 7, 2016
1 parent e1cddda commit 01a4c56
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
Expand Up @@ -241,6 +241,7 @@
data-surveyid="<?php echo $surveyid;?>"
data-gid="<?php echo $gid;?>"
data-qid="<?php echo $qid;?>"
data-scale-id="<?php echo $scale_id-1; // -1 : because it's incremented via < ?>"
/>
</p>

Expand Down
Expand Up @@ -36,17 +36,17 @@
<input
type='hidden'
class='oldcode code-title'
id='oldcode_<?php echo $qid; ?>_<?php echo $scale_id; ?>'
name='oldcode_<?php echo $qid; ?>_<?php echo $scale_id; ?>'
id='oldcode_<?php echo $position; ?>_<?php echo $scale_id; ?>'
name='oldcode_<?php echo $position; ?>_<?php echo $scale_id; ?>'
value="<?php echo $title; ?>"
/>

<input
type='text'
class="code form-control input-lg"
id='code_<?php echo $qid; ?>_<?php echo $scale_id; ?>'
id='code_<?php echo $position; ?>_<?php echo $scale_id; ?>'
class='code code-title'
name='code_<?php echo $qid; ?>_<?php echo $scale_id; ?>'
name='code_<?php echo $position; ?>_<?php echo $scale_id; ?>'
value="<?php echo $title; ?>"
maxlength='20' size='20'
pattern='<?php echo $sPattern; ?>'
Expand Down
40 changes: 31 additions & 9 deletions scripts/admin/answers.js
Expand Up @@ -4,7 +4,7 @@ $(document).ready(function(){
$('.tab-page:first .answertable tbody').sortable({ containment:'parent',
update:aftermove,
distance:3});
$('#editanswersform').submit(checkForDuplicateCodes)
$('#editanswersform').submit(checkForDuplicateCodes);
$('#btnlsreplace').click(transferlabels);
$('#btnlsinsert').click(transferlabels);
$('#labelsets').click(lspreview);
Expand All @@ -15,7 +15,13 @@ $(document).ready(function(){
$('input[name=savelabeloption]:radio').click(setlabel);
flag = [false, false];
$('#btnsave').click(savelabel);
updaterowproperties();
//updaterowproperties();

updateanswercount();





$(document).on("click", '.btnaddanswer', addinput);
$(document).on("click", '.btndelanswer', deleteinput);
Expand Down Expand Up @@ -68,7 +74,7 @@ function deleteinput()
updaterowproperties();
}

/**/
/*
function addinput()
{
var x;
Expand Down Expand Up @@ -161,23 +167,23 @@ function addinput()
$('.tab-page:first .answertable tbody').sortable('refresh');
updaterowproperties();
}

*/


/**
* add input : the ajax way
*/
function addinput()
{
$that = $(this); // The "add" button

$currentRow = $that.parents('.row-container'); // The row containing the "add" button
console.log($currentRow.attr('id'));
$currentTable = $that.parents('.answertable');
$commonId = $currentRow.data('common-id'); // The common id of this row in the other languages
$elDatas = $('#add-input-javascript-datas'); // This hidden element on the page contains various datas for this function
$url = $elDatas.data('url'); // Url for the request
$errormessage = $elDatas.data('errormessage'); // the error message if the AJAX request failed
$languages = JSON.stringify(langs); // The languages

// We get all the subquestion codes currently displayed
Expand Down Expand Up @@ -215,15 +221,19 @@ function addinput()

$arrayOfHtml = JSON.parse(arrayofhtml); // Convert the JSON to a javascript object

//console.log($arrayOfHtml);

// We insert each row for each language
$.each($arrayOfHtml, function(lang, htmlRow){
$elRowToUpdate = $('#row_'+lang+'_'+$commonId); // The row for the current language
console.log('#row_'+lang+'_'+$commonId);
console.log($elRowToUpdate);
$elRowToUpdate.after(htmlRow); // We insert the HTML of the new row after this one
});

$('#answercount_'+$scaleId).val($position+2);
console.log($scaleId);
console.log($position);
//console.log('scale: '+$scaleId);
//console.log('position: '+$position);

},
error : function(html, statut){
Expand All @@ -232,7 +242,8 @@ function addinput()
}
});
}
*/


function aftermove(event,ui)
{
// But first we have change the sortorder in translations, too
Expand Down Expand Up @@ -270,6 +281,16 @@ function aftermove(event,ui)
updaterowproperties();
}

function updateanswercount()
{
$elDatas = $('#add-input-javascript-datas');
scale_id = $elDatas.data('scale-id');
rownumber = ($('tr').length );
$('#answercount_'+scale_id).val(rownumber);
//console.log('#answercount_'+scale_id);
//console.log($('#answercount_'+scale_id).val());
}

// This function adjust the alternating table rows and renames/renumbers IDs and names
// if the list has really changed
function updaterowproperties()
Expand Down Expand Up @@ -373,6 +394,7 @@ function checkForDuplicateCodes()
}
else
{
updateanswercount();
return true;
}
}
Expand Down

0 comments on commit 01a4c56

Please sign in to comment.