Skip to content

Commit

Permalink
Dev: Fix regexp tab in condition designer
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 12, 2016
1 parent 2db450d commit 87f46d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
Expand Up @@ -118,7 +118,7 @@
<li role='presentation' class='target-tab'>
<a href='#TOKENATTRS' aria-controls='TOKENATTRS' role='tab' data-toggle='tab'><?php eT('Token fields'); ?></a>
</li>
<li role='presentation' class='target-tab'>
<li role='presentation' class='target-tab disabled'>
<a href='#REGEXP' aria-controls='REGEXP' role='tab' data-toggle='tab'><?php eT('RegExp'); ?></a>
</li>
</ul>
Expand Down
64 changes: 31 additions & 33 deletions scripts/admin/conditions.js
Expand Up @@ -161,23 +161,33 @@ function populateCanswersSelect(evt) {
}
}

/**
* When user selects method in "Comparison operator", we need to
* disable/enable regexp and activate the tab.
*/
function selectTabFromOper() {
var val = $('#method').val();
if(val == 'RX') {
$('#conditiontarget').bootTabs('enable', 4);
$('#conditiontarget').bootTabs('option','active', 4);
$('#conditiontarget').bootTabs('disable', 0);
$('#conditiontarget').bootTabs('disable', 1);
$('#conditiontarget').bootTabs('disable', 2);
$('#conditiontarget').bootTabs('disable', 3);
$('a[href="#CANSWERSTAB"]').parent().addClass('disabled');
$('a[href="#CONST"]').parent().addClass('disabled');
$('a[href="#PREVQUESTIONS"]').parent().addClass('disabled');
$('a[href="#TOKENATTRS"]').parent().addClass('disabled');
$('a[href="#REGEXP"]').parent().removeClass('disabled');
$('a[href="#REGEXP"]').trigger('click');
}
else {
$('#conditiontarget').bootTabs('enable', 0);
$('#conditiontarget').bootTabs('enable', 1);
$('#conditiontarget').bootTabs('enable', 2);
if (!isAnonymousSurvey) $('#conditiontarget').bootTabs('enable', 3);
$('#conditiontarget').bootTabs('option','active', 0);
$('#conditiontarget').bootTabs('disable', 4);
//if (!isAnonymousSurvey) $('#conditiontarget').bootTabs('enable', 3);

$('a[href="#CANSWERSTAB"]').parent().removeClass('disabled');
$('a[href="#CONST"]').parent().removeClass('disabled');
$('a[href="#PREVQUESTIONS"]').parent().removeClass('disabled');
$('a[href="#TOKENATTRS"]').parent().removeClass('disabled');
$('a[href="#REGEXP"]').parent().addClass('disabled');

// If regexp tab is selected, trigger click on first tab instead
if ($('a[href="#REGEXP"]').parent().hasClass('active')) {
$('a[href="#CANSWERSTAB"]').trigger('click');
}
}
}

Expand Down Expand Up @@ -260,40 +270,20 @@ $(document).ready(function(){
);

// Select the condition target Tab depending on operator
//selectTabFromOper($('#method').val());
//selectTabFromOper($('#method').val());
$('#method').change(selectTabFromOper);

$('#cquestions').change(populateCanswersSelect);

$('#csrctoken').change(function() {
$('#cqid').val(0);
});

// At editing, a hidden field gives the Tab that should be selected
// Louis : that suppose to be a numerical input not a string !!!
//if ($('#editTargetTab').val() != '') {
//$('#conditiontarget').bootTabs('option','active', $('#editTargetTab').val());
//}

// At editing, a hidden field gives the Tab that should be selected
/*
if ($('#editSourceTab').val() != '') {
var val = $('#editSourceTab').val();
// Only two tabs: SRCPREVQUEST, SRCTOKENATTRS
var nr = (val === '#SRCPREVQUEST' ? 0 : 1);
$('#conditionsource').bootTabs('option','active', val);
$('#conditionsource').tabs({active: nr});
}
*/

// At editing, if cquestions is set, populate answers
if ($('#cquestions').val() != '') {
populateCanswersSelect(null);
}

//$('#conditiontarget').bootTabs('option','active', 1);

$('.nav-tabs').click(function(e) {
e.preventDefault();
$(this).tab('show');
Expand All @@ -317,6 +307,14 @@ $(document).ready(function(){
$('input[name="editTargetTab"]').val(href);
});

// Disable clicks on disabled tabs (regexp)
$(".nav-tabs a[data-toggle=tab]").on("click", function(e) {
if ($(this).parent().hasClass("disabled")) {
e.preventDefault();
return false;
}
});

});

/**
Expand Down

0 comments on commit 87f46d9

Please sign in to comment.