salix/modules/item/front/src/ticket-descriptor-popover/index.js

98 lines
2.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import Component from 'core/src/lib/component';
import './style.scss';
class Controller extends Component {
2018-10-18 09:41:25 +00:00
constructor($element, $scope, $http, $timeout, $q) {
super($element, $scope);
2018-10-18 09:41:25 +00:00
this.$timeout = $timeout;
this.$http = $http;
2018-10-18 09:41:25 +00:00
this.$q = $q;
this.ticket = null;
}
2018-10-18 09:41:25 +00:00
set ticketFk(id) {
if (id == this._ticketFk) return;
2018-10-18 09:41:25 +00:00
this._ticketFk = id;
this.ticket = null;
this.getCard();
}
2018-10-18 09:41:25 +00:00
set ticket(value) {
this._ticket = value;
this.$timeout(() => this.$.popover.relocate());
}
get ticket() {
return this._ticket;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
2018-10-18 09:41:25 +00:00
get quicklinks() {
return this._quicklinks;
}
show() {
this.$.popover.parent = this.parent;
this.$.popover.show();
}
2018-10-18 09:41:25 +00:00
getCard() {
if (this.canceler)
this.canceler.resolve();
this.canceler = this.$q.defer();
let options = {timeout: this.canceler.promise};
let filter = {
include: [
{relation: 'warehouse', scope: {fields: ['name']}},
{relation: 'agencyMode', scope: {fields: ['name']}},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name']
}
}
},
{
relation: 'tracking',
scope: {
fields: ['stateFk'],
include: {
relation: 'state',
fields: ['name']
}
}
}
]
};
let json = encodeURIComponent(JSON.stringify(filter));
let query = `/ticket/api/Tickets/${this._ticketFk}?filter=${json}`;
this.$http.get(query, options).then(
response => {
this.ticket = response.data;
this.canceler = null;
}
);
}
}
2018-10-18 09:41:25 +00:00
Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q'];
ngModule.component('vnTicketDescriptorPopover', {
template: require('./index.html'),
2018-10-18 09:41:25 +00:00
controller: Controller,
bindings: {
ticketFk: '<',
quicklinks: '<'
2018-10-18 09:41:25 +00:00
}
});