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'), comparator: 'name',
Backbone = require('backbone'), model: Log,
Log = require('app/models/log'); url: '/api/logs/'
})
return Backbone.Collection.extend({
comparator: 'name',
model: Log,
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'), comparator: 'name',
Backbone = require('backbone'), model: Mission,
Mission = require('app/models/mission'); url: '/api/missions/'
})
return Backbone.Collection.extend({
comparator: 'name',
model: Mission,
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'), comparator: 'name',
Backbone = require('backbone'), model: Mod,
Mod = require('app/models/mod'); url: '/api/mods/'
})
return Backbone.Collection.extend({
comparator: 'name',
model: Mod,
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'), comparator: function (a, b) {
Backbone = require('backbone'), return a.get('title').toLowerCase().localeCompare(b.get('title').toLowerCase())
Server = require('app/models/server'); },
model: Server,
return Backbone.Collection.extend({ url: '/api/servers/'
comparator: function (a, b) { })
return a.get('title').toLowerCase().localeCompare(b.get('title').toLowerCase());
},
model: Server,
url: '/api/servers/'
});
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,34 +1,26 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
defaults: {
var $ = require('jquery'), additionalConfigurationOptions: '',
_ = require('underscore'), admin_password: '',
Backbone = require('backbone'); allowed_file_patching: 1,
auto_start: false,
return Backbone.Model.extend({ battle_eye: false,
defaults: { file_patching: false,
additionalConfigurationOptions: '', forcedDifficulty: '',
admin_password: '', max_players: null,
allowed_file_patching: 1, mods: [],
auto_start: false, motd: '',
battle_eye: false, number_of_headless_clients: 0,
file_patching: false, parameters: [],
forcedDifficulty: '', password: '',
max_players: null, persistent: false,
mods: [], port: 2302,
motd: '', state: null,
number_of_headless_clients: 0, title: '',
parameters: [], von: false,
password: '', verify_signatures: false
persistent: false, },
port: 2302, urlRoot: '/api/servers/'
state: null, })
title: '',
von: false,
verify_signatures: false,
},
urlRoot: '/api/servers/',
});
});

View File

@ -1,17 +1,9 @@
define(function (require) { var Backbone = require('backbone')
"use strict"; module.exports = Backbone.Model.extend({
defaults: {
var $ = require('jquery'), path: '',
_ = require('underscore'), type: ''
Backbone = require('backbone'); },
urlRoot: '/api/settings'
return Backbone.Model.extend({ })
defaults: {
path: '',
type: '',
},
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: {
logs: 'logs',
missions: 'missions',
mods: 'mods',
'servers/:id': 'server',
'': 'home'
},
routes: { initialize: function () {
"logs": "logs", layoutView.navigation.show(new NavigationView({ settings: settings, servers: servers }))
"missions": "missions",
"mods": "mods",
"servers/:id": "server",
"": "home",
},
initialize: function () { var initialized = false
layoutView.navigation.show(new NavigationView({settings: settings, servers: servers}));
var initialized = false; /* global io */
var socket = io.connect()
socket.on('missions', function (_missions) {
missions.set(_missions)
})
socket.on('mods', function (_mods) {
mods.set(_mods)
})
socket.on('servers', function (_servers) {
servers.set(_servers)
var socket = io.connect(); if (!initialized) {
socket.on('missions', function (_missions) { initialized = true
missions.set(_missions); Backbone.history.start()
});
socket.on('mods', function (_mods) {
mods.set(_mods);
});
socket.on('servers', function (_servers) {
servers.set(_servers);
if (!initialized) {
initialized = true;
Backbone.history.start();
}
});
socket.on('settings', function (_settings) {
settings.set(_settings);
});
},
home: function () {
layoutView.content.show(new ServersView({collection: servers}));
},
logs: function () {
var logs = new Logs();
logs.fetch();
layoutView.content.show(new LogsListView({collection: logs}));
},
missions: function () {
layoutView.content.show(new MissionsView({missions: missions}));
},
mods: function () {
layoutView.content.show(new ModsListView({collection: mods}));
},
server: function (id) {
var server = servers.get(id);
if (server) {
layoutView.content.show(new ServerView({
model: server,
missions: missions,
mods: mods,
}));
} else {
this.navigate("#", true);
} }
})
socket.on('settings', function (_settings) {
settings.set(_settings)
})
},
home: function () {
layoutView.content.show(new ServersView({ collection: servers }))
},
logs: function () {
var logs = new Logs()
logs.fetch()
layoutView.content.show(new LogsListView({ collection: logs }))
},
missions: function () {
layoutView.content.show(new MissionsView({ missions: missions }))
},
mods: function () {
layoutView.content.show(new ModsListView({ collection: mods }))
},
server: function (id) {
var server = servers.get(id)
if (server) {
layoutView.content.show(new ServerView({
model: server,
missions: missions,
mods: mods
}))
} else {
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'),
_ = require('underscore'), module.exports = Marionette.LayoutView.extend({
Backbone = require('backbone'), template: _.template(tpl),
Marionette = require('marionette'),
tpl = require('text!tpl/layout.html'); regions: {
navigation: '#navigation',
return Marionette.LayoutView.extend({ content: '#content'
template: _.template(tpl), }
})
regions: {
navigation: "#navigation",
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'),
_ = require('underscore'), module.exports = Marionette.ItemView.extend({
Backbone = require('backbone'), template: _.template(tpl)
Marionette = require('marionette'), })
tpl = require('text!tpl/login.html');
return Marionette.ItemView.extend({
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({
childView: ListItemView,
return Marionette.CompositeView.extend({ childViewContainer: 'tbody',
childView: ListItemView, template: template
childViewContainer: "tbody", })
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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click .destroy': 'deleteLog'
template: template, },
events: { deleteLog: function (event) {
"click .destroy": "deleteLog", var self = this
sweetAlert({
title: 'Are you sure?',
text: 'The log will be deleted from the server!',
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: 'Yes, delete it!'
}, },
function () {
deleteLog: function (event) { self.model.destroy()
var self = this; })
sweetAlert({ }
title: "Are you sure?", })
text: "The log will be deleted from the server!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
},
function(){
self.model.destroy();
});
},
});
});

View File

@ -1,64 +1,58 @@
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'), template: _.template(tpl),
Backbone = require('backbone'), templateHelpers: function () {
Marionette = require('marionette'), return {
UploadView = require('app/views/missions/upload'), filterValue: this.filterValue
WorkshopView = require('app/views/missions/workshop'), }
ListView = require('app/views/missions/list'), },
tpl = require('text!tpl/missions/index.html');
regions: {
uploadView: '#upload',
workshopView: '#workshop',
listView: '#list'
},
events: {
'click #refresh': 'refresh',
'keyup #filterMissions': 'updateFilter'
},
initialize: function () {
this.filterValue = ''
},
updateFilter: function (event) {
this.filterValue = event.target.value
this.listView.currentView.filterValue = this.filterValue
this.listView.currentView.render()
},
onRender: function () {
this.uploadView.show(new UploadView())
this.workshopView.show(new WorkshopView())
this.listView.show(new ListView({ collection: this.options.missions, filterValue: this.filterValue }))
},
refresh: function (event) {
event.preventDefault()
$.ajax({
url: '/api/missions/refresh',
type: 'POST',
success: function (resp) {
},
error: function (resp) {
return Marionette.LayoutView.extend({
template: _.template(tpl),
templateHelpers: function() {
return {
filterValue: this.filterValue
} }
}, })
}
regions: { })
uploadView: "#upload",
workshopView: "#workshop",
listView: "#list",
},
events: {
"click #refresh": "refresh",
"keyup #filterMissions": "updateFilter",
},
initialize: function () {
this.filterValue = ''
},
updateFilter: function (event) {
this.filterValue = event.target.value;
this.listView.currentView.filterValue = this.filterValue;
this.listView.currentView.render();
},
onRender: function() {
this.uploadView.show(new UploadView());
this.workshopView.show(new WorkshopView());
this.listView.show(new ListView({collection: this.options.missions, filterValue: this.filterValue}));
},
refresh: function (event) {
event.preventDefault();
$.ajax({
url: "/api/missions/refresh",
type: 'POST',
success: 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({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({ initialize: function (options) {
childView: ListItemView, this.filterValue = options.filterValue
childViewContainer: "tbody", },
template: template,
initialize: function (options) { filter: function (child, index, collection) {
this.filterValue = options.filterValue; return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0
}, }
})
filter: function (child, index, collection) {
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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click .delete': 'deleteMission'
template: template, },
events: { deleteMission: function (event) {
"click .delete": "deleteMission" var self = this
sweetAlert({
title: 'Are you sure?',
text: 'The mission will be deleted from the server!',
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: 'Yes, delete it!'
}, },
function () {
deleteMission: function (event) { self.model.destroy()
var self = this; })
sweetAlert({ }
title: "Are you sure?", })
text: "The mission will be deleted from the server!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
},
function(){
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'), template: _.template(tpl),
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({ events: {
template: _.template(tpl), 'click form button': 'submit'
},
events: { submit: function () {
'click form button': 'submit', var self = this
}, var $form = this.$el.find('form')
submit: function () { var $uploadBtn = $form.find('button[type=submit]')
var self = this; var laddaBtn = Ladda.create($uploadBtn.get(0))
var $form = this.$el.find('form'); laddaBtn.start()
var $uploadBtn = $form.find('button[type=submit]'); $.ajax('/api/missions', {
var laddaBtn = Ladda.create($uploadBtn.get(0)); success: function (data) {
laddaBtn.start(); laddaBtn.stop()
self.render()
$.ajax("/api/missions", { },
success: function(data) { error: function () {
laddaBtn.stop(); laddaBtn.stop()
self.render(); },
}, files: $form.find(':file'),
error: function () { iframe: true
laddaBtn.stop(); })
}, }
files: $form.find(":file"), })
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'), template: _.template(tpl),
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({ events: {
template: _.template(tpl), 'click form button': 'submit'
},
events: { initialize: function (options) {
'click form button': 'submit', this.missions = options.missions
}, },
initialize: function (options) { submit: function () {
this.missions = options.missions; var self = this
}, var $form = this.$el.find('form')
submit: function () { var $downloadBtn = $form.find('button[type=submit]')
var self = this; var laddaBtn = Ladda.create($downloadBtn.get(0))
var $form = this.$el.find('form'); laddaBtn.start()
var $downloadBtn = $form.find('button[type=submit]'); $.ajax({
var laddaBtn = Ladda.create($downloadBtn.get(0)); url: '/api/missions/workshop',
laddaBtn.start(); type: 'POST',
data: {
$.ajax({ id: $form.find('input.workshop').val()
url: '/api/missions/workshop', },
type: 'POST', dataType: 'json',
data: { success: function (data) {
id: $form.find("input.workshop").val(), laddaBtn.stop()
}, self.render()
dataType: 'json', },
success: function (data) { error: function () {
laddaBtn.stop(); laddaBtn.stop()
self.render(); }
}, })
error: function () { }
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({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({ events: {
childView: ListItemView, 'click #refresh': 'refresh'
childViewContainer: "tbody", },
template: template,
events: { refresh: function (event) {
"click #refresh": "refresh", event.preventDefault()
}, $.ajax({
url: '/api/mods/refresh',
type: 'POST',
success: function (resp) {
refresh: function (event) { },
event.preventDefault(); error: function (resp) {
$.ajax({
url: "/api/mods/refresh",
type: 'POST',
success: 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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click .destroy': 'deleteMod'
template: template, },
events: { deleteMod: function (event) {
"click .destroy": "deleteMod", var self = this
sweetAlert({
title: 'Are you sure?',
text: 'The mod will be deleted from the server!',
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: 'Yes, delete it!'
}, },
function () {
deleteMod: function (event) { self.model.destroy()
var self = this; })
sweetAlert({ }
title: "Are you sure?", })
text: "The mod will be deleted from the server!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
},
function(){
self.model.destroy();
});
},
});
});

View File

@ -1,48 +1,42 @@
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'), template: _.template(tpl),
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({ templateHelpers: function () {
template: _.template(tpl), return {
isActiveRoute: function (route) {
templateHelpers: function() { return Backbone.history.fragment === route ? 'active' : ''
return {
isActiveRoute: function (route) {
return Backbone.history.fragment === route ? 'active' : ''
}
} }
},
events: {
"click #settings": "settings"
},
initialize: function (options) {
this.settings = options.settings;
this.servers = options.servers;
this.serversListView = new ServersListView({ collection: this.servers })
Backbone.history.on('route', this.render);
},
onDomRefresh: function () {
this.serversListView.setElement('#servers-list');
this.serversListView.render();
},
settings: function (event) {
event.preventDefault();
var view = new SettingsView({ model: this.settings });
new Backbone.BootstrapModal({ content: view, animate: true, cancelText: false }).open();
} }
}); },
}); events: {
'click #settings': 'settings'
},
initialize: function (options) {
this.settings = options.settings
this.servers = options.servers
this.serversListView = new ServersListView({ collection: this.servers })
Backbone.history.on('route', this.render)
},
onDomRefresh: function () {
this.serversListView.setElement('#servers-list')
this.serversListView.render()
},
settings: function (event) {
event.preventDefault()
var view = new SettingsView({ model: this.settings })
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'), tagName: 'ul',
Backbone = require('backbone'), childView: ListItemView
Marionette = require('marionette'), })
ListItemView = require('app/views/navigation/servers/list_item');
return Marionette.CollectionView.extend({
tagName: 'ul',
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({
className: function () {
return Marionette.ItemView.extend({ return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : ''
className: function () { },
return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : '' tagName: 'li',
}, template: template
tagName: "li", })
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'), template: _.template(tpl),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/empty.html');
return Marionette.ItemView.extend({ initialize: function (options) {
tagName: "tr", this.servers = options.servers
template: _.template(tpl), }
})
initialize: function (options) {
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'), template: _.template(tpl),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/form.html');
return Marionette.ItemView.extend({ initialize: function (options) {
template: _.template(tpl), this.servers = options.servers
this.bind('ok', this.submit)
},
initialize: function (options) { serialize: function () {
this.servers = options.servers; return {
this.bind("ok", this.submit); additionalConfigurationOptions: this.$('form .additional-configuration-options').val(),
}, admin_password: this.$('form .admin-password').val(),
allowed_file_patching: this.$('form .allowed-file-patching').prop('checked') ? 2 : 1,
serialize : function() { auto_start: this.$('form .auto-start').prop('checked'),
return { battle_eye: this.$('form .battle-eye').prop('checked'),
additionalConfigurationOptions: this.$("form .additional-configuration-options").val(), file_patching: this.$('form .file-patching').prop('checked'),
admin_password: this.$("form .admin-password").val(), forcedDifficulty: this.$('form .forcedDifficulty').val(),
allowed_file_patching: this.$("form .allowed-file-patching").prop("checked") ? 2 : 1, max_players: this.$('form .max-players').val(),
auto_start: this.$("form .auto-start").prop("checked"), motd: this.$('form .motd').val(),
battle_eye: this.$("form .battle-eye").prop("checked"), number_of_headless_clients: this.$('form .headless-clients').val(),
file_patching: this.$("form .file-patching").prop("checked"), password: this.$('form .password').val(),
forcedDifficulty: this.$("form .forcedDifficulty").val(), persistent: this.$('form .persistent').prop('checked'),
max_players: this.$("form .max-players").val(), port: this.$('form .port').val(),
motd: this.$("form .motd").val(), title: this.$('form .title').val(),
number_of_headless_clients: this.$("form .headless-clients").val(), von: this.$('form .von').prop('checked'),
password: this.$("form .password").val(), verify_signatures: this.$('form .verify_signatures').prop('checked')
persistent: this.$("form .persistent").prop("checked"),
port: this.$("form .port").val(),
title: this.$("form .title").val(),
von: this.$("form .von").prop("checked"),
verify_signatures: this.$("form .verify_signatures").prop("checked"),
};
},
submit: function (modal) {
modal.preventClose();
this.model.set(this.serialize());
var self = this;
this.model.save({}, {
success: function() {
modal.close();
self.servers.fetch({success : function () {
Backbone.history.navigate('#servers/' + self.model.get('id'), true);
}});
},
error: function() {
alert("Error :(");
}
});
} }
}); },
}); submit: function (modal) {
modal.preventClose()
this.model.set(this.serialize())
var self = this
this.model.save({}, {
success: function () {
modal.close()
self.servers.fetch({
success: function () {
Backbone.history.navigate('#servers/' + self.model.get('id'), true)
}
})
},
error: function (model, response) {
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'), template: _.template(tpl),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/servers/info.html');
return Marionette.LayoutView.extend({ events: {
template: _.template(tpl), 'click #start': 'start',
'click #stop': 'stop'
},
events: { start: function (event) {
"click #start": "start", var self = this
"click #stop": "stop", 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
})
},
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 () {
start: function (event) {
var self = this;
event.preventDefault();
$.ajax({ $.ajax({
url: "/api/servers/" + this.model.get('id') + "/start", 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
}); })
}, })
}
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(){
$.ajax({
url: "/api/servers/" + self.model.get('id') + "/stop",
type: 'POST',
success: function (resp) {
self.model.set("pid", resp.pid);
self.render();
},
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({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({ emptyView: EmptyView,
childView: ListItemView,
childViewContainer: "tbody",
template: template,
emptyView: EmptyView, events: {
'click #add-server': 'addServer'
},
events: { buildChildView: function (item, ChildViewType, childViewOptions) {
"click #add-server": "addServer" // build the final list of options for the item view type
}, var options = _.extend({ model: item }, childViewOptions)
buildChildView: function(item, ChildViewType, childViewOptions){ if (ChildViewType === EmptyView) {
// build the final list of options for the item view type options = _.extend({ servers: this.collection }, options)
var options = _.extend({model: item}, childViewOptions); }
if (ChildViewType == EmptyView) { // create the item view instance
options = _.extend({servers: this.collection}, options); var view = new ChildViewType(options)
} // return it
return view
},
// create the item view instance addServer: function () {
var view = new ChildViewType(options); var view = new AddServerView({ model: new Server(), servers: this.collection })
// return it new Backbone.BootstrapModal({ content: view, servers: this.collection }).open()
return view; }
}, })
addServer: function () {
var view = new AddServerView({model: new Server(), servers: this.collection});
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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click .clone': 'clone',
template: template, 'click .delete': 'delete'
},
events: { modelEvents: {
"click .clone": "clone", change: 'serverUpdated'
"click .delete": "delete", },
clone: function (e) {
var title = this.model.get('title') + ' Clone'
var clone = this.model.clone()
clone.set({ id: null, title: title, auto_start: false })
clone.save()
},
delete: function (event) {
var self = this
sweetAlert({
title: 'Are you sure?',
text: 'Your server configuration will be deleted!',
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: 'Yes, delete it!'
}, },
function () {
self.model.destroy()
})
},
modelEvents: { serverUpdated: function (event) {
"change": "serverUpdated", this.render()
}, }
})
clone: function (e) {
var title = this.model.get('title') + ' Clone';
var clone = this.model.clone();
clone.set({id: null, title: title, auto_start: false});
clone.save();
},
delete: function (event) {
var self = this;
sweetAlert({
title: "Are you sure?",
text: "Your server configuration will be deleted!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
},
function(){
self.model.destroy();
});
},
serverUpdated: function (event) {
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'), childView: ListItemView,
Backbone = require('backbone'), childViewContainer: 'tbody',
Marionette = require('marionette'), template: _.template(tpl),
ListItemView = require('app/views/servers/missions/available/list_item'),
tpl = require('text!tpl/servers/missions/available/list.html');
return Marionette.CompositeView.extend({ initialize: function (options) {
childView: ListItemView, this.filterValue = options.filterValue
childViewContainer: "tbody", },
template: _.template(tpl),
initialize: function (options) { filter: function (child, index, collection) {
this.filterValue = options.filterValue; return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0
}, },
filter: function (child, index, collection) { buildChildView: function (item, ChildViewType, childViewOptions) {
return child.get('name').toLowerCase().indexOf(this.filterValue.toLowerCase()) >= 0; var self = this
}, var options = _.extend({ model: item }, childViewOptions)
var view = new ChildViewType(options)
buildChildView: function(item, ChildViewType, childViewOptions){ view.on('add', function (model) {
var self = this; self.trigger('add', model)
var options = _.extend({model: item}, childViewOptions); })
var view = new ChildViewType(options); return view
view.on('add', function (model) { }
self.trigger('add', model); })
});
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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click .add': 'add'
template: template, },
events: { add: function () {
"click .add": "add" this.trigger('add', this.model)
}, }
})
add: function () {
this.trigger('add', this.model);
},
});
});

View File

@ -1,73 +1,67 @@
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'), template: _.template(tpl),
Backbone = require('backbone'), templateHelpers: function () {
Marionette = require('marionette'), return {
MissionRotations = require('app/collections/mission_rotations'), filterValue: this.filterValue
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({ regions: {
template: _.template(tpl), availableView: '#available',
templateHelpers: function() { rotationView: '#rotation'
return { },
filterValue: this.filterValue
}
},
regions: { events: {
availableView: "#available", 'keyup #filterMissions': 'updateFilter'
rotationView: "#rotation", },
},
events: { modelEvents: {
"keyup #filterMissions": "updateFilter", change: 'serverUpdated'
}, },
modelEvents: { initialize: function (options) {
"change": "serverUpdated", this.missions = options.missions
}, this.filterValue = ''
initialize: function (options) { this.rotationCollection = new MissionRotations(this.model.get('missions'))
this.missions = options.missions;
this.filterValue = ''
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.on('add', function (model) {
self.rotationCollection.add([{
name: model.get('name').replace('.pbo', '')
}])
})
this.rotationListView = new RotationListView({ collection: this.rotationCollection })
},
this.availableListView = new AvailableListView({collection: this.missions, filterValue: this.filterValue}); onRender: function () {
this.availableListView.on('add', function (model) { this.availableView.show(this.availableListView)
self.rotationCollection.add([{ this.rotationView.show(this.rotationListView)
name: model.get('name').replace('.pbo', ''), },
}]);
});
this.rotationListView = new RotationListView({collection: this.rotationCollection});
},
onRender: function() { updateFilter: function (event) {
this.availableView.show(this.availableListView); this.filterValue = event.target.value
this.rotationView.show(this.rotationListView); this.availableView.currentView.filterValue = this.filterValue
}, this.availableView.currentView.render()
},
updateFilter: function (event) { serverUpdated: function () {
this.filterValue = event.target.value; this.rotationCollection.set(this.model.get('missions'))
this.availableView.currentView.filterValue = this.filterValue; },
this.availableView.currentView.render();
},
serverUpdated: function() { serialize: function () {
this.rotationCollection.set(this.model.get('missions')); return {
}, missions: this.rotationCollection.toJSON()
}
serialize : function() { }
return { })
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'), childView: ListItemView,
Backbone = require('backbone'), childViewContainer: 'tbody',
Marionette = require('marionette'), template: _.template(tpl),
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({ events: {
childView: ListItemView, 'click .add-mission': 'addMission'
childViewContainer: "tbody", },
template: _.template(tpl),
events: { addMission: function (e) {
"click .add-mission": "addMission", e.preventDefault()
}, this.collection.add(new MissionRotation())
}
addMission: function (e) { })
e.preventDefault();
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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click button.delete': 'delete',
template: template, 'change select#difficulty': 'changed',
'change input#name': 'changed'
},
events: { changed: function (e) {
"click button.delete": "delete", var val = $(e.target).val()
"change select#difficulty": "changed", this.model.set(e.target.id, val)
"change input#name": "changed", },
},
changed: function (e) { delete: function (e) {
var val = $(e.target).val(); e.preventDefault()
this.model.set(e.target.id, val); this.model.destroy()
}, },
delete: function (e) { onRender: function () {
e.preventDefault(); var difficulty = this.model.get('difficulty')
this.model.destroy(); var $option = this.$el.find("#difficulty option[value='" + difficulty + "']")
}, $option.attr('selected', 'selected')
}
onRender: function() { })
var difficulty = this.model.get('difficulty');
var $option = this.$el.find("#difficulty option[value='" + difficulty + "']");
$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'), childView: ListItemView,
Backbone = require('backbone'), template: _.template(tpl),
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({ events: {
childView: ListItemView, 'click .check-all': 'checkAll',
template: _.template(tpl), 'click .uncheck-all': 'uncheckAll'
},
events: { buildChildView: function (item, ChildViewType, childViewOptions) {
"click .check-all": "checkAll", var options = _.extend({ model: item, server: this.options.server }, childViewOptions)
"click .uncheck-all": "uncheckAll", var view = new ChildViewType(options)
}, return view
},
buildChildView: function(item, ChildViewType, childViewOptions){ changeAllCheckbox: function (checked) {
var options = _.extend({model: item, server: this.options.server}, childViewOptions); this.$('input:checkbox').map(function (idx, el) {
var view = new ChildViewType(options); return $(el).prop('checked', checked)
return view; })
}, },
changeAllCheckbox: function(checked) { checkAll: function (e) {
this.$('input:checkbox').map(function (idx, el) { e.preventDefault()
return $(el).prop('checked', checked); this.changeAllCheckbox(true)
}) },
},
checkAll: function(e) { uncheckAll: function (e) {
e.preventDefault(); e.preventDefault()
this.changeAllCheckbox(true); this.changeAllCheckbox(false)
}, },
uncheckAll: function(e) { serialize: function () {
e.preventDefault(); return {
this.changeAllCheckbox(false); mods: this.$('input:checkbox:checked').map(function (idx, el) {
}, return $(el).val()
}).get()
serialize: function() { }
return { }
mods: this.$('input:checkbox:checked').map(function (idx, el) { })
return $(el).val();
}).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',
template: template,
return ModListItemView.extend({ templateHelpers: function () {
tagName: "tr", return {
template: template, enabled: this.options.server.get('mods').indexOf(this.model.get('name')) > -1
}
templateHelpers: function(){ }
return { })
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'), childView: ListItemView,
Backbone = require('backbone'), childViewContainer: 'tbody',
Marionette = require('marionette'), template: _.template(tpl),
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({ events: {
childView: ListItemView, 'click .add-parameter': 'addParameter'
childViewContainer: "tbody", },
template: _.template(tpl),
events: { modelEvents: {
"click .add-parameter": "addParameter", change: 'serverUpdated'
}, },
modelEvents: { initialize: function (options) {
"change": "serverUpdated", this.collection = new Parameters()
}, this.serverUpdated()
},
initialize: function (options) { addParameter: function (e) {
this.collection = new Parameters(); e.preventDefault()
this.serverUpdated(); this.collection.add(new Parameter())
}, },
addParameter: function (e) { serialize: function () {
e.preventDefault(); return {
this.collection.add(new Parameter()); parameters: this.collection.map(function (parameter) {
}, return parameter.get('parameter')
})
}
},
serialize : function() { serverUpdated: function () {
return { this.collection.reset(this.model.get('parameters').map(function (parameter) {
parameters: this.collection.map(function (parameter) { return new Parameter({
return parameter.get('parameter'); parameter: parameter
}), })
}; }))
}, }
})
serverUpdated: function () {
this.collection.reset(this.model.get('parameters').map(function (parameter) {
return new 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',
template: template,
return Marionette.ItemView.extend({ events: {
tagName: "tr", 'click button.delete': 'delete',
template: template, 'change input#parameter': 'changed',
'click button.clone': 'clone'
},
events: { changed: function (e) {
"click button.delete": "delete", var val = $(e.target).val()
"change input#parameter": "changed", this.model.set(e.target.id, val)
"click button.clone": "clone", },
},
changed: function (e) { delete: function (e) {
var val = $(e.target).val(); e.preventDefault()
this.model.set(e.target.id, val); this.model.destroy()
}, }
})
delete: function (e) {
e.preventDefault();
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'), template: _.template(tpl),
Backbone = require('backbone'), templateHelpers: {
Marionette = require('marionette'), players: function () {
tpl = require('text!tpl/servers/players.html'); return _.sortBy(this.state.players, function (player) {
return player.name
return Marionette.LayoutView.extend({ })
template: _.template(tpl), }
templateHelpers: { }
players: function(){ })
return _.sortBy(this.state.players, function (player) {
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'), template: _.template(tpl),
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({ regions: {
template: _.template(tpl), infoView: '#tab-info',
missionsView: '#tab-missions',
modsView: '#tab-mods',
parametersView: '#parameters',
playersView: '#tab-players',
settingsView: '#settings'
},
regions: { events: {
infoView: "#tab-info", 'click .nav-tabs a': 'tabs',
missionsView: "#tab-missions", submit: 'save'
modsView: "#tab-mods", },
parametersView: "#parameters",
playersView: "#tab-players",
settingsView: "#settings",
},
events: { modelEvents: {
"click .nav-tabs a" : "tabs", change: 'serverUpdated'
"submit": "save", },
},
modelEvents: { initialize: function (options) {
"change": "serverUpdated", this.missions = options.missions
}, this.mods = options.mods
},
initialize: function (options) { onRender: function () {
this.missions = options.missions; this.infoView.show(new InfoView({ model: this.model }))
this.mods = options.mods; this.missionsView.show(new MissionsView({ missions: this.missions, model: this.model }))
}, this.modsView.show(new ModsListView({ collection: this.mods, server: this.model }))
this.parametersView.show(new ParametersListView({ model: this.model }))
this.playersView.show(new PlayersView({ model: this.model }))
this.settingsView.show(new FormView({ model: this.model }))
},
onRender: function() { serverUpdated: function () {
this.infoView.show(new InfoView({model: this.model})); this.infoView.currentView.render()
this.missionsView.show(new MissionsView({missions: this.missions, model: this.model})); this.modsView.currentView.render()
this.modsView.show(new ModsListView({collection: this.mods, server: this.model})); this.parametersView.currentView.render()
this.parametersView.show(new ParametersListView({model: this.model})); this.playersView.currentView.render()
this.playersView.show(new PlayersView({model: this.model})); this.settingsView.currentView.render()
this.settingsView.show(new FormView({model: this.model})); },
},
serverUpdated: function() { save: function (e) {
this.infoView.currentView.render(); e.preventDefault()
this.modsView.currentView.render(); var self = this
this.parametersView.currentView.render(); var oldId = this.model.get('id')
this.playersView.currentView.render(); var data = this.settingsView.currentView.serialize()
this.settingsView.currentView.render(); _.extend(data, this.missionsView.currentView.serialize())
}, _.extend(data, this.modsView.currentView.serialize())
_.extend(data, this.parametersView.currentView.serialize())
save: function (e) { this.model.save(data, {
e.preventDefault(); success: function () {
var self = this; var newId = self.model.get('id')
var oldId = this.model.get('id'); if (oldId !== newId) {
var data = this.settingsView.currentView.serialize(); Backbone.history.navigate('#servers/' + newId, true)
_.extend(data, this.missionsView.currentView.serialize()); } else {
_.extend(data, this.modsView.currentView.serialize()); self.serverUpdated()
_.extend(data, this.parametersView.currentView.serialize());
this.model.save(data, {
success: function() {
var newId = self.model.get('id');
if (oldId != newId) {
Backbone.history.navigate('#servers/' + newId, true);
} else {
self.serverUpdated();
}
},
error: function() {
alert("Error :(");
} }
}); },
}, error: function (model, response) {
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'), template: _.template(tpl),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/settings.html');
return Marionette.ItemView.extend({ modelEvents: {
template: _.template(tpl), change: 'render'
},
modelEvents: { templateHelpers: {
'change': 'render', isTypeChecked: function (type) {
}, return this.type === type ? 'checked' : ''
}
templateHelpers: { }
isTypeChecked: function(type) { })
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' },