Feedback form: code optimization

This commit is contained in:
bergware
2024-02-03 23:53:10 +01:00
parent c72a87723f
commit 080a3e28d3
2 changed files with 26 additions and 25 deletions

View File

@@ -388,7 +388,7 @@ function openChanges(cmd,title,nchan,button=0) {
$('div.spinner.fixed').hide();
swal({title:title,text:"<pre id='swalbody'></pre><hr>",html:true,animation:'none',showConfirmButton:button!=0,confirmButtonText:"<?=_('Close')?>"},function(close){
$('.sweet-alert').hide('fast').removeClass('nchan');
if ($('#submit-button').length > 0) $('#submit-button').remove();
if ($('#submit_button').length > 0) $('#submit_button').remove();
});
$('.sweet-alert').addClass('nchan');
$('pre#swalbody').html(data);

View File

@@ -204,49 +204,50 @@ function form_submit(url, params, panel, diagnostics) {
}
$(function() {
$('button.confirm').text("<?=_('Cancel')?>");
if ($('#submit_button').length == 0) $('button.confirm').before('<input type="button" id="submit_button" value="<?=_('Submit')?>" disabled>');
$('input[name=mode]').click(function() {
var panel = $('input[name=mode]:checked').val();
var showPanel = '#'+panel+'_panel';
$('.allpanels').not(showPanel).fadeOut('fast');
var loadfunction = window[panel+'_load'];
var tab = $('input[name=mode]:checked').val();
var panel = '#'+tab+'_panel';
var email = "<?=_('Contact Email Address')?>";
$('.allpanels').not(panel).fadeOut('fast');
var loadfunction = window[tab+'_load'];
if (typeof loadfunction !== 'undefined' && $.isFunction(loadfunction)) {
loadfunction();
} else {
$(showPanel).fadeIn('fast');
$(panel).fadeIn('fast');
}
var required = (panel == 'troubleshoot');
var email = "<?=_('Contact Email Address')?>";
var option = " (<?=_('optional')?>)";
$('input#email').prop('placeholder',email+(required?'':option)).prop('required',required);
$('#submit_button').prop('disabled',validInput($('#'+panel+'_panel textarea')));
var required = ['troubleshoot'].includes(tab);
var optional = required ? "" : " (<?=_('optional')?>)";
$('input#email').prop('placeholder',email+optional).prop('required',required);
$('#submit_button').prop('disabled',validInput($('#'+tab+'_panel textarea')));
});
$('button.confirm').text("<?=_('Cancel')?>");
if ($('#submit_button').length == 0) $('button.confirm').before('<input type="button" id="submit_button" value="<?=_('Submit')?>" disabled>');
$('textarea').on('input change',function(){
$('#submit_button').prop('disabled',validInput($(this)));
});
$('input#email').on('input change',function(){
var panel = $('input[name=mode]:checked').val();
$('#submit_button').prop('disabled',validInput($('#'+panel+'_panel textarea')));
var tab = $('input[name=mode]:checked').val();
$('#submit_button').prop('disabled',validInput($('#'+tab+'_panel textarea')));
});
$('#submit_button').click(function() {
switch ($('input[name=mode]:checked').val()) {
case 'featureRequest':
form_submit('https://keys.lime-technology.com/feedback/featurerequest',{description:$('#featureRequest').val()}, $('#featureRequest_panel'));
var tab = '#'+$('input[name=mode]:checked').val();
switch (tab) {
case '#featureRequest':
form_submit('https://keys.lime-technology.com/feedback/featurerequest',{description:$(tab).val()}, $(tab+'_panel'));
break;
case 'bugReport':
form_submit('https://keys.lime-technology.com/feedback/bugreport',{description:$('#bugReport').val()}, $('#bugReport_panel'), 1);
case '#bugReport':
form_submit('https://keys.lime-technology.com/feedback/bugreport',{description:$(tab).val()}, $(tab+'_panel'), 1);
break;
case 'troubleshoot':
case '#troubleshoot':
// @todo - update this to use a new troubleshoot endpoint
form_submit('https://keys.lime-technology.com/feedback/bugreport',{description:$('#troubleshoot').val()}, $('#troubleshoot_panel'), 1);
form_submit('https://keys.lime-technology.com/feedback/bugreport',{description:$(tab).val()}, $(tab+'_panel'), 1);
break;
case 'otherComment':
form_submit('https://keys.lime-technology.com/feedback/comment',{description:$('#otherComment').val()}, $('#otherComment_panel'));
case '#otherComment':
form_submit('https://keys.lime-technology.com/feedback/comment',{description:$(tab).val()}, $(tab+'_panel'));
break;
}
});