From 7d98e35d1c6b521e559728244cdc1e3cb475b113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sun, 22 Sep 2019 23:02:31 +0200 Subject: [PATCH] Modernize frontend from old CommonJS format --- .gitignore | 1 - package.json | 3 - public/js/app.js | 22 +-- public/js/app/collections/logs.js | 21 +-- .../js/app/collections/mission_rotations.js | 17 +- public/js/app/collections/missions.js | 21 +-- public/js/app/collections/mods.js | 21 +-- public/js/app/collections/parameters.js | 17 +- public/js/app/collections/servers.js | 25 +-- public/js/app/models/log.js | 28 ++- public/js/app/models/mission.js | 24 +-- public/js/app/models/mission_rotation.js | 22 +-- public/js/app/models/mod.js | 24 +-- public/js/app/models/parameter.js | 20 +-- public/js/app/models/server.js | 58 +++---- public/js/app/models/settings.js | 24 +-- public/js/app/router.js | 164 +++++++++--------- public/js/app/views/layout.js | 33 ++-- public/js/app/views/login.js | 23 +-- public/js/app/views/logs/list.js | 26 ++- public/js/app/views/logs/list_item.js | 56 +++--- public/js/app/views/missions/index.js | 114 ++++++------ public/js/app/views/missions/list.js | 38 ++-- public/js/app/views/missions/list_item.js | 56 +++--- public/js/app/views/missions/upload.js | 65 ++++--- public/js/app/views/missions/workshop.js | 79 ++++----- public/js/app/views/mods/list.js | 55 +++--- public/js/app/views/mods/list_item.js | 57 +++--- public/js/app/views/navigation.js | 78 ++++----- .../js/app/views/navigation/servers/list.js | 19 +- .../app/views/navigation/servers/list_item.js | 29 ++-- public/js/app/views/servers/empty.js | 27 ++- public/js/app/views/servers/form.js | 111 ++++++------ public/js/app/views/servers/info.js | 91 +++++----- public/js/app/views/servers/list.js | 71 ++++---- public/js/app/views/servers/list_item.js | 86 +++++---- .../views/servers/missions/available/list.js | 55 +++--- .../servers/missions/available/list_item.js | 34 ++-- public/js/app/views/servers/missions/index.js | 114 ++++++------ .../views/servers/missions/rotation/list.js | 41 ++--- .../servers/missions/rotation/list_item.js | 59 +++---- public/js/app/views/servers/mods/list.js | 84 ++++----- public/js/app/views/servers/mods/list_item.js | 33 ++-- .../js/app/views/servers/parameters/list.js | 85 +++++---- .../app/views/servers/parameters/list_item.js | 49 +++--- public/js/app/views/servers/players.js | 33 ++-- public/js/app/views/servers/view.js | 157 +++++++++-------- public/js/app/views/settings.js | 35 ++-- webpack.config.js | 7 +- 49 files changed, 1060 insertions(+), 1352 deletions(-) diff --git a/.gitignore b/.gitignore index 017bcf4..45a1365 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Logs -logs *.log npm-debug.log* diff --git a/package.json b/package.json index f407787..89540ca 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,6 @@ "standard": { "env": [ "mocha" - ], - "ignore": [ - "public/" ] }, "dependencies": { diff --git a/public/js/app.js b/public/js/app.js index 7ba318e..f1cfbb9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -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() +}) diff --git a/public/js/app/collections/logs.js b/public/js/app/collections/logs.js index 411caec..c63a56e 100644 --- a/public/js/app/collections/logs.js +++ b/public/js/app/collections/logs.js @@ -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/' +}) diff --git a/public/js/app/collections/mission_rotations.js b/public/js/app/collections/mission_rotations.js index 98a0c4f..8264429 100644 --- a/public/js/app/collections/mission_rotations.js +++ b/public/js/app/collections/mission_rotations.js @@ -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 +}) diff --git a/public/js/app/collections/missions.js b/public/js/app/collections/missions.js index 97e148b..e2358f4 100644 --- a/public/js/app/collections/missions.js +++ b/public/js/app/collections/missions.js @@ -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/' +}) diff --git a/public/js/app/collections/mods.js b/public/js/app/collections/mods.js index 7833b1a..3907dc9 100644 --- a/public/js/app/collections/mods.js +++ b/public/js/app/collections/mods.js @@ -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/' +}) diff --git a/public/js/app/collections/parameters.js b/public/js/app/collections/parameters.js index 0027461..84049ff 100644 --- a/public/js/app/collections/parameters.js +++ b/public/js/app/collections/parameters.js @@ -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 +}) diff --git a/public/js/app/collections/servers.js b/public/js/app/collections/servers.js index f0aaa21..894116d 100644 --- a/public/js/app/collections/servers.js +++ b/public/js/app/collections/servers.js @@ -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/' +}) diff --git a/public/js/app/models/log.js b/public/js/app/models/log.js index 2f538a7..23c8d61 100644 --- a/public/js/app/models/log.js +++ b/public/js/app/models/log.js @@ -1,18 +1,10 @@ -define(function (require) { - - "use strict"; - - var $ = require('jquery'), - _ = require('underscore'), - Backbone = require('backbone'); - - return Backbone.Model.extend({ - defaults: { - name: '', - formattedSize: '0 B', - size: 0, - }, - idAttribute: 'name', - }); - -}); +var Backbone = require('backbone') + +module.exports = Backbone.Model.extend({ + defaults: { + name: '', + formattedSize: '0 B', + size: 0 + }, + idAttribute: 'name' +}) diff --git a/public/js/app/models/mission.js b/public/js/app/models/mission.js index 493e93a..36fb26c 100644 --- a/public/js/app/models/mission.js +++ b/public/js/app/models/mission.js @@ -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/' +}) diff --git a/public/js/app/models/mission_rotation.js b/public/js/app/models/mission_rotation.js index abc5af0..adc98dc 100644 --- a/public/js/app/models/mission_rotation.js +++ b/public/js/app/models/mission_rotation.js @@ -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' + } +}) diff --git a/public/js/app/models/mod.js b/public/js/app/models/mod.js index 3fa1006..f5a278f 100644 --- a/public/js/app/models/mod.js +++ b/public/js/app/models/mod.js @@ -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/' +}) diff --git a/public/js/app/models/parameter.js b/public/js/app/models/parameter.js index b89e0ca..c09bbaa 100644 --- a/public/js/app/models/parameter.js +++ b/public/js/app/models/parameter.js @@ -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: '' + } +}) diff --git a/public/js/app/models/server.js b/public/js/app/models/server.js index bc73012..41bbfb3 100644 --- a/public/js/app/models/server.js +++ b/public/js/app/models/server.js @@ -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/' +}) diff --git a/public/js/app/models/settings.js b/public/js/app/models/settings.js index 889410c..9364119 100644 --- a/public/js/app/models/settings.js +++ b/public/js/app/models/settings.js @@ -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' +}) diff --git a/public/js/app/router.js b/public/js/app/router.js index 2906bdf..e3647db 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -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) } + } - }); - -}); +}) diff --git a/public/js/app/views/layout.js b/public/js/app/views/layout.js index ad1e406..4eef6c9 100644 --- a/public/js/app/views/layout.js +++ b/public/js/app/views/layout.js @@ -1,20 +1,13 @@ -define(function (require) { - - "use strict"; - - var $ = require('jquery'), - _ = require('underscore'), - Backbone = require('backbone'), - Marionette = require('marionette'), - tpl = require('text!tpl/layout.html'); - - return Marionette.LayoutView.extend({ - template: _.template(tpl), - - regions: { - navigation: "#navigation", - content: "#content" - } - }); - -}); \ No newline at end of file +var _ = require('underscore') +var Marionette = require('marionette') + +var tpl = require('tpl/layout.html') + +module.exports = Marionette.LayoutView.extend({ + template: _.template(tpl), + + regions: { + navigation: '#navigation', + content: '#content' + } +}) diff --git a/public/js/app/views/login.js b/public/js/app/views/login.js index fa4acfa..9d08e8c 100644 --- a/public/js/app/views/login.js +++ b/public/js/app/views/login.js @@ -1,15 +1,8 @@ -define(function (require) { - - "use strict"; - - var $ = require('jquery'), - _ = require('underscore'), - Backbone = require('backbone'), - Marionette = require('marionette'), - tpl = require('text!tpl/login.html'); - - return Marionette.ItemView.extend({ - template: _.template(tpl) - }); - -}); \ No newline at end of file +var _ = require('underscore') +var Marionette = require('marionette') + +var tpl = require('tpl/login.html') + +module.exports = Marionette.ItemView.extend({ + template: _.template(tpl) +}) diff --git a/public/js/app/views/logs/list.js b/public/js/app/views/logs/list.js index 19e7fb2..a8654e0 100644 --- a/public/js/app/views/logs/list.js +++ b/public/js/app/views/logs/list.js @@ -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 +}) diff --git a/public/js/app/views/logs/list_item.js b/public/js/app/views/logs/list_item.js index 62649de..36757dd 100644 --- a/public/js/app/views/logs/list_item.js +++ b/public/js/app/views/logs/list_item.js @@ -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() + }) + } +}) diff --git a/public/js/app/views/missions/index.js b/public/js/app/views/missions/index.js index 534f884..f23f3c2 100644 --- a/public/js/app/views/missions/index.js +++ b/public/js/app/views/missions/index.js @@ -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) { - - }, - }); - }, - }); - -}); + }) + } +}) diff --git a/public/js/app/views/missions/list.js b/public/js/app/views/missions/list.js index 037fd78..86994e6 100644 --- a/public/js/app/views/missions/list.js +++ b/public/js/app/views/missions/list.js @@ -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 + } +}) diff --git a/public/js/app/views/missions/list_item.js b/public/js/app/views/missions/list_item.js index 4bde857..a1c991d 100644 --- a/public/js/app/views/missions/list_item.js +++ b/public/js/app/views/missions/list_item.js @@ -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() + }) + } +}) diff --git a/public/js/app/views/missions/upload.js b/public/js/app/views/missions/upload.js index 75d1751..d151fba 100644 --- a/public/js/app/views/missions/upload.js +++ b/public/js/app/views/missions/upload.js @@ -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 + }) + } +}) diff --git a/public/js/app/views/missions/workshop.js b/public/js/app/views/missions/workshop.js index 6d19816..10f8db8 100644 --- a/public/js/app/views/missions/workshop.js +++ b/public/js/app/views/missions/workshop.js @@ -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() + } + }) + } +}) diff --git a/public/js/app/views/mods/list.js b/public/js/app/views/mods/list.js index 26dbe4e..a752ce3 100644 --- a/public/js/app/views/mods/list.js +++ b/public/js/app/views/mods/list.js @@ -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) { - - }, - }); - }, - }); -}); + } + }) + } +}) diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index 13206a9..724e3a5 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -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() + }) + } +}) diff --git a/public/js/app/views/navigation.js b/public/js/app/views/navigation.js index 6838a1a..badcc99 100644 --- a/public/js/app/views/navigation.js +++ b/public/js/app/views/navigation.js @@ -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() + } +}) diff --git a/public/js/app/views/navigation/servers/list.js b/public/js/app/views/navigation/servers/list.js index 3a626af..10c206a 100644 --- a/public/js/app/views/navigation/servers/list.js +++ b/public/js/app/views/navigation/servers/list.js @@ -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 +}) diff --git a/public/js/app/views/navigation/servers/list_item.js b/public/js/app/views/navigation/servers/list_item.js index dad61fc..44df646 100644 --- a/public/js/app/views/navigation/servers/list_item.js +++ b/public/js/app/views/navigation/servers/list_item.js @@ -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 +}) diff --git a/public/js/app/views/servers/empty.js b/public/js/app/views/servers/empty.js index 7fe58b1..074031d 100644 --- a/public/js/app/views/servers/empty.js +++ b/public/js/app/views/servers/empty.js @@ -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 + } +}) diff --git a/public/js/app/views/servers/form.js b/public/js/app/views/servers/form.js index 2b0c552..b49de4c 100644 --- a/public/js/app/views/servers/form.js +++ b/public/js/app/views/servers/form.js @@ -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' + }) + } + }) + } +}) diff --git a/public/js/app/views/servers/info.js b/public/js/app/views/servers/info.js index c82fe1d..1d2ac16 100644 --- a/public/js/app/views/servers/info.js +++ b/public/js/app/views/servers/info.js @@ -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 - }); - }); - }, - }); -}); + }) + }) + } +}) diff --git a/public/js/app/views/servers/list.js b/public/js/app/views/servers/list.js index 0feb7c4..71ce904 100644 --- a/public/js/app/views/servers/list.js +++ b/public/js/app/views/servers/list.js @@ -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() + } +}) diff --git a/public/js/app/views/servers/list_item.js b/public/js/app/views/servers/list_item.js index 6a9426d..e61eb19 100644 --- a/public/js/app/views/servers/list_item.js +++ b/public/js/app/views/servers/list_item.js @@ -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() + } +}) diff --git a/public/js/app/views/servers/missions/available/list.js b/public/js/app/views/servers/missions/available/list.js index 79abacc..f24bb63 100644 --- a/public/js/app/views/servers/missions/available/list.js +++ b/public/js/app/views/servers/missions/available/list.js @@ -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 + } +}) diff --git a/public/js/app/views/servers/missions/available/list_item.js b/public/js/app/views/servers/missions/available/list_item.js index b21c4c6..6f51ff1 100644 --- a/public/js/app/views/servers/missions/available/list_item.js +++ b/public/js/app/views/servers/missions/available/list_item.js @@ -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) + } +}) diff --git a/public/js/app/views/servers/missions/index.js b/public/js/app/views/servers/missions/index.js index 50ab5d1..2be68dd 100644 --- a/public/js/app/views/servers/missions/index.js +++ b/public/js/app/views/servers/missions/index.js @@ -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() + } + } +}) diff --git a/public/js/app/views/servers/missions/rotation/list.js b/public/js/app/views/servers/missions/rotation/list.js index 6dcf788..872ffb9 100644 --- a/public/js/app/views/servers/missions/rotation/list.js +++ b/public/js/app/views/servers/missions/rotation/list.js @@ -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()) + } +}) diff --git a/public/js/app/views/servers/missions/rotation/list_item.js b/public/js/app/views/servers/missions/rotation/list_item.js index 7abaca5..f399daa 100644 --- a/public/js/app/views/servers/missions/rotation/list_item.js +++ b/public/js/app/views/servers/missions/rotation/list_item.js @@ -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') + } +}) diff --git a/public/js/app/views/servers/mods/list.js b/public/js/app/views/servers/mods/list.js index cff9454..9e261a7 100644 --- a/public/js/app/views/servers/mods/list.js +++ b/public/js/app/views/servers/mods/list.js @@ -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() + } + } +}) diff --git a/public/js/app/views/servers/mods/list_item.js b/public/js/app/views/servers/mods/list_item.js index d06e603..3168672 100644 --- a/public/js/app/views/servers/mods/list_item.js +++ b/public/js/app/views/servers/mods/list_item.js @@ -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 + } + } +}) diff --git a/public/js/app/views/servers/parameters/list.js b/public/js/app/views/servers/parameters/list.js index c2e0904..97631cb 100644 --- a/public/js/app/views/servers/parameters/list.js +++ b/public/js/app/views/servers/parameters/list.js @@ -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 + }) + })) + } +}) diff --git a/public/js/app/views/servers/parameters/list_item.js b/public/js/app/views/servers/parameters/list_item.js index 6494f7d..11c06e9 100644 --- a/public/js/app/views/servers/parameters/list_item.js +++ b/public/js/app/views/servers/parameters/list_item.js @@ -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() + } +}) diff --git a/public/js/app/views/servers/players.js b/public/js/app/views/servers/players.js index 2be83ba..371a50e 100644 --- a/public/js/app/views/servers/players.js +++ b/public/js/app/views/servers/players.js @@ -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 + }) + } + } +}) diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 936e0ef..51dd3a7 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -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') + } +}) diff --git a/public/js/app/views/settings.js b/public/js/app/views/settings.js index 735fe98..9dddb5d 100644 --- a/public/js/app/views/settings.js +++ b/public/js/app/views/settings.js @@ -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' : '' + } + } +}) diff --git a/webpack.config.js b/webpack.config.js index 45a994d..500f26c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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' },