<commit_before>{% extends 'base.html' %}

{% block content %}
{% load staticfiles %}
{% load crispy_forms_tags %}
<link href="/static/index.css" rel="stylesheet" type="text/css"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function() {

  var books = "{"+{% for book in books %}"'{{book}}':'{{book}}',"+{% endfor %}"}";

  $(".editable_select").editable(function(value, settings){
    $(this).html(value)
    $('div[id^="lessonsOf"]').hide()
    $('#lessonsOf'+value).show()
    }, { 
    indicator : '<img src="img/indicator.gif">',
    data   : books,
    type   : "select",
    submit : "OK",
    style  : "inherit",
    submitdata : function() {
      return {id : 2};
    }
  });
  $(".editable_select_json").editable("<?php print $url ?>save.php", { 
    indicator : '<img src="img/indicator.gif">',
    loadurl : "<?php print $url ?>json.php",
    type   : "select",
    submit : "OK",
    style  : "inherit"
  });
  $(".editable_text").editable(function(value, settings){
    $(this).html(value)
    }, { 
      type   : 'text',
      select : true,
      submit : 'OK',
      cancel : 'cancel',
  });
  $(".editable_textarea").editable("<?php print $url ?>save.php", { 
      indicator : "<img src='img/indicator.gif'>",
      type   : 'textarea',
      submitdata: { _method: "put" },
      select : true,
      submit : 'OK',
      cancel : 'cancel',
      cssclass : "editable"
  });
  $(".editable_textile").editable("<?php print $url ?>save.php?renderer=textile", { 
      indicator : "<img src='img/indicator.gif'>",
      loadurl   : "<?php print $url ?>load.php",
      type      : "textarea",
      submit    : "OK",
      cancel    : "Cancel",
      tooltip   : "Click to edit..."
  });
  
  $(".click").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Click to edit...",
      style  : "inherit"
  });
  $(".dblclick").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Doubleclick to edit...",
      event     : "dblclick",
      style  : "inherit"
  });
  $(".mouseover").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Move mouseover to edit...",
      event     : "mouseover",
      style  : "inherit"
  });
  
  /* Should not cause error. */
  $("#nosuch").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      type   : 'textarea',
      submit : 'OK'
  });

});

function showExamform() {
  if (!$("#examform").is(":visible")) {
    $("#deleteform").hide();
    $(".checkexam").hide();
    $("#examform").show();
  } else {
    $("#examform").hide();
  }
};
function showDeleteform() {
  if (!$("#deleteform").is(":visible")) {
    $("#examform").hide();
    $("#deleteform").show();
    $(".checkexam").show();

  } else {
    $("#deleteform").hide();
    $(".checkexam").hide();
  }
};
function appendexam(cb) {
  var n = cb.name;
  var v = cb.value;
  if (cb.checked) { 
    $(cb).clone().attr({id:v+'inform',class:'checkexaminform',style:'display:none'}).prependTo('#deleteform');
    $("."+v+"lesson").show();
    $("#checkall"+v).show();
    $(".checkexam").prop('disabled', true);
    cb.disabled=false;
    $("#deletesubmit").prop('disabled', false);
  } else {
    $('#'+v+'inform').remove();
    $("."+v+"lessoninform").remove();
    $("."+v+"lesson").prop('checked',false);
    $("."+v+"lesson").hide();
    $(".checkall").prop('checked',false);
    $("#checkall"+v).hide();
    $(".checkexam").prop('disabled', false);
    $("#deletesubmit").prop('disabled', true);
  }
};
function appendlesson(cb) {
  if (cb.checked) { 
    $(cb).clone().attr({id:cb.value+'inform',class:cb.class+'inform',style:'display:none'}).prependTo('#deleteform');
  } else {
    $('.checkall').prop('checked', false);
    $('#'+cb.value+'inform').remove();
  }
};
function checkall(cb,v) {
  if (cb.checked) {
    $("."+v+"lessoninform").remove();//need remove added lessons then add all
    $("."+v+"lesson").prop('checked',true);
    $("."+v+"lesson").each(function() {
        $(this).clone().attr({id:this.value+'inform','class':v+"lessoninform",style:'display:none'}).prependTo('#deleteform');
     });
  } else {
    $("."+v+"lesson").prop('checked',false);
    $("."+v+"lessoninform").remove();
  }
};
function addExam() {
  var form = $('#examform');
  var name = $('#text_1').html();
  var book = $('#select_1').html();
  $('<input>').attr({name:'name', value:name, hidden:'true'}).appendTo(form);
  $('<input>').attr({name:'book', value:book, hidden:'true'}).appendTo(form);
  form.submit();
};
</script>
<div class="jumbotron">
  <h1>Crike -- 试题管理</h1>
  <button class="btn btn-success btn-lg" onclick="showExamform();">添加试卷</button>
  <button class="btn btn-danger  btn-lg" onclick="showDeleteform();">删除试卷</button>
</div>
<!-- add new item -->
<div class='row'>
  <form id='examform' style="display: none" enctype="multipart/form-data" method="post" action="/admin/exams/">
    {% csrf_token %}
    <h2><p class="editable_text" id="text_1">New Exam</p></h2>
    <p>选择<b class="editable_select" id="select_1" style="display: inline">课本</b>中课程
    {% for book in books %}
    <div id="lessonsOf{{book.name}}" style="display:none,inline">
      {% for lesson in book.lessons %}
      <input type='checkbox' name='addlessons' value='{{lesson.name}}'>{{lesson.name}}
      {% endfor %}
    </div>生成词汇题<br>
    {% endfor %}
    <div id="checkall{{exam.name}}" style="display:none">
      <input class="checkall" type="checkbox" onclick="checkall(this,'{{exam.name}}')">
      <label style="font-size:50%" for="checkall{{exam.name}}">全选</label>
    </div>
    <input type="submit" value="save" onclick="this.disabled=true; this.value='Please Wait...';addExam();">
    <strong>{{ Uploadwarning }}</strong>
  </form>

  {% if Showform == "deleteform" %}
  <form id="deleteform" style="display:block" enctype="multipart/form-data" method="post" action="/admin/exams/">
  {% else %}
  <form id="deleteform" style="display:none" enctype="multipart/form-data" method="post" action="/admin/exams/">
  {% endif %}
    {% csrf_token %}
    <label>请选择要删除的试卷</label>
    <input hidden='true' name='extra' value='delete'>
    <input id="deletesubmit" type="submit" disabled="true" value="delete">
    <strong>{{ Deletewarning }}</strong>
  </form>
</div>
<!-- Cycle through entries -->
{% for exam in exams %}
<div class='row'>
  <h2>
    <input class="checkexam" style="display:none" type="checkbox" name='delexam' value='{{exam.name}}' onclick="appendexam(this);">
    {{ exam.name }}
    <div id="checkall{{exam.name}}" style="display:none">
      <input class="checkall" type="checkbox" onclick="checkall(this,'{{exam.name}}')">
      <label style="font-size:50%" for="checkall{{exam.name}}">全选</label>
    </div>
  </h2>
  
  <!-- vocabularies -->
  {% for lesson in exam.lessons|dictsort:"name" %}
  <div class="col-6 col-sm-6 col-lg-2">  
    <a class="pin" title="删除" style="width:100%;" href='/admin/exam/{{exam.name}}/lesson/{{lesson.name}}/'>
      {{lesson.name}}
      <label style="color:sienna;float:right;">sum:{{lesson.words|length}}</label>
    </a>
  </div>
  {% endfor %}

  <!-- reading comprehensions -->
  {% for reading in exam.readings %}
  <form style="display:none">
    {% csrf_token %}
    {{reading.name}}<br><!--TODO editable reading areas-->
    <button class="btn btn-success" onclick="showExamform();">添加</button>
  </form>
  {% endfor %}
  <form>
    {% csrf_token %}
    <input hidden='true' name='extra' value='add'>
  <!--add reading form here-->
  </form>
</div>
{% endfor %}

<span id="dummy"></span>
{% block body_footer %}
<script src="{% static 'jeditable/jquery.jeditable.js' %}" type="text/javascript" charset="utf-8"></script>
{% endblock %}

{% endblock %}
<commit_msg>template: show lesson select result on the fly<commit_after>{% extends 'base.html' %}

{% block content %}
{% load staticfiles %}
{% load crispy_forms_tags %}
<link href="/static/index.css" rel="stylesheet" type="text/css"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function() {

  var books = "{"+{% for book in books %}"'{{book}}':'{{book}}',"+{% endfor %}"}";

  $(".editable_select").editable(function(value, settings){
    $(this).html(value)
    $('div[id^="lessonsOf"]').hide()
    $('#lessonsOf'+value).show()
    }, { 
    indicator : '<img src="img/indicator.gif">',
    data   : books,
    type   : "select",
    submit : "OK",
    style  : "inherit",
    submitdata : function() {
      return {id : 2};
    }
  });
  $(".editable_select_json").editable("<?php print $url ?>save.php", { 
    indicator : '<img src="img/indicator.gif">',
    loadurl : "<?php print $url ?>json.php",
    type   : "select",
    submit : "OK",
    style  : "inherit"
  });
  $(".editable_text").editable(function(value, settings){
    $(this).html(value)
    }, { 
      type   : 'text',
      select : true,
      submit : 'OK',
      cancel : 'cancel',
  });
  $(".editable_textarea").editable("<?php print $url ?>save.php", { 
      indicator : "<img src='img/indicator.gif'>",
      type   : 'textarea',
      submitdata: { _method: "put" },
      select : true,
      submit : 'OK',
      cancel : 'cancel',
      cssclass : "editable"
  });
  $(".editable_textile").editable("<?php print $url ?>save.php?renderer=textile", { 
      indicator : "<img src='img/indicator.gif'>",
      loadurl   : "<?php print $url ?>load.php",
      type      : "textarea",
      submit    : "OK",
      cancel    : "Cancel",
      tooltip   : "Click to edit..."
  });
  
  $(".click").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Click to edit...",
      style  : "inherit"
  });
  $(".dblclick").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Doubleclick to edit...",
      event     : "dblclick",
      style  : "inherit"
  });
  $(".mouseover").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      tooltip   : "Move mouseover to edit...",
      event     : "mouseover",
      style  : "inherit"
  });
  
  /* Should not cause error. */
  $("#nosuch").editable("<?php print $url ?>echo.php", { 
      indicator : "<img src='img/indicator.gif'>",
      type   : 'textarea',
      submit : 'OK'
  });

});

function showExamform() {
  if (!$("#examform").is(":visible")) {
    $("#deleteform").hide();
    $(".checkexam").hide();
    $("#examform").show();
  } else {
    $("#examform").hide();
  }
};
function showDeleteform() {
  if (!$("#deleteform").is(":visible")) {
    $("#examform").hide();
    $("#deleteform").show();
    $(".checkexam").show();

  } else {
    $("#deleteform").hide();
    $(".checkexam").hide();
  }
};
function appendexam(cb) {
  var n = cb.name;
  var v = cb.value;
  if (cb.checked) { 
    $(cb).clone().attr({id:v+'inform',class:'checkexaminform',style:'display:none'}).prependTo('#deleteform');
    $("."+v+"lesson").show();
    $("#checkall"+v).show();
    $(".checkexam").prop('disabled', true);
    cb.disabled=false;
    $("#deletesubmit").prop('disabled', false);
  } else {
    $('#'+v+'inform').remove();
    $("."+v+"lessoninform").remove();
    $("."+v+"lesson").prop('checked',false);
    $("."+v+"lesson").hide();
    $(".checkall").prop('checked',false);
    $("#checkall"+v).hide();
    $(".checkexam").prop('disabled', false);
    $("#deletesubmit").prop('disabled', true);
  }
};
function appendlesson(cb) {
  if (cb.checked) { 
    $(cb).clone().attr({id:cb.value+'inform',class:cb.class+'inform',style:'display:none'}).prependTo('#deleteform');
  } else {
    $('.checkall').prop('checked', false);
    $('#'+cb.value+'inform').remove();
  }
};
function checkall(cb,v) {
  if (cb.checked) {
    $("."+v+"lessoninform").remove();//need remove added lessons then add all
    $("."+v+"lesson").prop('checked',true);
    $("."+v+"lesson").each(function() {
        $(this).clone().attr({id:this.value+'inform','class':v+"lessoninform",style:'display:none'}).prependTo('#deleteform');
     });
  } else {
    $("."+v+"lesson").prop('checked',false);
    $("."+v+"lessoninform").remove();
  }
};
function addExam() {
  var form = $('#examform');
  var name = $('#text_1').html();
  var book = $('#select_1').html();
  $('<input>').attr({name:'name', value:name, hidden:'true'}).appendTo(form);
  $('<input>').attr({name:'book', value:book, hidden:'true'}).appendTo(form);
  form.submit();
};
function onClickpin(pin) {
  $(pin).find("input:checkbox").prop('checked',true);
};
function onChecklesson(me, book, name, length) {
  $('<div class="col-6 col-sm-6 col-lg-2"><div class="pin" style="width:100%" name="addlessons" value='+name+
      ' onclick="onClickpin(this)"><a>'+book+'/'+name+
      '<label style="color:sienna;float:right;">sum:'+length+
      '</label></a></div></div>').appendTo($(me).parents('form'));
}
</script>
<div class="jumbotron">
  <h1>Crike -- 试题管理</h1>
  <button class="btn btn-success btn-lg" onclick="showExamform();">添加试卷</button>
  <button class="btn btn-danger  btn-lg" onclick="showDeleteform();">删除试卷</button>
</div>
<!-- add new item -->
<div class='row'>
  <form id='examform' style="display: none" enctype="multipart/form-data" method="post" action="/admin/exams/">
    {% csrf_token %}
    <h2><p class="editable_text" id="text_1">New Exam</p></h2>
    <h3>词汇测验</h3>
    <p>课本:<b class="editable_select" id="select_1" style="display: inline">点击选择</b>
    {% for book in books %}
    <div id="lessonsOf{{book.name}}" style="display:none">
      <b>选择课程</b>
      {% for lesson in book.lessons|dictsort:"name" %}
      <input type='checkbox' onclick="onChecklesson(this,'{{book.name}}','{{lesson.name}}','{{lesson.words|length}}');">{{lesson.name}}
      {% endfor %}
    </div>
    {% endfor %}

    <div id="checkall{{exam.name}}" style="display:none">
      <input class="checkall" type="checkbox" onclick="checkall(this,'{{exam.name}}')">
      <label style="font-size:50%" for="checkall{{exam.name}}">全选</label>
    </div>
    <input type="submit" value="save" onclick="this.disabled=true; this.value='Please Wait...';addExam();">
    <strong>{{ Uploadwarning }}</strong>
  </form>

  {% if Showform == "deleteform" %}
  <form id="deleteform" style="display:block" enctype="multipart/form-data" method="post" action="/admin/exams/">
  {% else %}
  <form id="deleteform" style="display:none" enctype="multipart/form-data" method="post" action="/admin/exams/">
  {% endif %}
    {% csrf_token %}
    <label>请选择要删除的试卷</label>
    <input hidden='true' name='extra' value='delete'>
    <input id="deletesubmit" type="submit" disabled="true" value="delete">
    <strong>{{ Deletewarning }}</strong>
  </form>
</div>
<!-- Cycle through entries -->
{% for exam in exams %}
<div class='row'>
  <h2>
    <input class="checkexam" style="display:none" type="checkbox" name='delexam' value='{{exam.name}}' onclick="appendexam(this);">
    {{ exam.name }}
    <div id="checkall{{exam.name}}" style="display:none">
      <input class="checkall" type="checkbox" onclick="checkall(this,'{{exam.name}}')">
      <label style="font-size:50%" for="checkall{{exam.name}}">全选</label>
    </div>
  </h2>
  
  <!-- vocabularies -->
  {% for lesson in exam.lessons|dictsort:"name" %}
  <div class="col-6 col-sm-6 col-lg-2">  
    <a class="pin" title="删除" style="width:100%;" href='/admin/exam/{{exam.name}}/lesson/{{lesson.name}}/'>
      {{lesson.name}}
      <label style="color:sienna;float:right;">sum:{{lesson.words|length}}</label>
    </a>
  </div>
  {% endfor %}

  <!-- reading comprehensions -->
  {% for reading in exam.readings %}
  <form style="display:none">
    {% csrf_token %}
    {{reading.name}}<br><!--TODO editable reading areas-->
    <button class="btn btn-success" onclick="showExamform();">添加</button>
  </form>
  {% endfor %}
  <form>
    {% csrf_token %}
    <input hidden='true' name='extra' value='add'>
  <!--add reading form here-->
  </form>
</div>
{% endfor %}

<span id="dummy"></span>
{% block body_footer %}
<script src="{% static 'jeditable/jquery.jeditable.js' %}" type="text/javascript" charset="utf-8"></script>
{% endblock %}

{% endblock %}

{'fraction_non_alphanumeric': 0.2457482993197279, 'fraction_numerical': 0.0036443148688046646, 'mean_word_length': 3.7272466264714326, 'pattern_counts': {'":': 4, '<': 210, '<?xml version=': 0, '>': 210, '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': '4442462', 'n_tokens_mistral': 5953, 'n_tokens_neox': 5827, 'n_words': 976}