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

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-06-03 11:01:47 +00:00
import ngModule from '../module';
2019-11-21 13:00:27 +00:00
import Component from 'core/lib/component';
class Controller extends Component {
2020-02-11 12:25:41 +00:00
constructor($element, $, $httpParamSerializer) {
2019-11-21 13:00:27 +00:00
super($element, $);
2020-02-11 12:25:41 +00:00
this.$httpParamSerializer = $httpParamSerializer;
2019-01-07 07:49:01 +00:00
this.moreOptions = [
2019-11-21 13:00:27 +00:00
{name: 'Simple ticket', callback: this.newTicket},
{name: 'Send SMS', callback: this.showSMSDialog},
2020-02-11 12:25:41 +00:00
{name: 'Send consumer report', callback: this.showConsumerReportDialog}
2019-01-07 07:49:01 +00:00
];
}
onMoreChange(callback) {
callback.call(this);
2018-08-02 08:06:11 +00:00
}
2019-10-21 12:21:52 +00:00
get client() {
return this._client;
}
2018-08-02 08:06:11 +00:00
set client(value) {
this._client = value;
if (!value) return;
2019-11-21 13:00:27 +00:00
if (this.$params.sendSMS)
this.showSMSDialog();
2018-08-02 08:06:11 +00:00
this._quicklinks = {
btnOne: {
icon: 'icon-ticket',
2018-09-04 09:49:00 +00:00
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 = {}) {
2018-08-02 08:06:11 +00:00
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
2019-01-07 07:49:01 +00:00
newTicket() {
this.$state.go('ticket.create', {clientFk: this.client.id});
}
2019-11-21 13:00:27 +00:00
showSMSDialog() {
2020-02-21 07:37:37 +00:00
const client = this.client;
const phone = this.$params.phone || client.mobile || client.phone;
2019-11-21 13:00:27 +00:00
const message = this.$params.message || '';
this.newSMS = {
2020-02-21 07:37:37 +00:00
destinationFk: client.id,
2019-11-21 13:00:27 +00:00
destination: phone,
message: message
};
this.$.sms.open();
}
2020-02-11 12:25:41 +00:00
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);
}
}
}
2018-05-31 06:57:25 +00:00
2020-02-11 12:25:41 +00:00
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnClientDescriptor', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
bindings: {
client: '<',
quicklinks: '<'
},
2018-05-23 12:26:51 +00:00
controller: Controller
2017-06-03 11:01:47 +00:00
});