Download mods from play withSIX

This commit is contained in:
Björn Dahlgren 2014-05-07 01:35:44 +02:00
parent 6efdf0d34a
commit 21a9fd8e5f
6 changed files with 79 additions and 2 deletions

View File

@ -9,7 +9,8 @@ define(function (require) {
return Backbone.Model.extend({ return Backbone.Model.extend({
defaults: { defaults: {
name: '' name: ''
} },
urlRoot: '/api/mods/',
}); });
}); });

View File

@ -0,0 +1,46 @@
define(function (require) {
'use strict';
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
FormView = require('marionette-formview'),
Mod = require('app/models/mod'),
tpl = require('text!tpl/mods/form.html');
return Marionette.ItemView.extend({
template: _.template(tpl),
initialize: function (options) {
this.mods = options.mods;
this.model = new Mod();
this.bind('ok', this.submit);
},
submit: function (modal) {
var self = this;
var $form = $('form');
modal.preventClose();
$form.find('.form-group').removeClass('has-error');
$form.find('.help-block').text('');
this.model.save({ name: $form.find('.mod').val() }, {
success: function () {
self.mods.fetch({
success : function () {
modal.close();
}
});
},
error: function () {
$form.find('.form-group').addClass('has-error');
$form.find('.help-block').text('Problem downloading mod');
}
});
},
});
});

View File

@ -7,6 +7,7 @@ define(function (require) {
Backbone = require('backbone'), Backbone = require('backbone'),
Marionette = require('marionette'), Marionette = require('marionette'),
ListItemView = require('app/views/mods/list_item'), ListItemView = require('app/views/mods/list_item'),
FormView = require('app/views/mods/form'),
tpl = require('text!tpl/mods/list.html'), tpl = require('text!tpl/mods/list.html'),
template = _.template(tpl); template = _.template(tpl);
@ -16,6 +17,10 @@ define(function (require) {
itemViewContainer: "tbody", itemViewContainer: "tbody",
template: template, template: template,
events: {
"click #download": "download"
},
initialize: function (options) { initialize: function (options) {
this.on("itemview:mods:update", this.update, this); this.on("itemview:mods:update", this.update, this);
}, },
@ -23,5 +28,11 @@ define(function (require) {
update: function() { update: function() {
this.collection.fetch(); this.collection.fetch();
}, },
download: function (event) {
event.preventDefault();
var view = new FormView({mods: this.collection});
new Backbone.BootstrapModal({ content: view }).open();
},
}); });
}); });

View File

@ -0,0 +1,11 @@
<p>
Use foldername from <a href='http://play.withsix.com/' target=_blank>play withSIX</a>
</p>
<form class="form" role="form">
<div class="form-group">
<label for="mod" class="control-label">Mod</label>
<input type="text" class="form-control mod" name="mod" id="mod" data-field="mod">
<span class="help-block"></span>
</div>
</form>

View File

@ -8,3 +8,5 @@
<!-- want to insert collection items, here --> <!-- want to insert collection items, here -->
<tbody></tbody> <tbody></tbody>
</table> </table>
<a class="btn btn-primary" id="download" href="#">Download new mod</a>

View File

@ -66,7 +66,13 @@ exports.index = function(req, res){
}; };
exports.create = function(req, res){ exports.create = function(req, res){
res.send('create mod'); downloadMod(req.body.name, function (mods, err) {
if (mods && !err) {
res.send(mods);
} else {
res.send(500, err);
}
});
}; };
exports.show = function(req, res){ exports.show = function(req, res){