partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

PreferencePlugin.js (1400B)


      1 Ext.define('PartKeepr.Components.Widgets.PreferencePlugin', {
      2     extend: 'Ext.plugin.Abstract',
      3     alias: 'plugin.preference',
      4 
      5     /**
      6      * @var {String} Specifies the preference key to bind the component to.
      7      */
      8     preferenceKey: null,
      9 
     10     /**
     11      * @var {String} Specifies if the preference is a system or user preference. Allowed values are "system" or "user".
     12      */
     13     preferenceScope: "system",
     14 
     15     preferenceDefault: null,
     16 
     17     pluginId: 'preference',
     18 
     19     init: function (cmp)
     20     {
     21         this.setCmp(cmp);
     22 
     23         cmp.on("beforerender", this.loadPreference, this);
     24     },
     25     loadPreference: function ()
     26     {
     27         if (this.preferenceScope === "system")
     28         {
     29             this.getCmp().setValue(
     30                 PartKeepr.getApplication().getSystemPreference(this.preferenceKey, this.preferenceDefault)
     31             );
     32         } else
     33         {
     34             this.getCmp().setValue(
     35                 PartKeepr.getApplication().getUserPreference(this.preferenceKey, this.preferenceDefault)
     36             );
     37         }
     38     },
     39     savePreference: function ()
     40     {
     41         if (this.preferenceScope === "system")
     42         {
     43             PartKeepr.getApplication().setSystemPreference(this.preferenceKey, this.getCmp().getValue());
     44         } else
     45         {
     46             PartKeepr.getApplication().setUserPreference(this.preferenceKey, this.getCmp().getValue());
     47         }
     48     }
     49 });