Sha256: b548dc0a0aabe791d6f41e103c25ccb79ca47aee0a56dcd48cd957b2c1b6e18f

Contents?: true

Size: 1.99 KB

Versions: 25

Compression:

Stored size: 1.99 KB

Contents

{
  Blacklight.onLoad(function() {
    window.new_sort_manager = new SortManager
  })

  class SortManager {
    constructor() {
      this.element = $("#sortable")
      this.sorting_info = {}
      this.initialize_sort()
      this.element.data("current-order", this.order)
      this.save_manager = window.save_manager
    }

    initialize_sort() {
      this.element.sortable({handle: ".panel-heading"})
      this.element.disableSelection()
      this.element.on("sortstop", this.stopped_sorting)
      this.element.on("sortstart", this.started_sorting)
    }

    persist() {
      let params = {}
      params[this.singular_class_name] = {
        "ordered_member_ids": this.order
      }
      params["_method"] = "PATCH"
      let persisting = $.post(
        `/concern/${this.class_name}/${this.id}`,
        params
      ).done(() => {
        this.element.data("current-order", this.order)
      })
      return persisting
    }

    get_sort_position(item) {
      return this.element.children().index(item)
    }

    get stopped_sorting() {
      return (event, ui) => {
        this.sorting_info.end = this.get_sort_position($(ui.item))
        if(this.sorting_info.end == this.sorting_info.start) {
          return
        }
        if(this.order.toString() != this.element.data("current-order").toString()) {
          this.save_manager.push_changed(this)
        } else {
          this.save_manager.mark_unchanged(this)
        }
      }
    }

    get started_sorting() {
      return (event, ui) => {
        this.sorting_element = $(ui.item)
        this.sorting_info.start = this.get_sort_position(ui.item)
      }
    }

    get id() {
      return this.element.data("id")
    }

    get class_name() {
      return this.element.data("class-name")
    }

    get singular_class_name() {
      return this.element.data("singular-class-name")
    }

    get order() {
      return $("*[data-reorder-id]").map(
        function() {
          return $(this).data("reorder-id")
        }
      ).toArray()
    }
  }
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
curation_concerns-1.0.0.beta3 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-1.0.0.beta2 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-1.0.0.beta1 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.14.0 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.14.0.pre4 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.14.0.pre3 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.14.0.pre2 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.14.0.pre1 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.13.1 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.13.0 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre9 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre8 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre7 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre6 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre5 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre4 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre3 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre2 app/assets/javascripts/curation_concerns/file_manager/sorting.es6
curation_concerns-0.12.0.pre1 app/assets/javascripts/curation_concerns/file_manager/sorting.es6