<commit_before>/* ----------------------------- begin view ----------------------------------*/
var view = {
  fillFields: function(obj,fields,func){
    fields=fields.split(/, */);
    fields.map(function(f){
        ($('#'+f)[func])(obj[f]);
    });
  },
  selectFields: function(fields,func){
    var obj = {};
    fields=fields.split(/, */);
    fields.map(function(f){
        var v = ($('#'+f)[func])();
        obj[f]=(v);
    });
    return obj;
  },
  showErrEmail: function () {
    var c = '.input-group';
    $(c).removeClass('has-success');
    $(c).addClass('has-error');
    view.hideElement('.glyphicon-ok');
    view.showElement('.glyphicon-remove');
  },
  showSuccessEmail: function () {
    var c = '.input-group';
    $(c).removeClass('has-error');
    $(c).addClass('has-success');
    view.hideElement('.glyphicon-remove');
    view.showElement('.glyphicon-ok');
  },
  addBookItem: function (book) {
    return $('#pattern').html()
      .replace(/{id}/g, book.id)
      .replace(/{title}/g, book.title)
      .replace(/{author}/g, book.author);
  },
  addBooksItems: function (books, doClean) {
    var content = $('#content');
    var contentHTML = ((doClean) ? '' : content.html());

    for (var i in books) {
      contentHTML += view.addBookItem(books[i]);
    }

    content.html(contentHTML);
    $('.blockI').matchHeight(); // Aligns all the height of the book
  },
  showNot_found: function (searchText, pathUrl) {
      var contentNotFound = $('#not_found').html()
      .replace(/{searchText}/g, searchText);
      $('#content').html(contentNotFound);
  },
  nullToDash: function (string) {
    return (((string == null) || (string == 0)) ? '-' : string);
  },

  addBooksListRow: function (book) {
    var date;
    if (book.date) {
      date = new Date(book.date);
      date.setDate(date.getDate() + book.term);
      date = date.toDateString();
    }

    return $('#pattern').html()
      .replace(/{id}/g, book.id)
      .replace(/{title}/g, book.title)
      .replace(/{author}/g, book.author)
      .replace(/{name}/g, view.nullToDash(book.name))
      .replace(/{email}/g, view.nullToDash(book.email))
      .replace(/{phone}/g, view.nullToDash(book.phone))
      .replace(/{date}/g, view.nullToDash(date))
      .replace(/{pawn}/g, view.nullToDash(book.pawn));
  },

  addBooksList: function (books) {
    var content = $('#table_content');
    var contentHTML = '';

    for (var i in books) {
      console.log(view.addBooksListRow(books[i]));
      contentHTML += view.addBooksListRow(books[i]);
    }

    content.html(contentHTML);

    $('.book_list_row').click(function () {
      $(location).attr('href', 'admin/book/' + $(this).attr('data-book-id'));
    });
  },

  fillBookInfo: function (book) {
    console.log(book);
    view.fillFields(book,'title,author,year,pages,isbn,description',"html");
    $('#id').attr({'book-id': book.id,'busy': book.event});
    $('#bookImg img').attr('src', '/img/books/' + book.id + '.jpg');
    $('.description').html(book.description);
  },
  normalDateFormat: function (date) {
    return date.toISOString().substring(0, 10);
  },
  addPopUpBlock: function (title, text) {
    $('#main').after('<div id="test-modal" class="mfp-hide white-popup-block"><h1>' + title + '</h1><p>' + text + '</p><p><a class="popup-modal-dismiss" href="#">X</a></p></div>');
  },

  showError: function (text) {
    swal('Ооопс!', text, 'error');
  },

  showSuccess: function (text) {
    console.log(text);
    swal('Отлично!', text, 'success');
  },

  showSubscribe: function (text, bookId) {
    swal({
        title: 'Хотите почитать?',
        text: text,
        type: 'input',
        showCancelButton: true,
        closeOnConfirm: false,
        animation: 'slide-from-top',
        inputPlaceholder: 'Введите свой e-mail',
        confirmButtonColor: '#27AE60',
        showLoaderOnConfirm: true
      },
      function (inputValue) {
        if (inputValue === false) {
          return false;
        }
        if (!controller.validateEmail(inputValue)) {
          swal.showInputError('Вы где-то ошиблись. Проверьте введенные данные.');
          return false;
        }
        doAjaxQuery('GET', '/api/v1/books/' + bookId + '/order', {'email': inputValue}, function (res) {
          view.showSuccess('Ваш e-mail ' + inputValue + '\nдобавлен в список ожидания.');<commit_msg>delete console log<commit_after>/* ----------------------------- begin view ----------------------------------*/
var view = {
  fillFields: function(obj,fields,func){
    fields=fields.split(/, */);
    fields.map(function(f){
        ($('#'+f)[func])(obj[f]);
    });
  },
  selectFields: function(fields,func){
    var obj = {};
    fields=fields.split(/, */);
    fields.map(function(f){
        var v = ($('#'+f)[func])();
        obj[f]=(v);
    });
    return obj;
  },
  showErrEmail: function () {
    var c = '.input-group';
    $(c).removeClass('has-success');
    $(c).addClass('has-error');
    view.hideElement('.glyphicon-ok');
    view.showElement('.glyphicon-remove');
  },
  showSuccessEmail: function () {
    var c = '.input-group';
    $(c).removeClass('has-error');
    $(c).addClass('has-success');
    view.hideElement('.glyphicon-remove');
    view.showElement('.glyphicon-ok');
  },
  addBookItem: function (book) {
    return $('#pattern').html()
      .replace(/{id}/g, book.id)
      .replace(/{title}/g, book.title)
      .replace(/{author}/g, book.author);
  },
  addBooksItems: function (books, doClean) {
    var content = $('#content');
    var contentHTML = ((doClean) ? '' : content.html());

    for (var i in books) {
      contentHTML += view.addBookItem(books[i]);
    }

    content.html(contentHTML);
    $('.blockI').matchHeight(); // Aligns all the height of the book
  },
  showNot_found: function (searchText, pathUrl) {
      var contentNotFound = $('#not_found').html()
      .replace(/{searchText}/g, searchText);
      $('#content').html(contentNotFound);
  },
  nullToDash: function (string) {
    return (((string == null) || (string == 0)) ? '-' : string);
  },

  addBooksListRow: function (book) {
    var date;
    if (book.date) {
      date = new Date(book.date);
      date.setDate(date.getDate() + book.term);
      date = date.toDateString();
    }

    return $('#pattern').html()
      .replace(/{id}/g, book.id)
      .replace(/{title}/g, book.title)
      .replace(/{author}/g, book.author)
      .replace(/{name}/g, view.nullToDash(book.name))
      .replace(/{email}/g, view.nullToDash(book.email))
      .replace(/{phone}/g, view.nullToDash(book.phone))
      .replace(/{date}/g, view.nullToDash(date))
      .replace(/{pawn}/g, view.nullToDash(book.pawn));
  },

  addBooksList: function (books) {
    var content = $('#table_content');
    var contentHTML = '';

    for (var i in books) {
      contentHTML += view.addBooksListRow(books[i]);
    }

    content.html(contentHTML);

    $('.book_list_row').click(function () {
      $(location).attr('href', 'admin/book/' + $(this).attr('data-book-id'));
    });
  },

  fillBookInfo: function (book) {
    view.fillFields(book,'title,author,year,pages,isbn,description',"html");
    $('#id').attr({'book-id': book.id,'busy': book.event});
    $('#bookImg img').attr('src', '/img/books/' + book.id + '.jpg');
    $('.description').html(book.description);
  },
  normalDateFormat: function (date) {
    return date.toISOString().substring(0, 10);
  },
  addPopUpBlock: function (title, text) {
    $('#main').after('<div id="test-modal" class="mfp-hide white-popup-block"><h1>' + title + '</h1><p>' + text + '</p><p><a class="popup-modal-dismiss" href="#">X</a></p></div>');
  },

  showError: function (text) {
    swal('Ооопс!', text, 'error');
  },

  showSuccess: function (text) {
    swal('Отлично!', text, 'success');
  },

  showSubscribe: function (text, bookId) {
    swal({
        title: 'Хотите почитать?',
        text: text,
        type: 'input',
        showCancelButton: true,
        closeOnConfirm: false,
        animation: 'slide-from-top',
        inputPlaceholder: 'Введите свой e-mail',
        confirmButtonColor: '#27AE60',
        showLoaderOnConfirm: true
      },
      function (inputValue) {
        if (inputValue === false) {
          return false;
        }
        if (!controller.validateEmail(inputValue)) {
          swal.showInputError('Вы где-то ошиблись. Проверьте введенные данные.');
          return false;
        }
        doAjaxQuery('GET', '/api/v1/books/' + bookId + '/order', {'email': inputValue}, function (res) {
          view.showSuccess('Ваш e-mail ' + inputValue + '\nдобавлен в список ожидания.');
{'fraction_non_alphanumeric': 0.215625, 'fraction_numerical': 0.0025462962962962965, 'mean_word_length': 2.776660839160839, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '7617184', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2859, 'n_words': 508}