Skip to content

Commit

Permalink
Merge pull request #2217 from gabrieljenik/bug/17773-master--Code-nam…
Browse files Browse the repository at this point in the history
…e-change-while-we-updated-from-Edit-Question-screen

Fixed issue #17773: Code name change while we updated from Edit Question screen
  • Loading branch information
gabrieljenik committed Mar 3, 2022
2 parents 2a35c4c + ad622ba commit 13826d6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -12,7 +12,7 @@
*/

$config['versionnumber'] = '5.3.2';
$config['dbversionnumber'] = 482;
$config['dbversionnumber'] = 483;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
Expand Down
15 changes: 15 additions & 0 deletions application/helpers/update/updates/Update_483.php
@@ -0,0 +1,15 @@
<?php

namespace LimeSurvey\Helpers\Update;

class Update_483 extends DatabaseUpdateBase
{
/**
* @inheritDoc
*/
public function up()
{
// Allow label sets to contain full subquestion codes
alterColumn('{{labels}}', 'code', "string(20)", false);
}
}
Expand Up @@ -45,7 +45,7 @@

<td>
<input type='hidden' class='hiddencode' value='<?php echo $row['code'] ?>'/>
<input type='text' class='codeval form-control ' id='code_<?php echo $row['sortorder'] ?>' name='code_<?php echo $row['sortorder'] ?>' maxlength='5' size='6' value='<?php echo $row['code'] ?>'/>
<input type='text' class='codeval form-control ' id='code_<?php echo $row['sortorder'] ?>' name='code_<?php echo $row['sortorder'] ?>' maxlength='20' size='20' value='<?php echo $row['code'] ?>'/>
</td>

<td>
Expand Down
3 changes: 3 additions & 0 deletions application/views/questionAdministration/modals.twig
Expand Up @@ -49,6 +49,9 @@
</select>
</div>
<div class="row">
<div id="longcodesalert" class="col-sm-12" style="display: none;">
<div class="alert alert-warning ls-space margin bottom-0 top-15">{{ gT('Warning: Some answer codes will be truncated.') }}</div>
</div>
<div id='labelsetpreview' class="col-sm-12 ls-space margin top-15" >
</div>
</div>
Expand Down
23 changes: 20 additions & 3 deletions assets/scripts/admin/questionEditor.js
Expand Up @@ -622,6 +622,7 @@ $(document).on('ready pjax:scriptcomplete', function () {
function labelSetDestruct() {
$('#labelsets').select2('destroy');
$('#labelsetpreview').empty();
$('#longcodesalert').hide();
}

/**
Expand Down Expand Up @@ -649,6 +650,8 @@ $(document).on('ready pjax:scriptcomplete', function () {
const $tabindex = $('<ul class="nav nav-tabs" role="tablist"></ul>');
const $tabbody = $('<div class="tab-content" style="max-height: 50vh; overflow:auto;"></div>');

var hasInvalidCodes = false;
const source = $('#labelsetbrowserModal').data('source');
const i = 0;
$.each(json.languages, (language, languageName) => {
const $linkItem = $aTemplate.clone();
Expand All @@ -670,18 +673,27 @@ $(document).on('ready pjax:scriptcomplete', function () {

labelSet.labels.forEach((label) => {
// Label title is not concatenated directly because it may have non-encoded HTML
const $labelTitleDiv = $('<div class="col-md-8"></div>');
const $labelTitleDiv = $('<div class="col-md-7"></div>');
$labelTitleDiv.text(label.title);
const $listItem = $listItemTemplate.clone();
$listItem.append(`<div class="col-md-3 text-right" style="border-right: 4px solid #cdcdcd">${label.code}</div>`);
$listItem.append(`<div class="col-md-5 text-right" style="border-right: 4px solid #cdcdcd">${label.code}</div>`);
$listItem.append($labelTitleDiv);
$listItem.append('<div class="col-md-1"></div>');
$listItem.attr('data-label', JSON.stringify(label));
$itemList.append($listItem);

if (source === 'answeroptions' && label.code.length > 5) {
hasInvalidCodes = true;
}
});

$bodyItem.append(`<h4>${labelSet.label_name}</h4>`); // jshint ignore: line
$itemList.appendTo($bodyItem);

if (hasInvalidCodes) {
$('#longcodesalert').show();
} else {
$('#longcodesalert').hide();
}
});
$('#labelsetpreview').empty();
$('<div></div>').append($tabindex).append($tabbody).appendTo($('#labelsetpreview'));
Expand Down Expand Up @@ -811,6 +823,9 @@ $(document).on('ready pjax:scriptcomplete', function () {
$tr = $row.eq(4);
} else if (source === 'answeroptions') {
$tr = $row.eq(2);

// Make sure codes are limited to 5 characters
label.code = label.code.substr(0, 5);
} else {
throw 'source is not subquestions or answeroptions: ' + source;
}
Expand Down Expand Up @@ -1672,6 +1687,8 @@ $(document).on('ready pjax:scriptcomplete', function () {
$('#labelsetbrowserModal').modal('show');

initLabelSetModal(event);

$('#labelsetbrowserModal').data('source', source);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion installer/create-database.php
Expand Up @@ -173,7 +173,7 @@ function populateDatabase($oDB)
$oDB->createCommand()->createTable('{{labels}}', array(
'id' => "pk",
'lid' => "integer NOT NULL DEFAULT 0",
'code' => "string(5) NOT NULL default ''",
'code' => "string(20) NOT NULL default ''",
'sortorder' => "integer NOT NULL",
'assessment_value' => "integer NOT NULL default '0'",
), $options);
Expand Down

0 comments on commit 13826d6

Please sign in to comment.