salix/modules/agency/front/index/index.js

82 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-12-04 12:18:27 +00:00
import ngModule from '../module';
2018-09-19 13:05:07 +00:00
export default class Controller {
2019-03-14 14:07:24 +00:00
constructor($scope, $http, $state) {
2018-09-19 13:05:07 +00:00
this.$scope = $scope;
2019-03-14 14:07:24 +00:00
this.$http = $http;
this.$state = $state;
2018-09-19 13:05:07 +00:00
this.filter = {
2019-09-25 18:06:42 +00:00
include: {
relation: 'agencyMode',
scope: {fields: ['name']}
}
2018-09-19 13:05:07 +00:00
};
}
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
2019-02-04 11:14:07 +00:00
: {name: {like: `%${value}%`}};
2019-09-25 18:06:42 +00:00
case 'name':
return {[param]: {like: `%${value}%`}};
2018-09-19 13:05:07 +00:00
case 'agencyModeFk':
return {[param]: value};
}
}
2018-09-25 07:28:55 +00:00
2019-03-14 14:07:24 +00:00
/**
* Clones a zone and all its properties
* @param {Object} event - Event object
* @param {Object} zone - Selected item
*/
clone(event, zone) {
this.stopEvent(event);
this.selectedZone = zone;
this.$scope.clone.show();
}
/**
* Clone response callback
* @param {String} response - Response string (['ACCEPT', 'CANCEL'])
*/
onCloneAccept(response) {
if (!(response == 'ACCEPT' && this.selectedZone)) return;
const query = `/agency/api/Zones/${this.selectedZone.id}/clone`;
this.$http.post(query).then(res => {
if (res && res.data)
this.$state.go('zone.card.basicData', {id: res.data.id});
});
this.selectedZone = null;
}
/**
* Opens a summary modal
* @param {Object} event - Event object
* @param {Object} zone - Selected item
*/
2018-09-25 07:28:55 +00:00
preview(event, zone) {
2019-03-14 14:07:24 +00:00
this.stopEvent(event);
this.selectedZone = zone;
this.$scope.summary.show();
}
/**
* Prevents normal event propagation
* @param {Object} event - Event object
*/
stopEvent(event) {
2018-09-25 07:28:55 +00:00
event.preventDefault();
event.stopImmediatePropagation();
}
2018-09-19 13:05:07 +00:00
}
2019-03-14 14:07:24 +00:00
Controller.$inject = ['$scope', '$http', '$state'];
2018-09-19 13:05:07 +00:00
ngModule.component('vnZoneIndex', {
template: require('./index.html'),
controller: Controller
});