<commit_before>// a workbook for a course
//   teach can add elements to book
//   quiz - link to a test
//   questions - question displayd direct on page
//   container - a link to a sub-workbook
//       a container is like a chapter
//       can contain (quiz,question,container)

var wb = { render: {} };
var wbinfo = { trail:[] };

var tablets = {};   // workaround for lack of drag and drop on tablets

function showdate(jsdate) {
  var d = new Date(jsdate);
  var mdate = d.getDate();
  var mmonth = d.getMonth() + 1; //months are zero based
  var myear = d.getFullYear();
  var hh = d.getHours();
  var mm = d.getMinutes();
  return mdate+'.'+mmonth+'-'+myear + ' '+hh+':'+mm;
}

var dragstate = {};   // state of draggable elements
// some qtypes have dragndrop enabled
// they need to store state


function makeTrail() {
    var trail = '';
    var prev = wbinfo.coursename;
    for (var i=0,l=wbinfo.trail.length; i<l; i++) {
      var e = wbinfo.trail[i];
      trail += '<span id="tt'+e.id+'_a" class="cont container">'+prev+'</span>';
      prev = e.name;
    }
    if (l > 0) trail += '<span class="chapter">' + prev + '</span>';
    return trail;
}



function showResults() {
    var group;
    try {
      group = wbinfo.coursename.split('_');
      group = group[1];
    } catch(err) {
      group = '';
    }
    var reslist = {};
    var display = '<ul>';
    var trail = makeTrail();
    var s = '<div id="wbmain"><h1 class="cont" id="tt'+wbinfo.containerid+'">Resultat</h1>'+trail+'<div id="results"></div></div>';
    $j("#main").html(s);
    $j.getJSON('/getuseranswers',{ container:wbinfo.containerid, group:group }, function(results) {
           // results = { res:{ uid ... }, ulist:{ 12:1, 13:1, 14:2, 15:2 }
           if (results) {
             for (var uid in results.ret) {
                var tot=0, score = 0;
                var ulist = results.ret[uid];
                for (var inst in ulist) {
                  var res = ulist[inst];
                  tot += res.points;
                  score += res.score;
                }
                reslist[res.userid] = score + " av "+ tot;
             }
             for (var uui in results.ulist) {
               var started = results.ulist[uui];
               var fn = '--', ln = '--', resultat = 'ikke startet';
               if (students[uui]) {
                 fn = students[uui].firstname.caps();
                 ln = students[uui].lastname.caps();
               }
               if (reslist[uui]) {
                 resultat = reslist[uui];
               }
               display += '<li>' + fn + ' ' + ln + ' ' + resultat + '</li>';
             }
             display += '</ul>';
             $j("#results").html(display );
           }
        });

}


function renderPage() {
  $j.getJSON('/getqcon',{ container:wbinfo.containerid }, function(container) {
    tablets = { usedlist:{} };    // forget any stored info for dragndrop for tablets on rerender
    var courseinfo;
    try {
      eval( 'courseinfo = '+container.qtext);
    }
    catch(err) {
      courseinfo = {};
    }
    wbinfo.courseinfo = courseinfo;
    wbinfo.qlistorder = courseinfo.qlistorder || [];
    // call the render functions indexed by layout
    // render the question list and update order if changed
    // typeset any math
    // prepare the workbook editor (setupWB)
    var header = wb.render[wbinfo.layout].header(wbinfo.title,wbinfo.ingress,wbinfo.weeksummary);
    var body = wb.render[wbinfo.layout].body(wbinfo.bodytext);

    var trail = makeTrail();

    // if this is a quiz ...
    if (container.qtype == 'quiz') {
      trail += '<h1 id="quiz">QUIZ</h1>';
    }

    var s = '<div id="wbmain">'+header + trail + body + '</div>';
    $j("#main").html(s);
    if (userinfo.department == 'Undervisning') {
      $j("span.wbteachedit").addClass("wbedit");
    }
    $j(".totip").tooltip({position:"bottom right" } );
    $j("#main").undelegate("#editwb","click");
    $j("#main").delegate("#editwb","click", function() {
        setupWB(header);
    });
    $j("#main").undelegate("#edqlist","click");
    $j("#main").delegate("#edqlist","click", function() {
        edqlist();
    });
    $j("#main").undelegate("span.drop","click");
    $j("#main").delegate("span.drop","click", function() {
        //$j("h1.wbhead").html( this.id );
        var thisq = this.id.substr(2).split('_')[0];
        var thisinst = this.id.substr(2).split('_')[1];
        if (thisq == tablets.qnr && thisinst == tablets.instance && tablets.dropvalue) {
          $j("#"+this.id).html( tablets.dropvalue );
          $j("#"+tablets.active).addClass('used');
          $j("#"+tablets.active).removeClass('act');
          tablets.usedlist[tablets.active] = this.id;
          delete tablets.dropvalue;
        } 
    });
    $j("#main").undelegate("span.dragme","click");
    $j("#main").delegate("span.dragme","click", function() {
        //$j("h1.wbhead").html( this.id );
        $j("span.dragme").removeClass('act');
        if (tablets.usedlist[this.id]) {
          $j("#" + tablets.usedlist[tablets.active]).html('&nbsp;&nbsp;&nbsp;&nbsp;');
          delete tablets.usedlist[tablets.active];
        }
        tablets.active = this.id;
        $j("#"+tablets.active).addClass('act');
        tablets.qnr = this.id.substr(3).split('_')[0];
        tablets.instance = this.id.substr(3).split('_')[1];
        tablets.dropvalue = this.innerHTML;
    });
    $j("#main").undelegate("#quiz","click");
    $j("#main").delegate("#quiz","click", function() {
        showResults();
    });
    function afterEffects() {
        MathJax.Hub.Queue(["Typeset",MathJax.Hub,"main"]);
        $j("span.dragme").draggable( {
              revert:true, 
              start:function(event,ui) {
                var droppid = ui.helper.attr("id");
                $j("#"+droppid).removeClass('used');
                var parid = $j("#"+droppid).parent().attr("id");
                $j("#"+parid+' span[droppid="'+droppid+'"]').removeAttr('droppid').removeClass("filled").html("&nbsp;&nbsp;&nbsp;&nbsp;");<commit_msg>one line fix for dragdrop for tablets<commit_after>// a workbook for a course
//   teach can add elements to book
//   quiz - link to a test
//   questions - question displayd direct on page
//   container - a link to a sub-workbook
//       a container is like a chapter
//       can contain (quiz,question,container)

var wb = { render: {} };
var wbinfo = { trail:[] };

var tablets = {};   // workaround for lack of drag and drop on tablets

function showdate(jsdate) {
  var d = new Date(jsdate);
  var mdate = d.getDate();
  var mmonth = d.getMonth() + 1; //months are zero based
  var myear = d.getFullYear();
  var hh = d.getHours();
  var mm = d.getMinutes();
  return mdate+'.'+mmonth+'-'+myear + ' '+hh+':'+mm;
}

var dragstate = {};   // state of draggable elements
// some qtypes have dragndrop enabled
// they need to store state


function makeTrail() {
    var trail = '';
    var prev = wbinfo.coursename;
    for (var i=0,l=wbinfo.trail.length; i<l; i++) {
      var e = wbinfo.trail[i];
      trail += '<span id="tt'+e.id+'_a" class="cont container">'+prev+'</span>';
      prev = e.name;
    }
    if (l > 0) trail += '<span class="chapter">' + prev + '</span>';
    return trail;
}



function showResults() {
    var group;
    try {
      group = wbinfo.coursename.split('_');
      group = group[1];
    } catch(err) {
      group = '';
    }
    var reslist = {};
    var display = '<ul>';
    var trail = makeTrail();
    var s = '<div id="wbmain"><h1 class="cont" id="tt'+wbinfo.containerid+'">Resultat</h1>'+trail+'<div id="results"></div></div>';
    $j("#main").html(s);
    $j.getJSON('/getuseranswers',{ container:wbinfo.containerid, group:group }, function(results) {
           // results = { res:{ uid ... }, ulist:{ 12:1, 13:1, 14:2, 15:2 }
           if (results) {
             for (var uid in results.ret) {
                var tot=0, score = 0;
                var ulist = results.ret[uid];
                for (var inst in ulist) {
                  var res = ulist[inst];
                  tot += res.points;
                  score += res.score;
                }
                reslist[res.userid] = score + " av "+ tot;
             }
             for (var uui in results.ulist) {
               var started = results.ulist[uui];
               var fn = '--', ln = '--', resultat = 'ikke startet';
               if (students[uui]) {
                 fn = students[uui].firstname.caps();
                 ln = students[uui].lastname.caps();
               }
               if (reslist[uui]) {
                 resultat = reslist[uui];
               }
               display += '<li>' + fn + ' ' + ln + ' ' + resultat + '</li>';
             }
             display += '</ul>';
             $j("#results").html(display );
           }
        });

}


function renderPage() {
  $j.getJSON('/getqcon',{ container:wbinfo.containerid }, function(container) {
    tablets = { usedlist:{} };    // forget any stored info for dragndrop for tablets on rerender
    var courseinfo;
    try {
      eval( 'courseinfo = '+container.qtext);
    }
    catch(err) {
      courseinfo = {};
    }
    wbinfo.courseinfo = courseinfo;
    wbinfo.qlistorder = courseinfo.qlistorder || [];
    // call the render functions indexed by layout
    // render the question list and update order if changed
    // typeset any math
    // prepare the workbook editor (setupWB)
    var header = wb.render[wbinfo.layout].header(wbinfo.title,wbinfo.ingress,wbinfo.weeksummary);
    var body = wb.render[wbinfo.layout].body(wbinfo.bodytext);

    var trail = makeTrail();

    // if this is a quiz ...
    if (container.qtype == 'quiz') {
      trail += '<h1 id="quiz">QUIZ</h1>';
    }

    var s = '<div id="wbmain">'+header + trail + body + '</div>';
    $j("#main").html(s);
    if (userinfo.department == 'Undervisning') {
      $j("span.wbteachedit").addClass("wbedit");
    }
    $j(".totip").tooltip({position:"bottom right" } );
    $j("#main").undelegate("#editwb","click");
    $j("#main").delegate("#editwb","click", function() {
        setupWB(header);
    });
    $j("#main").undelegate("#edqlist","click");
    $j("#main").delegate("#edqlist","click", function() {
        edqlist();
    });
    $j("#main").undelegate("span.drop","click");
    $j("#main").delegate("span.drop","click", function() {
        //$j("h1.wbhead").html( this.id );
        var thisq = this.id.substr(2).split('_')[0];
        var thisinst = this.id.substr(2).split('_')[1];
        if (thisq == tablets.qnr && thisinst == tablets.instance && tablets.dropvalue) {
          $j("#"+this.id).html( tablets.dropvalue );
          $j("#"+tablets.active).addClass('used');
          $j("#"+tablets.active).removeClass('act');
          tablets.usedlist[tablets.active] = this.id;
          delete tablets.dropvalue;
        } 
    });
    $j("#main").undelegate("span.dragme","click");
    $j("#main").delegate("span.dragme","click", function() {
        //$j("h1.wbhead").html( this.id );
        $j("span.dragme").removeClass('act');
        if (tablets.usedlist[this.id]) {
          $j("#" + tablets.usedlist[tablets.active]).html('&nbsp;&nbsp;&nbsp;&nbsp;');
          delete tablets.usedlist[tablets.active];
        }
        tablets.active = this.id;
        $j("#"+tablets.active).removeClass('used');
        $j("#"+tablets.active).addClass('act');
        tablets.qnr = this.id.substr(3).split('_')[0];
        tablets.instance = this.id.substr(3).split('_')[1];
        tablets.dropvalue = this.innerHTML;
    });
    $j("#main").undelegate("#quiz","click");
    $j("#main").delegate("#quiz","click", function() {
        showResults();
    });
    function afterEffects() {
        MathJax.Hub.Queue(["Typeset",MathJax.Hub,"main"]);
        $j("span.dragme").draggable( {
              revert:true, 
              start:function(event,ui) {
                var droppid = ui.helper.attr("id");
                $j("#"+droppid).removeClass('used');
                var parid = $j("#"+droppid).parent().attr("id");
                $j("#"+parid+' span[droppid="'+droppid+'"]').removeAttr('droppid').removeClass("filled").html("&nbsp;&nbsp;&nbsp;&nbsp;");
{'fraction_non_alphanumeric': 0.19278485145282404, 'fraction_numerical': 0.005223636957231472, 'mean_word_length': 2.3080453563714904, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '2240407', 'n_tokens_mistral': 4026, 'n_tokens_neox': 3923, 'n_words': 794}