123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore', '../../lib/@waca/dashboard-common/dist/ui/SearchableListView', '../../lib/@waca/core-client/js/core-client/i18n/Formatter'], function ($, _, BaseListView, Formatter) {
- var aORDER = ['no', 'asc', 'desc'];
- var View = null;
- /**
- * Extends base list view to provide search functionality within the list view.
- * If you extend this class you should implement the following methods
- * @see _getSearchableItems
- * @see _getSearchableFieldValue
- */
- View = BaseListView.extend({
- onSortClick: function onSortClick(event) {
- var $parent = $(event.target.parentElement);
- this.sortStateKey = $parent.data('role');
- var order = $parent.data('options').sort;
- this.sortStateOrder = this._getSortOrder(order);
- this._resetSortIcons();
- this._updateSortIcon($parent.find('.sortingIcon'), this.sortStateOrder);
- var sSearchInput = this._getSearchInputText();
- if (sSearchInput) {
- this.searchData(sSearchInput);
- } else {
- this._renderResultListItems(this._getSearchableItems());
- }
- },
- /**
- * Overridden method to provide a list of items that are searchable for this view
- */
- _getSearchableItems: function _getSearchableItems() {
- return this._listitems.slice();
- },
- /**
- * Overridden method to sort
- */
- _sortListItems: function _sortListItems(sortedItems) {
- var key = this.sortStateKey;
- var order = this.sortStateOrder;
- if (order === 'no') {
- return sortedItems;
- }
- sortedItems.sort(function (a, b) {
- var aValue = a[key].toLowerCase();
- var bValue = b[key].toLowerCase();
- return aValue < bValue ? -1 : aValue > bValue ? 1 : 0;
- });
- if (order === 'desc') {
- sortedItems.reverse();
- }
- return sortedItems;
- },
- _getSortOrder: function _getSortOrder(order) {
- var orderIndex = aORDER.indexOf(order);
- var sortOrderIndex = orderIndex + 1;
- if (sortOrderIndex === aORDER.length) {
- sortOrderIndex = 0;
- }
- return aORDER[sortOrderIndex];
- },
- prepareListItem: function prepareListItem(item) {
- var sDateTime = item['last-modified'] || item.lastModifiedDate;
- if (sDateTime) {
- var lastModifiedDateString = Formatter.formatDateTime(sDateTime, {
- type: 'date',
- formatLength: 'medium'
- });
- item.lastModified = lastModifiedDateString;
- }
- return item;
- },
- _resetSortIcons: function _resetSortIcons() {
- var sortIconHeaders = this.$el.find('.sortingIcon').removeClass().addClass('sortingIcon wfg_sorted_no');
- _.each(sortIconHeaders, function (header) {
- $(header).parent().data('options').sort = 'no';
- }.bind(this));
- },
- _updateSortIcon: function _updateSortIcon(target, sortOrder) {
- var $target = $(target);
- $target.removeClass('wfg_sorted_no').addClass('wfg_sorted_' + sortOrder);
- $target.parent().data('options').sort = sortOrder;
- }
- });
- return View;
- });
- //# sourceMappingURL=TableView.js.map
|