<commit_before>var _ = require('lib/underscore')._;
var Response = require('models/response');
var ButtonView = require('ui/common/components/ButtonView');

function MultiRecordCategoryView(multiRecordCategory, response, number, pageNumber) {
  var view_height = 400;
  var self = Ti.UI.createView({
    layout : 'vertical',
    height : Titanium.UI.SIZE
  });

  var childrenViews = [];

  var button = new ButtonView('Add a Record', { 'width' : '50%' });
  self.add(button);

  var getDeleteRecordButton = function() {
    return new ButtonView("Delete the record", { 'width' : '50%' });
  };

  var QuestionView = require('ui/common/questions/QuestionView');

  var deleteRecord = function(recordID) {
    var Record = require('models/record');
    record = Record.findOneById(recordID);
    record.destroyWithAnswers();
    removeRecordFromView(recordID);
  };

  var removeRecordFromView = function(recordID) {
    childrenViews = _(childrenViews).reject(function(childView) {
      return childView.recordID == recordID;
    });
    showSubQuestions();
  };

  var addRecord = function(e, recordID) {
    if(!recordID) {
      var Record = require('models/record');
      var record = Record.createRecord({
        category_id : multiRecordCategory.id
      });
      recordID = record.id;
    }

    var subQuestions = multiRecordCategory.firstLevelSubQuestions();
    _(subQuestions).each(function(subQuestion, index) {
      var subQuestionAnswer = response && recordID ? response.answerForQuestion(subQuestion.id, recordID) : null;
      var subQuestionNumber = number + '.' + (index + 1);
      childrenViews.push(new QuestionView(subQuestion, subQuestionAnswer, response, subQuestionNumber, null, pageNumber, recordID));
    });
    var lastQuestionInRecord = _(childrenViews).last();
    var deleteRecordButton = getDeleteRecordButton();
    lastQuestionInRecord.add(deleteRecordButton);
    deleteRecordButton.addEventListener('click', function() {
      deleteRecord(recordID);
    });
    showSubQuestions();
  };

  var showSubQuestions = function(selectedRowID) {
    Ti.App.fireEvent('show.sub.questions');
  };
<commit_msg>Add the deleteRecordButton to the page and not the last question in the record.<commit_after>var _ = require('lib/underscore')._;
var Response = require('models/response');
var ButtonView = require('ui/common/components/ButtonView');

function MultiRecordCategoryView(multiRecordCategory, response, number, pageNumber) {
  var view_height = 400;
  var self = Ti.UI.createView({
    layout : 'vertical',
    height : Titanium.UI.SIZE
  });

  var childrenViews = [];

  var button = new ButtonView('Add a Record', { 'width' : '50%' });
  self.add(button);

  var getDeleteRecordButton = function() {
    return new ButtonView("Delete the record", { 'width' : '50%' });
  };

  var QuestionView = require('ui/common/questions/QuestionView');

  var deleteRecord = function(recordID) {
    var Record = require('models/record');
    record = Record.findOneById(recordID);
    record.destroyWithAnswers();
    removeRecordFromView(recordID);
  };

  var removeRecordFromView = function(recordID) {
    childrenViews = _(childrenViews).reject(function(childView) {
      return childView.recordID == recordID;
    });
    showSubQuestions();
  };

  var addRecord = function(e, recordID) {
    if(!recordID) {
      var Record = require('models/record');
      var record = Record.createRecord({
        category_id : multiRecordCategory.id
      });
      recordID = record.id;
    }

    var subQuestions = multiRecordCategory.firstLevelSubQuestions();
    _(subQuestions).each(function(subQuestion, index) {
      var subQuestionAnswer = response && recordID ? response.answerForQuestion(subQuestion.id, recordID) : null;
      var subQuestionNumber = number + '.' + (index + 1);
      childrenViews.push(new QuestionView(subQuestion, subQuestionAnswer, response, subQuestionNumber, null, pageNumber, recordID));
    });
    var deleteRecordButton = getDeleteRecordButton();
    deleteRecordButton.recordID = recordID;
    childrenViews.push(deleteRecordButton);
    deleteRecordButton.getSubQuestions = function() {
      return null;
    };
    deleteRecordButton.addEventListener('click', function() {
      deleteRecord(recordID);
    });
    showSubQuestions();
  };

  var showSubQuestions = function(selectedRowID) {
    Ti.App.fireEvent('show.sub.questions');
  };

{'fraction_non_alphanumeric': 0.12709560489352062, 'fraction_numerical': 0.0036248300860897147, 'mean_word_length': 4.098152424942263, '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': '673936', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1222, 'n_words': 258}