import ngModule from '../module'; import './style.scss'; export default class Controller { constructor($scope, $state, $stateParams, $translate) { this.$ = $scope; this.$translate = $translate; this.$stateParams = $stateParams; this.$state = $state; this.selectedTicket = null; this.moreOptions = [ {callback: () => { this.goToTurns('ticket.weekly'); }, name: 'Turns', always: true}, ]; if (!$stateParams.q) { let today = new Date(); today.setHours(0, 0, 0, 0); let tomorrow = new Date(today); tomorrow.setHours(23, 59, 59, 999); let sixDays = new Date(today); sixDays.setDate(today.getDate() + 6); sixDays.setHours(23, 59, 59, 999); this.filter = Object.assign({}, {myTeam: true, from: today, to: sixDays}); } } $postLink() { if (this.filter && this.filter != {}) this.onSearch(this.filter); } onSearch(params) { if (params) this.$.model.applyFilter(null, params); else this.$.model.clear(); } goToLines(event, ticketFk) { this.preventDefault(event); let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); window.open(url, '_blank'); } goToTurns() { this.$state.go('ticket.weekly'); } onMoreOpen() { let options = this.moreOptions.filter(o => o.always || this.isChecked); this.$.moreButton.data = options; } onMoreChange(callback) { callback.call(this); } compareDate(date) { let today = new Date(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); let comparation = today - timeTicket; if (comparation == 0) return 'warning'; if (comparation < 0) return 'success'; } stateColor(ticket) { if (ticket.alertLevelCode === 'OK') return 'success'; else if (ticket.alertLevelCode === 'FREE') return 'notice'; else if (ticket.alertLevel === 1) return 'warning'; else if (ticket.alertLevel === 0) return 'alert'; } showClientDescriptor(event, clientFk) { this.preventDefault(event); this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; this.$.clientDescriptor.show(); } showWorkerDescriptor(event, userId) { this.preventDefault(event); this.selectedWorker = userId; this.$.workerDescriptor.parent = event.target; this.$.workerDescriptor.show(); } preview(event, ticket) { this.preventDefault(event); this.selectedTicket = ticket; this.$.summary.show(); } preventDefault(event) { event.preventDefault(); event.stopImmediatePropagation(); } } Controller.$inject = ['$scope', '$state', '$stateParams', '$translate']; ngModule.component('vnTicketIndex', { template: require('./index.html'), controller: Controller });