1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-19 20:51:35 +01:00

save button for options

This commit is contained in:
Kyle Spearrin 2018-06-26 09:04:12 -04:00
parent 28f4ed9144
commit ce3b4cd817
3 changed files with 38 additions and 32 deletions

View File

@ -2,23 +2,28 @@
<h1>{{'options' | i18n}}</h1> <h1>{{'options' | i18n}}</h1>
</div> </div>
<p>{{'optionsDesc' | i18n}}</p> <p>{{'optionsDesc' | i18n}}</p>
<div class="row"> <form (ngSubmit)="submit()" ngNativeValidate>
<div class="col-6"> <div class="row">
<div class="form-group"> <div class="col-6">
<label for="locale">{{'language' | i18n}}</label> <div class="form-group">
<select id="locale" name="Locale" [(ngModel)]="locale" (change)="saveLocale()" class="form-control"> <label for="locale">{{'language' | i18n}}</label>
<option *ngFor="let o of localeOptions" [ngValue]="o.value">{{o.name}}</option> <select id="locale" name="Locale" [(ngModel)]="locale" class="form-control">
</select> <option *ngFor="let o of localeOptions" [ngValue]="o.value">{{o.name}}</option>
<small class="form-text text-muted">{{'languageDesc' | i18n}}</small> </select>
<small class="form-text text-muted">{{'languageDesc' | i18n}}</small>
</div>
</div> </div>
</div> </div>
</div> <div class="form-group">
<div class="form-group"> <div class="form-check">
<div class="form-check"> <input class="form-check-input" type="checkbox" id="disableIcons" name="DisableIcons" [(ngModel)]="disableIcons">
<input class="form-check-input" type="checkbox" id="disableIcons" name="DisableIcons" [(ngModel)]="disableIcons" (change)="saveIcons()"> <label class="form-check-label" for="disableIcons">
<label class="form-check-label" for="disableIcons"> {{'disableIcons' | i18n}}
{{'disableIcons' | i18n}} </label>
</label> </div>
<small class="form-text text-muted">{{'disableIconsDesc' | i18n}}</small>
</div> </div>
<small class="form-text text-muted">{{'disableIconsDesc' | i18n}}</small> <button type="submit" class="btn btn-primary" appBlurClick>
</div> {{'save' | i18n}}
</button>
</form>

View File

@ -3,6 +3,7 @@ import {
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
@ -20,8 +21,11 @@ export class OptionsComponent implements OnInit {
locale: string; locale: string;
localeOptions: any[]; localeOptions: any[];
private startingLocale: string;
constructor(private storageService: StorageService, private stateService: StateService, constructor(private storageService: StorageService, private stateService: StateService,
private analytics: Angulartics2, i18nService: I18nService) { private analytics: Angulartics2, private i18nService: I18nService,
private toasterService: ToasterService) {
this.localeOptions = [{ name: i18nService.t('default'), value: null }]; this.localeOptions = [{ name: i18nService.t('default'), value: null }];
i18nService.supportedTranslationLocales.forEach((locale) => { i18nService.supportedTranslationLocales.forEach((locale) => {
this.localeOptions.push({ name: locale, value: locale }); this.localeOptions.push({ name: locale, value: locale });
@ -30,24 +34,18 @@ export class OptionsComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.disableIcons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); this.disableIcons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
this.locale = await this.storageService.get<string>(ConstantsService.localeKey); this.locale = this.startingLocale = await this.storageService.get<string>(ConstantsService.localeKey);
} }
async saveIcons() { async submit() {
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableIcons); await this.storageService.save(ConstantsService.disableFaviconKey, this.disableIcons);
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableIcons); await this.stateService.save(ConstantsService.disableFaviconKey, this.disableIcons);
this.callAnalytics('Website Icons', !this.disableIcons);
}
async saveLocale() {
await this.storageService.save(ConstantsService.localeKey, this.locale); await this.storageService.save(ConstantsService.localeKey, this.locale);
this.analytics.eventTrack.next({ action: 'Set Locale ' + this.locale }); this.analytics.eventTrack.next({ action: 'Saved Options' });
window.location.reload(); if (this.locale !== this.startingLocale) {
window.location.reload();
} else {
this.toasterService.popAsync('success', null, this.i18nService.t('optionsUpdated'));
}
} }
private callAnalytics(name: string, enabled: boolean) {
const status = enabled ? 'Enabled' : 'Disabled';
this.analytics.eventTrack.next({ action: `${status} ${name}` });
}
} }

View File

@ -900,6 +900,9 @@
"optionsDesc": { "optionsDesc": {
"message": "Customize your web vault experience." "message": "Customize your web vault experience."
}, },
"optionsUpdated": {
"message": "Options updated"
},
"language": { "language": {
"message": "Language" "message": "Language"
}, },