diff --git a/src/frontend/js/app/controller.js b/src/frontend/js/app/controller.js index ab9d11d3..46ff67cc 100644 --- a/src/frontend/js/app/controller.js +++ b/src/frontend/js/app/controller.js @@ -214,6 +214,19 @@ module.exports = { } }, + /** + * Nginx Stream Form + * + * @param [model] + */ + showNginxStreamForm: function (model) { + if (Cache.User.isAdmin() || Cache.User.canManage('proxy_hosts')) { + require(['./main', './nginx/stream/form'], function (App, View) { + App.UI.showModalDialog(new View({model: model})); + }); + } + }, + /** * Nginx Dead Hosts */ diff --git a/src/frontend/js/app/nginx/stream/delete.ejs b/src/frontend/js/app/nginx/stream/delete.ejs new file mode 100644 index 00000000..d7ba3a21 --- /dev/null +++ b/src/frontend/js/app/nginx/stream/delete.ejs @@ -0,0 +1,19 @@ +
diff --git a/src/frontend/js/app/nginx/stream/delete.js b/src/frontend/js/app/nginx/stream/delete.js new file mode 100644 index 00000000..94105e8d --- /dev/null +++ b/src/frontend/js/app/nginx/stream/delete.js @@ -0,0 +1,36 @@ +'use strict'; + +const Mn = require('backbone.marionette'); +const App = require('../../main'); +const template = require('./delete.ejs'); + +require('jquery-serializejson'); + +module.exports = Mn.View.extend({ + template: template, + className: 'modal-dialog', + + ui: { + form: 'form', + buttons: '.modal-footer button', + cancel: 'button.cancel', + save: 'button.save' + }, + + events: { + + 'click @ui.save': function (e) { + e.preventDefault(); + + App.Api.Nginx.Streams.delete(this.model.get('id')) + .then(() => { + App.Controller.showNginxStream(); + App.UI.closeModal(); + }) + .catch(err => { + alert(err.message); + this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); + }); + } + } +}); diff --git a/src/frontend/js/app/nginx/stream/form.ejs b/src/frontend/js/app/nginx/stream/form.ejs new file mode 100644 index 00000000..c1feee13 --- /dev/null +++ b/src/frontend/js/app/nginx/stream/form.ejs @@ -0,0 +1,52 @@ + diff --git a/src/frontend/js/app/nginx/stream/form.js b/src/frontend/js/app/nginx/stream/form.js new file mode 100644 index 00000000..143e54ed --- /dev/null +++ b/src/frontend/js/app/nginx/stream/form.js @@ -0,0 +1,93 @@ +'use strict'; + +const _ = require('underscore'); +const Mn = require('backbone.marionette'); +const App = require('../../main'); +const StreamModel = require('../../../models/stream'); +const template = require('./form.ejs'); + +require('jquery-serializejson'); +require('jquery-mask-plugin'); +require('selectize'); + +module.exports = Mn.View.extend({ + template: template, + className: 'modal-dialog', + max_file_size: 5120, + + ui: { + form: 'form', + forward_ip: 'input[name="forward_ip"]', + buttons: '.modal-footer button', + cancel: 'button.cancel', + save: 'button.save' + }, + + events: { + 'click @ui.save': function (e) { + e.preventDefault(); + + if (!this.ui.form[0].checkValidity()) { + $('').hide().appendTo(this.ui.form).click().remove(); + return; + } + + let view = this; + let data = this.ui.form.serializeJSON(); + + // Manipulate + data.forward_port = parseInt(data.forward_port, 10); + _.map(data, function (item, idx) { + if (typeof item === 'string' && item === '1') { + item = true; + } else if (typeof item === 'object' && item !== null) { + _.map(item, function (item2, idx2) { + if (typeof item2 === 'string' && item2 === '1') { + item[idx2] = true; + } + }); + } + data[idx] = item; + }); + + let method = App.Api.Nginx.Streams.create; + let is_new = true; + + if (this.model.get('id')) { + // edit + is_new = false; + method = App.Api.Nginx.Streams.update; + 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) { + App.Controller.showNginxStream(); + } + }); + }) + .catch(err => { + alert(err.message); + this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); + }); + } + }, + + onRender: function () { + this.ui.forward_ip.mask('099.099.099.099', { + clearIfNotMatch: true, + placeholder: '000.000.000.000' + }); + }, + + initialize: function (options) { + if (typeof options.model === 'undefined' || !options.model) { + this.model = new StreamModel.Model(); + } + } +}); diff --git a/src/frontend/js/app/nginx/stream/list/item.ejs b/src/frontend/js/app/nginx/stream/list/item.ejs index bd4d19e0..b1aab6e4 100644 --- a/src/frontend/js/app/nginx/stream/list/item.ejs +++ b/src/frontend/js/app/nginx/stream/list/item.ejs @@ -1,32 +1,40 @@