2017-08-24 10:54:15 -04:00
|
|
|
/// <reference path="../../../typings/globals/jquery/index.d.ts" />
|
2016-12-02 13:00:55 -05:00
|
|
|
import { Component } from '@angular/core';
|
2017-01-21 00:15:00 -05:00
|
|
|
import { NavController, AlertController } from 'ionic-angular';
|
2016-12-02 13:00:55 -05:00
|
|
|
import { Storage } from '@ionic/storage';
|
2017-01-18 17:51:06 -05:00
|
|
|
import { SavedPage, UserProfile } from '../../libs/UserProfile';
|
2016-12-02 13:00:55 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'settings',
|
|
|
|
templateUrl: 'settings.html'
|
|
|
|
})
|
2016-12-27 21:10:00 -05:00
|
|
|
export class SettingsPage
|
|
|
|
{
|
2017-08-24 10:54:15 -04:00
|
|
|
textSize = 0;
|
2016-12-31 18:12:50 -05:00
|
|
|
userProfile: UserProfile;
|
2016-12-27 21:10:00 -05:00
|
|
|
|
2017-01-21 00:15:00 -05:00
|
|
|
constructor(
|
|
|
|
public navCtrl: NavController
|
|
|
|
, public local: Storage
|
|
|
|
, private alertCtrl: AlertController)
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile = new UserProfile(UserProfile.createDefaultUser());
|
|
|
|
|
2016-12-01 15:21:07 -05:00
|
|
|
// Check if there is a profile saved in local storage
|
2016-12-27 21:10:00 -05:00
|
|
|
this.local.get('profile').then(profile =>
|
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
let t = this.userProfile;
|
2016-12-28 15:57:16 -05:00
|
|
|
|
|
|
|
if (profile !== null)
|
|
|
|
t = JSON.parse(profile);
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.update(t, local);
|
2016-12-27 21:10:00 -05:00
|
|
|
}).catch(error =>
|
|
|
|
{
|
2016-12-01 15:21:07 -05:00
|
|
|
console.log(error);
|
2016-12-02 13:00:55 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
textSizeChanged()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.textSizeChanged();
|
|
|
|
this.save();
|
2016-12-02 13:00:55 -05:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
save()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.save(this.local);
|
2016-12-27 21:10:00 -05:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
reset()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.reset(this.local);
|
2016-12-02 13:00:55 -05:00
|
|
|
}
|
2017-01-18 17:51:06 -05:00
|
|
|
|
|
|
|
removePage(page: SavedPage)
|
|
|
|
{
|
2017-01-21 00:15:00 -05:00
|
|
|
let alert = this.alertCtrl.create({
|
|
|
|
title: 'Confirm Delete',
|
|
|
|
message: 'Do you want to delete the ' + page.title + ' page?',
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
text: 'Cancel',
|
|
|
|
role: 'cancel',
|
|
|
|
handler: () =>
|
|
|
|
{
|
|
|
|
console.log('Cancel clicked');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Ok',
|
|
|
|
handler: () =>
|
|
|
|
{
|
|
|
|
let idx = this.userProfile.user.saved_pages.indexOf(page);
|
|
|
|
this.userProfile.user.saved_pages.splice(idx, 1);
|
2017-01-18 17:51:06 -05:00
|
|
|
|
2017-01-21 00:15:00 -05:00
|
|
|
// save the users settings.
|
|
|
|
this.userProfile.save(this.local);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
alert.present();
|
2017-01-18 17:51:06 -05:00
|
|
|
}
|
2017-08-24 10:54:15 -04:00
|
|
|
}
|