67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
import ngModule from '../module';
|
|
import SearchPanel from 'core/components/searchbar/search-panel';
|
|
|
|
class Controller extends SearchPanel {
|
|
constructor($scope) {
|
|
super();
|
|
this.$ = $scope;
|
|
this.moreFields = [
|
|
{field: 'id'},
|
|
{field: 'description'},
|
|
{field: 'name'}
|
|
];
|
|
}
|
|
|
|
initializeMoreFields() {
|
|
if (!this.$.filter.moreFields || !this.$.filter.moreFields.length)
|
|
this.$.filter.moreFields = [{}];
|
|
}
|
|
|
|
set filter(value) {
|
|
if (!value)
|
|
value = {};
|
|
if (!value.tags)
|
|
value.tags = [{}];
|
|
|
|
this.$.filter = value;
|
|
}
|
|
|
|
get itemTypes() {
|
|
if (this.$.filter) {
|
|
if (!this.$.filter.categoryFk)
|
|
return '/item/api/ItemTypes';
|
|
return `/item/api/ItemCategories/${this.$.filter.categoryFk}/itemTypes`;
|
|
}
|
|
}
|
|
|
|
get filter() {
|
|
if (this.$.filter.moreFields) {
|
|
this.$.filter.moreFields.forEach(element => {
|
|
this.$.filter[element.field] = element.value;
|
|
});
|
|
}
|
|
let filter = Object.assign({}, this.$.filter);
|
|
delete filter.moreFields;
|
|
return filter;
|
|
}
|
|
|
|
getSourceTable(selection) {
|
|
if (!selection || selection.isFree === true)
|
|
return null;
|
|
|
|
if (selection.sourceTable) {
|
|
return '/api/'
|
|
+ selection.sourceTable.charAt(0).toUpperCase()
|
|
+ selection.sourceTable.substring(1) + 's';
|
|
} else if (selection.sourceTable == null)
|
|
return `/api/ItemTags/filterItemTags/${selection.id}`;
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope'];
|
|
|
|
ngModule.component('vnItemSearchPanel', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|