1
$(document).ready(function(){
2
$("#new_projectset_form").submit(add_projectset);
3
$(".new_project").submit(add_project);
5
$('.add-project-link').click(show_add);
6
$('.add-projectset-link').click(show_add);
9
function serializeForm(form){
11
mylist = form.serializeArray();
13
for (var i = 0; i < mylist.length; i++){
14
data[mylist[i].name] = mylist[i].value;
20
function add_project(){
21
var add_project_form = $(this);
22
function callback(xhr) {
23
if (xhr.status == 200) {
24
add_project_form.slideToggle('fast');
25
var response = JSON.parse(xhr.responseText);
26
var projectlist = $('#projectslist_' + response.projectset_id);
27
var new_element = response.html.split('\n').slice(1).join('\n');
28
projectlist.children(".list_empty_indicator").remove()
29
add_section = projectlist.children(".add-project");
30
$(add_section).before(new_element).hide().slideDown();
31
} else if (xhr.status == 400) {
32
alert("Could not create project: " + xhr.getResponseHeader("X-IVLE-Error"));
34
alert("Project creation failed due to an internal server error.");
38
var data = serializeForm($(this));
40
ajax_call(callback, $(this).attr("action"), "", data, 'POST');
45
function add_projectset(){
47
$("#add_projectset").attr('disabled', 'disabled');
49
function callback(xhr) {
50
var response = JSON.parse(xhr.responseText);
51
$('#projectset_list').append(response.html);
52
var projectset_div = $('#projectset_' + response.projectset_id);
53
projectset_div.hide();
54
projectset_div.slideDown();
55
$("#add_projectset").removeAttr('disabled');
56
projectset_div.find(".new_project").submit(add_project);
57
projectset_div.find(".add-project-link").click(show_add);
60
var data = serializeForm($("#new_projectset_form"));
62
data['ivle.op'] = 'add_projectset';
64
ajax_call(callback, $("#new_projectset_form").attr("action"), "", data,
71
$(this).next().slideToggle();