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