diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 95711dd0c..9413400ce 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -18,20 +18,6 @@ export default class Controller { this.$.balanceCreateDialog.show(); }, name: 'Payment on account...', always: true} ]; - - if (!$stateParams.q) - this.setDefaultFilter(); - } - - setDefaultFilter() { - const today = new Date(); - today.setHours(0, 0, 0, 0); - - const tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 1); - tomorrow.setHours(23, 59, 59, 999); - - this.filter = {from: today, to: tomorrow}; } setBalanceCreateDialog() { @@ -51,26 +37,27 @@ export default class Controller { this.$.balanceCreateDialog.description += description.join(', '); } - buildFilterDates() { - let today = new Date(); - this.today = today.setHours(0, 0, 0, 0); + getScopeDates(days) { + const today = new Date(); + today.setHours(0, 0, 0, 0); - let buildDate = new Date(today); - buildDate.setDate(today.getDate() + this.scopeDays); - buildDate.setHours(23, 59, 59, 999); + const daysOnward = new Date(today); + daysOnward.setDate(today.getDate() + days); + daysOnward.setHours(23, 59, 59, 999); - this.daysOnward = buildDate; + return {from: today, to: daysOnward}; } onSearch(params) { if (params) { + let newParams = params; if (params.scopeDays) { - params.scopeDays = parseInt(params.scopeDays); - this.scopeDays = params.scopeDays; - this.buildFilterDates(); - params = Object.assign(params, {from: this.today, to: this.daysOnward}); - } - this.$.model.applyFilter(null, params); + const scopeDates = this.getScopeDates(params.scopeDays); + Object.assign(newParams, scopeDates); + } else if (Object.entries(params).length == 0) + newParams = this.getScopeDates(1); + + this.$.model.applyFilter(null, newParams); } else this.$.model.clear(); }