Skip to content

Commit

Permalink
White and black rows has been extracted to separated modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
radek-anuszewski committed Apr 4, 2017
1 parent 0632881 commit 791181b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
12 changes: 12 additions & 0 deletions chessapp/src/main/webapp/src/board/black-row-view.js
@@ -0,0 +1,12 @@
define(function (require) {
const Mn = require("backbone.marionette");

return Mn.View.extend({
template: _.template(`<div></div><br>`),
tagName: 'section',
onRender: function () {
this.$el.addClass(`starts-with-black`);
this.$el.attr(`id`, `row-${this.model.get(`index`)}`);
}
});
});
12 changes: 4 additions & 8 deletions chessapp/src/main/webapp/src/board/chessboard-view.js
Expand Up @@ -2,23 +2,19 @@ define(function (require) {
const Mn = require("backbone.marionette");
const _ = require('underscore');
const $ = require('jquery');
const WhiteRowView = require('./white-row-view');
const BlackRowView = require('./black-row-view');

return Mn.CollectionView.extend({
// el: "#chessboard-fields", Why kurwa!?!?!?!?!
tagName: 'article',
template: _.template($("#chessboard-view").html()),
childView: function (item) {
if (item.odd) {
return Mn.View.extend({
template: _.template('Odd row<br>'),
tagName: 'section',
});
return WhiteRowView;
}
if (item.even) {
return Mn.View.extend({
template: _.template('Even row<br>'),
tagName: 'section',
});
return BlackRowView;
}
},
// Use attach HTML in some way
Expand Down
12 changes: 12 additions & 0 deletions chessapp/src/main/webapp/src/board/white-row-view.js
@@ -0,0 +1,12 @@
define(function (require) {
const Mn = require("backbone.marionette");

return Mn.View.extend({
template: _.template(`<div></div><br>`),
tagName: 'section',
onRender: function () {
this.$el.addClass(`starts-with-white`);
this.$el.attr(`id`, `row-${this.model.get(`index`)}`);
}
});
});
5 changes: 3 additions & 2 deletions chessapp/src/main/webapp/src/home/home-view.js
Expand Up @@ -19,8 +19,9 @@ define(function (require) {
_getRows: function () {
const RowModel = Backbone.Model.extend({
initialize ({index}) {
this.even = !!(!(index % 2));
this.odd = !!(index % 2);
this.even = !(this.odd);
this.index = index;
},
});
const Rows = Backbone.Collection.extend({
Expand All @@ -29,7 +30,7 @@ define(function (require) {
const rows = new Rows();
for (let index = 0; index < 8; index++) {
rows.add(new RowModel({
index,
index: (index + 1),
}));
}
return rows;
Expand Down

0 comments on commit 791181b

Please sign in to comment.