This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from pulibrary/bulk_mark
Bulk mark as facing pages.
- Loading branch information
Showing
7 changed files
with
507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export default class BulkActionManager { | ||
constructor(element) { | ||
this.sortable_element.on("selectablestop", this.stopped_selecting) | ||
this.element = element | ||
} | ||
get stopped_selecting() { | ||
return () => { | ||
let selected_count = this.selected_elements.length | ||
if(selected_count > 0) { | ||
this.initialize_bulk() | ||
} else { | ||
this.element.hide() | ||
this.element.find("input[name=bulk_hint]").off("change") | ||
this.element.find("input[name=bulk_hint]").prop('checked', false) | ||
} | ||
} | ||
} | ||
|
||
initialize_bulk() { | ||
let master = this | ||
if(this.all_values_the_same(this.selected_viewing_hint_values)) { | ||
let selected_val = this.selected_viewing_hint_values[0] | ||
this.element.find(`input[name=bulk_hint][value="${selected_val}"]`).prop('checked', true) | ||
} | ||
this.element.find("input[name=bulk_hint]").on("change", function(event) { | ||
let val = $(this).val() | ||
master.selected_viewing_hints.prop("checked", false) | ||
master.selected_viewing_hints.filter(`*[value="${val}"]`).prop("checked", true).change() | ||
}) | ||
this.element.show() | ||
} | ||
|
||
get selected_elements() { | ||
return this.sortable_element.find("li .panel.ui-selected") | ||
} | ||
|
||
get selected_viewing_hints() { | ||
return this.selected_elements.find('input[name="file_set[viewing_hint]"]') | ||
} | ||
|
||
get selected_viewing_hint_values() { | ||
return this.selected_viewing_hints.filter(":checked").map(function() {return $(this).val()}).toArray() | ||
} | ||
|
||
get sortable_element() { | ||
return $("#order-grid") | ||
} | ||
|
||
all_values_the_same(array) { | ||
for(var i = 1; i < array.length; i++) | ||
{ | ||
if(array[i] !== array[0]) | ||
return false | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,9 @@ | |
#file-manager-extra-tools { | ||
@extend .clearfix; | ||
} | ||
#bulk-actions { | ||
h2 { | ||
margin-top: 0; | ||
} | ||
display: none; | ||
} |
1 change: 1 addition & 0 deletions
1
app/views/curation_concerns/base/_file_manager_actions.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<%= render "custom_file_manager_actions" %> | ||
<%= render "file_manager_bulk_form" %> | ||
<%= render "file_manager_resource_form" %> |
14 changes: 14 additions & 0 deletions
14
app/views/curation_concerns/base/_file_manager_bulk_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div id="bulk-actions" class="well"> | ||
<h2>Bulk Actions</h2> | ||
<label>Mark As:</label> | ||
<% hints = [["Single Page", :''], ["Non-Paged", :"non-paged"], ["Facing pages",:"facing-pages"]] %> | ||
<% hints.each do |label, val| %> | ||
<div class="radio"> | ||
<%= content_tag :label do %> | ||
<%= tag :input, name: "bulk_hint", id: "bulk_hint_#{val}", type: :radio, value: val, checked: false, class: 'resource-radio-button' %> | ||
<%= label %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<%# <%= f.input :viewing_hint, collection: [:"", :"non-paged", :"facing-pages"], as: :radio_buttons, label: false, defaults: { input_html: { class: '' }}%> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
BulkActionManager = require("file_manager/bulk_actions") | ||
describe "bulk actions manager", -> | ||
bulk_manager = null | ||
beforeEach -> | ||
loadFixtures("file_manager_three_children.html") | ||
bulk_manager = new BulkActionManager($("#bulk-actions")) | ||
describe "bulk panel display", -> | ||
it "is made to display when there are selected elements", -> | ||
spyOn(bulk_manager.element, "show") | ||
bulk_manager.sortable_element.find("li .panel").addClass("ui-selected") | ||
bulk_manager.sortable_element.trigger("selectablestop") | ||
expect(bulk_manager.element.show).toHaveBeenCalled() | ||
it "is hidden when there are no elements", -> | ||
spyOn(bulk_manager.element, "hide") | ||
bulk_manager.sortable_element.trigger("selectablestop") | ||
expect(bulk_manager.element.hide).toHaveBeenCalled() | ||
it "marks all selected elements' boxes when selected", -> | ||
bulk_manager.sortable_element.find("li .panel").addClass("ui-selected") | ||
bulk_manager.sortable_element.trigger("selectablestop") | ||
|
||
# Mark non-paged | ||
radio = $("#bulk-actions #bulk_hint_non-paged") | ||
radio.prop('checked', true) | ||
radio.change() | ||
|
||
expect(bulk_manager.selected_viewing_hint_values).toEqual(["non-paged","non-paged","non-paged"]) |
397 changes: 397 additions & 0 deletions
397
spec/javascripts/fixtures/file_manager_three_children.html
Large diffs are not rendered by default.
Oops, something went wrong.