salix/modules/order/front/catalog/index.js

129 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-07-24 07:35:23 +00:00
import ngModule from '../module';
2018-09-14 07:10:30 +00:00
import './style.scss';
2018-07-24 07:35:23 +00:00
class Controller {
2018-10-31 13:56:54 +00:00
constructor($scope, $state) {
2018-07-24 07:35:23 +00:00
this.$scope = $scope;
this.$state = $state;
2018-10-31 13:56:54 +00:00
// Static autocomplete data
this.wayList = [
{way: 'ASC', name: 'Ascendant'},
{way: 'DESC', name: 'Descendant'},
2018-09-14 07:10:30 +00:00
];
2018-10-31 13:56:54 +00:00
this.defaultFieldList = [
{field: 'relevancy DESC, name', name: 'Name'},
{field: 'price', name: 'Price'}
];
this.fieldList = [];
this.fieldList = this.fieldList.concat(this.defaultFieldList);
this._way = this.wayList[0].way;
this._field = this.fieldList[0].field;
2018-07-24 07:35:23 +00:00
}
2018-10-31 13:56:54 +00:00
/**
* Fills order autocomplete with tags
* obtained from last filtered
*/
onDataChange() {
const items = this.$scope.model.data;
if (!items) return;
this.fieldList = [];
this.fieldList = this.fieldList.concat(this.defaultFieldList);
items.forEach(item => {
item.tags.forEach(itemTag => {
const alreadyAdded = this.fieldList.find(order => {
return order.field == itemTag.tagFk;
});
if (!alreadyAdded)
this.fieldList.push({
name: itemTag.name,
field: itemTag.tagFk,
isTag: true
});
});
});
2018-07-24 07:35:23 +00:00
}
2018-10-31 13:56:54 +00:00
/**
* Get order way ASC/DESC
*/
get way() {
return this._way;
2018-07-24 07:35:23 +00:00
}
2018-10-31 13:56:54 +00:00
set way(value) {
this._way = value;
if (value)
this.applyOrder();
}
/**
* Get order fields
*/
get field() {
return this._field;
}
set field(value) {
this._field = value;
if (value)
this.applyOrder();
}
/**
* Returns order param
*
* @return {Object} - Order param
*/
getOrderBy() {
let field = this.$scope.field;
let args = {
field: this.field,
way: this.way
};
if (field.selection && field.selection.isTag)
args.isTag = true;
return args;
}
/**
* Apply order to model
*/
applyOrder() {
this.$scope.model.addFilter(null, {orderBy: this.getOrderBy()});
2018-07-24 07:35:23 +00:00
}
2018-08-21 11:38:16 +00:00
preview(event, item) {
event.preventDefault();
this.$scope.pricesPopover.show(event, item);
}
onDescriptorLoad() {
this.$scope.popover.relocate();
}
$onChanges() {
2018-10-31 13:56:54 +00:00
if (this.order && this.order.isConfirmed)
this.$state.go('order.card.line');
}
2018-07-24 07:35:23 +00:00
}
2018-10-31 13:56:54 +00:00
Controller.$inject = ['$scope', '$state'];
2018-07-24 07:35:23 +00:00
2018-08-21 11:38:16 +00:00
ngModule.component('vnOrderCatalog', {
2018-07-24 07:35:23 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
2018-10-31 13:56:54 +00:00
order: '<',
},
2018-07-24 07:35:23 +00:00
});