salix/modules/client/front/consumption-search-panel/index.js

57 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2020-06-12 07:18:19 +00:00
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
2020-10-05 05:53:03 +00:00
class Controller extends SearchPanel {
constructor($, $element) {
super($, $element);
2020-11-06 07:21:25 +00:00
this.filter = this.$.filter;
if (!this.dateParams)
this.getUpcomingCampaing();
}
get dateParams() {
if (this.$params.q) {
const params = JSON.parse(this.$params.q);
if (params.from || params.to)
return true;
}
return false;
2020-10-05 06:50:07 +00:00
}
getUpcomingCampaing() {
2020-10-05 05:53:03 +00:00
this.$http.get('Campaigns/upcoming').then(res => {
2020-11-06 07:21:25 +00:00
this.filter.campaign = res.data.id;
2020-10-05 05:53:03 +00:00
});
}
2020-11-06 07:21:25 +00:00
onChangeDate(value) {
if (value)
this.filter.campaign = null;
}
2020-10-05 05:53:03 +00:00
get campaignSelection() {
return this._campaignSelection;
}
set campaignSelection(value) {
this._campaignSelection = value;
2020-11-06 07:21:25 +00:00
if (value) {
const from = new Date(value.dated);
from.setDate(from.getDate() - value.scopeDays);
2020-10-05 05:53:03 +00:00
2020-11-06 07:21:25 +00:00
this.filter.to = value.dated;
this.filter.from = from;
}
2020-10-05 05:53:03 +00:00
}
}
ngModule.vnComponent('vnConsumptionSearchPanel', {
2020-06-12 07:18:19 +00:00
template: require('./index.html'),
2020-10-05 05:53:03 +00:00
controller: Controller
2020-06-12 07:18:19 +00:00
});