List missions

This commit is contained in:
Björn Dahlgren 2014-04-04 09:28:33 +00:00
parent 7b863098a9
commit 92e2c02b8d
11 changed files with 128 additions and 5 deletions

View File

@ -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/'
});
});

View File

@ -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();
}});
}
});
});

View File

@ -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();
}});
}
});

View File

@ -0,0 +1,15 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
title: ''
}
});
});

View File

@ -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();

View File

@ -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,
});
});

View File

@ -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
});
});

View File

@ -0,0 +1,8 @@
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="file" class="col-sm-2 control-label">File</label>
<div class="col-sm-10">
<input type="file" class="form-control path" id="file" data-field="file" placeholder="Mission to upload">
</div>
</div>
</form>

View File

@ -0,0 +1 @@
<a href='#missions/<%-name%>'><%-name%></a>

View File

@ -12,6 +12,7 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" id="dashboard">Dashboard</a></li>
<li><a href="#missions" id="missions">Missions</a></li>
<li><a href="#mods" id="mods">Mods</a></li>
<li><a href="#" id="settings">Settings</a></li>
<li class="dropdown">

View File

@ -8,13 +8,25 @@ exports.index = function(req, res){
if (err) {
res.send(err);
} else {
res.send(files);
var missions = files.map(function (filename) {
return { name: filename }
});
res.send(missions);
}
});
};
exports.create = function(req, res){
res.send('create mission');
var missionFile = req.files.mission;
fs.readFile(missionFile.path, function (err, data) {
var newPath = config.path + '/mpmissions' + missionFile.name;
fs.writeFile(newPath, data, function (err) {
res.json(missionFile);
});
});
};
exports.show = function(req, res){