diff --git a/public/js/app/router.js b/public/js/app/router.js index 637e70e..359c8a6 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -14,11 +14,13 @@ define(function (require) { Logs = require('app/collections/logs'), Missions = require('app/collections/missions'), Mods = require('app/collections/mods'), + Settings = require('app/models/settings'), Servers = require('app/collections/servers'), $body = $('body'), missions = new Missions(), mods = new Mods(), + settings = new Settings(), servers = new Servers(), layoutView = new LayoutView({el: $body}).render(); @@ -33,18 +35,19 @@ define(function (require) { }, initialize: function () { - layoutView.navigation.show(new NavigationView({servers: servers})); + layoutView.navigation.show(new NavigationView({settings: settings, servers: servers})); sweetAlertInitialize(); missions.fetch(); + settings.fetch(); var initialized = false; var socket = io.connect(); socket.on('mods', function (_mods) { - mods.set(_mods).sort(); + mods.set(_mods); }); socket.on('servers', function (_servers) { - servers.set(_servers).sort(); + servers.set(_servers); if (!initialized) { initialized = true; diff --git a/public/js/app/views/layout.js b/public/js/app/views/layout.js index c535a67..ad1e406 100644 --- a/public/js/app/views/layout.js +++ b/public/js/app/views/layout.js @@ -8,7 +8,7 @@ define(function (require) { Marionette = require('marionette'), tpl = require('text!tpl/layout.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), regions: { diff --git a/public/js/app/views/logs/list.js b/public/js/app/views/logs/list.js index db6875b..19e7fb2 100644 --- a/public/js/app/views/logs/list.js +++ b/public/js/app/views/logs/list.js @@ -12,8 +12,8 @@ define(function (require) { template = _.template(tpl); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + 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 d15872d..62649de 100644 --- a/public/js/app/views/logs/list_item.js +++ b/public/js/app/views/logs/list_item.js @@ -16,10 +16,10 @@ define(function (require) { template: template, events: { - "click .destroy": "destroy", + "click .destroy": "deleteLog", }, - destroy: function (event) { + deleteLog: function (event) { var self = this; sweetAlert({ title: "Are you sure?", diff --git a/public/js/app/views/missions/index.js b/public/js/app/views/missions/index.js index 636400f..f534ee2 100644 --- a/public/js/app/views/missions/index.js +++ b/public/js/app/views/missions/index.js @@ -11,7 +11,7 @@ define(function (require) { ListView = require('app/views/missions/list'), tpl = require('text!tpl/missions/index.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), regions: { diff --git a/public/js/app/views/missions/list.js b/public/js/app/views/missions/list.js index 1ce9d82..ed02862 100644 --- a/public/js/app/views/missions/list.js +++ b/public/js/app/views/missions/list.js @@ -12,12 +12,8 @@ define(function (require) { template = _.template(tpl); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: template, - - initialize: function (options) { - this.listenTo(this.collection, "change reset", this.render); - }, }); }); diff --git a/public/js/app/views/missions/list_item.js b/public/js/app/views/missions/list_item.js index dee0626..4bde857 100644 --- a/public/js/app/views/missions/list_item.js +++ b/public/js/app/views/missions/list_item.js @@ -16,10 +16,10 @@ define(function (require) { template: template, events: { - "click .delete": "delete" + "click .delete": "deleteMission" }, - delete: function (event) { + deleteMission: function (event) { var self = this; sweetAlert({ title: "Are you sure?", diff --git a/public/js/app/views/missions/upload.js b/public/js/app/views/missions/upload.js index 08cb6ba..316a0b8 100644 --- a/public/js/app/views/missions/upload.js +++ b/public/js/app/views/missions/upload.js @@ -20,7 +20,6 @@ define(function (require) { initialize: function (options) { this.missions = options.missions; - this.model = new Mission(); }, submit: function () { diff --git a/public/js/app/views/mods/list.js b/public/js/app/views/mods/list.js index 168c6a5..26dbe4e 100644 --- a/public/js/app/views/mods/list.js +++ b/public/js/app/views/mods/list.js @@ -12,18 +12,14 @@ define(function (require) { template = _.template(tpl); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: template, events: { "click #refresh": "refresh", }, - initialize: function (options) { - this.listenTo(this.collection, "change reset", this.render); - }, - refresh: function (event) { event.preventDefault(); $.ajax({ diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index 93351c8..13206a9 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -17,10 +17,10 @@ define(function (require) { template: template, events: { - "click .destroy": "destroy", + "click .destroy": "deleteMod", }, - destroy: function (event) { + deleteMod: function (event) { var self = this; sweetAlert({ title: "Are you sure?", diff --git a/public/js/app/views/navigation.js b/public/js/app/views/navigation.js index 4efa59e..4acc3e6 100644 --- a/public/js/app/views/navigation.js +++ b/public/js/app/views/navigation.js @@ -19,6 +19,7 @@ define(function (require) { }, initialize: function (options) { + this.settings = options.settings; this.servers = options.servers; this.serversListView = new ServersListView({ collection: this.servers }) }, @@ -30,7 +31,7 @@ define(function (require) { settings: function (event) { event.preventDefault(); - var view = new SettingsView(); + var view = new SettingsView({ model: this.settings }); new Backbone.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 af70776..3a626af 100644 --- a/public/js/app/views/navigation/servers/list.js +++ b/public/js/app/views/navigation/servers/list.js @@ -10,6 +10,6 @@ define(function (require) { return Marionette.CollectionView.extend({ tagName: 'ul', - itemView: ListItemView, + childView: ListItemView, }); }); diff --git a/public/js/app/views/servers/info.js b/public/js/app/views/servers/info.js index efa111a..c82fe1d 100644 --- a/public/js/app/views/servers/info.js +++ b/public/js/app/views/servers/info.js @@ -9,7 +9,7 @@ define(function (require) { swal = require('sweet-alert'), tpl = require('text!tpl/servers/info.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), events: { diff --git a/public/js/app/views/servers/list.js b/public/js/app/views/servers/list.js index e73425a..0feb7c4 100644 --- a/public/js/app/views/servers/list.js +++ b/public/js/app/views/servers/list.js @@ -15,8 +15,8 @@ define(function (require) { template = _.template(tpl); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: template, emptyView: EmptyView, @@ -25,20 +25,16 @@ define(function (require) { "click #add-server": "addServer" }, - initialize: function (options) { - this.listenTo(this.collection, "change reset", this.render); - }, - - buildItemView: function(item, ItemViewType, itemViewOptions){ + buildChildView: function(item, ChildViewType, childViewOptions){ // build the final list of options for the item view type - var options = _.extend({model: item}, itemViewOptions); + var options = _.extend({model: item}, childViewOptions); - if (ItemViewType == EmptyView) { + if (ChildViewType == EmptyView) { options = _.extend({servers: this.collection}, options); } // create the item view instance - var view = new ItemViewType(options); + var view = new ChildViewType(options); // return it return view; }, diff --git a/public/js/app/views/servers/missions/available/list.js b/public/js/app/views/servers/missions/available/list.js index 59c9d4b..78c8a9e 100644 --- a/public/js/app/views/servers/missions/available/list.js +++ b/public/js/app/views/servers/missions/available/list.js @@ -10,14 +10,14 @@ define(function (require) { tpl = require('text!tpl/servers/missions/available/list.html'); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: _.template(tpl), - buildItemView: function(item, ItemViewType, itemViewOptions){ + buildChildView: function(item, ChildViewType, childViewOptions){ var self = this; - var options = _.extend({model: item}, itemViewOptions); - var view = new ItemViewType(options); + var options = _.extend({model: item}, childViewOptions); + var view = new ChildViewType(options); view.on('add', function (model) { self.trigger('add', model); }); diff --git a/public/js/app/views/servers/missions/index.js b/public/js/app/views/servers/missions/index.js index 8a4bfca..f38e97a 100644 --- a/public/js/app/views/servers/missions/index.js +++ b/public/js/app/views/servers/missions/index.js @@ -11,7 +11,7 @@ define(function (require) { RotationListView = require('app/views/servers/missions/rotation/list'), tpl = require('text!tpl/servers/missions/index.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), regions: { @@ -25,7 +25,6 @@ define(function (require) { initialize: function (options) { this.missions = options.missions; - this.model = options.server; this.rotationCollection = new MissionRotations(this.model.get('missions')); diff --git a/public/js/app/views/servers/missions/rotation/list.js b/public/js/app/views/servers/missions/rotation/list.js index 5c97fe2..6dcf788 100644 --- a/public/js/app/views/servers/missions/rotation/list.js +++ b/public/js/app/views/servers/missions/rotation/list.js @@ -11,8 +11,8 @@ define(function (require) { tpl = require('text!tpl/servers/missions/rotation/list.html'); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: _.template(tpl), events: { diff --git a/public/js/app/views/servers/mods/list.js b/public/js/app/views/servers/mods/list.js index 7ede2c1..cff9454 100644 --- a/public/js/app/views/servers/mods/list.js +++ b/public/js/app/views/servers/mods/list.js @@ -12,7 +12,7 @@ define(function (require) { tpl = require('text!tpl/servers/mods/list.html'); return ModsListView.extend({ - itemView: ListItemView, + childView: ListItemView, template: _.template(tpl), events: { @@ -20,9 +20,9 @@ define(function (require) { "click .uncheck-all": "uncheckAll", }, - buildItemView: function(item, ItemViewType, itemViewOptions){ - var options = _.extend({model: item, server: this.options.server}, itemViewOptions); - var view = new ItemViewType(options); + buildChildView: function(item, ChildViewType, childViewOptions){ + var options = _.extend({model: item, server: this.options.server}, childViewOptions); + var view = new ChildViewType(options); return view; }, diff --git a/public/js/app/views/servers/parameters/list.js b/public/js/app/views/servers/parameters/list.js index 11b915c..c2e0904 100644 --- a/public/js/app/views/servers/parameters/list.js +++ b/public/js/app/views/servers/parameters/list.js @@ -12,22 +12,21 @@ define(function (require) { tpl = require('text!tpl/servers/parameters/list.html'); return Marionette.CompositeView.extend({ - itemView: ListItemView, - itemViewContainer: "tbody", + childView: ListItemView, + childViewContainer: "tbody", template: _.template(tpl), events: { "click .add-parameter": "addParameter", }, - initialize: function (options) { - this.model = options.server; + modelEvents: { + "change": "serverUpdated", + }, - this.collection = new Parameters(this.model.get('parameters').map(function (parameter) { - return new Parameter({ - parameter: parameter, - }); - })); + initialize: function (options) { + this.collection = new Parameters(); + this.serverUpdated(); }, addParameter: function (e) { @@ -42,6 +41,14 @@ define(function (require) { }), }; }, + + 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/players.js b/public/js/app/views/servers/players.js index fe9960e..2be83ba 100644 --- a/public/js/app/views/servers/players.js +++ b/public/js/app/views/servers/players.js @@ -8,7 +8,7 @@ define(function (require) { Marionette = require('marionette'), tpl = require('text!tpl/servers/players.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), templateHelpers: { players: function(){ diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 00e9e0a..936e0ef 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -15,7 +15,7 @@ define(function (require) { PlayersView = require('app/views/servers/players'), tpl = require('text!tpl/servers/view.html'); - return Marionette.Layout.extend({ + return Marionette.LayoutView.extend({ template: _.template(tpl), regions: { @@ -43,9 +43,9 @@ define(function (require) { onRender: function() { this.infoView.show(new InfoView({model: this.model})); - this.missionsView.show(new MissionsView({missions: this.missions, server: 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({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})); }, diff --git a/public/js/app/views/settings.js b/public/js/app/views/settings.js index e25128d..735fe98 100644 --- a/public/js/app/views/settings.js +++ b/public/js/app/views/settings.js @@ -6,7 +6,6 @@ define(function (require) { _ = require('underscore'), Backbone = require('backbone'), Marionette = require('marionette'), - Settings = require('app/models/settings'), tpl = require('text!tpl/settings.html'); return Marionette.ItemView.extend({ @@ -16,11 +15,6 @@ define(function (require) { 'change': 'render', }, - initialize: function () { - this.model = new Settings() - this.model.fetch(); - }, - templateHelpers: { isTypeChecked: function(type) { return this.type === type ? 'checked' : ''; diff --git a/public/js/lib/backbone.js b/public/js/lib/backbone.js index 3b2593d..6860502 100644 --- a/public/js/lib/backbone.js +++ b/public/js/lib/backbone.js @@ -1,2 +1,7 @@ -(function(){var t=this;var e=t.Backbone;var i=[];var r=i.push;var s=i.slice;var n=i.splice;var a;if(typeof exports!=="undefined"){a=exports}else{a=t.Backbone={}}a.VERSION="1.1.0";var h=t._;if(!h&&typeof require!=="undefined")h=require("underscore");a.$=t.jQuery||t.Zepto||t.ender||t.$;a.noConflict=function(){t.Backbone=e;return this};a.emulateHTTP=false;a.emulateJSON=false;var o=a.Events={on:function(t,e,i){if(!l(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,i){if(!l(this,"once",t,[e,i])||!e)return this;var r=this;var s=h.once(function(){r.off(t,s);e.apply(this,arguments)});s._callback=e;return this.on(t,s,i)},off:function(t,e,i){var r,s,n,a,o,u,c,f;if(!this._events||!l(this,"off",t,[e,i]))return this;if(!t&&!e&&!i){this._events={};return this}a=t?[t]:h.keys(this._events);for(o=0,u=a.length;o").attr(t);this.setElement(e,false)}else{this.setElement(h.result(this,"el"),false)}}});a.sync=function(t,e,i){var r=T[t];h.defaults(i||(i={}),{emulateHTTP:a.emulateHTTP,emulateJSON:a.emulateJSON});var s={type:r,dataType:"json"};if(!i.url){s.url=h.result(e,"url")||U()}if(i.data==null&&e&&(t==="create"||t==="update"||t==="patch")){s.contentType="application/json";s.data=JSON.stringify(i.attrs||e.toJSON(i))}if(i.emulateJSON){s.contentType="application/x-www-form-urlencoded";s.data=s.data?{model:s.data}:{}}if(i.emulateHTTP&&(r==="PUT"||r==="DELETE"||r==="PATCH")){s.type="POST";if(i.emulateJSON)s.data._method=r;var n=i.beforeSend;i.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",r);if(n)return n.apply(this,arguments)}}if(s.type!=="GET"&&!i.emulateJSON){s.processData=false}if(s.type==="PATCH"&&E){s.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var o=i.xhr=a.ajax(h.extend(s,i));e.trigger("request",e,o,i);return o};var E=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};a.ajax=function(){return a.$.ajax.apply(a.$,arguments)};var k=a.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var $=/(\(\?)?:\w+/g;var H=/\*\w+/g;var A=/[\-{}\[\]+?.,\\\^$|#\s]/g;h.extend(k.prototype,o,{initialize:function(){},route:function(t,e,i){if(!h.isRegExp(t))t=this._routeToRegExp(t);if(h.isFunction(e)){i=e;e=""}if(!i)i=this[e];var r=this;a.history.route(t,function(s){var n=r._extractParameters(t,s);i&&i.apply(r,n);r.trigger.apply(r,["route:"+e].concat(n));r.trigger("route",e,n);a.history.trigger("route",r,e,n)});return this},navigate:function(t,e){a.history.navigate(t,e);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=h.result(this,"routes");var t,e=h.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(A,"\\$&").replace(S,"(?:$1)?").replace($,function(t,e){return e?t:"([^/]+)"}).replace(H,"(.*?)");return new RegExp("^"+t+"$")},_extractParameters:function(t,e){var i=t.exec(e).slice(1);return h.map(i,function(t){return t?decodeURIComponent(t):null})}});var I=a.History=function(){this.handlers=[];h.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var N=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/[?#].*$/;I.started=false;h.extend(I.prototype,o,{interval:50,getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=this.location.pathname;var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(N,"")},start:function(t){if(I.started)throw new Error("Backbone.history has already been started");I.started=true;this.options=h.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var e=this.getFragment();var i=document.documentMode;var r=P.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(O,"/");if(r&&this._wantsHashChange){this.iframe=a.$('