~azzar1/unity/add-show-desktop-key

1099.1.213 by Nick Chadwick
Modifief exercise view, so that exercises can now be viewed in an
1
/* IVLE - Informatics Virtual Learning Environment
2
 * Copyright (C) 2007-2009 The University of Melbourne
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 *
18
 * Author: Nick Chadwick
19
 */
20
1099.1.217 by Nick Chadwick
working on making the exercise editor complete
21
/* Show and hide the given page element */
1099.1.214 by Nick Chadwick
The skeleton for editing an exercise has now been created. The next
22
function tog(something)
23
{
24
  $('#' + something).toggle("slow");
1099.1.213 by Nick Chadwick
Modifief exercise view, so that exercises can now be viewed in an
25
}
1099.1.216 by Nick Chadwick
Started adding in add and save options in the exercise edit view, to
26
1099.1.217 by Nick Chadwick
working on making the exercise editor complete
27
/* Edit the exercise values */
28
function edit_exercise()
1099.1.216 by Nick Chadwick
Started adding in add and save options in the exercise edit view, to
29
{
30
31
    var exercise_id = $('#exercise_id').val();
32
    var exercise_name = $('#exercise_name').val();
33
    var exercise_num_rows = $('#exercise_num_rows').val();
34
    var exercise_desc = $('#exercise_include').val();
35
    var exercise_partial = $('#exercise_partial').val();
36
    var exercise_solution = $('#exercise_solution').val();
37
    var exercise_include = $('#exercise_include').val();
38
    
39
    var callback = function(xhr)
40
    {
41
        var testresponse;
42
        try
43
        {
44
            testresponse = JSON.parse(xhr.responseText);
1099.1.217 by Nick Chadwick
working on making the exercise editor complete
45
            alert('Exercise Saved');
1099.1.216 by Nick Chadwick
Started adding in add and save options in the exercise edit view, to
46
            return;
47
        }
48
        catch(ex)
49
        {
50
            alert('Error updating Exercise');
51
            return;
52
        }
53
    }
54
    
1099.1.217 by Nick Chadwick
working on making the exercise editor complete
55
    update_path = "api/+exercises/" + exercise;
1099.1.216 by Nick Chadwick
Started adding in add and save options in the exercise edit view, to
56
    
57
    var args = {'name': exercise_name, 'description': exercise_desc, 
58
                'partial': exercise_partial, 'solution': exercise_solution,
59
                'include': exercise_include, 'num_rows': exercise_num_rows,
1099.1.217 by Nick Chadwick
working on making the exercise editor complete
60
                'ivle.op': 'edit_exercise'};
61
    ajax_call(callback, update_path, "", args, 'POST');
62
}
63
64
/* Modify and add suites */
65
function edit_suite(suiteid)
66
{
67
    var desc = $('#test_suite_description_' + suiteid).val();
68
    var func = $('#test_suite_function_' + suiteid).val();
69
    var stdin = $('#test_suite_stdin_' + suiteid).val();
70
    
71
    var callback = function(xhr)
72
    {
73
        var testresponse;
74
        try
75
        {
76
            testresponse = JSON.parse(xhr.responseText);
77
            alert('Suite Saved');
78
            window.location.reload();
79
            return;
80
        }
81
        catch(ex)
82
        {
83
            alert('Error Saving Test Suite');
84
            return;
85
        }
86
    }
87
    
88
    var args = {'ivle.op': 'edit_suite', 'description': desc, 'function': func,
89
                'stdin': stdin, 'suiteid': suiteid};
90
    update_path = "api/+exercises/" + exercise;
91
    ajax_call(callback, update_path, "", args, 'POST');
92
}
93
94
function add_suite()
95
{
96
    var desc = $('#new_test_suite_description').val();
97
    var func = $('#new_test_suite_function').val();
98
    var stdin = $('#new_test_suite_stdin').val();
99
    
100
    var callback = function(xhr)
101
    {
102
        var testresponse;
103
        try
104
        {
105
            testresponse = JSON.parse(xhr.responseText);
106
            alert('Suite Created Sucessfully');
107
            window.location.reload();
108
            return;
109
        }
110
        catch(ex)
111
        {
112
            alert('Error Creating Test Suite');
113
        }
114
    }
115
    
116
    var args = {'ivle.op': 'add_suite', 'description': desc, 'function': func,
117
                'stdin': stdin};
118
    update_path = "api/+exercises/" + exercise;
119
    ajax_call(callback, update_path, "", args, 'POST');
120
}
121
122
/* Modify and add Variables */
123
function edit_var(varid)
124
{
125
    var var_name = $('#var_type_' + varid).val();
126
    var var_val = $('#var_val' + varid).val();
127
    var var_type = $('#var_name_' + varid).val();
128
    var argno = $('#var_argno_' + varid).val();
129
130
    var callback = function(xhr)
131
    {
132
        var testresponse;
133
        try
134
        {
135
            testresponse = JSON.parse(xhr.responseText);
136
            alert('Variable Added Sucessfully');
137
            window.location.reload();
138
            return;
139
        }
140
        catch(ex)
141
        {
142
            alert('Error Creating Test Suite');
143
            return;
144
        }
145
    }
146
147
    var args = {'ivle.op': 'edit_var'};
148
    
149
    update_path = "api/+exercises/" + exercise;
150
    ajax_call(callback, update_path, "", args, 'POST')
151
152
}
153
154
function add_var(suiteid)
155
{
156
    var var_name = $('#new_var_type_' + suiteid).val();
157
    var var_val = $('#new_var_val' + suiteid).val();
158
    var var_type = $('#new_var_name_' + suiteid).val();
159
    var argno = $('#new_var_argno_' + suiteid).val();
160
    
161
    var callback = function(xhr)
162
    {
163
        var testresponse;
164
        try
165
        {
166
            testresponse = JSON.parse(xhr.responseText);
167
            alert('Variable Added Sucessfully');
168
            window.location.reload();
169
            return;
170
        }
171
        catch(ex)
172
        {
173
            alert('Error Creating Test Suite');
174
            return;
175
        }
176
    }
177
    
178
    var args = {'ivle.op': 'add_var', 'var_name': var_name, 
179
                'var_val': var_val, 'var_type': var_type, 
180
                'argno': argno, 'suiteid': suiteid};
181
    update_path = "api/+exercises/" + exercise;
1099.1.216 by Nick Chadwick
Started adding in add and save options in the exercise edit view, to
182
    ajax_call(callback, update_path, "", args, 'POST');
183
}