partkeepr

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

FormattingConfiguration.js (3300B)


      1 Ext.define('PartKeepr.Components.UserPreferences.Preferences.FormattingConfiguration', {
      2     extend: 'PartKeepr.Components.Preferences.PreferenceEditor',
      3 
      4     initComponent: function ()
      5     {
      6         this.createWidgets();
      7         this.loadDefaults();
      8 
      9         this.items = [
     10             this.priceNumDecimalsField,
     11             this.useThousandSeparatorCheckbox,
     12             this.currencySymbolField,
     13             this.currencyAtEndCheckbox
     14         ];
     15 
     16 
     17         this.callParent();
     18     },
     19     /**
     20      * Loads the defaults for the user preferences
     21      */
     22     loadDefaults: function ()
     23     {
     24         var numDecimals = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.numdecimals", 2);
     25         this.priceNumDecimalsField.setValue(numDecimals);
     26 
     27         var useThousandsSeparator = PartKeepr.getApplication().getUserPreference(
     28             "partkeepr.formatting.currency.thousandsSeparator", true);
     29         this.useThousandSeparatorCheckbox.setValue(useThousandsSeparator);
     30 
     31 
     32         var currencyAtEnd = PartKeepr.getApplication().getUserPreference(
     33             "partkeepr.formatting.currency.currencySymbolAtEnd", true);
     34         this.currencyAtEndCheckbox.setValue(currencyAtEnd);
     35 
     36         var currencySymbol = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.symbol", "€");
     37         this.currencySymbolField.setValue(currencySymbol);
     38     },
     39 
     40     /**
     41      * Creates the widgets used in this form.
     42      */
     43     createWidgets: function ()
     44     {
     45         this.priceNumDecimalsField = Ext.create("Ext.form.field.Number", {
     46             name: 'priceNumDecimalsField',
     47             fieldLabel: i18n('Decimal precision'),
     48             labelWidth: 120,
     49             columnWidth: 0.5,
     50             minValue: 0,
     51             maxValue: 4,
     52             allowDecimals: false
     53         });
     54 
     55         this.useThousandSeparatorCheckbox = Ext.create("Ext.form.field.Checkbox", {
     56             boxLabel: i18n("Separate thousands"),
     57             labelWidth: 120,
     58             hideEmptyLabel: false
     59         });
     60 
     61         this.currencySymbolField = Ext.create("Ext.form.field.Text", {
     62             fieldLabel: i18n("Currency Symbol"),
     63             labelWidth: 120,
     64             maxLength: 5
     65         });
     66 
     67         this.currencyAtEndCheckbox = Ext.create("Ext.form.field.Checkbox", {
     68             boxLabel: i18n("Currency Symbol after value"),
     69             labelWidth: 120,
     70             hideEmptyLabel: false
     71         });
     72     },
     73     
     74     onSave: function ()
     75     {
     76         PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.numdecimals",
     77             this.priceNumDecimalsField.getValue());
     78 
     79         PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.thousandsSeparator",
     80             this.useThousandSeparatorCheckbox.getValue());
     81 
     82         PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.symbol",
     83             this.currencySymbolField.getValue());
     84 
     85         PartKeepr.getApplication().setUserPreference(
     86             "partkeepr.formatting.currency.currencySymbolAtEnd", this.currencyAtEndCheckbox.getValue());
     87     },
     88     statics: {
     89         iconCls: 'fugue-icon ui-text-field-format',
     90         title: i18n('Formatting'),
     91         menuPath: [{iconCls: 'fugue-icon ui-scroll-pane-image', text: i18n("User Interface")}]
     92     }
     93 });