Sha256: 75d90107276dbf8494adfba175d0a711e3e65d125a3b80e897f5fc246de0d225

Contents?: true

Size: 1.07 KB

Versions: 57

Compression:

Stored size: 1.07 KB

Contents

$.fn.alchemyPageSelect = function (options) {
  var pageTemplate = HandlebarsTemplates.page

  return this.select2({
    placeholder: options.placeholder,
    allowClear: options.hasOwnProperty("allowClear")
      ? options.allowClear
      : true,
    minimumInputLength: 3,
    initSelection: function (_$el, callback) {
      if (options.initialSelection) {
        callback(options.initialSelection)
      }
    },
    ajax: {
      url: options.url,
      datatype: "json",
      quietMillis: 300,
      data: function (term, page) {
        return {
          q: $.extend(
            {
              name_cont: term
            },
            options.query_params
          ),
          page: page
        }
      },
      results: function (data) {
        var meta = data.meta

        return {
          results: data.pages,
          more: meta.page * meta.per_page < meta.total_count
        }
      }
    },
    formatSelection: function (page) {
      return page.text || page.name
    },
    formatResult: function (page) {
      return pageTemplate({ page: page })
    }
  })
}

Version data entries

57 entries across 57 versions & 1 rubygems

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