ng-jhipster
Version:
A Jhipster util library for Angular 2
56 lines (55 loc) • 2.07 kB
JavaScript
import { Directive, Input, Output, Renderer, EventEmitter, ElementRef } from '@angular/core';
import { ConfigHelper } from '../helper';
export var JhiSortDirective = (function () {
function JhiSortDirective(el, renderer) {
this.sortIcon = 'fa-sort';
this.sortAscIcon = 'fa-sort-asc';
this.sortDescIcon = 'fa-sort-desc';
this.sortIconSelector = 'span.fa';
this.predicateChange = new EventEmitter();
this.ascendingChange = new EventEmitter();
this.element = el.nativeElement;
var config = ConfigHelper.getConfig();
this.sortIcon = config.sortIconSelector;
this.sortAscIcon = config.sortAscIcon;
this.sortDescIcon = config.sortDescIcon;
this.sortIconSelector = config.sortIconSelector;
}
JhiSortDirective.prototype.sort = function (field) {
this.resetClasses();
if (field !== this.predicate) {
this.ascending = true;
}
else {
this.ascending = !this.ascending;
}
this.predicate = field;
this.predicateChange.emit(field);
this.ascendingChange.emit(this.ascending);
this.callback();
};
JhiSortDirective.prototype.resetClasses = function () {
var allThIcons = this.element.querySelectorAll(this.sortIconSelector)[0];
allThIcons.classList.remove(this.sortAscIcon + ' ' + this.sortDescIcon);
allThIcons.classList.add(this.sortIcon);
};
;
JhiSortDirective.decorators = [
{ type: Directive, args: [{
selector: '[jhiSort]'
},] },
];
/** @nocollapse */
JhiSortDirective.ctorParameters = function () { return [
{ type: ElementRef, },
{ type: Renderer, },
]; };
JhiSortDirective.propDecorators = {
'predicate': [{ type: Input },],
'ascending': [{ type: Input },],
'callback': [{ type: Input },],
'predicateChange': [{ type: Output },],
'ascendingChange': [{ type: Output },],
};
return JhiSortDirective;
}());