'use strict'; /** * This file is used when creating or editing a rubric */ let table = undefined; let add_row = undefined; function convert_from_json(src_json) { /** * This function loads JSON and shows it on the table * This is used when loading a non-empty Rubric for editing */ add_row.click(); if (src_json !== "[]") { let src_obj = JSON.parse(src_json); for (let i = 0; i < src_obj.length; i++) { let row = src_obj[i]; let row_elem = $(table.find(".r_row").eq(i)); row_elem.find(".row-name").val(row['name']); row_elem.find(".row-description").val(row['description']); for (let y = 0; y < row.cells.length; y++) { let cell = row.cells[y]; let cell_elem = $(row_elem.children(".data-cell").eq(y)); cell_elem.find(".cell-score").val(cell['score']); cell_elem.find(".cell-description").val(cell['description']); if (y !== row.cells.length - 1) row_elem.find(".add-cell-button").click(); } if (i !== src_obj.length - 1) add_row.click(); } } } function convert_to_json() { /** * This function converts the table into JSON to send to the backend */ let new_rubric = []; table.find(".r_row").each(function (index, object) { let new_row = { "name": $(object).find(".row-name").val(), "description": $(object).find(".row-description").val(), "cells": [] }; $(object).children(".data-cell").each(function (index, cell) { let new_cell = { "score": parseFloat($(cell).find(".cell-score").val()), "description": $(cell).find(".cell-description").val() }; new_row["cells"].push(new_cell); }); new_rubric.push(new_row); }); return JSON.stringify(new_rubric); } function delete_row_callback(event) { /** * This function is run when the "Delete" button is clicked on a row * It deletes the row. */ $(event.target).parents("tr").remove(); } function delete_cell_callback(event) { /** * This function is run when the "Delete" button is clicked on a cell * It deletes the cell */ $(event.target).parents("td").remove(); } function add_row_callback() { /** * This function is run to add a row to the table, it loads HTML from the template div */ let new_row = $("