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

93 lines
2.4 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $, $httpParamSerializer) {
super($element, $);
this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [
{name: 'Simple ticket', callback: this.newTicket},
{name: 'Send SMS', callback: this.showSMSDialog},
{name: 'Send consumer report', callback: this.showConsumerReportDialog}
];
}
onMoreChange(callback) {
callback.call(this);
}
get client() {
return this._client;
}
set client(value) {
this._client = value;
if (!value) return;
if (this.$params.sendSMS)
this.showSMSDialog();
this._quicklinks = {
btnOne: {
icon: 'icon-ticket',
state: `ticket.index({q: '{"clientFk": ${value.id}}'})`,
tooltip: 'Client ticket list'
},
btnTwo: {
icon: 'icon-basketadd',
state: `order.create({clientFk: ${value.id}})`,
tooltip: 'New order'
}
};
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
newTicket() {
this.$state.go('ticket.create', {clientFk: this.client.id});
}
showSMSDialog() {
const client = this.client;
const phone = this.$params.phone || client.mobile || client.phone;
const message = this.$params.message || '';
this.newSMS = {
destinationFk: client.id,
destination: phone,
message: message
};
this.$.sms.open();
}
showConsumerReportDialog() {
this.$.consumerReportDialog.show();
}
sendConsumerReport(response) {
if (response === 'accept') {
const data = {from: this.from, to: this.to, clientId: this.client.id};
const serializedParams = this.$httpParamSerializer(data);
const url = `api/report/campaign-metrics?${serializedParams}`;
window.open(url);
}
}
}
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnClientDescriptor', {
template: require('./index.html'),
bindings: {
client: '<',
quicklinks: '<'
},
controller: Controller
});