partkeepr

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

commit d66f0185af35014273a112fab44e1c7e5271a835
parent c2e6fa92f65e4470bb3150e5a1982a69253758c2
Author: Timo A. Hummel <felicitus@felicitus.org>
Date:   Mon, 14 Mar 2016 18:12:30 +0100

Merge pull request #617 from partkeepr/PartKeepr-593

Added dedicated save button, fixes #593
Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/FormattingPreferences.js | 220+++++++++++++++++++++++++++++++++++++------------------------------------------
1 file changed, 102 insertions(+), 118 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/FormattingPreferences.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/FormattingPreferences.js @@ -2,123 +2,108 @@ * Contains the formatting preferences for various places throughout the system */ Ext.define('PartKeepr.FormattingPreferencesPanel', { - extend: 'Ext.form.FormPanel', - title: i18n("Formatting"), - bodyStyle: 'background:#DBDBDB;padding: 10px;', - - /** - * Indicates that values are currently being loaded. This is a workaround because when we initially set the values - * for the fields below, we would actually trigger an immediate update. This can only be solved when the - * configuration framework gets a dedicated "save" button. - * - * @workaround - * @var boolean - */ - loading: true, - - initComponent: function () { - - this.createWidgets(); - this.loadDefaults(); - - - this.items = [ - this.priceNumDecimalsField, - this.useThousandSeparatorCheckbox, - this.currencySymbolField, - this.currencyAtEndCheckbox - ]; - - this.callParent(); - }, - /** - * Loads the defaults for the user preferences - * - * @param none - * @return nothing - */ - loadDefaults: function () { - var numDecimals = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.numdecimals", 2); - this.priceNumDecimalsField.setValue(numDecimals); - - var useThousandsSeparator = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.thousandsSeparator", true); - this.useThousandSeparatorCheckbox.setValue(useThousandsSeparator); - - - var currencyAtEnd = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.currencySymbolAtEnd", true); - this.currencyAtEndCheckbox.setValue(currencyAtEnd); - - var currencySymbol = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.symbol", "€"); - this.currencySymbolField.setValue(currencySymbol); - - this.loading = false; - }, - /** - * Creates the widgets used in this form. - * - * @param none - * @return nothing - * - */ - createWidgets: function () { - this.priceNumDecimalsField = Ext.create("Ext.form.field.Number", { - name: 'priceNumDecimalsField', - fieldLabel: i18n('Decimal precision'), - labelWidth: 120, - columnWidth: 0.5, - minValue: 0, - maxValue: 4, - allowDecimals: false, - listeners: { - change: function(field, newValue) { - if (!this.loading) { - PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.numdecimals", newValue); - } - }, - scope: this - } - }); - - this.useThousandSeparatorCheckbox = Ext.create("Ext.form.field.Checkbox", { - boxLabel: i18n("Separate thousands"), + extend: 'Ext.form.Panel', + title: i18n("Formatting"), + bodyStyle: 'background:#DBDBDB;padding: 10px;', + + buttonAlign: 'left', + + initComponent: function () + { + + this.createWidgets(); + this.loadDefaults(); + + + this.buttons = [ + { + text: i18n("Save"), + handler: "saveSettings", + scope: this + } + ]; + this.items = [ + this.priceNumDecimalsField, + this.useThousandSeparatorCheckbox, + this.currencySymbolField, + this.currencyAtEndCheckbox + ]; + + this.callParent(); + }, + saveSettings: function () + { + PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.numdecimals", + this.priceNumDecimalsField.getValue()); + + PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.thousandsSeparator", + this.useThousandSeparatorCheckbox.getValue()); + + PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.symbol", + this.currencySymbolField.getValue()); + + PartKeepr.getApplication().setUserPreference( + "partkeepr.formatting.currency.currencySymbolAtEnd", this.currencyAtEndCheckbox.getValue()); + + }, + /** + * Loads the defaults for the user preferences + * + * @param none + * @return nothing + */ + loadDefaults: function () + { + var numDecimals = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.numdecimals", 2); + this.priceNumDecimalsField.setValue(numDecimals); + + var useThousandsSeparator = PartKeepr.getApplication().getUserPreference( + "partkeepr.formatting.currency.thousandsSeparator", true); + this.useThousandSeparatorCheckbox.setValue(useThousandsSeparator); + + + var currencyAtEnd = PartKeepr.getApplication().getUserPreference( + "partkeepr.formatting.currency.currencySymbolAtEnd", true); + this.currencyAtEndCheckbox.setValue(currencyAtEnd); + + var currencySymbol = PartKeepr.getApplication().getUserPreference("partkeepr.formatting.currency.symbol", "€"); + this.currencySymbolField.setValue(currencySymbol); + }, + /** + * Creates the widgets used in this form. + * + * @param none + * @return nothing + * + */ + createWidgets: function () + { + this.priceNumDecimalsField = Ext.create("Ext.form.field.Number", { + name: 'priceNumDecimalsField', + fieldLabel: i18n('Decimal precision'), labelWidth: 120, - hideEmptyLabel: false, - listeners: { - change: function(field, newValue) { - if (!this.loading) { - PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.thousandsSeparator", newValue); - } - }, - scope: this - } - }); - - this.currencySymbolField = Ext.create("Ext.form.field.Text", { - fieldLabel: i18n("Currency Symbol"), + columnWidth: 0.5, + minValue: 0, + maxValue: 4, + allowDecimals: false + }); + + this.useThousandSeparatorCheckbox = Ext.create("Ext.form.field.Checkbox", { + boxLabel: i18n("Separate thousands"), + labelWidth: 120, + hideEmptyLabel: false + }); + + this.currencySymbolField = Ext.create("Ext.form.field.Text", { + fieldLabel: i18n("Currency Symbol"), labelWidth: 120, - maxLength: 5, - listeners: { - change: function(field, newValue) { - if (!this.loading) { - PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.symbol", newValue); - } - }, - scope: this - } - }); - - this.currencyAtEndCheckbox = Ext.create("Ext.form.field.Checkbox", { - boxLabel: i18n("Currency Symbol after value"), + maxLength: 5 + }); + + this.currencyAtEndCheckbox = Ext.create("Ext.form.field.Checkbox", { + boxLabel: i18n("Currency Symbol after value"), labelWidth: 120, - hideEmptyLabel: false, - listeners: { - change: function(field, newValue) { - if (!this.loading) { - PartKeepr.getApplication().setUserPreference("partkeepr.formatting.currency.currencySymbolAtEnd", newValue); - } - }, - scope: this - } - }); - } -});- \ No newline at end of file + hideEmptyLabel: false + }); + } +});