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

59 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-08-23 22:16:16 +00:00
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
MissionRotations = require('app/collections/mission_rotations'),
AvailableListView = require('app/views/servers/missions/available/list'),
RotationListView = require('app/views/servers/missions/rotation/list'),
tpl = require('text!tpl/servers/missions/index.html');
return Marionette.Layout.extend({
template: _.template(tpl),
regions: {
availableView: "#available",
rotationView: "#rotation",
},
2015-09-19 22:04:22 +00:00
modelEvents: {
"change": "serverUpdated",
},
2015-08-23 22:16:16 +00:00
initialize: function (options) {
this.missions = options.missions;
2015-09-19 22:04:22 +00:00
this.model = options.server;
2015-08-23 22:16:16 +00:00
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-09-19 22:04:22 +00:00
this.availableListView = new AvailableListView({collection: this.missions});
this.availableListView.on('add', function (model) {
2015-08-23 22:16:16 +00:00
self.rotationCollection.add([{
name: model.get('name').replace('.pbo', ''),
}]);
});
2015-09-19 22:04:22 +00:00
this.rotationListView = new RotationListView({collection: this.rotationCollection});
},
onRender: function() {
this.availableView.show(this.availableListView);
this.rotationView.show(this.rotationListView);
},
2015-08-23 22:16:16 +00:00
2015-09-19 22:04:22 +00:00
serverUpdated: function() {
this.rotationCollection.set(this.model.get('missions'));
2015-08-23 22:16:16 +00:00
},
serialize : function() {
return {
missions: this.rotationCollection.toJSON(),
};
},
});
});