2018-07-24 02:56:39 -04:00
|
|
|
'use strict';
|
|
|
|
|
2018-08-15 23:08:56 -04:00
|
|
|
const Mn = require('backbone.marionette');
|
|
|
|
const App = require('../../main');
|
|
|
|
const AccessListModel = require('../../../models/access-list');
|
|
|
|
const template = require('./form.ejs');
|
2018-07-24 02:56:39 -04:00
|
|
|
|
|
|
|
require('jquery-serializejson');
|
|
|
|
require('jquery-mask-plugin');
|
|
|
|
require('selectize');
|
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
|
|
|
template: template,
|
|
|
|
className: 'modal-dialog',
|
|
|
|
|
|
|
|
ui: {
|
2018-08-15 23:08:56 -04:00
|
|
|
form: 'form',
|
|
|
|
buttons: '.modal-footer button',
|
|
|
|
cancel: 'button.cancel',
|
|
|
|
save: 'button.save'
|
2018-07-24 02:56:39 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click @ui.save': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (!this.ui.form[0].checkValidity()) {
|
|
|
|
$('<input type="submit">').hide().appendTo(this.ui.form).click().remove();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let view = this;
|
|
|
|
let data = this.ui.form.serializeJSON();
|
|
|
|
|
|
|
|
// Manipulate
|
2018-08-15 23:08:56 -04:00
|
|
|
// ...
|
2018-07-24 02:56:39 -04:00
|
|
|
|
2018-08-15 23:08:56 -04:00
|
|
|
let method = App.Api.Nginx.AccessLists.create;
|
|
|
|
let is_new = true;
|
2018-07-24 02:56:39 -04:00
|
|
|
|
|
|
|
if (this.model.get('id')) {
|
|
|
|
// edit
|
|
|
|
is_new = false;
|
2018-08-15 23:08:56 -04:00
|
|
|
method = App.Api.Nginx.AccessLists.update;
|
2018-07-24 02:56:39 -04:00
|
|
|
data.id = this.model.get('id');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
|
|
|
|
method(data)
|
|
|
|
.then(result => {
|
|
|
|
view.model.set(result);
|
|
|
|
|
|
|
|
App.UI.closeModal(function () {
|
|
|
|
if (is_new) {
|
2018-08-15 23:08:56 -04:00
|
|
|
App.Controller.showNginxAccess();
|
2018-07-24 02:56:39 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
alert(err.message);
|
|
|
|
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function (options) {
|
|
|
|
if (typeof options.model === 'undefined' || !options.model) {
|
2018-08-15 23:08:56 -04:00
|
|
|
this.model = new AccessListModel.Model();
|
2018-07-24 02:56:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|