record defaults during initialization, fixes #682

This commit is contained in:
El RIDO 2021-04-05 13:24:53 +02:00
parent 5fd829aa09
commit 77ee40909f
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
4 changed files with 53 additions and 11 deletions

View File

@ -3508,6 +3508,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
let createButtonsDisplayed = false,
viewButtonsDisplayed = false,
burnAfterReadingDefault = false,
openDiscussionDefault = false,
$attach,
$burnAfterReading,
$burnAfterReadingOption,
@ -4152,11 +4154,10 @@ jQuery.PrivateBin = (function($, RawDeflate) {
me.resetInput = function()
{
clearAttachmentInput();
$openDiscussion.prop('checked', false);
$burnAfterReading.prop('checked', false);
$openDiscussionOption.removeClass('buttondisabled');
$burnAfterReadingOption.removeClass('buttondisabled');
$burnAfterReading.prop('checked', burnAfterReadingDefault);
$openDiscussion.prop('checked', openDiscussionDefault);
if (openDiscussionDefault) $openDiscussionOption.removeClass('buttondisabled');
if (burnAfterReadingDefault) $burnAfterReadingOption.removeClass('buttondisabled');
// TODO: reset expiration time
};
@ -4356,7 +4357,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
changeBurnAfterReading();
changeOpenDiscussion();
// get default value from template or fall back to set value
// get default values from template or fall back to set value
burnAfterReadingDefault = me.getBurnAfterReading();
openDiscussionDefault = me.getOpenDiscussion();
pasteExpiration = Model.getExpirationDefault() || pasteExpiration;
createButtonsDisplayed = false;

View File

@ -363,7 +363,7 @@ describe('TopNav', function () {
);
it(
'reset inputs to defaults (options on)',
'reset inputs to defaults (burnafterreading on)',
function () {
var results = [];
$('body').html(
@ -380,10 +380,9 @@ describe('TopNav', function () {
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
!$.PrivateBin.TopNav.getOpenDiscussion()
);
$('#burnafterreading').removeAttr('checked');
$('#opendiscussion').removeAttr('checked');
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
@ -394,6 +393,46 @@ describe('TopNav', function () {
results.push(
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
!$.PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
assert.ok(results.every(element => element));
}
);
it(
'reset inputs to defaults (opendiscussion on)',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li id="burnafterreadingoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="burnafterreading" name="burnafterreading" /> ' +
'Burn after reading</label></li><li id="opendiscussionoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="opendiscussion" name="opendiscussion" checked="checked" /> ' +
'Open discussion</label></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
);
$('#opendiscussion').removeAttr('checked');
$('#burnafterreading').prop('checked', true);
results.push(
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
!$.PrivateBin.TopNav.getOpenDiscussion()
);
$.PrivateBin.TopNav.resetInput();
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
);

View File

@ -72,7 +72,7 @@ endif;
?>
<script type="text/javascript" data-cfasync="false" src="js/purify-2.2.7.js" integrity="sha512-7Ka1I/nJuR2CL8wzIS5PJS4HgEMd0HJ6kfAl6fFhwFBB27rhztFbe0tS+Ex+Qg+5n4nZIT4lty4k4Di3+X9T4A==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-3IcMpzyLRym+sBfYDMbQknNHwBW6Yh+B4aqhGrh7nkqvvNEcShmuZSPg+OVbtTvpX/9ylJl217gmtXiMNu0lZg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-vJA5JXQBkfshqUIYHM/SkXWjBpwrZLlSXYRm+NERFD7t4Dg0tEdDV0NdBsItj1NXqfJ1062fT5okEav5eqUSMA==" crossorigin="anonymous"></script>
<!-- icon -->
<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />
<link rel="icon" type="image/png" href="img/favicon-32x32.png" sizes="32x32" />

View File

@ -50,7 +50,7 @@ endif;
?>
<script type="text/javascript" data-cfasync="false" src="js/purify-2.2.7.js" integrity="sha512-7Ka1I/nJuR2CL8wzIS5PJS4HgEMd0HJ6kfAl6fFhwFBB27rhztFbe0tS+Ex+Qg+5n4nZIT4lty4k4Di3+X9T4A==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-3IcMpzyLRym+sBfYDMbQknNHwBW6Yh+B4aqhGrh7nkqvvNEcShmuZSPg+OVbtTvpX/9ylJl217gmtXiMNu0lZg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-vJA5JXQBkfshqUIYHM/SkXWjBpwrZLlSXYRm+NERFD7t4Dg0tEdDV0NdBsItj1NXqfJ1062fT5okEav5eqUSMA==" crossorigin="anonymous"></script>
<!-- icon -->
<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />