2017-08-05 14:53:36 +08:00

77 lines
1.9 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',
];
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] = !['showCountryCode', 'showState', 'showCity'].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(),
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);
}
}
});