Modernize frontend from old CommonJS format

This commit is contained in:
Björn Dahlgren 2019-09-22 23:02:31 +02:00
parent 90c3d609f3
commit 7d98e35d1c
49 changed files with 1060 additions and 1352 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
# Logs # Logs
logs
*.log *.log
npm-debug.log* npm-debug.log*

View File

@ -14,9 +14,6 @@
"standard": { "standard": {
"env": [ "env": [
"mocha" "mocha"
],
"ignore": [
"public/"
] ]
}, },
"dependencies": { "dependencies": {

View File

@ -1,3 +1,5 @@
require('jquery.iframe-transport')
require('bootstrap/dist/css/bootstrap.css') require('bootstrap/dist/css/bootstrap.css')
require('ladda/dist/ladda-themeless.min.css') require('ladda/dist/ladda-themeless.min.css')
require('sweetalert/dist/sweetalert.css') require('sweetalert/dist/sweetalert.css')
@ -14,38 +16,38 @@ require.config({
}, },
shim: { shim: {
'backbone': { backbone: {
deps: ['underscore', 'jquery'], deps: ['underscore', 'jquery'],
exports: 'Backbone' exports: 'Backbone'
}, },
'backbone.babysitter': { 'backbone.babysitter': {
deps: ['backbone'], deps: ['backbone']
}, },
'backbone.bootstrap-modal': { 'backbone.bootstrap-modal': {
deps: ['backbone', 'bootstrap'] deps: ['backbone', 'bootstrap']
}, },
'bootstrap': { bootstrap: {
deps: ['jquery'] deps: ['jquery']
}, },
'ladda': { ladda: {
deps: ['bootstrap'] deps: ['bootstrap']
}, },
'marionette': { marionette: {
deps: ['backbone', 'backbone.babysitter'], deps: ['backbone', 'backbone.babysitter'],
exports: 'Marionette' exports: 'Marionette'
}, },
'marionette-formview': { 'marionette-formview': {
deps: ['marionette'] deps: ['marionette']
}, },
'sweetalert': { sweetalert: {
deps: ['bootstrap'] deps: ['bootstrap']
}, },
'underscore': { underscore: {
exports: '_' exports: '_'
} }
} }
}); })
require(['jquery', 'bootstrap', 'backbone', 'app/router'], function ($, Bootstrap, Backbone, Router) { require(['jquery', 'bootstrap', 'backbone', 'app/router'], function ($, Bootstrap, Backbone, Router) {
var router = new Router(); return new Router()
}); })

View File

@ -1,16 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var Log = require('app/models/log')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Log = require('app/models/log');
return Backbone.Collection.extend({
comparator: 'name', comparator: 'name',
model: Log, model: Log,
url: '/api/logs/' url: '/api/logs/'
}); })
});

View File

@ -1,14 +1,7 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var MissionRotation = require('app/models/mission_rotation')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'), model: MissionRotation
Backbone = require('backbone'), })
MissionRotation = require('app/models/mission_rotation');
return Backbone.Collection.extend({
model: MissionRotation,
});
});

View File

@ -1,16 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var Mission = require('app/models/mission')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Mission = require('app/models/mission');
return Backbone.Collection.extend({
comparator: 'name', comparator: 'name',
model: Mission, model: Mission,
url: '/api/missions/' url: '/api/missions/'
}); })
});

View File

@ -1,16 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var Mod = require('app/models/mod')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Mod = require('app/models/mod');
return Backbone.Collection.extend({
comparator: 'name', comparator: 'name',
model: Mod, model: Mod,
url: '/api/mods/' url: '/api/mods/'
}); })
});

View File

@ -1,14 +1,7 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var Parameter = require('app/models/parameter')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'), model: Parameter
Backbone = require('backbone'), })
Parameter = require('app/models/parameter');
return Backbone.Collection.extend({
model: Parameter,
});
});

View File

@ -1,18 +1,11 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; var Server = require('app/models/server')
var $ = require('jquery'), module.exports = Backbone.Collection.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Server = require('app/models/server');
return Backbone.Collection.extend({
comparator: function (a, b) { comparator: function (a, b) {
return a.get('title').toLowerCase().localeCompare(b.get('title').toLowerCase()); return a.get('title').toLowerCase().localeCompare(b.get('title').toLowerCase())
}, },
model: Server, model: Server,
url: '/api/servers/' url: '/api/servers/'
}); })
});

View File

@ -1,18 +1,10 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
name: '', name: '',
formattedSize: '0 B', formattedSize: '0 B',
size: 0, size: 0
}, },
idAttribute: 'name', idAttribute: 'name'
}); })
});

View File

@ -1,17 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
name: '' name: ''
}, },
idAttribute: 'name', idAttribute: 'name',
urlRoot: '/api/missions/', urlRoot: '/api/missions/'
}); })
});

View File

@ -1,16 +1,8 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
name: '', name: '',
difficulty: 'recruit', difficulty: 'recruit'
}, }
}); })
});

View File

@ -1,17 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
name: '' name: ''
}, },
idAttribute: 'name', idAttribute: 'name',
urlRoot: '/api/mods/', urlRoot: '/api/mods/'
}); })
});

View File

@ -1,15 +1,7 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
parameter: '' parameter: ''
}, }
}); })
});

View File

@ -1,12 +1,6 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
additionalConfigurationOptions: '', additionalConfigurationOptions: '',
admin_password: '', admin_password: '',
@ -26,9 +20,7 @@ define(function (require) {
state: null, state: null,
title: '', title: '',
von: false, von: false,
verify_signatures: false, verify_signatures: false
}, },
urlRoot: '/api/servers/', urlRoot: '/api/servers/'
}); })
});

View File

@ -1,17 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: { defaults: {
path: '', path: '',
type: '', type: ''
}, },
urlRoot: '/api/settings' urlRoot: '/api/settings'
}); })
});

View File

@ -1,95 +1,91 @@
define(function (require) { var $ = require('jquery')
var Backbone = require('backbone')
"use strict"; var LayoutView = require('app/views/layout')
var NavigationView = require('app/views/navigation')
var ServersView = require('app/views/servers/list')
var LogsListView = require('app/views/logs/list')
var MissionsView = require('app/views/missions/index')
var ModsListView = require('app/views/mods/list')
var ServerView = require('app/views/servers/view')
var Logs = require('app/collections/logs')
var Missions = require('app/collections/missions')
var Mods = require('app/collections/mods')
var Settings = require('app/models/settings')
var Servers = require('app/collections/servers')
var $ = require('jquery'), var $body = $('body')
Backbone = require('backbone'), var missions = new Missions()
LayoutView = require('app/views/layout'), var mods = new Mods()
NavigationView = require('app/views/navigation'), var settings = new Settings()
ServersView = require('app/views/servers/list'), var servers = new Servers()
LogsListView = require('app/views/logs/list'), var layoutView = new LayoutView({ el: $body }).render()
MissionsView = require('app/views/missions/index'),
ModsListView = require('app/views/mods/list'),
ServerView = require('app/views/servers/view'),
Logs = require('app/collections/logs'),
Missions = require('app/collections/missions'),
Mods = require('app/collections/mods'),
Settings = require('app/models/settings'),
Servers = require('app/collections/servers'),
$body = $('body'), module.exports = Backbone.Router.extend({
missions = new Missions(),
mods = new Mods(),
settings = new Settings(),
servers = new Servers(),
layoutView = new LayoutView({el: $body}).render();
return Backbone.Router.extend({
routes: { routes: {
"logs": "logs", logs: 'logs',
"missions": "missions", missions: 'missions',
"mods": "mods", mods: 'mods',
"servers/:id": "server", 'servers/:id': 'server',
"": "home", '': 'home'
}, },
initialize: function () { initialize: function () {
layoutView.navigation.show(new NavigationView({settings: settings, servers: servers})); layoutView.navigation.show(new NavigationView({ settings: settings, servers: servers }))
var initialized = false; var initialized = false
var socket = io.connect(); /* global io */
var socket = io.connect()
socket.on('missions', function (_missions) { socket.on('missions', function (_missions) {
missions.set(_missions); missions.set(_missions)
}); })
socket.on('mods', function (_mods) { socket.on('mods', function (_mods) {
mods.set(_mods); mods.set(_mods)
}); })
socket.on('servers', function (_servers) { socket.on('servers', function (_servers) {
servers.set(_servers); servers.set(_servers)
if (!initialized) { if (!initialized) {
initialized = true; initialized = true
Backbone.history.start(); Backbone.history.start()
} }
}); })
socket.on('settings', function (_settings) { socket.on('settings', function (_settings) {
settings.set(_settings); settings.set(_settings)
}); })
}, },
home: function () { home: function () {
layoutView.content.show(new ServersView({collection: servers})); layoutView.content.show(new ServersView({ collection: servers }))
}, },
logs: function () { logs: function () {
var logs = new Logs(); var logs = new Logs()
logs.fetch(); logs.fetch()
layoutView.content.show(new LogsListView({collection: logs})); layoutView.content.show(new LogsListView({ collection: logs }))
}, },
missions: function () { missions: function () {
layoutView.content.show(new MissionsView({missions: missions})); layoutView.content.show(new MissionsView({ missions: missions }))
}, },
mods: function () { mods: function () {
layoutView.content.show(new ModsListView({collection: mods})); layoutView.content.show(new ModsListView({ collection: mods }))
}, },
server: function (id) { server: function (id) {
var server = servers.get(id); var server = servers.get(id)
if (server) { if (server) {
layoutView.content.show(new ServerView({ layoutView.content.show(new ServerView({
model: server, model: server,
missions: missions, missions: missions,
mods: mods, mods: mods
})); }))
} else { } else {
this.navigate("#", true); this.navigate('#', true)
} }
} }
}); })
});

View File

@ -1,20 +1,13 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/layout.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/layout.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {
navigation: "#navigation", navigation: '#navigation',
content: "#content" content: '#content'
} }
}); })
});

View File

@ -1,15 +1,8 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/login.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/login.html');
return Marionette.ItemView.extend({
template: _.template(tpl) template: _.template(tpl)
}); })
});

View File

@ -1,19 +1,13 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var ListItemView = require('app/views/logs/list_item')
var tpl = require('tpl/logs/list.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/logs/list_item'),
tpl = require('text!tpl/logs/list.html'),
template = _.template(tpl); module.exports = Marionette.CompositeView.extend({
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: template, template: template
}); })
});

View File

@ -1,37 +1,31 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/logs/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/logs/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click .destroy": "deleteLog", 'click .destroy': 'deleteLog'
}, },
deleteLog: function (event) { deleteLog: function (event) {
var self = this; var self = this
sweetAlert({ sweetAlert({
title: "Are you sure?", title: 'Are you sure?',
text: "The log will be deleted from the server!", text: 'The log will be deleted from the server!',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonClass: "btn-danger", confirmButtonClass: 'btn-danger',
confirmButtonText: "Yes, delete it!", confirmButtonText: 'Yes, delete it!'
}, },
function () { function () {
self.model.destroy(); self.model.destroy()
}); })
}, }
}); })
});

View File

@ -1,17 +1,13 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var UploadView = require('app/views/missions/upload')
var WorkshopView = require('app/views/missions/workshop')
var ListView = require('app/views/missions/list')
var tpl = require('tpl/missions/index.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
UploadView = require('app/views/missions/upload'),
WorkshopView = require('app/views/missions/workshop'),
ListView = require('app/views/missions/list'),
tpl = require('text!tpl/missions/index.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
templateHelpers: function () { templateHelpers: function () {
return { return {
@ -20,14 +16,14 @@ define(function (require) {
}, },
regions: { regions: {
uploadView: "#upload", uploadView: '#upload',
workshopView: "#workshop", workshopView: '#workshop',
listView: "#list", listView: '#list'
}, },
events: { events: {
"click #refresh": "refresh", 'click #refresh': 'refresh',
"keyup #filterMissions": "updateFilter", 'keyup #filterMissions': 'updateFilter'
}, },
initialize: function () { initialize: function () {
@ -35,30 +31,28 @@ define(function (require) {
}, },
updateFilter: function (event) { updateFilter: function (event) {
this.filterValue = event.target.value; this.filterValue = event.target.value
this.listView.currentView.filterValue = this.filterValue; this.listView.currentView.filterValue = this.filterValue
this.listView.currentView.render(); this.listView.currentView.render()
}, },
onRender: function () { onRender: function () {
this.uploadView.show(new UploadView()); this.uploadView.show(new UploadView())
this.workshopView.show(new WorkshopView()); this.workshopView.show(new WorkshopView())
this.listView.show(new ListView({collection: this.options.missions, filterValue: this.filterValue})); this.listView.show(new ListView({ collection: this.options.missions, filterValue: this.filterValue }))
}, },
refresh: function (event) { refresh: function (event) {
event.preventDefault(); event.preventDefault()
$.ajax({ $.ajax({
url: "/api/missions/refresh", url: '/api/missions/refresh',
type: 'POST', type: 'POST',
success: function (resp) { success: function (resp) {
}, },
error: function (resp) { error: function (resp) {
}, }
}); })
}, }
}); })
});

View File

@ -1,27 +1,21 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var ListItemView = require('app/views/missions/list_item')
var tpl = require('tpl/missions/list.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/missions/list_item'),
tpl = require('text!tpl/missions/list.html'),
template = _.template(tpl); module.exports = Marionette.CompositeView.extend({
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: template, template: template,
initialize: function (options) { initialize: function (options) {
this.filterValue = options.filterValue; this.filterValue = options.filterValue
}, },
filter: function (child, index, collection) { filter: function (child, index, collection) {
return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0; return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0
}, }
}); })
});

View File

@ -1,37 +1,31 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/missions/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/missions/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click .delete": "deleteMission" 'click .delete': 'deleteMission'
}, },
deleteMission: function (event) { deleteMission: function (event) {
var self = this; var self = this
sweetAlert({ sweetAlert({
title: "Are you sure?", title: 'Are you sure?',
text: "The mission will be deleted from the server!", text: 'The mission will be deleted from the server!',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonClass: "btn-danger", confirmButtonClass: 'btn-danger',
confirmButtonText: "Yes, delete it!", confirmButtonText: 'Yes, delete it!'
}, },
function () { function () {
self.model.destroy(); self.model.destroy()
}); })
}, }
}); })
});

View File

@ -1,42 +1,35 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
var Ladda = require('ladda')
"use strict"; var tpl = require('tpl/missions/upload.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Ladda = require('ladda'),
IframeTransport = require('jquery.iframe-transport'),
Mission = require('app/models/mission'),
tpl = require('text!tpl/missions/upload.html');
return Marionette.ItemView.extend({
template: _.template(tpl), template: _.template(tpl),
events: { events: {
'click form button': 'submit', 'click form button': 'submit'
}, },
submit: function () { submit: function () {
var self = this; var self = this
var $form = this.$el.find('form'); var $form = this.$el.find('form')
var $uploadBtn = $form.find('button[type=submit]'); var $uploadBtn = $form.find('button[type=submit]')
var laddaBtn = Ladda.create($uploadBtn.get(0)); var laddaBtn = Ladda.create($uploadBtn.get(0))
laddaBtn.start(); laddaBtn.start()
$.ajax("/api/missions", { $.ajax('/api/missions', {
success: function (data) { success: function (data) {
laddaBtn.stop(); laddaBtn.stop()
self.render(); self.render()
}, },
error: function () { error: function () {
laddaBtn.stop(); laddaBtn.stop()
}, },
files: $form.find(":file"), files: $form.find(':file'),
iframe: true iframe: true
}); })
}, }
}); })
});

View File

@ -1,50 +1,43 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
var Ladda = require('ladda')
"use strict"; var tpl = require('tpl/missions/workshop.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Ladda = require('ladda'),
IframeTransport = require('jquery.iframe-transport'),
Mission = require('app/models/mission'),
tpl = require('text!tpl/missions/workshop.html');
return Marionette.ItemView.extend({
template: _.template(tpl), template: _.template(tpl),
events: { events: {
'click form button': 'submit', 'click form button': 'submit'
}, },
initialize: function (options) { initialize: function (options) {
this.missions = options.missions; this.missions = options.missions
}, },
submit: function () { submit: function () {
var self = this; var self = this
var $form = this.$el.find('form'); var $form = this.$el.find('form')
var $downloadBtn = $form.find('button[type=submit]'); var $downloadBtn = $form.find('button[type=submit]')
var laddaBtn = Ladda.create($downloadBtn.get(0)); var laddaBtn = Ladda.create($downloadBtn.get(0))
laddaBtn.start(); laddaBtn.start()
$.ajax({ $.ajax({
url: '/api/missions/workshop', url: '/api/missions/workshop',
type: 'POST', type: 'POST',
data: { data: {
id: $form.find("input.workshop").val(), id: $form.find('input.workshop').val()
}, },
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
laddaBtn.stop(); laddaBtn.stop()
self.render(); self.render()
}, },
error: function () { error: function () {
laddaBtn.stop(); laddaBtn.stop()
}, }
}); })
}, }
}); })
});

View File

@ -1,37 +1,32 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var ListItemView = require('app/views/mods/list_item')
var tpl = require('tpl/mods/list.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/mods/list_item'),
tpl = require('text!tpl/mods/list.html'),
template = _.template(tpl); module.exports = Marionette.CompositeView.extend({
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: template, template: template,
events: { events: {
"click #refresh": "refresh", 'click #refresh': 'refresh'
}, },
refresh: function (event) { refresh: function (event) {
event.preventDefault(); event.preventDefault()
$.ajax({ $.ajax({
url: "/api/mods/refresh", url: '/api/mods/refresh',
type: 'POST', type: 'POST',
success: function (resp) { success: function (resp) {
}, },
error: function (resp) { error: function (resp) {
}, }
}); })
}, }
}); })
});

View File

@ -1,38 +1,31 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/mods/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Ladda = require('ladda'),
swal = require('sweet-alert'),
tpl = require('text!tpl/mods/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click .destroy": "deleteMod", 'click .destroy': 'deleteMod'
}, },
deleteMod: function (event) { deleteMod: function (event) {
var self = this; var self = this
sweetAlert({ sweetAlert({
title: "Are you sure?", title: 'Are you sure?',
text: "The mod will be deleted from the server!", text: 'The mod will be deleted from the server!',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonClass: "btn-danger", confirmButtonClass: 'btn-danger',
confirmButtonText: "Yes, delete it!", confirmButtonText: 'Yes, delete it!'
}, },
function () { function () {
self.model.destroy(); self.model.destroy()
}); })
}, }
}); })
});

View File

@ -1,17 +1,13 @@
define(function (require) { var _ = require('underscore')
var Backbone = require('backbone')
var Marionette = require('marionette')
var BootstrapModal = require('backbone.bootstrap-modal')
"use strict"; var ServersListView = require('app/views/navigation/servers/list')
var SettingsView = require('app/views/settings')
var tpl = require('tpl/navigation.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
BootstrapModal = require('backbone.bootstrap-modal'),
ServersListView = require('app/views/navigation/servers/list'),
SettingsView = require('app/views/settings'),
tpl = require('text!tpl/navigation.html');
return Marionette.ItemView.extend({
template: _.template(tpl), template: _.template(tpl),
templateHelpers: function () { templateHelpers: function () {
@ -23,26 +19,24 @@ define(function (require) {
}, },
events: { events: {
"click #settings": "settings" 'click #settings': 'settings'
}, },
initialize: function (options) { initialize: function (options) {
this.settings = options.settings; this.settings = options.settings
this.servers = options.servers; this.servers = options.servers
this.serversListView = new ServersListView({ collection: this.servers }) this.serversListView = new ServersListView({ collection: this.servers })
Backbone.history.on('route', this.render); Backbone.history.on('route', this.render)
}, },
onDomRefresh: function () { onDomRefresh: function () {
this.serversListView.setElement('#servers-list'); this.serversListView.setElement('#servers-list')
this.serversListView.render(); this.serversListView.render()
}, },
settings: function (event) { settings: function (event) {
event.preventDefault(); event.preventDefault()
var view = new SettingsView({ model: this.settings }); var view = new SettingsView({ model: this.settings })
new Backbone.BootstrapModal({ content: view, animate: true, cancelText: false }).open(); new BootstrapModal({ content: view, animate: true, cancelText: false }).open()
} }
}); })
});

View File

@ -1,15 +1,8 @@
define(function (require) { var Marionette = require('marionette')
"use strict"; var ListItemView = require('app/views/navigation/servers/list_item')
var $ = require('jquery'), module.exports = Marionette.CollectionView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/navigation/servers/list_item');
return Marionette.CollectionView.extend({
tagName: 'ul', tagName: 'ul',
childView: ListItemView, childView: ListItemView
}); })
});

View File

@ -1,20 +1,15 @@
define(function (require) { var _ = require('underscore')
var Backbone = require('backbone')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/navigation/servers/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/navigation/servers/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
return Marionette.ItemView.extend({
className: function () { className: function () {
return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : '' return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : ''
}, },
tagName: "li", tagName: 'li',
template: template template: template
}); })
});

View File

@ -1,20 +1,13 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/servers/empty.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'), tagName: 'tr',
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/empty.html');
return Marionette.ItemView.extend({
tagName: "tr",
template: _.template(tpl), template: _.template(tpl),
initialize: function (options) { initialize: function (options) {
this.servers = options.servers; this.servers = options.servers
}, }
}); })
});

View File

@ -1,61 +1,62 @@
define(function (require) { var _ = require('underscore')
var Backbone = require('backbone')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/servers/form.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/form.html');
return Marionette.ItemView.extend({
template: _.template(tpl), template: _.template(tpl),
initialize: function (options) { initialize: function (options) {
this.servers = options.servers; this.servers = options.servers
this.bind("ok", this.submit); this.bind('ok', this.submit)
}, },
serialize: function () { serialize: function () {
return { return {
additionalConfigurationOptions: this.$("form .additional-configuration-options").val(), additionalConfigurationOptions: this.$('form .additional-configuration-options').val(),
admin_password: this.$("form .admin-password").val(), admin_password: this.$('form .admin-password').val(),
allowed_file_patching: this.$("form .allowed-file-patching").prop("checked") ? 2 : 1, allowed_file_patching: this.$('form .allowed-file-patching').prop('checked') ? 2 : 1,
auto_start: this.$("form .auto-start").prop("checked"), auto_start: this.$('form .auto-start').prop('checked'),
battle_eye: this.$("form .battle-eye").prop("checked"), battle_eye: this.$('form .battle-eye').prop('checked'),
file_patching: this.$("form .file-patching").prop("checked"), file_patching: this.$('form .file-patching').prop('checked'),
forcedDifficulty: this.$("form .forcedDifficulty").val(), forcedDifficulty: this.$('form .forcedDifficulty').val(),
max_players: this.$("form .max-players").val(), max_players: this.$('form .max-players').val(),
motd: this.$("form .motd").val(), motd: this.$('form .motd').val(),
number_of_headless_clients: this.$("form .headless-clients").val(), number_of_headless_clients: this.$('form .headless-clients').val(),
password: this.$("form .password").val(), password: this.$('form .password').val(),
persistent: this.$("form .persistent").prop("checked"), persistent: this.$('form .persistent').prop('checked'),
port: this.$("form .port").val(), port: this.$('form .port').val(),
title: this.$("form .title").val(), title: this.$('form .title').val(),
von: this.$("form .von").prop("checked"), von: this.$('form .von').prop('checked'),
verify_signatures: this.$("form .verify_signatures").prop("checked"), verify_signatures: this.$('form .verify_signatures').prop('checked')
}; }
}, },
submit: function (modal) { submit: function (modal) {
modal.preventClose(); modal.preventClose()
this.model.set(this.serialize()); this.model.set(this.serialize())
var self = this; var self = this
this.model.save({}, { this.model.save({}, {
success: function () { success: function () {
modal.close(); modal.close()
self.servers.fetch({success : function () { self.servers.fetch({
Backbone.history.navigate('#servers/' + self.model.get('id'), true); success: function () {
}}); Backbone.history.navigate('#servers/' + self.model.get('id'), true)
}
})
}, },
error: function() { error: function (model, response) {
alert("Error :("); sweetAlert({
title: 'Error',
text: 'An error occurred, please consult the logs',
type: 'error'
})
} }
}); })
} }
}); })
});

View File

@ -1,58 +1,53 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/servers/info.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/servers/info.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
events: { events: {
"click #start": "start", 'click #start': 'start',
"click #stop": "stop", 'click #stop': 'stop'
}, },
start: function (event) { start: function (event) {
var self = this; var self = this
event.preventDefault(); event.preventDefault()
$.ajax({ $.ajax({
url: "/api/servers/" + this.model.get('id') + "/start", url: '/api/servers/' + this.model.get('id') + '/start',
type: 'POST', type: 'POST',
success: function (resp) { success: function (resp) {
self.model.set("pid", resp.pid); self.model.set('pid', resp.pid)
self.render(); self.render()
}, },
error: $.noop error: $.noop
}); })
}, },
stop: function (event) { stop: function (event) {
var self = this; var self = this
event.preventDefault(); event.preventDefault()
sweetAlert({ sweetAlert({
title: "Are you sure?", title: 'Are you sure?',
text: "The server will stopped.", text: 'The server will stopped.',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonClass: "btn-warning", confirmButtonClass: 'btn-warning',
confirmButtonText: "Yes, stop it!", confirmButtonText: 'Yes, stop it!'
}, },
function () { function () {
$.ajax({ $.ajax({
url: "/api/servers/" + self.model.get('id') + "/stop", url: '/api/servers/' + self.model.get('id') + '/stop',
type: 'POST', type: 'POST',
success: function (resp) { success: function (resp) {
self.model.set("pid", resp.pid); self.model.set('pid', resp.pid)
self.render(); self.render()
}, },
error: $.noop error: $.noop
}); })
}); })
}, }
}); })
});

View File

@ -1,47 +1,42 @@
define(function (require) { var _ = require('underscore')
var Backbone = require('backbone')
var Marionette = require('marionette')
"use strict"; var Server = require('app/models/server')
var AddServerView = require('app/views/servers/form')
var EmptyView = require('app/views/servers/empty')
var ListItemView = require('app/views/servers/list_item')
var tpl = require('tpl/servers/list.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Server = require('app/models/server'),
AddServerView = require('app/views/servers/form'),
EmptyView = require('app/views/servers/empty'),
ListItemView = require('app/views/servers/list_item'),
tpl = require('text!tpl/servers/list.html'),
template = _.template(tpl); module.exports = Marionette.CompositeView.extend({
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: template, template: template,
emptyView: EmptyView, emptyView: EmptyView,
events: { events: {
"click #add-server": "addServer" 'click #add-server': 'addServer'
}, },
buildChildView: function (item, ChildViewType, childViewOptions) { buildChildView: function (item, ChildViewType, childViewOptions) {
// build the final list of options for the item view type // build the final list of options for the item view type
var options = _.extend({model: item}, childViewOptions); var options = _.extend({ model: item }, childViewOptions)
if (ChildViewType == EmptyView) { if (ChildViewType === EmptyView) {
options = _.extend({servers: this.collection}, options); options = _.extend({ servers: this.collection }, options)
} }
// create the item view instance // create the item view instance
var view = new ChildViewType(options); var view = new ChildViewType(options)
// return it // return it
return view; return view
}, },
addServer: function () { addServer: function () {
var view = new AddServerView({model: new Server(), servers: this.collection}); var view = new AddServerView({ model: new Server(), servers: this.collection })
new Backbone.BootstrapModal({ content: view, servers: this.collection }).open() new Backbone.BootstrapModal({ content: view, servers: this.collection }).open()
}, }
}); })
});

View File

@ -1,53 +1,47 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var tpl = require('tpl/servers/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/servers/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click .clone": "clone", 'click .clone': 'clone',
"click .delete": "delete", 'click .delete': 'delete'
}, },
modelEvents: { modelEvents: {
"change": "serverUpdated", change: 'serverUpdated'
}, },
clone: function (e) { clone: function (e) {
var title = this.model.get('title') + ' Clone'; var title = this.model.get('title') + ' Clone'
var clone = this.model.clone(); var clone = this.model.clone()
clone.set({id: null, title: title, auto_start: false}); clone.set({ id: null, title: title, auto_start: false })
clone.save(); clone.save()
}, },
delete: function (event) { delete: function (event) {
var self = this; var self = this
sweetAlert({ sweetAlert({
title: "Are you sure?", title: 'Are you sure?',
text: "Your server configuration will be deleted!", text: 'Your server configuration will be deleted!',
type: "warning", type: 'warning',
showCancelButton: true, showCancelButton: true,
confirmButtonClass: "btn-danger", confirmButtonClass: 'btn-danger',
confirmButtonText: "Yes, delete it!", confirmButtonText: 'Yes, delete it!'
}, },
function () { function () {
self.model.destroy(); self.model.destroy()
}); })
}, },
serverUpdated: function (event) { serverUpdated: function (event) {
this.render(); this.render()
}, }
}); })
});

View File

@ -1,36 +1,29 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var ListItemView = require('app/views/servers/missions/available/list_item')
var tpl = require('tpl/servers/missions/available/list.html')
var $ = require('jquery'), module.exports = Marionette.CompositeView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/servers/missions/available/list_item'),
tpl = require('text!tpl/servers/missions/available/list.html');
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: _.template(tpl), template: _.template(tpl),
initialize: function (options) { initialize: function (options) {
this.filterValue = options.filterValue; this.filterValue = options.filterValue
}, },
filter: function (child, index, collection) { filter: function (child, index, collection) {
return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0; return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0
}, },
buildChildView: function (item, ChildViewType, childViewOptions) { buildChildView: function (item, ChildViewType, childViewOptions) {
var self = this; var self = this
var options = _.extend({model: item}, childViewOptions); var options = _.extend({ model: item }, childViewOptions)
var view = new ChildViewType(options); var view = new ChildViewType(options)
view.on('add', function (model) { view.on('add', function (model) {
self.trigger('add', model); self.trigger('add', model)
}); })
return view; return view
}, }
}); })
});

View File

@ -1,25 +1,19 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/servers/missions/available/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/missions/available/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click .add": "add" 'click .add': 'add'
}, },
add: function () { add: function () {
this.trigger('add', this.model); this.trigger('add', this.model)
}, }
}); })
});

View File

@ -1,17 +1,12 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var MissionRotations = require('app/collections/mission_rotations')
var AvailableListView = require('app/views/servers/missions/available/list')
var RotationListView = require('app/views/servers/missions/rotation/list')
var tpl = require('tpl/servers/missions/index.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
MissionRotations = require('app/collections/mission_rotations'),
AvailableListView = require('app/views/servers/missions/available/list'),
RotationListView = require('app/views/servers/missions/rotation/list'),
tpl = require('text!tpl/servers/missions/index.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
templateHelpers: function () { templateHelpers: function () {
return { return {
@ -20,54 +15,53 @@ define(function (require) {
}, },
regions: { regions: {
availableView: "#available", availableView: '#available',
rotationView: "#rotation", rotationView: '#rotation'
}, },
events: { events: {
"keyup #filterMissions": "updateFilter", 'keyup #filterMissions': 'updateFilter'
}, },
modelEvents: { modelEvents: {
"change": "serverUpdated", change: 'serverUpdated'
}, },
initialize: function (options) { initialize: function (options) {
this.missions = options.missions; this.missions = options.missions
this.filterValue = '' this.filterValue = ''
this.rotationCollection = new MissionRotations(this.model.get('missions')); this.rotationCollection = new MissionRotations(this.model.get('missions'))
var self = this; var self = this
this.availableListView = new AvailableListView({collection: this.missions, filterValue: this.filterValue}); this.availableListView = new AvailableListView({ collection: this.missions, filterValue: this.filterValue })
this.availableListView.on('add', function (model) { this.availableListView.on('add', function (model) {
self.rotationCollection.add([{ self.rotationCollection.add([{
name: model.get('name').replace('.pbo', ''), name: model.get('name').replace('.pbo', '')
}]); }])
}); })
this.rotationListView = new RotationListView({collection: this.rotationCollection}); this.rotationListView = new RotationListView({ collection: this.rotationCollection })
}, },
onRender: function () { onRender: function () {
this.availableView.show(this.availableListView); this.availableView.show(this.availableListView)
this.rotationView.show(this.rotationListView); this.rotationView.show(this.rotationListView)
}, },
updateFilter: function (event) { updateFilter: function (event) {
this.filterValue = event.target.value; this.filterValue = event.target.value
this.availableView.currentView.filterValue = this.filterValue; this.availableView.currentView.filterValue = this.filterValue
this.availableView.currentView.render(); this.availableView.currentView.render()
}, },
serverUpdated: function () { serverUpdated: function () {
this.rotationCollection.set(this.model.get('missions')); this.rotationCollection.set(this.model.get('missions'))
}, },
serialize: function () { serialize: function () {
return { return {
missions: this.rotationCollection.toJSON(), missions: this.rotationCollection.toJSON()
}; }
}, }
}); })
});

View File

@ -1,28 +1,21 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var MissionRotation = require('app/models/mission_rotation')
var ListItemView = require('app/views/servers/missions/rotation/list_item')
var tpl = require('tpl/servers/missions/rotation/list.html')
var $ = require('jquery'), module.exports = Marionette.CompositeView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
MissionRotation = require('app/models/mission_rotation'),
ListItemView = require('app/views/servers/missions/rotation/list_item'),
tpl = require('text!tpl/servers/missions/rotation/list.html');
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: _.template(tpl), template: _.template(tpl),
events: { events: {
"click .add-mission": "addMission", 'click .add-mission': 'addMission'
}, },
addMission: function (e) { addMission: function (e) {
e.preventDefault(); e.preventDefault()
this.collection.add(new MissionRotation()); this.collection.add(new MissionRotation())
}, }
}); })
});

View File

@ -1,39 +1,34 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/servers/missions/rotation/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/missions/rotation/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click button.delete": "delete", 'click button.delete': 'delete',
"change select#difficulty": "changed", 'change select#difficulty': 'changed',
"change input#name": "changed", 'change input#name': 'changed'
}, },
changed: function (e) { changed: function (e) {
var val = $(e.target).val(); var val = $(e.target).val()
this.model.set(e.target.id, val); this.model.set(e.target.id, val)
}, },
delete: function (e) { delete: function (e) {
e.preventDefault(); e.preventDefault()
this.model.destroy(); this.model.destroy()
}, },
onRender: function () { onRender: function () {
var difficulty = this.model.get('difficulty'); var difficulty = this.model.get('difficulty')
var $option = this.$el.find("#difficulty option[value='" + difficulty + "']"); var $option = this.$el.find("#difficulty option[value='" + difficulty + "']")
$option.attr("selected", "selected"); $option.attr('selected', 'selected')
}, }
}); })
});

View File

@ -1,54 +1,46 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
"use strict"; var ModsListView = require('app/views/mods/list')
var ListItemView = require('app/views/servers/mods/list_item')
var tpl = require('tpl/servers/mods/list.html')
var $ = require('jquery'), module.exports = ModsListView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Mods = require('app/collections/mods'),
ModsListView = require('app/views/mods/list'),
ListItemView = require('app/views/servers/mods/list_item'),
tpl = require('text!tpl/servers/mods/list.html');
return ModsListView.extend({
childView: ListItemView, childView: ListItemView,
template: _.template(tpl), template: _.template(tpl),
events: { events: {
"click .check-all": "checkAll", 'click .check-all': 'checkAll',
"click .uncheck-all": "uncheckAll", 'click .uncheck-all': 'uncheckAll'
}, },
buildChildView: function (item, ChildViewType, childViewOptions) { buildChildView: function (item, ChildViewType, childViewOptions) {
var options = _.extend({model: item, server: this.options.server}, childViewOptions); var options = _.extend({ model: item, server: this.options.server }, childViewOptions)
var view = new ChildViewType(options); var view = new ChildViewType(options)
return view; return view
}, },
changeAllCheckbox: function (checked) { changeAllCheckbox: function (checked) {
this.$('input:checkbox').map(function (idx, el) { this.$('input:checkbox').map(function (idx, el) {
return $(el).prop('checked', checked); return $(el).prop('checked', checked)
}) })
}, },
checkAll: function (e) { checkAll: function (e) {
e.preventDefault(); e.preventDefault()
this.changeAllCheckbox(true); this.changeAllCheckbox(true)
}, },
uncheckAll: function (e) { uncheckAll: function (e) {
e.preventDefault(); e.preventDefault()
this.changeAllCheckbox(false); this.changeAllCheckbox(false)
}, },
serialize: function () { serialize: function () {
return { return {
mods: this.$('input:checkbox:checked').map(function (idx, el) { mods: this.$('input:checkbox:checked').map(function (idx, el) {
return $(el).val(); return $(el).val()
}).get(), }).get()
} }
}, }
}); })
});

View File

@ -1,24 +1,17 @@
define(function (require) { var _ = require('underscore')
"use strict"; var ModListItemView = require('app/views/mods/list_item')
var tpl = require('tpl/servers/mods/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ModListItemView = require('app/views/mods/list_item'),
tpl = require('text!tpl/servers/mods/list_item.html'),
template = _.template(tpl); module.exports = ModListItemView.extend({
tagName: 'tr',
return ModListItemView.extend({
tagName: "tr",
template: template, template: template,
templateHelpers: function () { templateHelpers: function () {
return { return {
enabled: this.options.server.get('mods').indexOf(this.model.get('name')) > -1 enabled: this.options.server.get('mods').indexOf(this.model.get('name')) > -1
} }
}, }
}); })
});

View File

@ -1,54 +1,47 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var Parameter = require('app/models/parameter')
var Parameters = require('app/collections/parameters')
var ListItemView = require('app/views/servers/parameters/list_item')
var tpl = require('tpl/servers/parameters/list.html')
var $ = require('jquery'), module.exports = Marionette.CompositeView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Parameter = require('app/models/parameter'),
Parameters = require('app/collections/parameters'),
ListItemView = require('app/views/servers/parameters/list_item'),
tpl = require('text!tpl/servers/parameters/list.html');
return Marionette.CompositeView.extend({
childView: ListItemView, childView: ListItemView,
childViewContainer: "tbody", childViewContainer: 'tbody',
template: _.template(tpl), template: _.template(tpl),
events: { events: {
"click .add-parameter": "addParameter", 'click .add-parameter': 'addParameter'
}, },
modelEvents: { modelEvents: {
"change": "serverUpdated", change: 'serverUpdated'
}, },
initialize: function (options) { initialize: function (options) {
this.collection = new Parameters(); this.collection = new Parameters()
this.serverUpdated(); this.serverUpdated()
}, },
addParameter: function (e) { addParameter: function (e) {
e.preventDefault(); e.preventDefault()
this.collection.add(new Parameter()); this.collection.add(new Parameter())
}, },
serialize: function () { serialize: function () {
return { return {
parameters: this.collection.map(function (parameter) { parameters: this.collection.map(function (parameter) {
return parameter.get('parameter'); return parameter.get('parameter')
}), })
}; }
}, },
serverUpdated: function () { serverUpdated: function () {
this.collection.reset(this.model.get('parameters').map(function (parameter) { this.collection.reset(this.model.get('parameters').map(function (parameter) {
return new Parameter({ return new Parameter({
parameter: parameter, parameter: parameter
}); })
})); }))
}, }
}); })
});

View File

@ -1,33 +1,28 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/servers/parameters/list_item.html')
var $ = require('jquery'), var template = _.template(tpl)
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/parameters/list_item.html'),
template = _.template(tpl); module.exports = Marionette.ItemView.extend({
tagName: 'tr',
return Marionette.ItemView.extend({
tagName: "tr",
template: template, template: template,
events: { events: {
"click button.delete": "delete", 'click button.delete': 'delete',
"change input#parameter": "changed", 'change input#parameter': 'changed',
"click button.clone": "clone", 'click button.clone': 'clone'
}, },
changed: function (e) { changed: function (e) {
var val = $(e.target).val(); var val = $(e.target).val()
this.model.set(e.target.id, val); this.model.set(e.target.id, val)
}, },
delete: function (e) { delete: function (e) {
e.preventDefault(); e.preventDefault()
this.model.destroy(); this.model.destroy()
}, }
}); })
});

View File

@ -1,22 +1,15 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/servers/players.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/players.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
templateHelpers: { templateHelpers: {
players: function () { players: function () {
return _.sortBy(this.state.players, function (player) { return _.sortBy(this.state.players, function (player) {
return player.name; return player.name
}); })
} }
}, }
}); })
});

View File

@ -1,90 +1,89 @@
define(function (require) { var $ = require('jquery')
var _ = require('underscore')
var Backbone = require('backbone')
var Marionette = require('marionette')
var sweetAlert = require('sweet-alert')
"use strict"; var FormView = require('app/views/servers/form')
var InfoView = require('app/views/servers/info')
var MissionsView = require('app/views/servers/missions/index')
var ModsListView = require('app/views/servers/mods/list')
var ParametersListView = require('app/views/servers/parameters/list')
var PlayersView = require('app/views/servers/players')
var tpl = require('tpl/servers/view.html')
var $ = require('jquery'), module.exports = Marionette.LayoutView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Mods = require('app/collections/mods'),
FormView = require('app/views/servers/form'),
InfoView = require('app/views/servers/info'),
MissionsView = require('app/views/servers/missions/index'),
ModsListView = require('app/views/servers/mods/list'),
ParametersListView = require('app/views/servers/parameters/list'),
PlayersView = require('app/views/servers/players'),
tpl = require('text!tpl/servers/view.html');
return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {
infoView: "#tab-info", infoView: '#tab-info',
missionsView: "#tab-missions", missionsView: '#tab-missions',
modsView: "#tab-mods", modsView: '#tab-mods',
parametersView: "#parameters", parametersView: '#parameters',
playersView: "#tab-players", playersView: '#tab-players',
settingsView: "#settings", settingsView: '#settings'
}, },
events: { events: {
"click .nav-tabs a" : "tabs", 'click .nav-tabs a': 'tabs',
"submit": "save", submit: 'save'
}, },
modelEvents: { modelEvents: {
"change": "serverUpdated", change: 'serverUpdated'
}, },
initialize: function (options) { initialize: function (options) {
this.missions = options.missions; this.missions = options.missions
this.mods = options.mods; this.mods = options.mods
}, },
onRender: function () { onRender: function () {
this.infoView.show(new InfoView({model: this.model})); this.infoView.show(new InfoView({ model: this.model }))
this.missionsView.show(new MissionsView({missions: this.missions, model: this.model})); this.missionsView.show(new MissionsView({ missions: this.missions, model: this.model }))
this.modsView.show(new ModsListView({collection: this.mods, server: this.model})); this.modsView.show(new ModsListView({ collection: this.mods, server: this.model }))
this.parametersView.show(new ParametersListView({model: this.model})); this.parametersView.show(new ParametersListView({ model: this.model }))
this.playersView.show(new PlayersView({model: this.model})); this.playersView.show(new PlayersView({ model: this.model }))
this.settingsView.show(new FormView({model: this.model})); this.settingsView.show(new FormView({ model: this.model }))
}, },
serverUpdated: function () { serverUpdated: function () {
this.infoView.currentView.render(); this.infoView.currentView.render()
this.modsView.currentView.render(); this.modsView.currentView.render()
this.parametersView.currentView.render(); this.parametersView.currentView.render()
this.playersView.currentView.render(); this.playersView.currentView.render()
this.settingsView.currentView.render(); this.settingsView.currentView.render()
}, },
save: function (e) { save: function (e) {
e.preventDefault(); e.preventDefault()
var self = this; var self = this
var oldId = this.model.get('id'); var oldId = this.model.get('id')
var data = this.settingsView.currentView.serialize(); var data = this.settingsView.currentView.serialize()
_.extend(data, this.missionsView.currentView.serialize()); _.extend(data, this.missionsView.currentView.serialize())
_.extend(data, this.modsView.currentView.serialize()); _.extend(data, this.modsView.currentView.serialize())
_.extend(data, this.parametersView.currentView.serialize()); _.extend(data, this.parametersView.currentView.serialize())
this.model.save(data, { this.model.save(data, {
success: function () { success: function () {
var newId = self.model.get('id'); var newId = self.model.get('id')
if (oldId != newId) { if (oldId !== newId) {
Backbone.history.navigate('#servers/' + newId, true); Backbone.history.navigate('#servers/' + newId, true)
} else { } else {
self.serverUpdated(); self.serverUpdated()
} }
}, },
error: function() { error: function (model, response) {
alert("Error :("); sweetAlert({
title: 'Error',
text: 'An error occurred, please consult the logs',
type: 'error'
})
} }
}); })
}, },
tabs: function (e) { tabs: function (e) {
e.preventDefault(); e.preventDefault()
$($(e.target).attr('href')).tab('show'); $($(e.target).attr('href')).tab('show')
}, }
}); })
});

View File

@ -1,25 +1,18 @@
define(function (require) { var _ = require('underscore')
var Marionette = require('marionette')
"use strict"; var tpl = require('tpl/settings.html')
var $ = require('jquery'), module.exports = Marionette.ItemView.extend({
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/settings.html');
return Marionette.ItemView.extend({
template: _.template(tpl), template: _.template(tpl),
modelEvents: { modelEvents: {
'change': 'render', change: 'render'
}, },
templateHelpers: { templateHelpers: {
isTypeChecked: function (type) { isTypeChecked: function (type) {
return this.type === type ? 'checked' : ''; return this.type === type ? 'checked' : ''
}, }
}, }
}); })
});

View File

@ -25,12 +25,6 @@ module.exports = {
} }
}, },
resolveLoader: {
alias: {
text: 'raw-loader'
}
},
plugins: [ plugins: [
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
_: 'underscore', _: 'underscore',
@ -43,6 +37,7 @@ module.exports = {
module: { module: {
loaders: [ loaders: [
{ test: /\.css$/, loaders: ['style-loader', 'css-loader'] }, { test: /\.css$/, loaders: ['style-loader', 'css-loader'] },
{ test: /\.html$/, loaders: ['raw-loader'] },
{ test: /\.json$/, loaders: ['json-loader'] }, { test: /\.json$/, loaders: ['json-loader'] },
{ test: /\.png$/, loader: 'url-loader?limit=8192&mimetype=image/png' }, { test: /\.png$/, loader: 'url-loader?limit=8192&mimetype=image/png' },
{ test: /\.jpe?g$/, loader: 'url-loader?limit=8192&mimetype=image/jpg' }, { test: /\.jpe?g$/, loader: 'url-loader?limit=8192&mimetype=image/jpg' },