From 77026aa4bc6db4fe94849616b105217f327bb3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sun, 13 Apr 2014 19:10:40 +0200 Subject: [PATCH] Dashboard with servers --- public/js/app/router.js | 8 ++--- .../app/views/{home.js => servers/empty.js} | 18 +++++----- public/js/app/views/servers/list.js | 36 +++++++++++++++++++ public/js/app/views/servers/list_item.js | 17 +++++++++ .../js/tpl/{home.html => servers/empty.html} | 0 public/js/tpl/servers/list.html | 10 ++++++ public/js/tpl/servers/list_item.html | 3 ++ 7 files changed, 79 insertions(+), 13 deletions(-) rename public/js/app/views/{home.js => servers/empty.js} (88%) create mode 100644 public/js/app/views/servers/list.js create mode 100644 public/js/app/views/servers/list_item.js rename public/js/tpl/{home.html => servers/empty.html} (100%) create mode 100644 public/js/tpl/servers/list.html create mode 100644 public/js/tpl/servers/list_item.html diff --git a/public/js/app/router.js b/public/js/app/router.js index 4f3d99e..b0ef15b 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -6,7 +6,7 @@ define(function (require) { Backbone = require('backbone'), LayoutView = require('app/views/layout'), NavigationView = require('app/views/navigation'), - HomeView = require('app/views/home'), + ServersView = require('app/views/servers/list'), MissionsListView= require('app/views/missions/list'), ModsListView = require('app/views/mods/list'), ServerView = require('app/views/servers/view'), @@ -20,7 +20,7 @@ define(function (require) { servers = new Servers(), layoutView = new LayoutView({el: $body}).render(), navigationView = new NavigationView({servers: servers}), - homeView = new HomeView({servers: servers}), + serversView = new ServersView({collection: servers}), missionsListView = new MissionsListView({collection: missions}), modsListView = new ModsListView({collection: mods}); @@ -41,8 +41,8 @@ define(function (require) { }, home: function () { - layoutView.content.show(homeView); - homeView.delegateEvents(); + layoutView.content.show(serversView); + serversView.delegateEvents(); }, missions: function () { diff --git a/public/js/app/views/home.js b/public/js/app/views/servers/empty.js similarity index 88% rename from public/js/app/views/home.js rename to public/js/app/views/servers/empty.js index 9470cdb..d8c0aca 100644 --- a/public/js/app/views/home.js +++ b/public/js/app/views/servers/empty.js @@ -1,29 +1,29 @@ define(function (require) { - + "use strict"; - + var $ = require('jquery'), _ = require('underscore'), Backbone = require('backbone'), Marionette = require('marionette'), AddServerView = require('app/views/servers/add'), - tpl = require('text!tpl/home.html'); - + tpl = require('text!tpl/servers/empty.html'); + return Marionette.ItemView.extend({ template: _.template(tpl), - + events: { "click #add-server": "addServer" }, - + initialize: function (options) { this.servers = options.servers; }, - + addServer: function () { var view = new AddServerView({servers: this.servers}); new Backbone.BootstrapModal({ content: view, servers: this.servers }).open() }, }); - -}); \ No newline at end of file + +}); diff --git a/public/js/app/views/servers/list.js b/public/js/app/views/servers/list.js new file mode 100644 index 0000000..c9a16b4 --- /dev/null +++ b/public/js/app/views/servers/list.js @@ -0,0 +1,36 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + EmptyView = require('app/views/servers/empty'), + ListItemView = require('app/views/servers/list_item'), + tpl = require('text!tpl/servers/list.html'), + + template = _.template(tpl); + + return Marionette.CompositeView.extend({ + itemView: ListItemView, + itemViewContainer: "tbody", + template: template, + + emptyView: EmptyView, + + buildItemView: function(item, ItemViewType, itemViewOptions){ + // build the final list of options for the item view type + var options = _.extend({model: item}, itemViewOptions); + + if (ItemViewType == EmptyView) { + options = _.extend({servers: this.collection}, options); + } + + // create the item view instance + var view = new ItemViewType(options); + // return it + return view; + }, + }); +}); diff --git a/public/js/app/views/servers/list_item.js b/public/js/app/views/servers/list_item.js new file mode 100644 index 0000000..ae42e87 --- /dev/null +++ b/public/js/app/views/servers/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/servers/list_item.html'), + + template = _.template(tpl); + + return Marionette.ItemView.extend({ + tagName: "tr", + template: template + }); +}); diff --git a/public/js/tpl/home.html b/public/js/tpl/servers/empty.html similarity index 100% rename from public/js/tpl/home.html rename to public/js/tpl/servers/empty.html diff --git a/public/js/tpl/servers/list.html b/public/js/tpl/servers/list.html new file mode 100644 index 0000000..1738772 --- /dev/null +++ b/public/js/tpl/servers/list.html @@ -0,0 +1,10 @@ + + + + + + + + + +
Server
diff --git a/public/js/tpl/servers/list_item.html b/public/js/tpl/servers/list_item.html new file mode 100644 index 0000000..4d41e10 --- /dev/null +++ b/public/js/tpl/servers/list_item.html @@ -0,0 +1,3 @@ + + <%-title%> +