App = new Marionette.Application
- App.getQuery = (includeFacetsQuery = true) ->
- query = @filterBarView.getQuery()
- if includeFacetsQuery and @codingRulesFacetsView
- _.extend query, @codingRulesFacetsView.getQuery()
- query
+ App.getQuery = ->
+ @filterBarView.getQuery()
App.restoreSorting = (params) ->
- App.fetchList = (firstPage, fromFacets = false) ->
- pristineQuery = @getQuery(false)
- query = @getQuery(fromFacets)
+ App.fetchList = (firstPage) ->
+ query = @getQuery()
- fetchQuery = _.extend { p: @pageIndex, ps: 25, facets: not fromFacets }, query
+ fetchQuery = _.extend { p: @pageIndex, ps: 25, facets: firstPage }, query
if @codingRules.sorting && @codingRules.sorting.sort
_.extend fetchQuery,
s: @codingRules.sorting.sort,
asc: @codingRules.sorting.asc
- @storeQuery pristineQuery, @codingRules.sorting
+ @storeQuery query, @codingRules.sorting
# Optimize requested fields
_.extend fetchQuery, f: 'name,lang,status,tags,sysTags'
scrollOffset = 0
@layout.showSpinner 'resultsRegion'
- @layout.showSpinner 'facetsRegion' unless fromFacets || !firstPage
+ @layout.showSpinner 'facetsRegion' if firstPage
jQuery.ajax
else
@codingRulesListView.selectCurrent()
- unless firstPage
- jQuery('.navigator-results')[0].scrollTop = scrollOffset
-
- unless fromFacets
+ if firstPage
@codingRulesFacetsView = new CodingRulesFacetsView
app: @
collection: new Backbone.Collection r.facets, comparator: 'property'
@layout.facetsRegion.show @codingRulesFacetsView
+ @filterBarView.restoreFromWsQuery query
+ @codingRulesFacetsView.restoreFromQuery query
+ else
+ jQuery('.navigator-results')[0].scrollTop = scrollOffset
@layout.onResize()
App.facetPropertyToLabels[property](value)
- App.fetchFirstPage = (fromFacets = false) ->
+ App.fetchFirstPage = ->
@pageIndex = 1
- App.fetchList true, fromFacets
+ App.fetchList true
- App.fetchNextPage = (fromFacets = true) ->
+ App.fetchNextPage = ->
if @pageIndex < @codingRules.paging.pages
@pageIndex++
- App.fetchList false, fromFacets
+ App.fetchList false
App.getQualityProfile = ->
selectOption: (e) ->
option = jQuery(e.currentTarget)
option.toggleClass 'active'
+ property = option.closest('.navigator-facets-list-item').data('property')
+ value = option.data('key')
+ @options.app.filterBarView.toggle(property, value)
@applyOptions()
applyOptions: ->
- @options.app.fetchFirstPage true
+ @options.app.fetchFirstPage()
- getQuery: ->
- q = {}
- if @ui.facets.each
- @ui.facets.each ->
- property = jQuery(@).data 'property'
- activeOptions = jQuery(@).find('.active').map(-> jQuery(@).data 'key').get()
- q[property] = activeOptions.join ',' if activeOptions.length > 0
- q
+ restoreFromQuery: (params) ->
+ @ui.options.each ->
+ jQuery(@).removeClass('active')
+ @ui.facets.each ->
+ property = jQuery(@).data 'property'
+ if !!params[property]
+ _(params[property].split(',')).map (value) ->
+ jQuery('.navigator-facets-list-item[data-property="' + property + '"] .navigator-facets-list-item-option[data-key="' + value + '"]').addClass 'active'
fetchNextPage: ->
@options.app.fetchNextPage()
+
+
+ restoreFromWsQuery: (query) ->
+ params = _.map(query, (value, key) ->
+ 'key': key
+ 'value': value
+ )
+ @restoreFromQuery params
+
+
+ toggle: (property, value) ->
+ filter = @collection.findWhere(property: property)
+ unless filter.view.isActive()
+ @moreCriteriaFilter.view.detailsView.enableByProperty(property)
+ choice = filter.view.choices.get(value)
+ choice.set 'checked', !choice.get('checked')
+ filter.view.detailsView.updateValue()
+ filter.view.detailsView.updateLists()