-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Flavio Costa
committed
Feb 26, 2017
1 parent
e15889f
commit e103ba9
Showing
12 changed files
with
123 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<ActionBar title="Book" icon="" class="action-bar"> | ||
</ActionBar> | ||
<StackLayout class="form"> | ||
<StackLayout class="input-field" > | ||
<StackLayout orientation="vertical" class="form-book"> | ||
<TextField [(ngModel)]="model.name" hint="name" class="input-active" ></TextField> | ||
<validator property="name" [listErrors]="listErrors"></validator> | ||
<TextField [(ngModel)]="model.author" hint="author" class="input-active" secure="true"></TextField> | ||
<validator property="author" [listErrors]="listErrors"></validator> | ||
<TextField [(ngModel)]="model.pages" hint="pages" class="input-active" secure="true"></TextField> | ||
<validator property="pages" [listErrors]="listErrors"></validator> | ||
<Button text="Save" (tap)="validate()" class="btn-simple"></Button> | ||
</StackLayout> | ||
</StackLayout> | ||
</StackLayout> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Book } from '../../model/book'; | ||
import { ValidationError, validate } from 'class-validator'; | ||
import { BasicComponent } from '../shared/basic-component'; | ||
import { Login } from '../../model/login'; | ||
var dialogs = require("ui/dialogs"); | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'book', | ||
templateUrl: './book.component.html' | ||
}) | ||
|
||
export class BookComponent extends BasicComponent<Book> { | ||
|
||
constructor() { | ||
super(new Book()); | ||
} | ||
|
||
afterValidate() { | ||
super.message("Save OK"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ValidationError, validate } from 'class-validator'; | ||
import { OnInit } from '@angular/core'; | ||
var dialogs = require("ui/dialogs"); | ||
import { BasicModel} from "../../model/basic-model"; | ||
|
||
|
||
export abstract class BasicComponent<T extends BasicModel> { | ||
|
||
model: T; | ||
|
||
listErrors: Array<ValidationError> = []; | ||
|
||
constructor(arg: T) { | ||
this.model = arg; | ||
} | ||
|
||
validate() { | ||
try { | ||
validate(this.model).then(errors => { | ||
if (errors.length > 0) { | ||
this.listErrors = errors; | ||
} else { | ||
this.listErrors = []; | ||
this.afterValidate(); | ||
} | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
||
afterValidate() { | ||
|
||
} | ||
|
||
message(message: string) { | ||
dialogs.alert(message).then(function () { | ||
console.log(message); | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export abstract class BasicModel { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ValidateIf, IsNotEmpty, IsEmail, IsEmailOptions, ValidateNested } from "class-validator"; | ||
import { BasicModel} from "./basic-model"; | ||
|
||
export class Book extends BasicModel { | ||
|
||
@IsNotEmpty({message:"Name is required"}) | ||
name: string; | ||
|
||
@IsNotEmpty({message:"Author is required"}) | ||
author: string; | ||
|
||
@IsNotEmpty({message:"Pages is required"}) | ||
pages: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.