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.
This allows scanned resources' FileSets to be re-ordered via JQuery-UI Sortable.
- Loading branch information
Trey Terrell
committed
Nov 3, 2015
1 parent
a3e4067
commit 6f332d4
Showing
13 changed files
with
310 additions
and
66 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
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
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,71 @@ | ||
jQuery -> | ||
window.sort_manager = new SortManager | ||
class Flash | ||
constructor: -> | ||
@element = $("*[data-reorder-action='flash']") | ||
@element.children(".close").click => | ||
@element.hide() | ||
reset_type: -> | ||
@element.removeClass("alert-success") | ||
@element.removeClass("alert-danger") | ||
set: (type, message) -> | ||
this.reset_type() | ||
@element.addClass("alert-#{type}") | ||
@element.children(".text").text(message) | ||
@element.show() | ||
@element.removeClass("hidden") | ||
class SortManager | ||
constructor: -> | ||
@element = $("#sortable") | ||
@sorting_info = {} | ||
@sorting_actions = [] | ||
this.initialize_sort() | ||
this.initialize_persist_button() | ||
this.initialize_flash() | ||
initialize_sort: -> | ||
@element.sortable() | ||
@element.disableSelection() | ||
@element.on("sortstop", this.stopped_sorting) | ||
@element.on("sortstart", this.started_sorting) | ||
initialize_persist_button: -> | ||
@persist_button = $("*[data-reorder-action='persist']") | ||
@persist_button.click(this.persist_ordering) | ||
initialize_flash: -> | ||
@flash = new Flash | ||
started_sorting: (event, ui) => | ||
@sorting_element = $(ui.item) | ||
@sorting_info.start = this.get_sort_position(ui.item) | ||
window.sorting_element = $(ui.item) | ||
stopped_sorting: (event, ui) => | ||
@sorting_info.end = this.get_sort_position($(ui.item)) | ||
return if @sorting_info.end == @sorting_info.start | ||
@persist_button.removeClass("disabled") | ||
get_sort_position: (item) -> | ||
@element.children().index(item) | ||
get_order: -> | ||
$("*[data-reorder-id]").map(-> | ||
$(this).data("reorder-id") | ||
).toArray() | ||
persist_ordering: (event) => | ||
event.preventDefault() | ||
return if @persisting == true | ||
@persisting = true | ||
console.log("Persisting Reordering") | ||
@persist_button.addClass("disabled") | ||
@persist_button.data("old-text", @persist_button.text()) | ||
@persist_button.text("Saving...") | ||
order = this.get_order() | ||
$.post("/concern/scanned_resources/#{@element.data("id")}/reorder.json", {order: order}).done( (data) => | ||
@sorting_actions = [] | ||
if data.message? | ||
@flash.set('success', data.message) | ||
).always( => | ||
@persist_button.text(@persist_button.data("old-text")) | ||
@persisting = false | ||
).fail( (data, message) => | ||
if data?.message? | ||
@flash.set('danger', data.message) | ||
else | ||
@flash.set('danger', "Unable to save new order.") | ||
@persist_button.removeClass("disabled") | ||
) |
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ | |
@import 'components/positioning'; | ||
|
||
@import "components/viewer"; | ||
@import "jquery-ui/sortable" |
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
Oops, something went wrong.