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

78 lines
1.8 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.moreOptions = [
{name: 'Simple ticket', callback: this.newTicket},
{name: 'Send SMS', callback: this.showSMSDialog},
];
}
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 phone = this.$params.phone || this.client.phone;
const message = this.$params.message || '';
this.newSMS = {
destinationFk: this.client.id,
destination: phone,
message: message
};
this.$.sms.open();
}
}
Controller.$inject = ['$element', '$scope'];
ngModule.component('vnClientDescriptor', {
template: require('./index.html'),
bindings: {
client: '<',
quicklinks: '<'
},
controller: Controller
});