Skip to content

Commit

Permalink
Merge pull request internetarchive#9805 from internetarchive/cdrini/a…
Browse files Browse the repository at this point in the history
…dd-checkboxes

Add checkboxes for copying authors and subjects to new work
  • Loading branch information
mekarpeles authored Aug 28, 2024
2 parents 686fa88 + d8454f7 commit 3f048df
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,14 @@ msgstr ""
msgid "WARNING: Any edits made to the work from this page will be ignored."
msgstr ""

#: books/edit/edition.html
msgid "Copy authors to new work"
msgstr ""

#: books/edit/edition.html
msgid "Copy subjects to new work"
msgstr ""

#: books/edit/edition.html
msgid "Please select an identifier."
msgstr ""
Expand Down
5 changes: 5 additions & 0 deletions openlibrary/plugins/openlibrary/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ export function initWorksMultiInputAutocomplete() {
});
});
});

// Show the new work options checkboxes only if "New work" selected
$('input[name="works--0"]').on('autocompleteselect', function(_event, ui) {
$('.new-work-options').toggle(ui.item.key === '__new__');
});
}

export function initSeedsMultiInputAutocomplete() {
Expand Down
29 changes: 27 additions & 2 deletions openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,33 @@ def save(self, formdata: web.Storage) -> None:
# Create a new work if so desired
new_work_key = (edition_data.get('works') or [{'key': None}])[0]['key']
if new_work_key == "__new__" and self.work is not None:
self.work = self.new_work(self.edition)
edition_data.works = [{'key': self.work.key}]
new_work = self.new_work(self.edition)
edition_data.works = [{'key': new_work.key}]

new_work_options = formdata.get(
'new_work_options',
{
'copy_authors': 'no',
'copy_subjects': 'no',
},
)

if (
new_work_options.get('copy_authors') == 'yes'
and 'authors' in self.work
):
new_work.authors = self.work.authors
if new_work_options.get('copy_subjects') == 'yes':
for field in (
'subjects',
'subject_places',
'subject_times',
'subject_people',
):
if field in self.work:
new_work[field] = self.work[field]

self.work = new_work
saveutil.save(self.work)

identifiers = edition_data.pop('identifiers', [])
Expand Down
11 changes: 11 additions & 0 deletions openlibrary/templates/books/edit/edition.html
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@
$else:
$:render_work_field(0, storage(title="", key=""))
</div>
<div class="new-work-options" style="display:none">
<label>
<input type="checkbox" name="new_work_options--copy_authors" value="yes">
$_("Copy authors to new work")
</label>
&ensp;
<label>
<input type="checkbox" name="new_work_options--copy_subjects" value="yes">
$_("Copy subjects to new work")
</label>
</div>
</div>

</div>
Expand Down

0 comments on commit 3f048df

Please sign in to comment.