Dionysus.module('Test', function (Test, Dionysus, Backbone, Marionette, $) {
  'use strict';

  var TestSuiteView = Marionette.ItemView.extend({
    template : JST['templates/home/psychtests/suite'],
    className : 'ui card',
    serializeData : function() {
      var data = this.serializeModel(this.model);
      data.tests = this.model.embedded('tests');
      return data;
    }
  });

  var TestSuiteCollectionView = Marionette.CompositeView.extend({
    template : JST['templates/home/psychtests/psychtest'],
    childView : TestSuiteView,
    childViewContainer : '.ui.cards'
  });

  // TODO: should put logic into controller
  var PsychTestQuestionOneByOneView = Marionette.ItemView.extend({
    template : JST['templates/home/psychtests/onebyone'],
    onRender : function() {
      this.$('.ui.radio.checkbox').checkbox();
    },
    initialize: function() {
      this.listenTo(this.model, 'change', this.updateCurrentQuestion, this);
      this.updateCurrentQuestion();
    },
    updateCurrentQuestion : function() {
      var model = this.model;
      var questions = model.embedded('questions') || [],
          total = questions.length,
          current = model.get('current');

      var index = current - 1;
      model.set('hasPrev', index > 0, { silent : true });
      model.set('hasNext', index < total - 1, { silent : true });
      model.set('total', questions.length, { silent : true });
      return this.render();
    },
    serializeData : function() {
      var model = this.model;
      var questions = model.embedded('questions'),
          index = model.get('current') - 1;
      var question = questions.find(function(item, i) { return index === i; });

      var data = this.serializeModel(this.model);
      data.question = this.serializeModel(question);
      return data;
    },
    events : {
      'click .prev' : function() {
        var model = this.model;
        if (model.get('hasPrev')) {
          model.set('current', model.get('current') - 1); 
        }
      },
      'click .next' : function() {
        var model = this.model;
        if (model.get('hasNext')) {
          model.set('current', model.get('current') + 1);
        }
      }
    }
  });

  var PsychTestQuestionTableView = Marionette.ItemView.extend({
    template : JST['templates/home/psychtests/table'],
    serializeData : function() {
      var model = this.model;
      var data = this.serializeModel(model);
      data.questions = this.serializeCollection(model.embedded('questions'));
      return data;
    },
    onRender : function() {
      this.$('.ui.radio.checkbox').checkbox();
    }
  });

  var TestController = Marionette.Controller.extend({
    showTestSuites : function() {
      var fetching = Dionysus.request('psychtestsuite:instances');
      $.when(fetching).done(function(suites) {
        Dionysus.mainRegion.show(new TestSuiteCollectionView({ collection: suites }));
      });
    },
    showTest: function (id) {
      var fetching = Dionysus.request('psychtest:instance', id);
      $.when(fetching).done(function (test) {
        var format = test.get('format');
        switch(format) {
          case 'TABLE':
            Dionysus.mainRegion.show(new PsychTestQuestionTableView({ model : test }));
            break;
          case 'ONE_BY_ONE':
            Dionysus.mainRegion.show(new PsychTestQuestionOneByOneView({ model : test}));
            break;
        }
        
      });
    }
  });

  Dionysus.addInitializer(function () {
    new Marionette.AppRouter({
      appRoutes: {
        'psychtest/:id(/)': 'showTest',
        'psychtestsuites(/)' : 'showTestSuites'
      },
      controller: new TestController()
    });
  });
});

@@ -588,52 +588,8 @@
 );%0A%0A
-  // TODO: should put logic into controller%0A
   va
@@ -830,199 +830,8 @@
     
-this.listenTo(this.model, 'change', this.updateCurrentQuestion, this);%0A      this.updateCurrentQuestion();%0A    %7D,%0A    updateCurrentQuestion : function() %7B%0A      var model = this.model;%0A      
 var 
@@ -834,32 +834,37 @@
 var questions = 
+this.
 model.embedded('
@@ -880,28 +880,28 @@
 ') %7C%7C %5B%5D
-,
 %0A      
-    
+this.
 total = 
@@ -920,296 +920,105 @@
 ngth
-,%0A   
+;%0A
       
- current = model.get('current');%0A%0A      var index = current - 1;%0A      model.set('hasPrev', index %3E 0, %7B silent : true %7D);%0A      model.set('hasNext', index %3C total - 1, %7B silent : true %7D);%0A      model.set('total', questions.length, %7B silent : true %7D);%0A      return this.render(
+this.listenTo(this.model, 'change', this.render, this);%0A      this.model.set('current', 1
 );%0A 
@@ -1147,21 +1147,23 @@
         
-index
+current
  = model
@@ -1181,91 +1181,86 @@
 nt')
- - 1;%0A      var question = questions.find(function(item, i) %7B return index === i; %7D
+,%0A          total = this.total;%0A%0A      var question = questions.at(current - 1
 );%0A%0A
@@ -1362,16 +1362,118 @@
 stion);%0A
+      data.hasPrev = (current %3E 1);%0A      data.hasNext = (current %3C total);%0A      data.total = total;%0A
       re
@@ -1544,37 +1544,39 @@
 ) %7B%0A        var 
-model
+current
  = this.model;%0A 
@@ -1576,42 +1576,48 @@
 odel
-;%0A        if (model.get('hasPrev')
+.get('current');%0A        if (current %3E 1
 ) %7B%0A
@@ -1618,32 +1618,37 @@
  1) %7B%0A          
+this.
 model.set('curre
@@ -1652,36 +1652,23 @@
 rrent', 
-model.get('
 current
-')
  - 1); %0A
@@ -1725,37 +1725,39 @@
 ) %7B%0A        var 
-model
+current
  = this.model;%0A 
@@ -1757,42 +1757,84 @@
 odel
-;%0A        if (model.get('hasNext')
+.get('current');%0A        var total = this.total;%0A        if (current %3C total
 ) %7B%0A
@@ -1843,16 +1843,21 @@
         
+this.
 model.se
@@ -1869,36 +1869,23 @@
 rrent', 
-model.get('
 current
-')
  + 1);%0A 

simplify Backbone View data generation