salix/modules/worker/front/index/index.js

55 lines
1.4 KiB
JavaScript

import ngModule from '../module';
export default class Controller {
constructor($) {
Object.assign(this, {
$,
selectedWorker: null,
include: [
{
relation: 'user',
scope: {fields: ['name', 'email']}
}, {
relation: 'client',
scope: {fields: ['fi']}
}, {
relation: 'department',
scope: {fields: ['department']}
}
]
});
}
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
: {or: [
{firstName: {like: `%${value}%`}},
{name: {like: `%${value}%`}}
]};
case 'name':
case 'firstName':
return {[param]: {like: `%${value}%`}};
case 'id':
return {[param]: value};
}
}
preview(event, worker) {
if (event.defaultPrevented) return;
event.preventDefault();
this.selectedWorker = worker;
this.$.preview.show();
event.stopImmediatePropagation();
}
}
Controller.$inject = ['$scope'];
ngModule.component('vnWorkerIndex', {
template: require('./index.html'),
controller: Controller
});