arma-server-web-admin/public/js/app/views/servers/missions/index.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

var _ = require('underscore')
var Marionette = require('marionette')
2015-08-23 22:16:16 +00:00
var MissionRotations = require('app/collections/mission_rotations')
var AvailableListView = require('app/views/servers/missions/available/list')
var RotationListView = require('app/views/servers/missions/rotation/list')
var tpl = require('tpl/servers/missions/index.html')
2015-08-23 22:16:16 +00:00
module.exports = Marionette.LayoutView.extend({
template: _.template(tpl),
templateHelpers: function () {
return {
filterValue: this.filterValue
}
},
2015-08-23 22:16:16 +00:00
regions: {
availableView: '#available',
rotationView: '#rotation'
},
2015-08-23 22:16:16 +00:00
events: {
'keyup #filterMissions': 'updateFilter'
},
2015-08-23 22:16:16 +00:00
modelEvents: {
change: 'serverUpdated'
},
2019-06-23 18:32:04 +00:00
initialize: function (options) {
this.missions = options.missions
this.filterValue = ''
2015-09-19 22:04:22 +00:00
this.rotationCollection = new MissionRotations(this.model.get('missions'))
2015-08-23 22:16:16 +00:00
var self = this
2015-08-23 22:16:16 +00:00
this.availableListView = new AvailableListView({
collection: this.missions,
filterValue: this.filterValue
})
this.availableListView.on('add', function (model) {
self.rotationCollection.add([{
difficulty: self.model.missionDifficulty(),
name: model.get('name').replace('.pbo', '')
}])
})
this.rotationListView = new RotationListView({
collection: this.rotationCollection,
server: this.model
})
},
2015-08-23 22:16:16 +00:00
onRender: function () {
this.availableView.show(this.availableListView)
this.rotationView.show(this.rotationListView)
},
2015-09-19 22:04:22 +00:00
updateFilter: function (event) {
this.filterValue = event.target.value
this.availableView.currentView.filterValue = this.filterValue
this.availableView.currentView.render()
},
2015-08-23 22:16:16 +00:00
serverUpdated: function () {
this.rotationCollection.set(this.model.get('missions'))
},
2019-06-23 18:32:04 +00:00
serialize: function () {
return {
missions: this.rotationCollection.toJSON()
}
}
})