<commit_before>//All the questoin in a survey
function ResponseEditView(responseID) {
	var _ = require('lib/underscore')._;
	var Question = require('models/question');
	var Answer = require('models/answer');
	var Response = require('models/response');
	var Survey = require('models/survey');
	var QuestionView = require('ui/common/questions/QuestionView');
	var ResponseViewHelper = require('ui/common/responses/ResponseViewHelper');
  var TopLevelView = require('ui/common/components/TopLevelView');
	var responseViewHelper = new ResponseViewHelper();
  var ButtonView = require('ui/common/components/ButtonView');
  var Toast = require('ui/common/components/Toast');

  var self = new TopLevelView('Edit Response');
	var scrollableView = Ti.UI.createScrollableView({
    top : self.headerHeight,
		showPagingControl : true
	});
  self.add(scrollableView);

	var response = Response.findOneById(responseID);
	var survey = Survey.findOneById(response.survey_id);
	var questions = survey.firstLevelQuestionsAndCategories();

  var validateAndUpdateAnswers = function(e, status) {
    activityIndicator.show();
		var questionViews = responseViewHelper.getQuestionViews(scrollableView.getViews());
		var answersData = _(questionViews).map(function(questionView, questionID) {
			Ti.API.info("questionid:" + questionID);
			Ti.API.info("content:" + questionView.getValueField().getValue());
			return {
				'id' : questionView.answerID,
				'question_id' : questionID,
				'content' : questionView.getValueField().getValue()
			};
		});
		var responseErrors = Response.validate(answersData, status);
    var toast;
		if (!_.isEmpty(responseErrors)) {
			responseViewHelper.displayErrors(responseErrors, questionViews);
			responseViewHelper.scrollToFirstErrorPage(scrollableView, responseErrors);
			toast = new Toast('There were some errors in the response.');
		} else {
			var response = Response.findOneById(responseID);
			response.update(status, answersData);
			toast = Toast('Response saved');
			self.fireEvent('ResponsesEditView:savedResponse');
		}
    toast.show();
		activityIndicator.hide();
	};

  responseViewHelper.paginate(questions, scrollableView,response, validateAndUpdateAnswers);

  var activityIndicator = Ti.UI.Android.createProgressIndicator({
    message : 'Saving...',
    location : Ti.UI.Android.PROGRESS_INDICATOR_DIALOG,
    type : Ti.UI.Android.PROGRESS_INDICATOR_INDETERMINANT
  });
  self.add(activityIndicator);

  self.cleanup = function() {
    self.remove(scrollableView);
    scrollableView = null;
  };

	return self;
}

module.exports = ResponseEditView;
<commit_msg>Added the page numbers in errors for ResponseEdit as well.<commit_after>//All the questoin in a survey
function ResponseEditView(responseID) {
	var _ = require('lib/underscore')._;
	var Question = require('models/question');
	var Answer = require('models/answer');
	var Response = require('models/response');
	var Survey = require('models/survey');
	var QuestionView = require('ui/common/questions/QuestionView');
	var ResponseViewHelper = require('ui/common/responses/ResponseViewHelper');
  var TopLevelView = require('ui/common/components/TopLevelView');
	var responseViewHelper = new ResponseViewHelper();
  var ButtonView = require('ui/common/components/ButtonView');
  var Toast = require('ui/common/components/Toast');

  var self = new TopLevelView('Edit Response');
	var scrollableView = Ti.UI.createScrollableView({
    top : self.headerHeight,
		showPagingControl : true
	});
  self.add(scrollableView);

	var response = Response.findOneById(responseID);
	var survey = Survey.findOneById(response.survey_id);
	var questions = survey.firstLevelQuestionsAndCategories();

  var validateAndUpdateAnswers = function(e, status) {
    activityIndicator.show();
		var questionViews = responseViewHelper.getQuestionViews(scrollableView.getViews());
		var answersData = _(questionViews).map(function(questionView, questionID) {
			Ti.API.info("questionid:" + questionID);
			Ti.API.info("content:" + questionView.getValueField().getValue());
			return {
				'id' : questionView.answerID,
				'question_id' : questionID,
				'content' : questionView.getValueField().getValue()
			};
		});
		var responseErrors = Response.validate(answersData, status);
    if (!_.isEmpty(responseErrors)) {
      responseViewHelper.displayErrors(responseErrors, questionViews);
      pagesWithErrors = responseViewHelper.scrollToFirstErrorPage(scrollableView, responseErrors);
      pagesWithErrors = _(pagesWithErrors).map(function(pageNumber) {
        return pageNumber + 1 ;
      });
      alert("There were errors in page(s) " + pagesWithErrors.toString());
    } else {
      var response = Response.findOneById(responseID);
      response.update(status, answersData);
			Toast('Response saved').show();
      self.fireEvent('ResponsesEditView:savedResponse');
    }
		activityIndicator.hide();
	};

  responseViewHelper.paginate(questions, scrollableView,response, validateAndUpdateAnswers);

  var activityIndicator = Ti.UI.Android.createProgressIndicator({
    message : 'Saving...',
    location : Ti.UI.Android.PROGRESS_INDICATOR_DIALOG,
    type : Ti.UI.Android.PROGRESS_INDICATOR_INDETERMINANT
  });
  self.add(activityIndicator);

  self.cleanup = function() {
    self.remove(scrollableView);
    scrollableView = null;
  };

	return self;
}

module.exports = ResponseEditView;

{'fraction_non_alphanumeric': 0.12407132243684993, 'fraction_numerical': 0.00018573551263001485, 'mean_word_length': 5.140250855188142, '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': '1555564', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1523, 'n_words': 290}