2 $('#flag-button').click(function(event) {
3 event.preventDefault();
5 if (confirm('Do you wish to flag this course for deletion?')) {
6 // disable thank button so it can't
9 $('#flag-button-disabled').show();
10 $(this).unbind('click');
12 // tell server that somebody thanked
23 $('#edit-course-form').dialog({
26 show: { effect: 'fade', duration: 500 },
30 $('#edit-button').click(function(event) {
31 $('#edit-course-form').dialog("open");
34 $('#edit-save-btn').click(function(event) {
38 data: $('#edit-course-form').children().serialize(),
40 success: function(data) {
41 if (data.fields.new_url) {
42 window.location.href = data.fields.new_url;
45 // We might want to use a template here instead of rehashing logic
46 // on both the client and server side
47 $('#edit-course-form').slideUp();
48 $('.validation_error').remove()
49 $('#course_form_errors').empty();
50 $('#course_name').text(data.fields.name);
51 $('#course_instructor_name').text(data.fields.instructor_name);
53 var $externalLinkSquare = $('<i>', {'class': 'fa fa-external-link-square'});
54 $('#course_url').text(data.fields.url.slice(0, 50) + ' ');
55 $('#course_url').append($externalLinkSquare);
56 $('#course_url').attr('href', data.fields.url);
57 if (data.fields.url === '') {
58 $('#course_link').parent().hide();
60 $('#course_link').parent().show();
63 error: function(resp) {
66 json = JSON.parse(resp.responseText);
68 json = { message: 'Unknown Error' };
71 var errors = json.errors;
73 // Delete all errors that currently exist
74 $('.validation_error').remove()
75 $('#course_form_errors').empty();
77 // Failed responses with no errors -> display message
79 $('#course_form_errors').text(json.message);
81 // Ugly, be works. Could look into backbone or something similar to make it cleaner.
83 $.each(errors.__all__, function(index, value) {
84 $('#course_form_errors').append($('<span>', { class: 'validation_error', text: value }));
88 if (errors.instructor_email) {
89 $.each(errors.instructor_email, function(index, value) {
90 $('#id_instructor_email').parent().children('legend').append($('<span>', { class: 'validation_error', text: value }));
95 $.each(errors.url, function(index, value) {
96 $('#id_url').parent().children('legend').append($('<span>', { class: 'validation_error' , text: value }));
104 KARMAWORLD.Course.initCourseNameAutocomplete({});
105 KARMAWORLD.Course.initInstructorNameAutocomplete({});
107 $('#data_table_list').dataTable({
108 // remove the default filter label
112 // we will set column widths explicitly
114 // don't provide a option for the user to change the table page length
115 'bLengthChange': false,
116 // sepcify the number of rows in a page
117 'iDisplayLength': 20,
118 // Position the filter bar at the top
119 // DIFF: do not show search bar (f)
120 'sDom': '<"top">rt<"bottom"p><"clear">',
121 // Specify options for each column
124 // 3rd element: likes
128 "mData": function ( source, type, val ) {
129 //console.log(source);
130 if (type === 'set') {
132 // Store the computed dislay and filter values for efficiency
133 // DIFF: label name change.
134 source.count_display = val=="" ? "" : "<span>"+val+" Thanks</span>";
137 else if (type === 'display') {
138 return source.count_display;
140 // 'sort', 'type', 'filter' and undefined all just use the integer
149 "mData": function ( source, type, val ) {
150 //console.log(source);
151 if (type === 'set') {
153 // DIFF: label name change.
154 source.date_display = val=="" ? "" : "<span>Uploaded "+val+"</span>";
157 else if (type === 'display') {
158 return source.date_display;
160 // for types 'sort', 'type', 'filter' and undefined use raw date
165 // 1st element: "sort by" label
172 'aaSorting': [[2,'desc']]