Added account picture upload
This commit is contained in:
parent
a2817436e0
commit
fc73151945
2 changed files with 44 additions and 9 deletions
|
@ -43,6 +43,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-block">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-3 form-control-label" for="file-input">Profile Picture</label>
|
||||||
|
<div class="col-md-9">
|
||||||
|
<input type="file" #fileInput formControlName="profile_picture">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div [ngSwitch]="accountType">
|
<div [ngSwitch]="accountType">
|
||||||
<div *ngSwitchCase="'organisation'">
|
<div *ngSwitchCase="'organisation'">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
|
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
|
||||||
import { Http, Response } from '@angular/http';
|
import { Http, Response } from '@angular/http';
|
||||||
import { ApiService } from '../providers/api-service';
|
import { ApiService } from '../providers/api-service';
|
||||||
|
@ -13,6 +13,7 @@ export class AccountEditComponent {
|
||||||
settingOrganisationForm: FormGroup;
|
settingOrganisationForm: FormGroup;
|
||||||
settingCustomerForm: FormGroup;
|
settingCustomerForm: FormGroup;
|
||||||
accountType: any;
|
accountType: any;
|
||||||
|
@ViewChild('fileInput') fileInput;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: Http,
|
private http: Http,
|
||||||
|
@ -20,10 +21,11 @@ export class AccountEditComponent {
|
||||||
private api: ApiService,
|
private api: ApiService,
|
||||||
) {
|
) {
|
||||||
this.settingForm = this.formBuilder.group({
|
this.settingForm = this.formBuilder.group({
|
||||||
email : ['', [Validators.required]],
|
email : ['', [Validators.required]],
|
||||||
postcode : ['', [Validators.required]],
|
postcode : ['', [Validators.required]],
|
||||||
password : ['', [Validators.required]],
|
password : ['', [Validators.required]],
|
||||||
new_password : [''],
|
new_password : [''],
|
||||||
|
profile_picture : [''],
|
||||||
});
|
});
|
||||||
this.settingOrganisationForm = this.formBuilder.group({
|
this.settingOrganisationForm = this.formBuilder.group({
|
||||||
name : ['', [Validators.required]],
|
name : ['', [Validators.required]],
|
||||||
|
@ -40,7 +42,7 @@ export class AccountEditComponent {
|
||||||
this.api.accountFullLoad().subscribe(
|
this.api.accountFullLoad().subscribe(
|
||||||
result => {
|
result => {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
this.settingForm.setValue({
|
this.settingForm.patchValue({
|
||||||
email: result.email,
|
email: result.email,
|
||||||
postcode: result.postcode,
|
postcode: result.postcode,
|
||||||
password: '',
|
password: '',
|
||||||
|
@ -73,8 +75,17 @@ export class AccountEditComponent {
|
||||||
|
|
||||||
let settingForm = this.settingForm.value;
|
let settingForm = this.settingForm.value;
|
||||||
let settingOrganisationForm = this.settingOrganisationForm.value;
|
let settingOrganisationForm = this.settingOrganisationForm.value;
|
||||||
|
|
||||||
let data = {
|
// image upload code
|
||||||
|
let fi = this.fileInput.nativeElement;
|
||||||
|
let data = new FormData();
|
||||||
|
|
||||||
|
if (fi.files && fi.files[0]) {
|
||||||
|
let fileToUpload = fi.files[0];
|
||||||
|
data.append("file", fileToUpload);
|
||||||
|
}
|
||||||
|
|
||||||
|
let submitData = {
|
||||||
email: settingForm.email,
|
email: settingForm.email,
|
||||||
postcode: settingForm.postcode,
|
postcode: settingForm.postcode,
|
||||||
password: settingForm.password,
|
password: settingForm.password,
|
||||||
|
@ -83,6 +94,10 @@ export class AccountEditComponent {
|
||||||
street_name: settingOrganisationForm.street_name,
|
street_name: settingOrganisationForm.street_name,
|
||||||
town: settingOrganisationForm.town,
|
town: settingOrganisationForm.town,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.append('form', JSON.stringify(submitData));
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
this.api
|
this.api
|
||||||
.accountEditUpdate(data)
|
.accountEditUpdate(data)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
@ -105,7 +120,16 @@ export class AccountEditComponent {
|
||||||
let settingForm = this.settingForm.value;
|
let settingForm = this.settingForm.value;
|
||||||
let settingCustomerForm = this.settingCustomerForm.value;
|
let settingCustomerForm = this.settingCustomerForm.value;
|
||||||
|
|
||||||
let data = {
|
// image upload code
|
||||||
|
let fi = this.fileInput.nativeElement;
|
||||||
|
let data = new FormData();
|
||||||
|
|
||||||
|
if (fi.files && fi.files[0]) {
|
||||||
|
let fileToUpload = fi.files[0];
|
||||||
|
data.append("file", fileToUpload);
|
||||||
|
}
|
||||||
|
|
||||||
|
let submitData = {
|
||||||
email: settingForm.email,
|
email: settingForm.email,
|
||||||
postcode: settingForm.postcode,
|
postcode: settingForm.postcode,
|
||||||
password: settingForm.password,
|
password: settingForm.password,
|
||||||
|
@ -113,6 +137,9 @@ export class AccountEditComponent {
|
||||||
full_name: settingCustomerForm.full_name,
|
full_name: settingCustomerForm.full_name,
|
||||||
display_name: settingCustomerForm.display_name,
|
display_name: settingCustomerForm.display_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.append('form', JSON.stringify(submitData));
|
||||||
|
|
||||||
this.api
|
this.api
|
||||||
.accountEditUpdate(data)
|
.accountEditUpdate(data)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
|
Reference in a new issue