Sha256: a869735c57cf65913f84c0d1ff8fe43ed0aee6ae90814c2c772636853fbfbe87

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

Locomotive.Views.Shared ||= {}
Locomotive.Views.Shared.Fields ||= {}

class Locomotive.Views.Shared.Fields.RelationshipView extends Backbone.View

  enable_select2: (element, options) ->
    options ||= {}
    options.init_selection_fn ||= (element, callback) -> null

    element.select2
      width:                '50%'
      minimumInputLength:   1
      quietMillis:          100
      allowClear:           true
      placeholder:          ' '
      initSelection: options.init_selection_fn
      ajax:
        url: options.url
        data: (term, page) ->
          q:    term
          page: page
        results: (data, page) =>
          results:  @build_results(data, options.groupBy)
          more:     data.length == options.perPage

  build_results: (raw_data, group_by) ->
    _.tap [], (list) =>
      _.each raw_data, (data) =>
        if !@collection? || !@collection.get(data._id)?
          data.text = data._label

          if group_by?
            group_name = _.result(data, group_by)

            # does the group exist?
            group = _.find list, (_group) -> _group.text == group_name

            unless group?
              # build a new group
              group = { text: group_name, children: [] }
              list.push(group)

            group.children.push(data)
          else
            list.push(data)

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.6 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.6.rc2 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.6.rc1 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.5 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.4 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.3 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.2 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.1 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.0 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.0.rc3 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.0.rc2 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.5.0.rc1 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.4.1 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee
locomotive_cms-2.4.0 app/assets/javascripts/locomotive/views/shared/fields/_relationship_view.js.coffee