2019-09-22 21:02:31 +00:00
|
|
|
var $ = require('jquery')
|
|
|
|
var _ = require('underscore')
|
|
|
|
var Marionette = require('marionette')
|
|
|
|
var sweetAlert = require('sweet-alert')
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2019-09-22 21:02:31 +00:00
|
|
|
var tpl = require('tpl/servers/info.html')
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2019-09-22 21:02:31 +00:00
|
|
|
module.exports = Marionette.LayoutView.extend({
|
|
|
|
template: _.template(tpl),
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2019-09-22 21:02:31 +00:00
|
|
|
events: {
|
|
|
|
'click #start': 'start',
|
|
|
|
'click #stop': 'stop'
|
|
|
|
},
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2019-09-22 21:02:31 +00:00
|
|
|
start: function (event) {
|
|
|
|
var self = this
|
|
|
|
event.preventDefault()
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/servers/' + this.model.get('id') + '/start',
|
|
|
|
type: 'POST',
|
|
|
|
success: function (resp) {
|
|
|
|
self.model.set('pid', resp.pid)
|
|
|
|
self.render()
|
|
|
|
},
|
|
|
|
error: $.noop
|
|
|
|
})
|
|
|
|
},
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2019-09-22 21:02:31 +00:00
|
|
|
stop: function (event) {
|
|
|
|
var self = this
|
|
|
|
event.preventDefault()
|
|
|
|
sweetAlert({
|
|
|
|
title: 'Are you sure?',
|
|
|
|
text: 'The server will stopped.',
|
|
|
|
type: 'warning',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonClass: 'btn-warning',
|
|
|
|
confirmButtonText: 'Yes, stop it!'
|
|
|
|
},
|
|
|
|
function () {
|
2014-04-06 21:09:52 +00:00
|
|
|
$.ajax({
|
2019-09-22 21:02:31 +00:00
|
|
|
url: '/api/servers/' + self.model.get('id') + '/stop',
|
2017-04-01 09:19:30 +00:00
|
|
|
type: 'POST',
|
2014-04-06 21:09:52 +00:00
|
|
|
success: function (resp) {
|
2019-09-22 21:02:31 +00:00
|
|
|
self.model.set('pid', resp.pid)
|
|
|
|
self.render()
|
2014-04-06 22:58:17 +00:00
|
|
|
},
|
|
|
|
error: $.noop
|
2019-09-22 21:02:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|