Custom locations: refactoring
This commit is contained in:
parent
9734b3d5c4
commit
920fddd961
2 changed files with 58 additions and 52 deletions
|
@ -6,62 +6,14 @@ const ProxyHostModel = require('../../../models/proxy-host');
|
||||||
const ProxyLocationModel = require('../../../models/proxy-host-location');
|
const ProxyLocationModel = require('../../../models/proxy-host-location');
|
||||||
const template = require('./form.ejs');
|
const template = require('./form.ejs');
|
||||||
const certListItemTemplate = require('../certificates-list-item.ejs');
|
const certListItemTemplate = require('../certificates-list-item.ejs');
|
||||||
const locationItemTemplate = require('./location-item.ejs');
|
|
||||||
const accessListItemTemplate = require('./access-list-item.ejs');
|
const accessListItemTemplate = require('./access-list-item.ejs');
|
||||||
|
const CustomLocation = require('./location');
|
||||||
const Helpers = require('../../../lib/helpers');
|
const Helpers = require('../../../lib/helpers');
|
||||||
|
|
||||||
|
|
||||||
require('jquery-serializejson');
|
require('jquery-serializejson');
|
||||||
require('selectize');
|
require('selectize');
|
||||||
|
|
||||||
const LocationView = Mn.View.extend({
|
|
||||||
template: locationItemTemplate,
|
|
||||||
className: 'location_block',
|
|
||||||
|
|
||||||
ui: {
|
|
||||||
toggle: 'input[type="checkbox"]',
|
|
||||||
config: '.config',
|
|
||||||
delete: '.location-delete'
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
'change @ui.toggle': function(el) {
|
|
||||||
if (el.target.checked) {
|
|
||||||
this.ui.config.show();
|
|
||||||
} else {
|
|
||||||
this.ui.config.hide();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'change .model': function (e) {
|
|
||||||
console.log(e);
|
|
||||||
const map = {};
|
|
||||||
map[e.target.name] = e.target.value;
|
|
||||||
this.model.set(map);
|
|
||||||
},
|
|
||||||
|
|
||||||
'click @ui.delete': function () {
|
|
||||||
this.model.destroy();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onRender: function() {
|
|
||||||
$(this.ui.config).hide();
|
|
||||||
},
|
|
||||||
|
|
||||||
templateContext: function() {
|
|
||||||
return {
|
|
||||||
i18n: App.i18n,
|
|
||||||
advanced_config: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const LocationCollectionView = Mn.CollectionView.extend({
|
|
||||||
className: 'locations_container',
|
|
||||||
childView: LocationView
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Mn.View.extend({
|
module.exports = Mn.View.extend({
|
||||||
template: template,
|
template: template,
|
||||||
className: 'modal-dialog',
|
className: 'modal-dialog',
|
||||||
|
@ -123,7 +75,6 @@ module.exports = Mn.View.extend({
|
||||||
let view = this;
|
let view = this;
|
||||||
let data = this.ui.form.serializeJSON();
|
let data = this.ui.form.serializeJSON();
|
||||||
|
|
||||||
console.log('FORM', data);
|
|
||||||
// Add locations
|
// Add locations
|
||||||
data.locations = [];
|
data.locations = [];
|
||||||
this.locationsCollection.models.forEach((location) => {
|
this.locationsCollection.models.forEach((location) => {
|
||||||
|
@ -290,12 +241,12 @@ module.exports = Mn.View.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom locations
|
// Custom locations
|
||||||
this.showChildView('locations_regions', new LocationCollectionView({
|
this.showChildView('locations_regions', new CustomLocation.LocationCollectionView({
|
||||||
collection: this.locationsCollection
|
collection: this.locationsCollection
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Check wether there are any location defined
|
// Check wether there are any location defined
|
||||||
if (Array.isArray(options.model.attributes.locations)) {
|
if (options.model && Array.isArray(options.model.attributes.locations)) {
|
||||||
options.model.attributes.locations.forEach((location) => {
|
options.model.attributes.locations.forEach((location) => {
|
||||||
let m = new ProxyLocationModel.Model(location);
|
let m = new ProxyLocationModel.Model(location);
|
||||||
this.locationsCollection.add(m);
|
this.locationsCollection.add(m);
|
||||||
|
|
55
src/frontend/js/app/nginx/proxy/location.js
Normal file
55
src/frontend/js/app/nginx/proxy/location.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
const locationItemTemplate = require('./location-item.ejs');
|
||||||
|
const Mn = require('backbone.marionette');
|
||||||
|
const App = require('../../main');
|
||||||
|
|
||||||
|
const LocationView = Mn.View.extend({
|
||||||
|
template: locationItemTemplate,
|
||||||
|
className: 'location_block',
|
||||||
|
|
||||||
|
ui: {
|
||||||
|
toggle: 'input[type="checkbox"]',
|
||||||
|
config: '.config',
|
||||||
|
delete: '.location-delete'
|
||||||
|
},
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'change @ui.toggle': function(el) {
|
||||||
|
if (el.target.checked) {
|
||||||
|
this.ui.config.show();
|
||||||
|
} else {
|
||||||
|
this.ui.config.hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'change .model': function (e) {
|
||||||
|
const map = {};
|
||||||
|
map[e.target.name] = e.target.value;
|
||||||
|
this.model.set(map);
|
||||||
|
},
|
||||||
|
|
||||||
|
'click @ui.delete': function () {
|
||||||
|
this.model.destroy();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onRender: function() {
|
||||||
|
$(this.ui.config).hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
templateContext: function() {
|
||||||
|
return {
|
||||||
|
i18n: App.i18n,
|
||||||
|
advanced_config: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const LocationCollectionView = Mn.CollectionView.extend({
|
||||||
|
className: 'locations_container',
|
||||||
|
childView: LocationView
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
LocationCollectionView,
|
||||||
|
LocationView
|
||||||
|
}
|
Loading…
Reference in a new issue