mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Make the edit form and delete dialog work again
This commit is contained in:
@@ -10,17 +10,15 @@ import * as models from '../../../models/models';
|
|||||||
directives: [NgIf]
|
directives: [NgIf]
|
||||||
})
|
})
|
||||||
export class AlbumDeletePrompt {
|
export class AlbumDeletePrompt {
|
||||||
private modalElement: any;
|
|
||||||
public album: models.Album;
|
public album: models.Album;
|
||||||
|
|
||||||
constructor(@ng.Inject(ng.ElementRef) elementRef: ng.ElementRef) {
|
constructor(@ng.Inject(ng.ElementRef) private _elementRef: ng.ElementRef) {
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
this.modalElement = (<any>window).jQuery(".modal", elementRef.nativeElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public show(album: models.Album) {
|
public show(album: models.Album) {
|
||||||
this.album = album;
|
this.album = album;
|
||||||
this.modalElement.modal();
|
|
||||||
|
// Consider rewriting this using Angular 2's "Renderer" API so as to avoid direct DOM access
|
||||||
|
(<any>window).jQuery(".modal", this._elementRef.nativeElement).modal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
<h2>Album <small>Edit</small></h2>
|
<h2>Album <small>Edit</small></h2>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<form class="form-horizontal" [ngFormModel]="form" (ng-submit)="onSubmitModelBased()">
|
<form class="form-horizontal" [ngFormModel]="form" (ngSubmit)="onSubmitModelBased()">
|
||||||
<form-field label="Artist" [validate]="form.controls.ArtistId">
|
<form-field label="Artist" [validate]="form.controls.ArtistId">
|
||||||
<select class="form-control" ng-control="ArtistId">
|
<select class="form-control" ngControl="ArtistId">
|
||||||
<option value="0">-- choose Artist --</option>
|
<option value="0">-- choose Artist --</option>
|
||||||
<option *ngFor="#artist of artists" [value]="artist.ArtistId">{{ artist.Name }}</option>
|
<option *ngFor="#artist of artists" [value]="artist.ArtistId">{{ artist.Name }}</option>
|
||||||
</select>
|
</select>
|
||||||
</form-field>
|
</form-field>
|
||||||
|
|
||||||
<form-field label="Genre" [validate]="form.controls.GenreId">
|
<form-field label="Genre" [validate]="form.controls.GenreId">
|
||||||
<select class="form-control" ng-control="GenreId">
|
<select class="form-control" ngControl="GenreId">
|
||||||
<option value="0">-- choose Genre --</option>
|
<option value="0">-- choose Genre --</option>
|
||||||
<option *ngFor="#genre of genres" [value]="genre.GenreId">{{ genre.Name }}</option>
|
<option *ngFor="#genre of genres" [value]="genre.GenreId">{{ genre.Name }}</option>
|
||||||
</select>
|
</select>
|
||||||
</form-field>
|
</form-field>
|
||||||
|
|
||||||
<form-field label="Title" [validate]="form.controls.Title">
|
<form-field label="Title" [validate]="form.controls.Title">
|
||||||
<input class="form-control" type="text" ng-control="Title">
|
<input class="form-control" type="text" ngControl="Title">
|
||||||
</form-field>
|
</form-field>
|
||||||
|
|
||||||
<form-field label="Price" [validate]="form.controls.Price">
|
<form-field label="Price" [validate]="form.controls.Price">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon">$</span>
|
<span class="input-group-addon">$</span>
|
||||||
<input class="form-control" type="text" ng-control="Price">
|
<input class="form-control" type="text" ngControl="Price">
|
||||||
</div>
|
</div>
|
||||||
</form-field>
|
</form-field>
|
||||||
|
|
||||||
<form-field label="Album Art URL" [validate]="form.controls.AlbumArtUrl">
|
<form-field label="Album Art URL" [validate]="form.controls.AlbumArtUrl">
|
||||||
<input class="form-control" ng-control="AlbumArtUrl">
|
<input class="form-control" ngControl="AlbumArtUrl">
|
||||||
</form-field>
|
</form-field>
|
||||||
|
|
||||||
<form-field label="Album Art">
|
<form-field label="Album Art">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as ng from 'angular2/core';
|
import * as ng from 'angular2/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
import { Control, ControlGroup, FormBuilder, Validators, NgIf, NgFor, FORM_DIRECTIVES } from 'angular2/common';
|
import { Control, ControlGroup, FormBuilder, Validators, NgIf, NgFor, FORM_DIRECTIVES } from 'angular2/common';
|
||||||
import * as router from 'angular2/router';
|
import * as router from 'angular2/router';
|
||||||
import * as models from '../../../models/models';
|
import * as models from '../../../models/models';
|
||||||
@@ -20,6 +21,7 @@ export class AlbumEdit {
|
|||||||
public genres: models.Genre[];
|
public genres: models.Genre[];
|
||||||
public originalAlbum: models.Album;
|
public originalAlbum: models.Album;
|
||||||
public changesSaved: boolean;
|
public changesSaved: boolean;
|
||||||
|
public formErrors: string[] = [];
|
||||||
|
|
||||||
private _http: Http;
|
private _http: Http;
|
||||||
|
|
||||||
@@ -69,12 +71,10 @@ export class AlbumEdit {
|
|||||||
var controls = this.form.controls;
|
var controls = this.form.controls;
|
||||||
var albumId = this.originalAlbum.AlbumId;
|
var albumId = this.originalAlbum.AlbumId;
|
||||||
|
|
||||||
this._putJson(`/api/albums/${ albumId }/update`, this.form.value).subscribe(response => {
|
this._putJson(`/api/albums/${ albumId }/update`, this.form.value).subscribe(successResponse => {
|
||||||
if (response.status === 200) {
|
|
||||||
this.changesSaved = true;
|
this.changesSaved = true;
|
||||||
} else {
|
}, errorResponse => {
|
||||||
AspNet.Validation.showValidationErrors(response, this.form);
|
AspNet.Validation.showValidationErrors(errorResponse, this.form);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,18 +84,13 @@ export class AlbumEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Need feedback on whether this really is the easiest way to PUT some JSON
|
// Need feedback on whether this really is the easiest way to PUT some JSON
|
||||||
private _putJson(url: string, body: any): Subscribable<Response> {
|
private _putJson(url: string, body: any): Observable<Response> {
|
||||||
return this._http.put(url, JSON.stringify(body), {
|
return this._http.put(url, JSON.stringify(body), {
|
||||||
headers: new Headers({ 'Content-Type': 'application/json' })
|
headers: new Headers({ 'Content-Type': 'application/json' })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public get formErrors(): string[] {
|
private ngDoCheck() {
|
||||||
return this.form.dirty ? Object.keys(this.form.errors || {}) : [];
|
this.formErrors = this.form.dirty ? Object.keys(this.form.errors || {}) : [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Figure out what type declaration is provided by Angular/RxJs and use that instead
|
|
||||||
interface Subscribable<T> {
|
|
||||||
subscribe(callback: (response: Response) => void): void;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import { NgIf, NgFor, AbstractControl } from 'angular2/common';
|
|||||||
directives: [NgIf, NgFor]
|
directives: [NgIf, NgFor]
|
||||||
})
|
})
|
||||||
export class FormField {
|
export class FormField {
|
||||||
|
public errorMessages: string[] = [];
|
||||||
private validate: AbstractControl;
|
private validate: AbstractControl;
|
||||||
|
|
||||||
public get errorMessages() {
|
private ngDoCheck() {
|
||||||
var errors = (this.validate && this.validate.dirty && this.validate.errors) || {};
|
var errors = (this.validate && this.validate.dirty && this.validate.errors) || {};
|
||||||
return Object.keys(errors).map(key => {
|
this.errorMessages = Object.keys(errors).map(key => {
|
||||||
return 'Error: ' + key;
|
return 'Error: ' + key;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user