<commit_before>Ext.define('adnat.controller.QuestionController', {
    extend: 'Ext.app.Controller',
    config: {
        routes: {
		},
        refs: {
			question: '#questionPanel',
			title: '#title',
			questionComponent: '#questionComponent',
			prevButton: '#prevButton',
			nextButton: '#nextButton',
        },
        control: {
			prevButton: {
				tap: "prevPage"
			},
			nextButton: {
				tap: "nextPage"
			},
        },
    },
	launch: function() {
        Ext.getStore('Questions').load({
            callback: this.onQuestionsStoreLoad,
            scope: this
        });
        this.on('swipe', this.onSwipe);
        this.getQuestion().on('swipe', this.onSwipe);
    },
	onQuestionsStoreLoad : function() {
		//console.log('onQuestionsStoreLoad');
        var s = Ext.getStore('Questions');
		//s.info();
		this.showQuestion(0,0);
    },
    onSwipe: function (event) {
		 if (event.direction == 'right') {
			 this.prevPage();
		 } else if (event.direction == 'left') {
			 this.nextPage();
		 }
    },
	showQuestion: function(newO,direction) {
		var q = getNextQuestion(newO, direction);
		setTitle(this,q);
		setQuestion(this.getQuestionComponent(), q);
		// find previous response if it exists and put on question
		// fixme ordinal == break if new version of questions
		var s = Ext.getStore('Responses');
		s.load();
		var r = s.findRecord('q', q.get('id'));
		if ( r != null ) {
			r.set('ordinal', q.get('ordinal'));
			this.getQuestion().setRecord(r);
		} else {
			q.set('q', q.get('id'));
			this.getQuestion().setRecord(q);
		}
		this.getQuestion().getScrollable().getScroller().scrollTo(0,0,false)
	},

    prevPage: function(){
		// fixme validate 
		r = Ext.create('adnat.model.Response', this.getQuestion().getValues() );
		Ext.getStore('Responses').saveResponse(r);
		this.showQuestion( r.get('ordinal') - 1, -1 ); 
        /*<commit_msg>no message<commit_after>Ext.define('adnat.controller.QuestionController', {
    extend: 'Ext.app.Controller',
    config: {
        routes: {
		},
        refs: {
			question: '#questionPanel',
			title: '#title',
			questionComponent: '#questionComponent',
			prevButton: '#prevButton',
			nextButton: '#nextButton',
        },
        control: {
			prevButton: {
				tap: "prevPage"
			},
			nextButton: {
				tap: "nextPage"
			},
        },
    },
	launch: function() {
        Ext.getStore('Questions').load({
            callback: this.onQuestionsStoreLoad,
            scope: this
        });
        this.on('swipe', this.onSwipe);
        this.getQuestion().on('swipe', this.onSwipe);
    },
	onQuestionsStoreLoad : function() {
		//console.log('onQuestionsStoreLoad');
        var s = Ext.getStore('Questions');
		//s.info();
		this.showQuestion(0,0);
    },
    onSwipe: function (event) {
		 if (event.direction == 'right') {
			 this.prevPage();
		 } else if (event.direction == 'left') {
			 this.nextPage();
		 }
    },
	showQuestion: function(newO,direction) {
		var q = getNextQuestion(newO, direction);
		console.log(q);
		setTitle(this,q);
		setQuestion(this.getQuestionComponent(), q);
		// find previous response if it exists and put on question
		// fixme ordinal == break if new version of questions
		var s = Ext.getStore('Responses');
		s.load();
		var r = s.findRecord('q', q.get('id'));
		if ( r != null ) {
			r.set('ordinal', q.get('ordinal'));
			this.getQuestion().setRecord(r);
		} else {
			q.set('q', q.get('id'));
			this.getQuestion().setRecord(q);
		}
		this.getQuestion().getScrollable().getScroller().scrollTo(0,0,false)
	},

    prevPage: function(){
		// fixme validate 
		r = Ext.create('adnat.model.Response', this.getQuestion().getValues() );
		Ext.getStore('Responses').saveResponse(r);
		this.showQuestion( r.get('ordinal') - 1, -1 ); 
        /*
{'fraction_non_alphanumeric': 0.1782966304059432, 'fraction_numerical': 0.003183868400106129, 'mean_word_length': 2.9435146443514646, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2959828', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1225, 'n_words': 226}