| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #docplaster
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | import {Component, Input, Output, EventEmitter} from 'angular2/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {Hero} from './hero'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let nextHeroDetailId = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // #docregion input-output-2
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  | // #enddocregion input-output-2
 | 
					
						
							|  |  |  |   selector: 'hero-detail', | 
					
						
							|  |  |  |   // #docregion input-output-2
 | 
					
						
							|  |  |  |   inputs: ['hero'], | 
					
						
							|  |  |  |   outputs: ['deleted'], | 
					
						
							|  |  |  |   // #enddocregion input-output-2
 | 
					
						
							|  |  |  |   template: `
 | 
					
						
							| 
									
										
										
										
											2016-01-27 18:54:33 -08:00
										 |  |  |   <div> | 
					
						
							|  |  |  |     <span [style.text-decoration]="lineThrough" >{{hero?.fullName}}</span> | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |     <img src="{{heroImageUrl}}" style="height:24px"> | 
					
						
							| 
									
										
										
										
											2016-01-27 18:54:33 -08:00
										 |  |  |     <a (click)="onDelete()">delete</a> | 
					
						
							|  |  |  |   </div>`,
 | 
					
						
							|  |  |  |     styles:['a { cursor: pointer; cursor: hand; }'] | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | // #docregion input-output-2
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | // #enddocregion input-output-2
 | 
					
						
							|  |  |  | export class HeroDetailComponent { | 
					
						
							| 
									
										
										
										
											2016-01-27 18:54:33 -08:00
										 |  |  |   constructor() { | 
					
						
							|  |  |  |     // Toggle the line-through style so we see something happen
 | 
					
						
							|  |  |  |     // even if no one attaches to the `deleted` event.
 | 
					
						
							|  |  |  |     // Subscribing in ctor rather than the more obvious thing of doing it in
 | 
					
						
							|  |  |  |     // OnDelete because don't want this mess to distract the chapter reader.
 | 
					
						
							|  |  |  |     this.deleted.subscribe(() => { | 
					
						
							|  |  |  |       this.lineThrough = this.lineThrough ? '' : 'line-through'; | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | // #docregion deleted
 | 
					
						
							|  |  |  |   deleted = new EventEmitter<Hero>(); | 
					
						
							|  |  |  |   onDelete() { | 
					
						
							|  |  |  |     this.deleted.emit(this.hero); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | // #enddocregion
 | 
					
						
							| 
									
										
										
										
											2016-01-27 18:54:33 -08:00
										 |  |  |    | 
					
						
							|  |  |  |   hero: Hero = new Hero('','Zzzzzzzz'); // default sleeping hero
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |   // heroImageUrl = 'http://www.wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png';
 | 
					
						
							|  |  |  |   // Public Domain terms of use: http://www.wpclipart.com/terms.html
 | 
					
						
							|  |  |  |   heroImageUrl = 'images/hero.png'; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:54:33 -08:00
										 |  |  |   lineThrough = '';   | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'big-hero-detail', | 
					
						
							|  |  |  |   template: `
 | 
					
						
							|  |  |  |   <div style="border: 1px solid black; padding:3px"> | 
					
						
							|  |  |  |     <img src="{{heroImageUrl}}" style="float:left; margin-right:8px;"> | 
					
						
							|  |  |  |     <div><b>{{hero?.fullName}}</b></div> | 
					
						
							|  |  |  |     <div>First: {{hero?.firstName}}</div> | 
					
						
							|  |  |  |     <div>Last: {{hero?.lastName}}</div> | 
					
						
							|  |  |  |     <div>Birthdate: {{hero?.birthdate | date:'longDate'}}</div> | 
					
						
							|  |  |  |     <div>Web: <a href="{{hero?.url}}" target="_blank">{{hero?.url}}</a></div> | 
					
						
							|  |  |  |     <div>Rate/hr: {{hero?.rate | currency:'EUR'}}</div> | 
					
						
							|  |  |  |     <br clear="all"> | 
					
						
							|  |  |  |     <button (click)="onDelete()">Delete</button> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  |   `
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class BigHeroDetailComponent extends HeroDetailComponent { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // #docregion input-output-1
 | 
					
						
							|  |  |  |   @Input()  hero: Hero; | 
					
						
							|  |  |  |   @Output() deleted = new EventEmitter<Hero>(); | 
					
						
							|  |  |  |   // #enddocregion input-output-1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onDelete() { | 
					
						
							|  |  |  |     this.deleted.emit(this.hero); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |