From 2e2ccb23aaa14f7f1e24215704ed1f7668fb67db Mon Sep 17 00:00:00 2001 From: encuestabizdevgit Date: Mon, 24 Jan 2022 15:18:26 -0300 Subject: [PATCH] Fixed issue #17773: Code name change while we updated from Edit Question screen --- application/config/version.php | 2 +- .../helpers/update/updatedb_helper.php | 7 ++++++ .../labels/_labelviewtabcontent_view.php | 2 +- .../views/questionAdministration/modals.twig | 3 +++ assets/scripts/admin/questionEditor.js | 23 ++++++++++++++++--- installer/create-database.php | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/application/config/version.php b/application/config/version.php index 9f14b4b962e..ab545f74487 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -12,7 +12,7 @@ */ $config['versionnumber'] = '5.2.11'; -$config['dbversionnumber'] = 479; +$config['dbversionnumber'] = 480; $config['buildnumber'] = ''; $config['updatable'] = true; $config['templateapiversion'] = 3; diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index 354fd891ade..fb2d682d8a2 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -5050,6 +5050,13 @@ function ($v) { $oDB->createCommand()->update('{{settings_global}}', ['stg_value' => 479], "stg_name='DBVersion'"); $oTransaction->commit(); } + // Allow label sets to contain full subquestion codes + if ($iOldDBVersion < 480) { + $oTransaction = $oDB->beginTransaction(); + alterColumn('{{labels}}', 'code', "string(20)", false); + $oDB->createCommand()->update('{{settings_global}}', ['stg_value' => 480], "stg_name='DBVersion'"); + $oTransaction->commit(); + } } catch (Exception $e) { Yii::app()->setConfig('Updating', false); $oTransaction->rollback(); diff --git a/application/views/admin/labels/_labelviewtabcontent_view.php b/application/views/admin/labels/_labelviewtabcontent_view.php index 19d1fa91dc4..9daf19ad114 100644 --- a/application/views/admin/labels/_labelviewtabcontent_view.php +++ b/application/views/admin/labels/_labelviewtabcontent_view.php @@ -45,7 +45,7 @@ '/> - ' name='code_' maxlength='5' size='6' value=''/> + ' name='code_' maxlength='20' size='20' value=''/> diff --git a/application/views/questionAdministration/modals.twig b/application/views/questionAdministration/modals.twig index a0a3ffe998f..96646e1961c 100644 --- a/application/views/questionAdministration/modals.twig +++ b/application/views/questionAdministration/modals.twig @@ -49,6 +49,9 @@
+
diff --git a/assets/scripts/admin/questionEditor.js b/assets/scripts/admin/questionEditor.js index 97c1147d2db..4b3cc8420a9 100644 --- a/assets/scripts/admin/questionEditor.js +++ b/assets/scripts/admin/questionEditor.js @@ -622,6 +622,7 @@ $(document).on('ready pjax:scriptcomplete', function () { function labelSetDestruct() { $('#labelsets').select2('destroy'); $('#labelsetpreview').empty(); + $('#longcodesalert').hide(); } /** @@ -649,6 +650,8 @@ $(document).on('ready pjax:scriptcomplete', function () { const $tabindex = $(''); const $tabbody = $('
'); + var hasInvalidCodes = false; + const source = $('#labelsetbrowserModal').data('source'); const i = 0; $.each(json.languages, (language, languageName) => { const $linkItem = $aTemplate.clone(); @@ -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 = $('
'); + const $labelTitleDiv = $('
'); $labelTitleDiv.text(label.title); const $listItem = $listItemTemplate.clone(); - $listItem.append(`
${label.code}
`); + $listItem.append(`
${label.code}
`); $listItem.append($labelTitleDiv); - $listItem.append('
'); $listItem.attr('data-label', JSON.stringify(label)); $itemList.append($listItem); + + if (source === 'answeroptions' && label.code.length > 5) { + hasInvalidCodes = true; + } }); $bodyItem.append(`

${labelSet.label_name}

`); // jshint ignore: line $itemList.appendTo($bodyItem); + + if (hasInvalidCodes) { + $('#longcodesalert').show(); + } else { + $('#longcodesalert').hide(); + } }); $('#labelsetpreview').empty(); $('
').append($tabindex).append($tabbody).appendTo($('#labelsetpreview')); @@ -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; } @@ -1657,6 +1672,8 @@ $(document).on('ready pjax:scriptcomplete', function () { $('#labelsetbrowserModal').modal('show'); initLabelSetModal(event); + + $('#labelsetbrowserModal').data('source', source); }, /** diff --git a/installer/create-database.php b/installer/create-database.php index 8579b8b2111..331fd3b6523 100755 --- a/installer/create-database.php +++ b/installer/create-database.php @@ -168,7 +168,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);