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
*.log
npm-debug.log*

View File

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

View File

@ -1,3 +1,5 @@
require('jquery.iframe-transport')
require('bootstrap/dist/css/bootstrap.css')
require('ladda/dist/ladda-themeless.min.css')
require('sweetalert/dist/sweetalert.css')
@ -14,38 +16,38 @@ require.config({
},
shim: {
'backbone': {
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'backbone.babysitter': {
deps: ['backbone'],
deps: ['backbone']
},
'backbone.bootstrap-modal': {
deps: ['backbone', 'bootstrap']
},
'bootstrap': {
bootstrap: {
deps: ['jquery']
},
'ladda': {
ladda: {
deps: ['bootstrap']
},
'marionette': {
marionette: {
deps: ['backbone', 'backbone.babysitter'],
exports: 'Marionette'
},
'marionette-formview': {
deps: ['marionette']
},
'sweetalert': {
sweetalert: {
deps: ['bootstrap']
},
'underscore': {
underscore: {
exports: '_'
}
}
});
})
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Log = require('app/models/log');
return Backbone.Collection.extend({
comparator: 'name',
model: Log,
url: '/api/logs/'
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
MissionRotation = require('app/models/mission_rotation');
return Backbone.Collection.extend({
model: MissionRotation,
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Mission = require('app/models/mission');
return Backbone.Collection.extend({
comparator: 'name',
model: Mission,
url: '/api/missions/'
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Mod = require('app/models/mod');
return Backbone.Collection.extend({
comparator: 'name',
model: Mod,
url: '/api/mods/'
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Parameter = require('app/models/parameter');
return Backbone.Collection.extend({
model: Parameter,
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Server = require('app/models/server');
return Backbone.Collection.extend({
comparator: function (a, b) {
return a.get('title').toLowerCase().localeCompare(b.get('title').toLowerCase());
},
model: Server,
url: '/api/servers/'
});
});
module.exports = Backbone.Collection.extend({
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";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
name: '',
formattedSize: '0 B',
size: 0,
},
idAttribute: 'name',
});
});
module.exports = Backbone.Model.extend({
defaults: {
name: '',
formattedSize: '0 B',
size: 0
},
idAttribute: 'name'
})

View File

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

View File

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

View File

@ -1,34 +1,26 @@
define(function (require) {
var Backbone = require('backbone')
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
additionalConfigurationOptions: '',
admin_password: '',
allowed_file_patching: 1,
auto_start: false,
battle_eye: false,
file_patching: false,
forcedDifficulty: '',
max_players: null,
mods: [],
motd: '',
number_of_headless_clients: 0,
parameters: [],
password: '',
persistent: false,
port: 2302,
state: null,
title: '',
von: false,
verify_signatures: false,
},
urlRoot: '/api/servers/',
});
});
module.exports = Backbone.Model.extend({
defaults: {
additionalConfigurationOptions: '',
admin_password: '',
allowed_file_patching: 1,
auto_start: false,
battle_eye: false,
file_patching: false,
forcedDifficulty: '',
max_players: null,
mods: [],
motd: '',
number_of_headless_clients: 0,
parameters: [],
password: '',
persistent: false,
port: 2302,
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";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
path: '',
type: '',
},
urlRoot : '/api/settings'
});
});
module.exports = 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'),
Backbone = require('backbone'),
LayoutView = require('app/views/layout'),
NavigationView = require('app/views/navigation'),
ServersView = require('app/views/servers/list'),
LogsListView = require('app/views/logs/list'),
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'),
var $body = $('body')
var missions = new Missions()
var mods = new Mods()
var settings = new Settings()
var servers = new Servers()
var layoutView = new LayoutView({ el: $body }).render()
$body = $('body'),
missions = new Missions(),
mods = new Mods(),
settings = new Settings(),
servers = new Servers(),
layoutView = new LayoutView({el: $body}).render();
module.exports = Backbone.Router.extend({
return Backbone.Router.extend({
routes: {
logs: 'logs',
missions: 'missions',
mods: 'mods',
'servers/:id': 'server',
'': 'home'
},
routes: {
"logs": "logs",
"missions": "missions",
"mods": "mods",
"servers/:id": "server",
"": "home",
},
initialize: function () {
layoutView.navigation.show(new NavigationView({ settings: settings, servers: servers }))
initialize: function () {
layoutView.navigation.show(new NavigationView({settings: settings, servers: servers}));
var initialized = false
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();
socket.on('missions', function (_missions) {
missions.set(_missions);
});
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);
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)
}
}
});
});
})

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'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/layout.html');
module.exports = Marionette.LayoutView.extend({
template: _.template(tpl),
return Marionette.LayoutView.extend({
template: _.template(tpl),
regions: {
navigation: "#navigation",
content: "#content"
}
});
});
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'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/login.html');
return Marionette.ItemView.extend({
template: _.template(tpl)
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/logs/list_item'),
tpl = require('text!tpl/logs/list.html'),
var template = _.template(tpl)
template = _.template(tpl);
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: template,
});
});
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/logs/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click .destroy': 'deleteLog'
},
events: {
"click .destroy": "deleteLog",
deleteLog: function (event) {
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!'
},
deleteLog: function (event) {
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();
});
},
});
});
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'),
_ = 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');
module.exports = 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) {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/missions/list_item'),
tpl = require('text!tpl/missions/list.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: template,
initialize: function (options) {
this.filterValue = options.filterValue
},
initialize: function (options) {
this.filterValue = options.filterValue;
},
filter: function (child, index, collection) {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/missions/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click .delete': 'deleteMission'
},
events: {
"click .delete": "deleteMission"
deleteMission: function (event) {
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!'
},
deleteMission: function (event) {
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();
});
},
});
});
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'),
_ = 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');
module.exports = Marionette.ItemView.extend({
template: _.template(tpl),
return Marionette.ItemView.extend({
template: _.template(tpl),
events: {
'click form button': 'submit'
},
events: {
'click form button': 'submit',
},
submit: function () {
var self = this
var $form = this.$el.find('form')
submit: function () {
var self = this;
var $form = this.$el.find('form');
var $uploadBtn = $form.find('button[type=submit]')
var laddaBtn = Ladda.create($uploadBtn.get(0))
laddaBtn.start()
var $uploadBtn = $form.find('button[type=submit]');
var laddaBtn = Ladda.create($uploadBtn.get(0));
laddaBtn.start();
$.ajax("/api/missions", {
success: function(data) {
laddaBtn.stop();
self.render();
},
error: function () {
laddaBtn.stop();
},
files: $form.find(":file"),
iframe: true
});
},
});
});
$.ajax('/api/missions', {
success: function (data) {
laddaBtn.stop()
self.render()
},
error: function () {
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'),
_ = 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');
module.exports = Marionette.ItemView.extend({
template: _.template(tpl),
return Marionette.ItemView.extend({
template: _.template(tpl),
events: {
'click form button': 'submit'
},
events: {
'click form button': 'submit',
},
initialize: function (options) {
this.missions = options.missions
},
initialize: function (options) {
this.missions = options.missions;
},
submit: function () {
var self = this
var $form = this.$el.find('form')
submit: function () {
var self = this;
var $form = this.$el.find('form');
var $downloadBtn = $form.find('button[type=submit]')
var laddaBtn = Ladda.create($downloadBtn.get(0))
laddaBtn.start()
var $downloadBtn = $form.find('button[type=submit]');
var laddaBtn = Ladda.create($downloadBtn.get(0));
laddaBtn.start();
$.ajax({
url: '/api/missions/workshop',
type: 'POST',
data: {
id: $form.find("input.workshop").val(),
},
dataType: 'json',
success: function (data) {
laddaBtn.stop();
self.render();
},
error: function () {
laddaBtn.stop();
},
});
},
});
});
$.ajax({
url: '/api/missions/workshop',
type: 'POST',
data: {
id: $form.find('input.workshop').val()
},
dataType: 'json',
success: function (data) {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/mods/list_item'),
tpl = require('text!tpl/mods/list.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: template,
events: {
'click #refresh': 'refresh'
},
events: {
"click #refresh": "refresh",
},
refresh: function (event) {
event.preventDefault()
$.ajax({
url: '/api/mods/refresh',
type: 'POST',
success: function (resp) {
refresh: function (event) {
event.preventDefault();
$.ajax({
url: "/api/mods/refresh",
type: 'POST',
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Ladda = require('ladda'),
swal = require('sweet-alert'),
tpl = require('text!tpl/mods/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click .destroy': 'deleteMod'
},
events: {
"click .destroy": "deleteMod",
deleteMod: function (event) {
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!'
},
deleteMod: function (event) {
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();
});
},
});
});
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'),
_ = 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');
module.exports = Marionette.ItemView.extend({
template: _.template(tpl),
return Marionette.ItemView.extend({
template: _.template(tpl),
templateHelpers: function() {
return {
isActiveRoute: function (route) {
return Backbone.history.fragment === route ? 'active' : ''
}
templateHelpers: function () {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ListItemView = require('app/views/navigation/servers/list_item');
return Marionette.CollectionView.extend({
tagName: 'ul',
childView: ListItemView,
});
});
module.exports = 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/navigation/servers/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
return Marionette.ItemView.extend({
className: function () {
return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : ''
},
tagName: "li",
template: template
});
});
module.exports = Marionette.ItemView.extend({
className: function () {
return Backbone.history.fragment === 'servers/' + this.model.get('id') ? 'active' : ''
},
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/empty.html');
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: _.template(tpl),
return Marionette.ItemView.extend({
tagName: "tr",
template: _.template(tpl),
initialize: function (options) {
this.servers = options.servers;
},
});
});
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/form.html');
module.exports = Marionette.ItemView.extend({
template: _.template(tpl),
return Marionette.ItemView.extend({
template: _.template(tpl),
initialize: function (options) {
this.servers = options.servers
this.bind('ok', this.submit)
},
initialize: function (options) {
this.servers = options.servers;
this.bind("ok", this.submit);
},
serialize : function() {
return {
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,
auto_start: this.$("form .auto-start").prop("checked"),
battle_eye: this.$("form .battle-eye").prop("checked"),
file_patching: this.$("form .file-patching").prop("checked"),
forcedDifficulty: this.$("form .forcedDifficulty").val(),
max_players: this.$("form .max-players").val(),
motd: this.$("form .motd").val(),
number_of_headless_clients: this.$("form .headless-clients").val(),
password: this.$("form .password").val(),
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 :(");
}
});
serialize: function () {
return {
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,
auto_start: this.$('form .auto-start').prop('checked'),
battle_eye: this.$('form .battle-eye').prop('checked'),
file_patching: this.$('form .file-patching').prop('checked'),
forcedDifficulty: this.$('form .forcedDifficulty').val(),
max_players: this.$('form .max-players').val(),
motd: this.$('form .motd').val(),
number_of_headless_clients: this.$('form .headless-clients').val(),
password: this.$('form .password').val(),
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 (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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/servers/info.html');
module.exports = Marionette.LayoutView.extend({
template: _.template(tpl),
return Marionette.LayoutView.extend({
template: _.template(tpl),
events: {
'click #start': 'start',
'click #stop': 'stop'
},
events: {
"click #start": "start",
"click #stop": "stop",
start: function (event) {
var self = this
event.preventDefault()
$.ajax({
url: '/api/servers/' + this.model.get('id') + '/start',
type: 'POST',
success: function (resp) {
self.model.set('pid', resp.pid)
self.render()
},
error: $.noop
})
},
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!'
},
start: function (event) {
var self = this;
event.preventDefault();
function () {
$.ajax({
url: "/api/servers/" + this.model.get('id') + "/start",
url: '/api/servers/' + self.model.get('id') + '/stop',
type: 'POST',
success: function (resp) {
self.model.set("pid", resp.pid);
self.render();
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(){
$.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'),
_ = 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'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: template,
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: template,
emptyView: EmptyView,
emptyView: EmptyView,
events: {
'click #add-server': 'addServer'
},
events: {
"click #add-server": "addServer"
},
buildChildView: function (item, ChildViewType, childViewOptions) {
// build the final list of options for the item view type
var options = _.extend({ model: item }, childViewOptions)
buildChildView: function(item, ChildViewType, childViewOptions){
// build the final list of options for the item view type
var options = _.extend({model: item}, childViewOptions);
if (ChildViewType === EmptyView) {
options = _.extend({ servers: this.collection }, options)
}
if (ChildViewType == EmptyView) {
options = _.extend({servers: this.collection}, options);
}
// create the item view instance
var view = new ChildViewType(options)
// return it
return view
},
// create the item view instance
var view = new ChildViewType(options);
// return it
return view;
},
addServer: function () {
var view = new AddServerView({model: new Server(), servers: this.collection});
new Backbone.BootstrapModal({ content: view, servers: this.collection }).open()
},
});
});
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/servers/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click .clone': 'clone',
'click .delete': 'delete'
},
events: {
"click .clone": "clone",
"click .delete": "delete",
modelEvents: {
change: 'serverUpdated'
},
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: {
"change": "serverUpdated",
},
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();
},
});
});
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'),
_ = 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');
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: _.template(tpl),
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: _.template(tpl),
initialize: function (options) {
this.filterValue = options.filterValue
},
initialize: function (options) {
this.filterValue = options.filterValue;
},
filter: function (child, index, collection) {
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;
},
buildChildView: function(item, ChildViewType, childViewOptions){
var self = this;
var options = _.extend({model: item}, childViewOptions);
var view = new ChildViewType(options);
view.on('add', function (model) {
self.trigger('add', model);
});
return view;
},
});
});
buildChildView: function (item, ChildViewType, childViewOptions) {
var self = this
var options = _.extend({ model: item }, childViewOptions)
var view = new ChildViewType(options)
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/missions/available/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click .add': 'add'
},
events: {
"click .add": "add"
},
add: function () {
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'),
_ = 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');
module.exports = Marionette.LayoutView.extend({
template: _.template(tpl),
templateHelpers: function () {
return {
filterValue: this.filterValue
}
},
return Marionette.LayoutView.extend({
template: _.template(tpl),
templateHelpers: function() {
return {
filterValue: this.filterValue
}
},
regions: {
availableView: '#available',
rotationView: '#rotation'
},
regions: {
availableView: "#available",
rotationView: "#rotation",
},
events: {
'keyup #filterMissions': 'updateFilter'
},
events: {
"keyup #filterMissions": "updateFilter",
},
modelEvents: {
change: 'serverUpdated'
},
modelEvents: {
"change": "serverUpdated",
},
initialize: function (options) {
this.missions = options.missions
this.filterValue = ''
initialize: function (options) {
this.missions = options.missions;
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.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});
this.availableListView.on('add', function (model) {
self.rotationCollection.add([{
name: model.get('name').replace('.pbo', ''),
}]);
});
this.rotationListView = new RotationListView({collection: this.rotationCollection});
},
onRender: function () {
this.availableView.show(this.availableListView)
this.rotationView.show(this.rotationListView)
},
onRender: function() {
this.availableView.show(this.availableListView);
this.rotationView.show(this.rotationListView);
},
updateFilter: function (event) {
this.filterValue = event.target.value
this.availableView.currentView.filterValue = this.filterValue
this.availableView.currentView.render()
},
updateFilter: function (event) {
this.filterValue = event.target.value;
this.availableView.currentView.filterValue = this.filterValue;
this.availableView.currentView.render();
},
serverUpdated: function () {
this.rotationCollection.set(this.model.get('missions'))
},
serverUpdated: function() {
this.rotationCollection.set(this.model.get('missions'));
},
serialize : function() {
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'),
_ = 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');
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: _.template(tpl),
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: _.template(tpl),
events: {
'click .add-mission': 'addMission'
},
events: {
"click .add-mission": "addMission",
},
addMission: function (e) {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/missions/rotation/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click button.delete': 'delete',
'change select#difficulty': 'changed',
'change input#name': 'changed'
},
events: {
"click button.delete": "delete",
"change select#difficulty": "changed",
"change input#name": "changed",
},
changed: function (e) {
var val = $(e.target).val()
this.model.set(e.target.id, val)
},
changed: function (e) {
var val = $(e.target).val();
this.model.set(e.target.id, val);
},
delete: function (e) {
e.preventDefault()
this.model.destroy()
},
delete: function (e) {
e.preventDefault();
this.model.destroy();
},
onRender: function() {
var difficulty = this.model.get('difficulty');
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'),
_ = 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');
module.exports = ModsListView.extend({
childView: ListItemView,
template: _.template(tpl),
return ModsListView.extend({
childView: ListItemView,
template: _.template(tpl),
events: {
'click .check-all': 'checkAll',
'click .uncheck-all': 'uncheckAll'
},
events: {
"click .check-all": "checkAll",
"click .uncheck-all": "uncheckAll",
},
buildChildView: function (item, ChildViewType, childViewOptions) {
var options = _.extend({ model: item, server: this.options.server }, childViewOptions)
var view = new ChildViewType(options)
return view
},
buildChildView: function(item, ChildViewType, childViewOptions){
var options = _.extend({model: item, server: this.options.server}, childViewOptions);
var view = new ChildViewType(options);
return view;
},
changeAllCheckbox: function (checked) {
this.$('input:checkbox').map(function (idx, el) {
return $(el).prop('checked', checked)
})
},
changeAllCheckbox: function(checked) {
this.$('input:checkbox').map(function (idx, el) {
return $(el).prop('checked', checked);
})
},
checkAll: function (e) {
e.preventDefault()
this.changeAllCheckbox(true)
},
checkAll: function(e) {
e.preventDefault();
this.changeAllCheckbox(true);
},
uncheckAll: function (e) {
e.preventDefault()
this.changeAllCheckbox(false)
},
uncheckAll: function(e) {
e.preventDefault();
this.changeAllCheckbox(false);
},
serialize: function() {
return {
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
ModListItemView = require('app/views/mods/list_item'),
tpl = require('text!tpl/servers/mods/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = ModListItemView.extend({
tagName: 'tr',
template: template,
return ModListItemView.extend({
tagName: "tr",
template: template,
templateHelpers: function(){
return {
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'),
_ = 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');
module.exports = Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: 'tbody',
template: _.template(tpl),
return Marionette.CompositeView.extend({
childView: ListItemView,
childViewContainer: "tbody",
template: _.template(tpl),
events: {
'click .add-parameter': 'addParameter'
},
events: {
"click .add-parameter": "addParameter",
},
modelEvents: {
change: 'serverUpdated'
},
modelEvents: {
"change": "serverUpdated",
},
initialize: function (options) {
this.collection = new Parameters()
this.serverUpdated()
},
initialize: function (options) {
this.collection = new Parameters();
this.serverUpdated();
},
addParameter: function (e) {
e.preventDefault()
this.collection.add(new Parameter())
},
addParameter: function (e) {
e.preventDefault();
this.collection.add(new Parameter());
},
serialize: function () {
return {
parameters: this.collection.map(function (parameter) {
return parameter.get('parameter')
})
}
},
serialize : function() {
return {
parameters: this.collection.map(function (parameter) {
return parameter.get('parameter');
}),
};
},
serverUpdated: function () {
this.collection.reset(this.model.get('parameters').map(function (parameter) {
return new 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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/parameters/list_item.html'),
var template = _.template(tpl)
template = _.template(tpl);
module.exports = Marionette.ItemView.extend({
tagName: 'tr',
template: template,
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
'click button.delete': 'delete',
'change input#parameter': 'changed',
'click button.clone': 'clone'
},
events: {
"click button.delete": "delete",
"change input#parameter": "changed",
"click button.clone": "clone",
},
changed: function (e) {
var val = $(e.target).val()
this.model.set(e.target.id, val)
},
changed: function (e) {
var val = $(e.target).val();
this.model.set(e.target.id, val);
},
delete: function (e) {
e.preventDefault();
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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/players.html');
return Marionette.LayoutView.extend({
template: _.template(tpl),
templateHelpers: {
players: function(){
return _.sortBy(this.state.players, function (player) {
return player.name;
});
}
},
});
});
module.exports = 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'),
_ = 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');
module.exports = Marionette.LayoutView.extend({
template: _.template(tpl),
return Marionette.LayoutView.extend({
template: _.template(tpl),
regions: {
infoView: '#tab-info',
missionsView: '#tab-missions',
modsView: '#tab-mods',
parametersView: '#parameters',
playersView: '#tab-players',
settingsView: '#settings'
},
regions: {
infoView: "#tab-info",
missionsView: "#tab-missions",
modsView: "#tab-mods",
parametersView: "#parameters",
playersView: "#tab-players",
settingsView: "#settings",
},
events: {
'click .nav-tabs a': 'tabs',
submit: 'save'
},
events: {
"click .nav-tabs a" : "tabs",
"submit": "save",
},
modelEvents: {
change: 'serverUpdated'
},
modelEvents: {
"change": "serverUpdated",
},
initialize: function (options) {
this.missions = options.missions
this.mods = options.mods
},
initialize: function (options) {
this.missions = options.missions;
this.mods = options.mods;
},
onRender: function () {
this.infoView.show(new InfoView({ 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.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() {
this.infoView.show(new InfoView({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.parametersView.show(new ParametersListView({model: this.model}));
this.playersView.show(new PlayersView({model: this.model}));
this.settingsView.show(new FormView({model: this.model}));
},
serverUpdated: function () {
this.infoView.currentView.render()
this.modsView.currentView.render()
this.parametersView.currentView.render()
this.playersView.currentView.render()
this.settingsView.currentView.render()
},
serverUpdated: function() {
this.infoView.currentView.render();
this.modsView.currentView.render();
this.parametersView.currentView.render();
this.playersView.currentView.render();
this.settingsView.currentView.render();
},
save: function (e) {
e.preventDefault();
var self = this;
var oldId = this.model.get('id');
var data = this.settingsView.currentView.serialize();
_.extend(data, this.missionsView.currentView.serialize());
_.extend(data, this.modsView.currentView.serialize());
_.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 :(");
save: function (e) {
e.preventDefault()
var self = this
var oldId = this.model.get('id')
var data = this.settingsView.currentView.serialize()
_.extend(data, this.missionsView.currentView.serialize())
_.extend(data, this.modsView.currentView.serialize())
_.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 (model, response) {
sweetAlert({
title: 'Error',
text: 'An error occurred, please consult the logs',
type: 'error'
})
}
})
},
tabs: function(e) {
e.preventDefault();
$($(e.target).attr('href')).tab('show');
},
});
});
tabs: function (e) {
e.preventDefault()
$($(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'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/settings.html');
module.exports = Marionette.ItemView.extend({
template: _.template(tpl),
return Marionette.ItemView.extend({
template: _.template(tpl),
modelEvents: {
change: 'render'
},
modelEvents: {
'change': 'render',
},
templateHelpers: {
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: [
new webpack.ProvidePlugin({
_: 'underscore',
@ -43,6 +37,7 @@ module.exports = {
module: {
loaders: [
{ test: /\.css$/, loaders: ['style-loader', 'css-loader'] },
{ test: /\.html$/, loaders: ['raw-loader'] },
{ test: /\.json$/, loaders: ['json-loader'] },
{ test: /\.png$/, loader: 'url-loader?limit=8192&mimetype=image/png' },
{ test: /\.jpe?g$/, loader: 'url-loader?limit=8192&mimetype=image/jpg' },