1 // Setup all the javascript stuff we need for the various
2 // incarnations of the Add Course form
6 var schoolSelected = false;
7 var courseNameSelected = false;
8 var instructorSelected = false;
10 function fieldEdited() {
11 if (schoolSelected && courseNameSelected && instructorSelected) {
12 $('#save-btn').hide();
13 $('#save-btn').addClass('disabled');
14 $('#existing-course-msg').show();
16 $('#save-btn').show();
17 $('#save-btn').removeClass('disabled');
18 $('#existing-course-msg').hide();
22 addCourse = function() {
23 // Show the add a course form
24 $('#add-course-form').show();
25 // Hide the add a course button
26 $('#add-course-btn').hide();
27 // Scroll the user's page to here
28 $('#add-course-divider').ScrollTo();
29 // Put focus in first input field
30 $('#str_school').focus();
33 // Set up the "Add Course" button at bottom
35 $('#add-course-btn').click(addCourse);
37 // Set up the "Add Course" button in the
39 $('#add_course_header_button').click(addCourse);
41 // Dismiss on exit x click FIXME
42 $(".lightbox_close").click(function() {
43 $(".modal_content").hide();
46 $("#str_school").autocomplete({
47 source: function(request, response){
49 url: json_school_list,
50 data: {q: request.term},
51 success: function(data) {
52 if (data['status'] === 'success') {
53 response($.map(data['schools'], function(item) {
61 // FIXME: do something if school not found
62 $('#create_school_link').show();
69 select: function(event, ui) {
70 // set the school id as the value of the hidden field
71 $('#id_school').val(ui.item.real_value);
72 schoolSelected = true;
73 $('#str_school').removeClass('error');
74 $('#save-btn').removeClass('disabled');
77 change: function(event, ui) {
78 if (ui.item == null) {
79 $('#id_school').val('');
80 schoolSelected = false;
81 $('#str_school').addClass('error');
82 $('#save-btn').addClass('disabled');
89 $("#id_name").autocomplete({
90 source: function(request, response){
91 var school_id = $('#id_school').val();
93 url: json_school_course_list,
94 data: {q: request.term, school_id: school_id},
95 success: function(data) {
96 if (data['status'] === 'success') {
97 response($.map(data['courses'], function(item) {
109 select: function(event, ui) {
110 courseNameSelected = true;
113 change: function(event, ui) {
114 if (ui.item == null) {
115 courseNameSelected = false;
122 $("#id_instructor_name").autocomplete({
123 source: function(request, response) {
124 var school_id = $('#id_school').val();
125 var course_name = $('#id_name').val();
127 url: json_school_course_instructor_list,
128 data: {q: request.term, school_id: school_id, course_name: course_name},
129 success: function(data) {
130 if (data['status'] === 'success') {
131 // Fill in the autocomplete entries
132 response($.map(data['instructors'], function(item) {
145 select: function(event, ui) {
146 instructorSelected = true;
147 $('#existing-course-btn').attr('href', ui.item.url);
150 change: function(event, ui) {
151 if (ui.item == null) {
152 instructorSelected = false;
153 $('#existing-course-btn').attr('href', '');