Skip to content

Commit

Permalink
fixed #25-Selectbutton for primeng
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtcndkn committed Feb 2, 2016
1 parent f4fbe45 commit bc3dbf5
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 14 deletions.
85 changes: 85 additions & 0 deletions components/selectbutton/selectbutton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/// <reference path="../../typedefinition/primeui.d.ts" />

import {Component, ElementRef, AfterViewInit, OnDestroy, OnChanges, Input, Output, SimpleChange, EventEmitter} from 'angular2/core';
import {SelectItem} from '../api/selectitem';

@Component({
selector: 'p-selectbutton',
template: `
<div class="pui-selectbutton pui-buttonset ui-widget ui-corner-all pui-buttonset-3">
<div *ngFor="#choice of choices;" class="pui-button ui-widget ui-state-default pui-button-text-only" [attr.data-value]="choice.value">
<span class="pui-button-text ui-c">{{choice.label}}</span>
</div>
</div>
`
})
export class Selectbutton {

initialized: boolean;

@Input() choices: SelectItem[];

@Input() formfield: string;

@Input() unselectable: boolean;

@Input() tabindex: number;

@Input() multiple: boolean;

@Input() style: string;

@Input() styleClass: string;

@Input() value: any;

@Output() valueChange: EventEmitter<any> = new EventEmitter();

@Output() onChange: EventEmitter<any> = new EventEmitter();

constructor(private el: ElementRef) {
this.initialized = false;
}

ngAfterViewInit() {
jQuery(this.el.nativeElement.children[0]).puiselectbutton({
value: this.value,
unselectable: this.unselectable,
tabindex : this.tabindex,
formfield: this.formfield,
multiple: this.multiple,
enhanced: true,
style: this.style,
styleClass: this.styleClass,
change: (event: Event, ui: PrimeUI.SelectbuttonEventParams) => {
this.onChange.next({ originalEvent: event, value: ui.value });
if (this.multiple) {
var values: any = [];
for (var i = 0; i < ui.index.length; i++) {
values.push(this.choices[ui.index[i]].value);
this.valueChange.next(values);
}

}
else {
this.valueChange.next(this.choices[ui.index].value);
}
}
});
this.initialized = true;
}

ngOnChanges(changes: { [key: string]: SimpleChange }) {
if (this.initialized) {
for (var key in changes) {
jQuery(this.el.nativeElement.children[0]).puiselectbutton('option', key, changes[key].currentValue);
}
}
}

ngOnDestroy() {
jQuery(this.el.nativeElement.children[0]).puiselectbutton('destroy');
this.initialized = false;
}

}
1 change: 1 addition & 0 deletions showcase/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<a class="SubMenuLink" [routerLink]="['RadioButtonDemo']" (click)="mobileMenuActive = false">&#9679; RadioButton</a>
<a class="SubMenuLink" [routerLink]="['RatingDemo']" (click)="mobileMenuActive = false">&#9679; Rating</a>
<a class="SubMenuLink" [routerLink]="['SpinnerDemo']" (click)="mobileMenuActive = false">&#9679; Spinner</a>
<a class="SubMenuLink" [routerLink]="['SelectbuttonDemo']" (click)="mobileMenuActive = false">&#9679; SelectButton</a>
<a class="SubMenuLink" [routerLink]="['ToggleButtonDemo']" (click)="mobileMenuActive = false">&#9679; ToggleButton</a>
</div>

Expand Down
4 changes: 3 additions & 1 deletion showcase/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {MessagesDemoComponent} from './demo/messages/messagesdemo.component';
import {GrowlDemoComponent} from './demo/growl/growldemo.component';
import {CarouselDemoComponent} from './demo/carousel/carouseldemo.component';
import {InputSwitchDemoComponent} from './demo/inputswitch/inputswitchdemo.component';
import {SelectbuttonDemoComponent} from './demo/selectbutton/selectbuttondemo.component';

@Component({
selector: 'primeng-showcase',
Expand Down Expand Up @@ -54,7 +55,8 @@ import {InputSwitchDemoComponent} from './demo/inputswitch/inputswitchdemo.compo
{path: '/messages', name: 'MessagesDemo', component: MessagesDemoComponent},
{path: '/growl', name: 'GrowlDemo', component: GrowlDemoComponent},
{path: '/carousel', name: 'CarouselDemo', component: CarouselDemoComponent},
{path: '/inputswitch', name: 'InputSwitchDemo', component: InputSwitchDemoComponent}
{path: '/inputswitch', name: 'InputSwitchDemo', component: InputSwitchDemoComponent},
{path: '/selectbutton', name: 'SelectbuttonDemo', component: SelectbuttonDemoComponent}
])
export class AppComponent {

Expand Down
169 changes: 169 additions & 0 deletions showcase/demo/selectbutton/selectbuttondemo.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<div class="ContentSideSections">
<div class="Content100 overHidden TextShadow">
<span class="fontSize30 TextShadow orange mediumFont marginBottom20 dispBlock">SelectButton</span>
<span class="defaultText dispTable">SelectButton is used to choose single or multiple items from a list using buttons.</span>
</div>
</div>

<div class="ContentSideSections Implementation">
<h3 class="first">Single</h3>
<p-selectbutton [choices]="teams" [(value)]="selectedTeam"></p-selectbutton>

<p>Selected Team: {{selectedTeam}}</p>

<h3>Multiple</h3>
<p-selectbutton [choices]="teams" [(value)]="selectedTeams" multiple="multiple"></p-selectbutton>

<p>Selected Teams: {{selectedTeams}} </p>

<h3>Preselect</h3>
<p-selectbutton [choices]="cars" [(value)]="selectedCar" style="width:190px"></p-selectbutton>
<p>Select Car: {{selectedCar}}</p>

<button type="button" (click)="selectedCar=null" pButton icon="fa-close">Clear Selected Car</button>
</div>

<div class="ContentSideSections Source">
<p-tabView effect="fade">
<p-tabPanel header="Documentation">
<h3>Import</h3>
<pre>
import {Panel} from 'primeng/primeng';
</pre>

<h3>Getting Started</h3>
<p>Panel is defined with p-panel element.</p>
<pre>
&lt;p-panel header="Title"&gt;
Content
&lt;/p-panel&gt;
</pre>
<h3>Toggleable</h3>
<p>Content of the panel can be expanded and collapsed using toggleable option. Duration of the toggle effect
is customized with toggleDuration and default state is defined with collapsed option. Orientation is "vertical" by default
and other possible value is "horizontal".</p>
<pre>
&lt;p-panel header="Title" toggleable="true"&gt;
Content
&lt;/p-panel&gt;
</pre>

<h3>Attributes</h3>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>header</td>
<td>string</td>
<td>null</td>
<td>Header text of the panel.</td>
</tr>
<tr>
<td>toggleable</td>
<td>boolean</td>
<td>false</td>
<td>Defines if content of panel can be expanded and collapsed.</td>
</tr>
<tr>
<td>toggleDuration</td>
<td>any</td>
<td>normal</td>
<td>Duration of the effect in milliseconds or pre-defined values like "slow","normal" and "fast".</td>
</tr>
<tr>
<td>toggleOrientation</td>
<td>string</td>
<td>vertical</td>
<td>Defines orientation of toggle direction, valid values are "vertical" and "horizontal".</td>
</tr>
<tr>
<td>collapsed</td>
<td>boolean</td>
<td>false</td>
<td>When specified, displays the panel as collapsed initially.</td>
</tr>
<tr>
<td>closable</td>
<td>boolean</td>
<td>false</td>
<td>Defines if panel can be hidden using close option.</td>
</tr>
<tr>
<td>closeDuration</td>
<td>any</td>
<td>normal</td>
<td>Duration of the effect in milliseconds or pre-defined values like "slow","normal" and "fast".</td>
</tr>
</tbody>
</table>
</div>

<h3>Events</h3>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>onBeforeCollapse</td>
<td>event: Toggle event</td>
<td>Callback to invoke before content is collapsed.</td>
</tr>
<tr>
<td>onAfterCollapse</td>
<td>event: Toggle event</td>
<td>Callback to invoke after content is collapsed.</td>
</tr>
<tr>
<td>onBeforeExpand</td>
<td>event: Toggle event</td>
<td>Callback to invoke before content is expanded.</td>
</tr>
<tr>
<td>onAfterExpand</td>
<td>event: Toggle event</td>
<td>Callback to invoke after content is expanded.</td>
</tr>
<tr>
<td>onBeforeClose</td>
<td>event: Toggle event</td>
<td>Callback to invoke before panel is closed.</td>
</tr>
<tr>
<td>onAfterClose</td>
<td>event: Toggle event</td>
<td>Callback to invoke after panel is closed.</td>
</tr>
</tbody>
</table>
</div>

<h3>Dependencies</h3>
<p>jQuery, jQuery UI WidgetFactory API, PrimeUI Panel.</p>
</p-tabPanel>

<p-tabPanel header="Source">
<pre>
&lt;p-panel header="Godfather I" toggleable="true"&gt;
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
&lt;/p-panel&gt;
</pre>
</p-tabPanel>
</p-tabView>
</div>
43 changes: 43 additions & 0 deletions showcase/demo/selectbutton/selectbuttondemo.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {Component} from 'angular2/core';
import {Selectbutton} from '../../../components/selectbutton/selectbutton';
import {TabView} from '../../../components/tabview/tabview';
import {TabPanel} from '../../../components/tabview/tabpanel';
import {Button} from '../../../components/button/button';
import {SelectItem} from '../../../components/api/selectitem';
import {ROUTER_DIRECTIVES} from 'angular2/router';

@Component({
templateUrl: 'showcase/demo/selectbutton/selectbuttondemo.component.html',
directives: [Selectbutton, TabPanel, TabView, Button, ROUTER_DIRECTIVES]
})
export class SelectbuttonDemoComponent {

teams: SelectItem[];

selectedTeam: string;

selectedTeams: string[];

cars: SelectItem[];

selectedCar: string = 'BMW';

constructor() {
this.teams = [];
this.teams.push({label: 'Barcelona', value: 'Barcelona'});
this.teams.push({label: 'Real Madrid', value: 'Real Madrid'});
this.teams.push({label: 'Bayern Munich', value: 'Bayern Munich'});

this.cars = [];
this.cars.push({ label: 'Audi', value: 'Audi' });
this.cars.push({ label: 'BMW', value: 'BMW' });
this.cars.push({ label: 'Fiat', value: 'Fiat' });
this.cars.push({ label: 'Ford', value: 'Ford' });
this.cars.push({ label: 'Honda', value: 'Honda' });
this.cars.push({ label: 'Jaguar', value: 'Jaguar' });
this.cars.push({ label: 'Mercedes', value: 'Mercedes' });
this.cars.push({ label: 'Renault', value: 'Renault' });
this.cars.push({ label: 'Volkswagen', value: 'Volkswagen' });
this.cars.push({ label: 'Volvo', value: 'Volvo' });
}
}
Loading

0 comments on commit bc3dbf5

Please sign in to comment.