From 446a93855d129e132fecc8bc45a2c40f35a846f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sat, 11 Apr 2020 01:14:39 +0200 Subject: [PATCH] Mission parameters --- package.json | 2 +- .../js/app/collections/mission_parameters.js | 7 ++++ public/js/app/models/mission_parameter.js | 8 +++++ public/js/app/models/mission_rotation.js | 3 +- .../views/servers/missions/parameters/list.js | 27 +++++++++++++++ .../servers/missions/parameters/list_item.js | 33 +++++++++++++++++++ .../servers/missions/rotation/list_item.js | 19 ++++++++++- .../tpl/servers/missions/parameters/list.html | 11 +++++++ .../missions/parameters/list_item.html | 32 ++++++++++++++++++ .../servers/missions/rotation/list_item.html | 9 ++++- 10 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 public/js/app/collections/mission_parameters.js create mode 100644 public/js/app/models/mission_parameter.js create mode 100644 public/js/app/views/servers/missions/parameters/list.js create mode 100644 public/js/app/views/servers/missions/parameters/list_item.js create mode 100644 public/js/tpl/servers/missions/parameters/list.html create mode 100644 public/js/tpl/servers/missions/parameters/list_item.html diff --git a/package.json b/package.json index 1a886d3..b2f6af2 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ ] }, "dependencies": { - "arma-server": "0.0.9", + "arma-server": "0.0.10", "async": "^0.9.0", "backbone": "1.3.3", "backbone.bootstrap-modal": "https://github.com/powmedia/backbone.bootstrap-modal/archive/632210077c2424be2ee6ea2aafe0d3fe016ae524.tar.gz", diff --git a/public/js/app/collections/mission_parameters.js b/public/js/app/collections/mission_parameters.js new file mode 100644 index 0000000..c55f8c7 --- /dev/null +++ b/public/js/app/collections/mission_parameters.js @@ -0,0 +1,7 @@ +var Backbone = require('backbone') + +var MissionParameter = require('app/models/mission_parameter') + +module.exports = Backbone.Collection.extend({ + model: MissionParameter +}) diff --git a/public/js/app/models/mission_parameter.js b/public/js/app/models/mission_parameter.js new file mode 100644 index 0000000..33a6b3e --- /dev/null +++ b/public/js/app/models/mission_parameter.js @@ -0,0 +1,8 @@ +var Backbone = require('backbone') + +module.exports = Backbone.Model.extend({ + defaults: { + name: '', + value: '' + } +}) diff --git a/public/js/app/models/mission_rotation.js b/public/js/app/models/mission_rotation.js index adc98dc..8e635b5 100644 --- a/public/js/app/models/mission_rotation.js +++ b/public/js/app/models/mission_rotation.js @@ -3,6 +3,7 @@ var Backbone = require('backbone') module.exports = Backbone.Model.extend({ defaults: { name: '', - difficulty: 'recruit' + difficulty: 'recruit', + params: [] } }) diff --git a/public/js/app/views/servers/missions/parameters/list.js b/public/js/app/views/servers/missions/parameters/list.js new file mode 100644 index 0000000..460d694 --- /dev/null +++ b/public/js/app/views/servers/missions/parameters/list.js @@ -0,0 +1,27 @@ +var _ = require('underscore') +var Marionette = require('marionette') + +var MissionParameter = require('app/models/mission_parameter') +var ListItemView = require('app/views/servers/missions/parameters/list_item') +var tpl = require('tpl/servers/missions/parameters/list.html') + +module.exports = Marionette.CompositeView.extend({ + childView: ListItemView, + childViewContainer: 'tbody', + template: _.template(tpl), + + events: { + 'click .add-parameter': 'addParameter' + }, + + childViewOptions: function (model, index) { + return { + index: index + } + }, + + addParameter: function (e) { + e.preventDefault() + this.collection.add(new MissionParameter()) + } +}) diff --git a/public/js/app/views/servers/missions/parameters/list_item.js b/public/js/app/views/servers/missions/parameters/list_item.js new file mode 100644 index 0000000..5fceec8 --- /dev/null +++ b/public/js/app/views/servers/missions/parameters/list_item.js @@ -0,0 +1,33 @@ +var $ = require('jquery') +var _ = require('underscore') +var Marionette = require('marionette') + +var tpl = require('tpl/servers/missions/parameters/list_item.html') + +var template = _.template(tpl) + +module.exports = Marionette.ItemView.extend({ + tagName: 'tr', + template: template, + + events: { + 'click button.parameter-delete': 'delete', + 'change input': 'changed' + }, + + changed: function (e) { + var val = $(e.target).val() + this.model.set(e.target.dataset.attr, val) + }, + + delete: function (e) { + e.preventDefault() + this.model.destroy() + }, + + templateHelpers: function () { + return { + index: this.options.index + } + } +}) diff --git a/public/js/app/views/servers/missions/rotation/list_item.js b/public/js/app/views/servers/missions/rotation/list_item.js index f399daa..0f38a1a 100644 --- a/public/js/app/views/servers/missions/rotation/list_item.js +++ b/public/js/app/views/servers/missions/rotation/list_item.js @@ -2,11 +2,13 @@ var $ = require('jquery') var _ = require('underscore') var Marionette = require('marionette') +var MissionParameters = require('app/collections/mission_parameters') +var ParametersListView = require('app/views/servers/missions/parameters/list') var tpl = require('tpl/servers/missions/rotation/list_item.html') var template = _.template(tpl) -module.exports = Marionette.ItemView.extend({ +module.exports = Marionette.LayoutView.extend({ tagName: 'tr', template: template, @@ -16,6 +18,20 @@ module.exports = Marionette.ItemView.extend({ 'change input#name': 'changed' }, + regions: { + parametersView: '.parameters' + }, + + initialize: function (options) { + this.parametersCollection = new MissionParameters(this.model.get('params')) + this.parametersCollection.on('all', this.updateMissionParameters, this) + this.parametersListView = new ParametersListView({ collection: this.parametersCollection }) + }, + + updateMissionParameters: function () { + this.model.set('params', this.parametersCollection.toJSON()) + }, + changed: function (e) { var val = $(e.target).val() this.model.set(e.target.id, val) @@ -27,6 +43,7 @@ module.exports = Marionette.ItemView.extend({ }, onRender: function () { + this.parametersView.show(this.parametersListView) var difficulty = this.model.get('difficulty') var $option = this.$el.find("#difficulty option[value='" + difficulty + "']") $option.attr('selected', 'selected') diff --git a/public/js/tpl/servers/missions/parameters/list.html b/public/js/tpl/servers/missions/parameters/list.html new file mode 100644 index 0000000..fb5e1af --- /dev/null +++ b/public/js/tpl/servers/missions/parameters/list.html @@ -0,0 +1,11 @@ +
+ + + +
+
+ + + + Add parameter + diff --git a/public/js/tpl/servers/missions/parameters/list_item.html b/public/js/tpl/servers/missions/parameters/list_item.html new file mode 100644 index 0000000..27870f6 --- /dev/null +++ b/public/js/tpl/servers/missions/parameters/list_item.html @@ -0,0 +1,32 @@ + +
+
+
+
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+
+
+
+ diff --git a/public/js/tpl/servers/missions/rotation/list_item.html b/public/js/tpl/servers/missions/rotation/list_item.html index 7fa47a6..9da4b12 100644 --- a/public/js/tpl/servers/missions/rotation/list_item.html +++ b/public/js/tpl/servers/missions/rotation/list_item.html @@ -20,11 +20,18 @@ +
+ +
+
+
+
+