diff --git a/public/js/app/models/mod.js b/public/js/app/models/mod.js index a87dc7c..4ac6396 100644 --- a/public/js/app/models/mod.js +++ b/public/js/app/models/mod.js @@ -9,7 +9,8 @@ define(function (require) { return Backbone.Model.extend({ defaults: { name: '' - } + }, + urlRoot: '/api/mods/', }); }); diff --git a/public/js/app/views/mods/form.js b/public/js/app/views/mods/form.js new file mode 100644 index 0000000..6e80d44 --- /dev/null +++ b/public/js/app/views/mods/form.js @@ -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'); + } + }); + }, + }); +}); diff --git a/public/js/app/views/mods/list.js b/public/js/app/views/mods/list.js index d0fa8c1..1aab85c 100644 --- a/public/js/app/views/mods/list.js +++ b/public/js/app/views/mods/list.js @@ -7,6 +7,7 @@ define(function (require) { Backbone = require('backbone'), Marionette = require('marionette'), ListItemView = require('app/views/mods/list_item'), + FormView = require('app/views/mods/form'), tpl = require('text!tpl/mods/list.html'), template = _.template(tpl); @@ -16,6 +17,10 @@ define(function (require) { itemViewContainer: "tbody", template: template, + events: { + "click #download": "download" + }, + initialize: function (options) { this.on("itemview:mods:update", this.update, this); }, @@ -23,5 +28,11 @@ define(function (require) { update: function() { this.collection.fetch(); }, + + download: function (event) { + event.preventDefault(); + var view = new FormView({mods: this.collection}); + new Backbone.BootstrapModal({ content: view }).open(); + }, }); }); diff --git a/public/js/tpl/mods/form.html b/public/js/tpl/mods/form.html new file mode 100644 index 0000000..07b8416 --- /dev/null +++ b/public/js/tpl/mods/form.html @@ -0,0 +1,11 @@ +
+ Use foldername from play withSIX +
+ + diff --git a/public/js/tpl/mods/list.html b/public/js/tpl/mods/list.html index 6f2affe..7ca7ca4 100644 --- a/public/js/tpl/mods/list.html +++ b/public/js/tpl/mods/list.html @@ -8,3 +8,5 @@ + +Download new mod diff --git a/routes/mods.js b/routes/mods.js index fc96620..3040234 100644 --- a/routes/mods.js +++ b/routes/mods.js @@ -66,7 +66,13 @@ exports.index = 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){