Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I go about implementing site settings into my Ember app?

Tags:

ember.js

I asked a question similar to this, here, specifically about how to implement specific settings for a specific controller. In short, I wanted to implement checkInSettings for the whole CheckInController so that my index, settings, and reports templates and controllers have access to the checkInSettings.

I did get my answer to that; however, I think that specific settings might be limiting and it would be better served by making a settings object or store, and defining something like settings.checkIn for the check in settings.

I've looked for resources online but haven't come up with many answers... So, how should I best go about creating application wide settings, with sub settings for specific areas of my app?

A note: I would like to refrain from using Ember Data since it is not Production Ready yet, and this app will eventually be consumer facing.

Thank you!

like image 805
josh Avatar asked Nov 11 '22 20:11

josh


1 Answers

Ember Data is a different beast. Store them on the application controller. Or if you don't want o clutter the application controller, create a singleton instance of a settings controller and store them there. (The same thing can be done just on the application controller, just use application instead of settings).

App.SettingsController = Ember.Controller.extend({
  someSettingOn: false,
  someOtherSetting: null
});

And then in other routes/controllers:

App.AnyRoute = Ember.Route.extend({
  anyMethod: function(){
    this.controllerFor('settings').toggleProperty('someSettingOn');
  }
})


App.AnyController = Ember.Controller.extend({
  needs: ['settings'],
  anyMethod: function(){
    var setting = this.get('controllers.settings.someOtherSetting');
    console.log(setting);
  },
  anyProperty: function(){
    if(this.get('controllers.settings.someSettingOn')){
        return 'yes';
    }
    return 'no';
  }.property('controllers.settings.someSettingOn')
})
like image 52
Kingpin2k Avatar answered Jan 04 '23 02:01

Kingpin2k