This commit is contained in:
Tim Lancina
2015-08-31 10:24:37 -05:00
parent a288b9bc0b
commit 43cc8ecf91
2 changed files with 53 additions and 14 deletions

View File

@ -5,7 +5,9 @@ import {Ion} from '../ion';
import {IonicConfig} from '../../config/config'; import {IonicConfig} from '../../config/config';
import {IonicComponent, IonicView} from '../../config/annotations'; import {IonicComponent, IonicView} from '../../config/annotations';
/**
* TODO
*/
@IonicComponent({ @IonicComponent({
selector: 'ion-search-bar', selector: 'ion-search-bar',
properties: [ properties: [
@ -27,12 +29,17 @@ import {IonicComponent, IonicView} from '../../config/annotations';
<button class="search-bar-cancel">{{cancelText}}</button>` <button class="search-bar-cancel">{{cancelText}}</button>`
}) })
export class SearchBar extends Ion { export class SearchBar extends Ion {
/**
* TODO
* @param {ElementRef} elementRef TODO
* @param {IonicConfig} config TODO
*/
constructor( constructor(
elementRef: ElementRef, elementRef: ElementRef,
ionicConfig: IonicConfig//, config: IonicConfig//,
//cd:ControlDirective //cd:ControlDirective
) { ) {
super(elementRef, ionicConfig); super(elementRef, config);
// this.controlDirective = cd; // this.controlDirective = cd;
// cd.valueAccessor = this; //ControlDirective should inject CheckboxControlDirective // cd.valueAccessor = this; //ControlDirective should inject CheckboxControlDirective
@ -87,4 +94,3 @@ export class SearchPipe extends Pipe {
} }
} }
*/ */

View File

@ -7,7 +7,9 @@ import {IonicConfig} from '../../config/config';
import {IonicDirective, IonicComponent} from '../../config/annotations' import {IonicDirective, IonicComponent} from '../../config/annotations'
import {dom} from 'ionic/util'; import {dom} from 'ionic/util';
/**
* TODO
*/
@IonicComponent({ @IonicComponent({
selector: 'ion-segment', selector: 'ion-segment',
appInjector: [ NgControl ], appInjector: [ NgControl ],
@ -33,8 +35,15 @@ import {dom} from 'ionic/util';
directives: [forwardRef(() => SegmentButton)] directives: [forwardRef(() => SegmentButton)]
}) })
export class Segment extends Ion { export class Segment extends Ion {
/**
* TODO
* @param {NgControl} ngControl TODO
* @param {ElementRef} elementRef TODO
* @param {IonicConfig} config TODO
* @param {Renderer} renderer TODO
*/
constructor( constructor(
cd: NgControl, ngControl: NgControl,
elementRef: ElementRef, elementRef: ElementRef,
ionicConfig: IonicConfig, ionicConfig: IonicConfig,
renderer: Renderer renderer: Renderer
@ -48,7 +57,7 @@ export class Segment extends Ion {
this.change = new EventEmitter('change'); this.change = new EventEmitter('change');
this.input = new EventEmitter('input'); this.input = new EventEmitter('input');
this.cd = cd; this.ngControl = ngControl;
this.buttons = []; this.buttons = [];
} }
@ -56,6 +65,7 @@ export class Segment extends Ion {
/** /**
* Called by child SegmentButtons to bind themselves to * Called by child SegmentButtons to bind themselves to
* the Segment. * the Segment.
* @param {SegmentButton} segmentButton The child SegmentButton to register.
*/ */
register(segmentButton) { register(segmentButton) {
this.buttons.push(segmentButton); this.buttons.push(segmentButton);
@ -69,6 +79,7 @@ export class Segment extends Ion {
/** /**
* Select the button with the given value. * Select the button with the given value.
* @param {string} value Value of the button to select.
*/ */
selectFromValue(value) { selectFromValue(value) {
for(let button of this.buttons) { for(let button of this.buttons) {
@ -80,6 +91,7 @@ export class Segment extends Ion {
/** /**
* Indicate a button should be selected. * Indicate a button should be selected.
* @param {SegmentButton} segmentButton The button to select.
*/ */
selected(segmentButton) { selected(segmentButton) {
for(let button of this.buttons) { for(let button of this.buttons) {
@ -92,10 +104,10 @@ export class Segment extends Ion {
setTimeout(() => { setTimeout(() => {
this.value = segmentButton.value; this.value = segmentButton.value;
this.cd.valueAccessor.writeValue(segmentButton.value); this.ngControl.valueAccessor.writeValue(segmentButton.value);
this.selectFromValue(segmentButton.value); this.selectFromValue(segmentButton.value);
this.cd.control.updateValue(segmentButton.value); this.ngControl.control.updateValue(segmentButton.value);
// Trigger on change // Trigger on change
this.change.next(); this.change.next();
@ -108,7 +120,9 @@ export class Segment extends Ion {
} }
} }
/**
* TODO
*/
@IonicDirective({ @IonicDirective({
selector: 'ion-segment', selector: 'ion-segment',
//properties: ['value'], //properties: ['value'],
@ -128,15 +142,27 @@ export class Segment extends Ion {
} }
}) })
export class SegmentControlValueAccessor { export class SegmentControlValueAccessor {
constructor(cd: NgControl, renderer: Renderer, elementRef: ElementRef, segment: Segment) { /**
* TODO
* @param {NgControl} ngControl TODO
* @param {Renderer} renderer TODO
* @param {ElementRef} elementRef TODO
* @param {Segment} segment TODO
*/
constructor(
ngControl: NgControl,
renderer: Renderer,
elementRef: ElementRef,
segment: Segment
) {
this.onChange = (_) => {}; this.onChange = (_) => {};
this.onTouched = (_) => {}; this.onTouched = (_) => {};
this.cd = cd; this.ngControl = ngControl;
this.renderer = renderer; this.renderer = renderer;
this.elementRef = elementRef; this.elementRef = elementRef;
this.segment = segment; this.segment = segment;
cd.valueAccessor = this; ngControl.valueAccessor = this;
} }
writeValue(value) { writeValue(value) {
@ -155,7 +181,9 @@ export class SegmentControlValueAccessor {
registerOnTouched(fn) { this.onTouched = fn; } registerOnTouched(fn) { this.onTouched = fn; }
} }
/**
* TODO
*/
@IonicDirective({ @IonicDirective({
selector: 'ion-segment-button', selector: 'ion-segment-button',
properties: [ properties: [
@ -167,6 +195,11 @@ export class SegmentControlValueAccessor {
} }
}) })
export class SegmentButton { export class SegmentButton {
/**
* TODO
* @param {Segment} segment TODO
* @param {ElementRef} elementRef TODO
*/
constructor( constructor(
@Host() segment: Segment, @Host() segment: Segment,
elementRef: ElementRef elementRef: ElementRef