salix/modules/zone/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
2019-10-30 15:57:14 +00:00
* @param {String} response - Response string (['accept', 'cancel'])
2019-03-14 14:07:24 +00:00
*/
onCloneAccept(response) {
2019-10-30 15:57:14 +00:00
if (!(response == 'accept' && this.selectedZone)) return;
const query = `Zones/${this.selectedZone.id}/clone`;
2019-03-14 14:07:24 +00:00
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
});