<commit_before>{% extends "master.twig" %}

{% block head %}
  <script src='/resources/js/editor.js'></script>
{% endblock %}

{% block title %}Questionnaire Editor{% endblock %}

{% block content %}

  {% if showAll %}

    {# List of questionnaires #}

    {% if questionnaires | length > 0 %}
      <table class="progress">
        <tr>
          <th>ID</th>
          <th>Title</th>
          <th>Pages</th>
          <th>Controls</th>
        </tr>
        {% for questionnaire in questionnaires %}
        <tr>
          <th>{{ questionnaire.id }}</th>
          <td><a href='/editor/{{ questionnaire.id }}'>{{ questionnaire.title }}</a></td>
          <td>{{ questionnaire.pages | length }}</td>
          <td>
            <button data-action="duplicate" data-id="{{ questionnaire.id }}">Duplicate</button>
            <button data-action="delete" data-id="{{ questionnaire.id }}">Delete</button>
          </td>
        </tr>
        {% endfor %}
      </table>
    {% else %}
      <p>There are currently no questionnaires.</p>
    {% endif %}
    <button data-action="create-questionnaire">Create new questionnaire</button>

  {% else %}

    <input type="hidden" id="questionnaire-id" value="{{ questionnaire.id }}" />

    {% if page %}

      {# Editing a single page in a questionnaire #}

      <input type="hidden" id="page-number" value="{{ pageNumber }}" />
      <table style='float: right;' class='progress'>
        <tr><th colspan="2">{{ questionnaire.title }}</th></tr>
        {% for pageRow in questionnaire.pages %}
          <tr>
            {% if loop.index == pageNumber %}
            <td>{{ loop.index }}. <strong>{{ pageRow.title }}</strong></td>
            {% else %}
            <td>{{ loop.index }}. <a href='/editor/{{ questionnaire.id }}/{{ loop.index }}'>{{ pageRow.title }}</td>
            {% endif %}
            <td>{{ pageRow.sections | length }} section{{ pageRow.sections | length == 1 ? '' : 's' }}</td>
          </tr>
        {% endfor %}
          <tr>
            <td colspan="2"><a href='/editor/{{ questionnaire.id }}' style='color: maroon'>Back to the list of pages</a></td>
          </tr>
          <tr id="ajax-status" style="display: none;">
            <th colspan="2">saving data...</th>
          </tr>
      </table>
      You are currently editing page {{ pageNumber }} of <strong>{{ questionnaire.title }}</strong>.

      {# Section workspace #}

      <div class="editor-workspace">
        <div class="editor-section" style="background: #dfeaea;">
          <input id="update-page-title" class="h2 invisible" placeholder="Page Title" value="{{ page.title }}" /><br>
          <input id="update-page-intro" class="invisible" placeholder="Intro text; will be displayed at the top of the page" style="width: 100%;" value="{{ page.intro }}"/>
        </div>
        <br>
        {% for section in page.sections %}
          <div class="editor-section">
            <div class="editor-section-controls">
              {% if not loop.first %}
              <button data-action="move-section" data-id="{{ loop.index0 }}" data-movement="-1">&uarr;</button>
              {% endif %}
              {% if not loop.last %}
              <button data-action="move-section" data-id="{{ loop.index0 }}" data-movement="1">&darr;</button>
              {% endif %}
              <button data-action="duplicate-section" data-id="{{ loop.index0 }}">Duplicate</button>
              <button data-action="delete-section" data-id="{{ loop.index0 }}">Delete</button><br>
              <label style="line-height: 3em;">
                <input data-action="section-collapsible" data-id="{{ loop.index0 }}" type="checkbox" {{ section.collapsible ? 'checked' : '' }}>
                Collapsible
              </label>
            </div>
            <input class="h3 invisible" value="{{ section.title }}" data-action="update-section-title" data-id="{{ loop.index0 }}" />
            <ul>
            {% for question in section.questions %}
              <li>{{ question.question }}</li>
            {% endfor %}
            {% if section.comments and section.border %}
              <li>Any other comments?</li>
            {% endif %}
            </ul>
          </div>
          <br>
        {% endfor %}
        <button id="add-section">Add a new section</button><br>
      </div>

    {% else %}

      {# Editing a questionnaires; viewing the list of pages #}

      <table class="progress">
        <tr>
          <th><label for="title-editor">Title</label></th>
          <td><input type="text" id="title-editor" value="{{ questionnaire.title }}" class="h2" /></td>
          <td>
            <button id="save-title">Save title</button>
          </td>
        </tr><commit_msg>Added a placeholder value for the section title<commit_after>{% extends "master.twig" %}

{% block head %}
  <script src='/resources/js/editor.js'></script>
{% endblock %}

{% block title %}Questionnaire Editor{% endblock %}

{% block content %}

  {% if showAll %}

    {# List of questionnaires #}

    {% if questionnaires | length > 0 %}
      <table class="progress">
        <tr>
          <th>ID</th>
          <th>Title</th>
          <th>Pages</th>
          <th>Controls</th>
        </tr>
        {% for questionnaire in questionnaires %}
        <tr>
          <th>{{ questionnaire.id }}</th>
          <td><a href='/editor/{{ questionnaire.id }}'>{{ questionnaire.title }}</a></td>
          <td>{{ questionnaire.pages | length }}</td>
          <td>
            <button data-action="duplicate" data-id="{{ questionnaire.id }}">Duplicate</button>
            <button data-action="delete" data-id="{{ questionnaire.id }}">Delete</button>
          </td>
        </tr>
        {% endfor %}
      </table>
    {% else %}
      <p>There are currently no questionnaires.</p>
    {% endif %}
    <button data-action="create-questionnaire">Create new questionnaire</button>

  {% else %}

    <input type="hidden" id="questionnaire-id" value="{{ questionnaire.id }}" />

    {% if page %}

      {# Editing a single page in a questionnaire #}

      <input type="hidden" id="page-number" value="{{ pageNumber }}" />
      <table style='float: right;' class='progress'>
        <tr><th colspan="2">{{ questionnaire.title }}</th></tr>
        {% for pageRow in questionnaire.pages %}
          <tr>
            {% if loop.index == pageNumber %}
            <td>{{ loop.index }}. <strong>{{ pageRow.title }}</strong></td>
            {% else %}
            <td>{{ loop.index }}. <a href='/editor/{{ questionnaire.id }}/{{ loop.index }}'>{{ pageRow.title }}</td>
            {% endif %}
            <td>{{ pageRow.sections | length }} section{{ pageRow.sections | length == 1 ? '' : 's' }}</td>
          </tr>
        {% endfor %}
          <tr>
            <td colspan="2"><a href='/editor/{{ questionnaire.id }}' style='color: maroon'>Back to the list of pages</a></td>
          </tr>
          <tr id="ajax-status" style="display: none;">
            <th colspan="2">saving data...</th>
          </tr>
      </table>
      You are currently editing page {{ pageNumber }} of <strong>{{ questionnaire.title }}</strong>.

      {# Section workspace #}

      <div class="editor-workspace">
        <div class="editor-section" style="background: #dfeaea;">
          <input id="update-page-title" class="h2 invisible" placeholder="Page Title" value="{{ page.title }}" /><br>
          <input id="update-page-intro" class="invisible" placeholder="Intro text; will be displayed at the top of the page" style="width: 100%;" value="{{ page.intro }}"/>
        </div>
        <br>
        {% for section in page.sections %}
          <div class="editor-section">
            <div class="editor-section-controls">
              {% if not loop.first %}
              <button data-action="move-section" data-id="{{ loop.index0 }}" data-movement="-1">&uarr;</button>
              {% endif %}
              {% if not loop.last %}
              <button data-action="move-section" data-id="{{ loop.index0 }}" data-movement="1">&darr;</button>
              {% endif %}
              <button data-action="duplicate-section" data-id="{{ loop.index0 }}">Duplicate</button>
              <button data-action="delete-section" data-id="{{ loop.index0 }}">Delete</button><br>
              <label style="line-height: 3em;">
                <input data-action="section-collapsible" data-id="{{ loop.index0 }}" type="checkbox" {{ section.collapsible ? 'checked' : '' }}>
                Collapsible
              </label>
            </div>
            <input class="h3 invisible" placeholder="Section Title" value="{{ section.title }}" data-action="update-section-title" data-id="{{ loop.index0 }}" />
            <ul>
            {% for question in section.questions %}
              <li>{{ question.question }}</li>
            {% endfor %}
            {% if section.comments and section.border %}
              <li>Any other comments?</li>
            {% endif %}
            </ul>
          </div>
          <br>
        {% endfor %}
        <button id="add-section">Add a new section</button><br>
      </div>

    {% else %}

      {# Editing a questionnaires; viewing the list of pages #}

      <table class="progress">
        <tr>
          <th><label for="title-editor">Title</label></th>
          <td><input type="text" id="title-editor" value="{{ questionnaire.title }}" class="h2" /></td>
          <td>
            <button id="save-title">Save title</button>
          </td>
        </tr>
{'fraction_non_alphanumeric': 0.1869482976040353, 'fraction_numerical': 0.004203446826397646, 'mean_word_length': 2.1121648136036626, 'pattern_counts': {'":': 0, '<': 231, '<?xml version=': 0, '>': 233, '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': '2083223', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2655, 'n_words': 642}