@state = new State
isContext: true,
contextQuery: @getContextQuery()
+ contextComponentUuid: window.config.resource
contextComponentName: window.config.resourceName
contextComponentQualifier: window.config.resourceQualifier
@updateContextFacets()
class extends CustomValuesFacet
getUrl: ->
- "#{baseUrl}/api/resources/search?f=s2&q=TRK&display_uuid=true"
+ q = @options.app.state.get 'contextComponentQualifier'
+ if q == 'VW' || q == 'SVW'
+ "#{baseUrl}/api/components/search"
+ else
+ "#{baseUrl}/api/resources/search?f=s2&q=TRK&display_uuid=true"
+
+
+ prepareSearch: ->
+ q = @options.app.state.get 'contextComponentQualifier'
+ if q == 'VW' || q == 'SVW'
+ @prepareSearchForViews()
+ else super
+
+
+ prepareSearchForViews: ->
+ componentUuid = this.options.app.state.get 'contextComponentUuid'
+ @$('.js-custom-value').select2
+ placeholder: 'Search...'
+ minimumInputLength: 2
+ allowClear: false
+ formatNoMatches: -> t 'select2.noMatches'
+ formatSearching: -> t 'select2.searching'
+ formatInputTooShort: -> tp 'select2.tooShort', 2
+ width: '100%'
+ ajax:
+ quietMillis: 300
+ url: @getUrl()
+ data: (term, page) ->
+ q: term
+ componentUuid: componentUuid
+ p: page
+ ps: 25
+ results: (data) ->
+ more: data.p * data.ps < data.total,
+ results: data.components.map (c) -> id: c.uuid, text: c.name
getValuesWithLabels: ->