Skip to content

Commit

Permalink
Bulk creation: fix private status based on the first form
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHoaro committed Oct 11, 2020
1 parent fe2c818 commit fa862e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ protected function buildLinkDataFromUrl(Request $request, string $url): array
$title = $request->getParam('title');
$description = $request->getParam('description');
$tags = $request->getParam('tags');
$private = filter_var($request->getParam('private'), FILTER_VALIDATE_BOOLEAN);
if ($request->getParam('private') !== null) {
$private = filter_var($request->getParam('private'), FILTER_VALIDATE_BOOLEAN);
} else {
$private = $this->container->conf->get('privacy.default_private_links', false);
}

// If this is an HTTP(S) link, we try go get the page to extract
// the title (otherwise we will to straight to the edit form.)
Expand Down
8 changes: 8 additions & 0 deletions assets/default/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,13 @@ function init(description) {
e.preventDefault();
toggleBulkCreationVisibility(bulkCreationButton, bulkCreationForm);
});

// Force to send falsy value if the checkbox is not checked.
const privateButton = bulkCreationForm.querySelector('input[type="checkbox"][name="private"]');
const privateHiddenButton = bulkCreationForm.querySelector('input[type="hidden"][name="private"]');
privateButton.addEventListener('click', () => {
privateHiddenButton.disabled = !privateHiddenButton.disabled;
});
privateHiddenButton.disabled = privateButton.checked;
}
})();
4 changes: 2 additions & 2 deletions tpl/default/addlink.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ <h2 class="window-title">{"Shaare multiple new links"|t}</h2>
</div>

<div>
<input type="checkbox" name="private"
{if="$default_private_links"} checked="checked"{/if}>
<input type="hidden" name="private" value="0">
<input type="checkbox" name="private" {if="$default_private_links"} checked="checked"{/if}>
&nbsp; <label for="lf_private">{'Private'|t}</label>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tpl/default/editlink.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2 class="window-title">

<div>
<input type="checkbox" name="lf_private" id="lf_private"
{if="($link_is_new && $default_private_links || $link.private == true)"}
{if="$link.private === true"}
checked="checked"
{/if}>
&nbsp;<label for="lf_private">{'Private'|t}</label>
Expand Down

0 comments on commit fa862e1

Please sign in to comment.