From 92e2c02b8d11958406a140f0721b03976eaac304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Fri, 4 Apr 2014 09:28:33 +0000 Subject: [PATCH] List missions --- public/js/app/collections/missions.js | 15 +++++++++++ public/js/app/forms/mission.js | 32 +++++++++++++++++++++++ public/js/app/forms/settings.js | 4 --- public/js/app/models/mission.js | 15 +++++++++++ public/js/app/router.js | 11 ++++++++ public/js/app/views/missions/list.js | 15 +++++++++++ public/js/app/views/missions/list_item.js | 17 ++++++++++++ public/js/tpl/forms/mission.html | 8 ++++++ public/js/tpl/missions/list_item.html | 1 + public/js/tpl/navigation.html | 1 + routes/missions.js | 14 +++++++++- 11 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 public/js/app/collections/missions.js create mode 100644 public/js/app/forms/mission.js create mode 100644 public/js/app/models/mission.js create mode 100644 public/js/app/views/missions/list.js create mode 100644 public/js/app/views/missions/list_item.js create mode 100644 public/js/tpl/forms/mission.html create mode 100644 public/js/tpl/missions/list_item.html diff --git a/public/js/app/collections/missions.js b/public/js/app/collections/missions.js new file mode 100644 index 0000000..b52a06e --- /dev/null +++ b/public/js/app/collections/missions.js @@ -0,0 +1,15 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Mission = require('app/models/mission'); + + return Backbone.Collection.extend({ + model: Mission, + url: '/api/missions/' + }); + +}); diff --git a/public/js/app/forms/mission.js b/public/js/app/forms/mission.js new file mode 100644 index 0000000..fbd924a --- /dev/null +++ b/public/js/app/forms/mission.js @@ -0,0 +1,32 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + FormView = require('marionette-formview'), + Settings = require('app/models/settings'), + tpl = require('text!tpl/forms/settings.html'); + + return FormView.extend({ + template: _.template(tpl), + + fields: { + path: { + el: ".mission", + required: "Please select a file." + } + }, + + initialize: function () { + var self = this; + new Mission().fetch({success: function (model, response, options) { + self.model = model; + self.runInitializers(); + }}); + } + }); + +}); \ No newline at end of file diff --git a/public/js/app/forms/settings.js b/public/js/app/forms/settings.js index 1fb6ff7..76dd6f2 100644 --- a/public/js/app/forms/settings.js +++ b/public/js/app/forms/settings.js @@ -25,10 +25,6 @@ define(function (require) { initialize: function () { var self = this; - new Settings().fetch({success: function (model, response, options) { - self.model = model; - self.runInitializers(); - }}); } }); diff --git a/public/js/app/models/mission.js b/public/js/app/models/mission.js new file mode 100644 index 0000000..22657a5 --- /dev/null +++ b/public/js/app/models/mission.js @@ -0,0 +1,15 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'); + + return Backbone.Model.extend({ + defaults: { + title: '' + } + }); + +}); diff --git a/public/js/app/router.js b/public/js/app/router.js index 2edbc19..20c39b0 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -7,22 +7,27 @@ define(function (require) { LayoutView = require('app/views/layout'), NavigationView = require('app/views/navigation'), HomeView = require('app/views/home'), + MissionsListView= require('app/views/missions/list'), ModsListView = require('app/views/mods/list'), ServerView = require('app/views/servers/view'), + Missions = require('app/collections/missions'), Mods = require('app/collections/mods'), Servers = require('app/collections/servers'), $body = $('body'), + missions = new Missions(), mods = new Mods(), servers = new Servers(), layoutView = new LayoutView({el: $body}).render(), navigationView = new NavigationView({servers: servers}), homeView = new HomeView({servers: servers}), + missionsListView = new MissionsListView({collection: missions}), modsListView = new ModsListView({collection: mods}); return Backbone.Router.extend({ routes: { + "missions": "missions", "mods": "mods", "servers/:id": "server", "": "home", @@ -30,6 +35,7 @@ define(function (require) { initialize: function () { layoutView.navigation.show(navigationView); + missions.fetch(); mods.fetch(); servers.fetch(); }, @@ -39,6 +45,11 @@ define(function (require) { homeView.delegateEvents(); }, + missions: function () { + layoutView.content.show(missionsListView); + missionsListView.delegateEvents(); + }, + mods: function () { layoutView.content.show(modsListView); modsListView.delegateEvents(); diff --git a/public/js/app/views/missions/list.js b/public/js/app/views/missions/list.js new file mode 100644 index 0000000..e40f0da --- /dev/null +++ b/public/js/app/views/missions/list.js @@ -0,0 +1,15 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + ListItemView = require('app/views/missions/list_item'); + + return Marionette.CollectionView.extend({ + tagName: 'ul', + itemView: ListItemView, + }); +}); diff --git a/public/js/app/views/missions/list_item.js b/public/js/app/views/missions/list_item.js new file mode 100644 index 0000000..df50be1 --- /dev/null +++ b/public/js/app/views/missions/list_item.js @@ -0,0 +1,17 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + tpl = require('text!tpl/missions/list_item.html'), + + template = _.template(tpl); + + return Marionette.ItemView.extend({ + tagName: "li", + template: template + }); +}); diff --git a/public/js/tpl/forms/mission.html b/public/js/tpl/forms/mission.html new file mode 100644 index 0000000..c7bbdb4 --- /dev/null +++ b/public/js/tpl/forms/mission.html @@ -0,0 +1,8 @@ +
+
+ +
+ +
+
+
diff --git a/public/js/tpl/missions/list_item.html b/public/js/tpl/missions/list_item.html new file mode 100644 index 0000000..0d8d125 --- /dev/null +++ b/public/js/tpl/missions/list_item.html @@ -0,0 +1 @@ +<%-name%> diff --git a/public/js/tpl/navigation.html b/public/js/tpl/navigation.html index a120b0d..3e766d9 100644 --- a/public/js/tpl/navigation.html +++ b/public/js/tpl/navigation.html @@ -12,6 +12,7 @@