2019-06-10 16:32:29 +08:00

97 lines
2.4 KiB
JavaScript

import Ember from 'ember';
import BaseListRoute from './../base-list';
const cols = ['showId',
'showName',
'showDateAdded',
'showYears',
'showYtdSale',
'showCountryCode',
'showState',
'showCity',
'showMs',
'showRegion',
'showSalesperson',
'showStatus',
'showIssue1',
// 'showIssue2',
// 'showIssue3',
'showApplication',
];
const config = {
showAll: false,
showAllChanged: Ember.observer('showAll', function() {
let me = this;
if (!me.get('lock')) {
let val = me.get('showAll');
cols.forEach(col => {
me.set(col, val);
});
}
}),
colChanged: Ember.observer(...cols.concat(function() {
let me = this;
me.set('lock', true);
me.set('showAll', cols.map(col => {
return me[col];
}).reduce((val, prevVal) => {
return val && prevVal;
}, true));
me.set('lock', false);
me.set('countOfShowing', cols.filter(col => {
return me[col];
}).length + 1);
}))
};
cols.forEach((col) => {
config[col] = ![
'showIssue1',
// 'showIssue2',
// 'showIssue3',
'showDateAdded',
'showYears',
'showCountryCode',
'showRegion',
'showState',
].includes(col);
});
config.countOfShowing = cols.filter(col => {
return config[col];
}).length + 1;
const TableOptions = Ember.Object.extend(config);
export default BaseListRoute.extend({
queryParams: {
criteria: {
refreshModel: true
}
},
breadcrumbs: [{text: 'Customers'}],
tableOptions: TableOptions.create(),
afterModel(model, transition) {
const me = this;
model.issueOptions = [{value: 'true', text: 'Artificial'},
{value: 'false', text: 'System'},
{value: 'null', text: 'None'}];
transition.then(function() {
// store current url
me.set('state.CUSTOMER_LIST_ROUTE', me.get('router.currentURL'));
});
},
setupController(controller) {
let me = this;
me._super(...arguments);
controller.set('tableOptions', me.get('tableOptions'));
},
actions: {
expandYtdSales(row) {
Ember.set(row, 'expand', true);
},
collapseYtdSales(row) {
Ember.set(row, 'expand', false);
}
}
});