record defaults during initialization, fixes #682
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user