Skip to content

Commit

Permalink
liferay#1268 - Emit event when item per page change and mock the pagi…
Browse files Browse the repository at this point in the history
…nation events
  • Loading branch information
marco-leo committed Oct 29, 2018
1 parent 6e6588f commit 5879c2a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
36 changes: 34 additions & 2 deletions packages/clay-pagination-bar/src/ClayPaginationBar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'clay-dropdown';
import 'clay-pagination';
import {Config} from 'metal-state';
import Component from 'metal-component';
import ClayComponent from 'clay-component';
import defineWebComponent from 'metal-web-component';
import Soy from 'metal-soy';

Expand All @@ -11,7 +11,39 @@ import templates from './ClayPaginationBar.soy.js';
* Metal ClayPaginationBar component.
* @extends Component
*/
class ClayPaginationBar extends Component {}
class ClayPaginationBar extends ClayComponent {
/**
* Continues the propagation of the page clicked event
* @param {!Event} event
* @protected
* @return {Boolean} If the event has been prevented or not.
*/
_handlePageClick(event) {
return !this.emit({
data: {
page: event.data.page,
},
name: 'pageClicked',
originalEvent: event,
});
}

/**
* Continues the propagation of the item per page clicked event
* @param {!Event} event
* @protected
* @return {Boolean} If the event has been prevented or not.
*/
_handleItemsPerPageClicked(event) {
return !this.emit({
data: {
item: event.data.item,
},
name: 'itemsPerPageClicked',
originalEvent: event,
});
}
}

/**
* State definition.
Expand Down
9 changes: 7 additions & 2 deletions packages/clay-pagination-bar/src/ClayPaginationBar.soy
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* This renders the component's whole content.
*/
{template .render}
{@param? _handleItemsPerPageClicked: any}
{@param? _handlePageClick: any}
{@param currentPage: int}
{@param entries: list<[
href: string,
label: int
label: int,
itemsPerPage: int
]>}
{@param selectedEntry: int}
{@param spritemap: string}
Expand Down Expand Up @@ -41,6 +44,7 @@

{call ClayDropdown.render}
{param elementClasses: 'pagination-items-per-page' /}
{param events: ['itemClicked': $_handleItemsPerPageClicked] /}
{param items: $entries /}
{param label: $selectedEntryLabel /}
{param spritemap: $spritemap /}
Expand All @@ -52,13 +56,14 @@
{let $lastShowingEntry: $currentPage * $selectedEntryItem.label < $totalEntries ? $currentPage * $selectedEntryItem.label : $totalEntries /}

{msg desc="Says which range of pages of the total are being showed"}
showing-{$firstShowingEntry}-to-{$lastShowingEntry}of-{$totalEntries}-entries
showing-{$firstShowingEntry}-to-{$lastShowingEntry}-of-{$totalEntries}-entries
{/msg}
</div>

{call ClayPagination.render}
{param baseHref: $baseHref /}
{param currentPage: $currentPage /}
{param events: ['pageClicked': $_handlePageClick] /}
{param spritemap: $spritemap /}
{param totalPages: ceiling($totalEntries / $selectedEntryItem.label) /}
{/call}
Expand Down

0 comments on commit 5879c2a

Please sign in to comment.