Sha256: eea556eeb760e20d8786208fdcbef853fa2bfc25c578cd43e80afd53e8842ad3

Contents?: true

Size: 1.01 KB

Versions: 107

Compression:

Stored size: 1.01 KB

Contents

$.fn.alchemyNodeSelect = function (options) {
  var renderNodeTemplate = function (node) {
    return HandlebarsTemplates.node({ node: node })
  }
  var queryParamsFromTerm = function (term) {
    return {
      filter: Object.assign(
        { name_or_page_name_cont: term },
        options.query_params
      )
    }
  }
  var resultsFromResponse = function (response) {
    var meta = response.meta
    var data = response.data
    var more = meta.page * meta.per_page < meta.total_count
    return { results: data, more: more }
  }

  return this.select2({
    placeholder: options.placeholder,
    allowClear: true,
    minimumInputLength: 3,
    initSelection: function (_$el, callback) {
      if (options.initialSelection) {
        callback(options.initialSelection)
      }
    },
    ajax: {
      url: options.url,
      datatype: "json",
      quietMillis: 300,
      data: queryParamsFromTerm,
      results: resultsFromResponse
    },
    formatSelection: renderNodeTemplate,
    formatResult: renderNodeTemplate
  })
}

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
alchemy_cms-7.0.15 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-6.1.10 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.14 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.13 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.12 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.11 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.10 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.9 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.8 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.7 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.6 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.5 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.4 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.3 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-6.1.9 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.2 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-6.1.8 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-6.1.7 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.1 app/assets/javascripts/alchemy/node_select.js
alchemy_cms-7.0.0 app/assets/javascripts/alchemy/node_select.js