import Ember from 'ember';

export default Ember.Controller.extend({
  session: Ember.inject.controller(),
  user: Ember.inject.controller('session'),

  isLoading: true,
  filterParams: {},
  searchParams: undefined,
  params: {},

  actions: {
    search: function () {
      var searchTerm = this.get('searchTerm');
      var params = searchTerm ? {navn: '~' + searchTerm} : undefined;
      this.set('searchParams', params); // Will trigger refresh with search params or filter if undefined
    }
  },

  onParamsChange: function () {
    var params = this.get('params');
    this.store.unloadAll('cabin');
    this.set('isLoading', true);
    this.store.query('cabin', params).then((cabins) => {
      this.set('model', cabins);
    });

  }.observes('params'),

  onFilterParamsChange: function () {
    this.set('params', this.get('filterParams'));
  }.observes('filterParams'),

  onSearchParamsChange: function () {
    this.set('params', this.get('searchParams') || this.get('filterParams'));
  }.observes('searchParams'),

  queryIsFilter: Ember.computed('params', {
    get: function () {
      var params = this.get('params');
      var queryIsFilter = (params && (params['privat.vedlikeholdes_av'] || params['privat.juridisk_eier'])) ? true : false;
      return queryIsFilter;
    }
  }),

  queryIsSearch: Ember.computed('params', {
    get: function () {
      return !!this.get('params.navn');
    }
  }),

  onModelChange: function () {
    this.set('isLoading', false);
  }.observes('model')
});

@@ -563,24 +563,30 @@
 et('params')
+ %7C%7C %7B%7D
 ;%0A    this.s
@@ -643,16 +643,65 @@
  true);%0A
+    Ember.set(params, 'fields', 'navn,grupper');%0A
     this

Include field grupper to be able to know wether user should be allowed to access this cabin or not