salix/modules/client/front/notification/index.js

121 lines
3.1 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.$checkAll = false;
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
field: 'socialName',
autocomplete: {
url: 'Clients',
showField: 'socialName',
valueField: 'socialName'
}
},
{
field: 'city',
autocomplete: {
url: 'Towns',
valueField: 'name',
showField: 'name'
}
}
]
};
this.campaign = {
id: null,
from: null,
to: null
};
this.getUpcomingCampaing();
}
get checked() {
const clients = this.$.model.data || [];
const checkedClients = [];
for (const buy of clients) {
if (buy.$checked)
checkedClients.push(buy);
}
return checkedClients;
}
onChangeDate(value) {
if (value)
this.campaign.id = null;
}
getUpcomingCampaing() {
2022-02-14 07:44:22 +00:00
this.$http.get('Campaigns/upcoming')
.then(res => this.campaign.id = res.data.id);
}
get campaignSelection() {
return this._campaignSelection;
}
set campaignSelection(value) {
this._campaignSelection = value;
if (value) {
const from = new Date(value.dated);
from.setDate(from.getDate() - value.scopeDays);
this.campaign.to = value.dated;
this.campaign.from = from;
}
}
onSendClientConsumption() {
const clientIds = this.checked.map(client => client.id);
const params = Object.assign({
clientIds: clientIds
}, this.campaign);
2022-05-09 11:15:48 +00:00
this.$http.post('schedule/consumption', params)
.then(() => this.$.filters.hide())
2022-02-14 07:44:22 +00:00
.then(() => this.vnApp.showSuccess(this.$t('Notifications sent!')));
}
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
: {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]};
case 'phone':
return {
or: [
{phone: value},
{mobile: value}
]
};
case 'name':
case 'socialName':
case 'city':
case 'email':
return {[param]: {like: `%${value}%`}};
case 'id':
case 'fi':
case 'postcode':
case 'salesPersonFk':
2022-08-12 13:31:59 +00:00
case 'provinceFk':
return {[param]: value};
}
}
}
ngModule.vnComponent('vnClientNotification', {
template: require('./index.html'),
controller: Controller
});