Chart.bundle.min.js
6 years ago
gutenberg_blocks.js
6 years ago
mce-button.js
6 years ago
tutor-admin.js
6 years ago
tutor-front.js
6 years ago
tutor-setup.js
6 years ago
tutor.js
6 years ago
tutor.js
1200 lines
| 1 | jQuery(document).ready(function($){ |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * Slider bar |
| 6 | */ |
| 7 | function tutor_slider_init(){ |
| 8 | $('.tutor-field-slider').each(function(){ |
| 9 | var $slider = $(this); |
| 10 | var $input = $slider.closest('.tutor-field-type-slider').find('input[type="hidden"]'); |
| 11 | var $showVal = $slider.closest('.tutor-field-type-slider').find('.tutor-field-type-slider-value'); |
| 12 | var min = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-min')); |
| 13 | var max = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-max')); |
| 14 | |
| 15 | $slider.slider({ |
| 16 | range: "max", |
| 17 | min: min, |
| 18 | max: max, |
| 19 | value: $input.val(), |
| 20 | slide: function( event, ui ) { |
| 21 | $showVal.text(ui.value); |
| 22 | $input.val(ui.value); |
| 23 | } |
| 24 | }); |
| 25 | }); |
| 26 | } |
| 27 | tutor_slider_init(); |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Video source tabs |
| 32 | */ |
| 33 | |
| 34 | if (jQuery().select2){ |
| 35 | $('.videosource_select2').select2({ |
| 36 | width: "100%", |
| 37 | templateSelection: iformat, |
| 38 | templateResult: iformat, |
| 39 | allowHtml: true |
| 40 | }); |
| 41 | } |
| 42 | //videosource_select2 |
| 43 | |
| 44 | function iformat(icon) { |
| 45 | var originalOption = icon.element; |
| 46 | return $('<span><i class="tutor-icon-' + $(originalOption).data('icon') + '"></i> ' + icon.text + '</span>'); |
| 47 | } |
| 48 | |
| 49 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 50 | var $that = $(this); |
| 51 | var selector = $(this).val(); |
| 52 | |
| 53 | if (selector){ |
| 54 | $('.video-metabox-source-input-wrap').show(); |
| 55 | }else{ |
| 56 | $('.video-metabox-source-input-wrap').hide(); |
| 57 | } |
| 58 | $that.closest('.tutor-option-field').find('.video-metabox-source-item').hide(); |
| 59 | $that.closest('.tutor-option-field').find('.video_source_wrap_'+selector).show(); |
| 60 | }); |
| 61 | |
| 62 | /** |
| 63 | * Course Builder |
| 64 | * |
| 65 | * @since v.1.3.4 |
| 66 | */ |
| 67 | |
| 68 | $(document).on( 'click', '.tutor-course-thumbnail-upload-btn', function( event ){ |
| 69 | event.preventDefault(); |
| 70 | var $that = $(this); |
| 71 | var frame; |
| 72 | if ( frame ) { |
| 73 | frame.open(); |
| 74 | return; |
| 75 | } |
| 76 | frame = wp.media({ |
| 77 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 78 | button: { |
| 79 | text: 'Use this media' |
| 80 | }, |
| 81 | multiple: false |
| 82 | }); |
| 83 | frame.on( 'select', function() { |
| 84 | var attachment = frame.state().get('selection').first().toJSON(); |
| 85 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', attachment.url); |
| 86 | $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id); |
| 87 | $('.tutor-course-thumbnail-delete-btn').show(); |
| 88 | }); |
| 89 | frame.open(); |
| 90 | }); |
| 91 | |
| 92 | //Delete Thumbnail |
| 93 | $(document).on( 'click', '.tutor-course-thumbnail-delete-btn', function( event ){ |
| 94 | event.preventDefault(); |
| 95 | var $that = $(this); |
| 96 | |
| 97 | var placeholder_src = $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('data-placeholder-src'); |
| 98 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', placeholder_src); |
| 99 | $that.closest('.tutor-thumbnail-wrap').find('input').val(''); |
| 100 | $('.tutor-course-thumbnail-delete-btn').hide(); |
| 101 | }); |
| 102 | |
| 103 | /** |
| 104 | * Quiz Builder |
| 105 | */ |
| 106 | |
| 107 | $(document).on('click', '.create_new_topic_btn', function (e) { |
| 108 | e.preventDefault(); |
| 109 | $('.tutor-metabox-add-topics').slideToggle(); |
| 110 | }); |
| 111 | |
| 112 | $(document).on('click', '#tutor-add-topic-btn', function (e) { |
| 113 | e.preventDefault(); |
| 114 | var $that = $(this); |
| 115 | var form_data = $that.closest('.tutor-metabox-add-topics').find('input, textarea').serialize()+'&action=tutor_add_course_topic'; |
| 116 | |
| 117 | $.ajax({ |
| 118 | url : ajaxurl, |
| 119 | type : 'POST', |
| 120 | data : form_data, |
| 121 | beforeSend: function () { |
| 122 | $that.addClass('tutor-updating-message'); |
| 123 | }, |
| 124 | success: function (data) { |
| 125 | if (data.success){ |
| 126 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 127 | $that.closest('.tutor-metabox-add-topics').find('input[type!="hidden"], textarea').each(function () { |
| 128 | $(this).val(''); |
| 129 | }); |
| 130 | $that.closest('.tutor-metabox-add-topics').slideUp(); |
| 131 | enable_sorting_topic_lesson(); |
| 132 | } |
| 133 | }, |
| 134 | complete: function () { |
| 135 | $that.removeClass('tutor-updating-message'); |
| 136 | } |
| 137 | }); |
| 138 | }); |
| 139 | |
| 140 | /** |
| 141 | * Resorting... |
| 142 | */ |
| 143 | function enable_sorting_topic_lesson(){ |
| 144 | if (jQuery().sortable) { |
| 145 | $(".course-contents").sortable({ |
| 146 | handle: ".course-move-handle", |
| 147 | start: function (e, ui) { |
| 148 | ui.placeholder.css('visibility', 'visible'); |
| 149 | }, |
| 150 | stop: function (e, ui) { |
| 151 | tutor_sorting_topics_and_lesson(); |
| 152 | }, |
| 153 | }); |
| 154 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 155 | connectWith: ".tutor-lessons", |
| 156 | items: "div.course-content-item", |
| 157 | start: function (e, ui) { |
| 158 | ui.placeholder.css('visibility', 'visible'); |
| 159 | }, |
| 160 | stop: function (e, ui) { |
| 161 | tutor_sorting_topics_and_lesson(); |
| 162 | }, |
| 163 | }); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | function tutor_sorting_topics_and_lesson(){ |
| 168 | var topics = {}; |
| 169 | $('.tutor-topics-wrap').each(function(index, item){ |
| 170 | var $topic = $(this); |
| 171 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 172 | var lessons = {}; |
| 173 | |
| 174 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 175 | var $lesson = $(this); |
| 176 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 177 | |
| 178 | lessons[lessonIndex] = lesson_id; |
| 179 | }); |
| 180 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 181 | }); |
| 182 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 183 | } |
| 184 | |
| 185 | $(document).on('change keyup', '.course-edit-topic-title-input', function (e) { |
| 186 | e.preventDefault(); |
| 187 | $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val()); |
| 188 | }); |
| 189 | |
| 190 | $(document).on('click', '.topic-edit-icon', function (e) { |
| 191 | e.preventDefault(); |
| 192 | $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle(); |
| 193 | }); |
| 194 | |
| 195 | $(document).on('click', '.tutor-topics-edit-button', function(e){ |
| 196 | e.preventDefault(); |
| 197 | var $button = $(this); |
| 198 | var $topic = $button.closest('.tutor-topics-wrap'); |
| 199 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 200 | var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val(); |
| 201 | var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val(); |
| 202 | |
| 203 | var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'}; |
| 204 | $.ajax({ |
| 205 | url : ajaxurl, |
| 206 | type : 'POST', |
| 207 | data : data, |
| 208 | beforeSend: function () { |
| 209 | $button.addClass('tutor-updating-message'); |
| 210 | }, |
| 211 | success: function (data) { |
| 212 | if (data.success){ |
| 213 | $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title); |
| 214 | $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp(); |
| 215 | } |
| 216 | }, |
| 217 | complete: function () { |
| 218 | $button.removeClass('tutor-updating-message'); |
| 219 | } |
| 220 | }); |
| 221 | }); |
| 222 | |
| 223 | /** |
| 224 | * Update Lesson Modal |
| 225 | */ |
| 226 | $(document).on('click', '.open-tutor-lesson-modal', function(e){ |
| 227 | e.preventDefault(); |
| 228 | |
| 229 | var $that = $(this); |
| 230 | var lesson_id = $that.attr('data-lesson-id'); |
| 231 | var topic_id = $that.attr('data-topic-id'); |
| 232 | var course_id = $('#post_ID').val(); |
| 233 | |
| 234 | $.ajax({ |
| 235 | url : ajaxurl, |
| 236 | type : 'POST', |
| 237 | data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'}, |
| 238 | beforeSend: function () { |
| 239 | $that.addClass('tutor-updating-message'); |
| 240 | }, |
| 241 | success: function (data) { |
| 242 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 243 | $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show'); |
| 244 | |
| 245 | var tinymceConfig = tinyMCEPreInit.mceInit.tutor_editor_config; |
| 246 | if ( ! tinymceConfig){ |
| 247 | tinymceConfig = tinyMCEPreInit.mceInit.course_description; |
| 248 | } |
| 249 | tinymce.init(tinymceConfig); |
| 250 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' ); |
| 251 | tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor"); |
| 252 | |
| 253 | $(document).trigger('lesson_modal_loaded', {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id}); |
| 254 | }, |
| 255 | complete: function () { |
| 256 | quicktags({id : "tutor_lesson_modal_editor"}); |
| 257 | $that.removeClass('tutor-updating-message'); |
| 258 | } |
| 259 | }); |
| 260 | }); |
| 261 | |
| 262 | /** |
| 263 | * Lesson upload thumbnail |
| 264 | */ |
| 265 | $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){ |
| 266 | event.preventDefault(); |
| 267 | var $that = $(this); |
| 268 | var frame; |
| 269 | if ( frame ) { |
| 270 | frame.open(); |
| 271 | return; |
| 272 | } |
| 273 | frame = wp.media({ |
| 274 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 275 | button: { |
| 276 | text: 'Use this media' |
| 277 | }, |
| 278 | multiple: false |
| 279 | }); |
| 280 | frame.on( 'select', function() { |
| 281 | var attachment = frame.state().get('selection').first().toJSON(); |
| 282 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html('<img src="'+attachment.url+'" alt="" /><a href="javascript:;" class="tutor-lesson-thumbnail-delete-btn"><i class="tutor-icon-line-cross"></i></a>'); |
| 283 | $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id); |
| 284 | $('.tutor-lesson-thumbnail-delete-btn').show(); |
| 285 | }); |
| 286 | frame.open(); |
| 287 | }); |
| 288 | |
| 289 | /** |
| 290 | * Lesson Feature Image Delete |
| 291 | * @since v.1.5.6 |
| 292 | */ |
| 293 | $(document).on('click', '.tutor-lesson-thumbnail-delete-btn', function(e){ |
| 294 | e.preventDefault(); |
| 295 | |
| 296 | var $that = $(this); |
| 297 | |
| 298 | $that.closest('.tutor-thumbnail-wrap').find('._lesson_thumbnail_id').val(''); |
| 299 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html(''); |
| 300 | $that.hide(); |
| 301 | |
| 302 | }); |
| 303 | |
| 304 | /** |
| 305 | * Delete Lesson from course builder |
| 306 | */ |
| 307 | $(document).on('click', '.tutor-delete-lesson-btn', function(e){ |
| 308 | e.preventDefault(); |
| 309 | |
| 310 | if( ! confirm('Are you sure?')){ |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | var $that = $(this); |
| 315 | var lesson_id = $that.attr('data-lesson-id'); |
| 316 | |
| 317 | $.ajax({ |
| 318 | url : ajaxurl, |
| 319 | type : 'POST', |
| 320 | data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'}, |
| 321 | beforeSend: function () { |
| 322 | $that.addClass('tutor-updating-message'); |
| 323 | }, |
| 324 | success: function (data) { |
| 325 | if (data.success){ |
| 326 | $that.closest('.course-content-item').remove(); |
| 327 | } |
| 328 | }, |
| 329 | complete: function () { |
| 330 | $that.removeClass('tutor-updating-message'); |
| 331 | } |
| 332 | }); |
| 333 | }); |
| 334 | |
| 335 | /** |
| 336 | * Confirmation for deleting Topic |
| 337 | */ |
| 338 | $(document).on('click', '.topic-delete-btn a', function(e){ |
| 339 | var topic_id = $(this).attr('data-topic-id'); |
| 340 | |
| 341 | if ( ! confirm('Are you sure to delete?')){ |
| 342 | e.preventDefault(); |
| 343 | } |
| 344 | }); |
| 345 | |
| 346 | $(document).on('click', '.tutor-expand-all-topic', function (e) { |
| 347 | e.preventDefault(); |
| 348 | $('.tutor-topics-body').slideDown(); |
| 349 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up'); |
| 350 | }); |
| 351 | $(document).on('click', '.tutor-collapse-all-topic', function (e) { |
| 352 | e.preventDefault(); |
| 353 | $('.tutor-topics-body').slideUp(); |
| 354 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down'); |
| 355 | }); |
| 356 | $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) { |
| 357 | e.preventDefault(); |
| 358 | var $that = $(this); |
| 359 | $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle(); |
| 360 | $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up'); |
| 361 | }); |
| 362 | |
| 363 | /** |
| 364 | * Create new quiz |
| 365 | */ |
| 366 | |
| 367 | $(document).on('click', '.quiz-modal-btn-first-step', function(e){ |
| 368 | e.preventDefault(); |
| 369 | |
| 370 | var $that = $(this); |
| 371 | var $quizTitle = $('[name="quiz_title"]'); |
| 372 | var quiz_title = $quizTitle.val(); |
| 373 | var quiz_description = $('[name="quiz_description"]').val(); |
| 374 | |
| 375 | if ( ! quiz_title){ |
| 376 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title'); |
| 377 | return; |
| 378 | }else{ |
| 379 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html(''); |
| 380 | } |
| 381 | |
| 382 | var course_id = $('#post_ID').val(); |
| 383 | var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id'); |
| 384 | |
| 385 | if ($('#tutor_quiz_builder_quiz_id').length) { |
| 386 | /** |
| 387 | * |
| 388 | * @type {jQuery} |
| 389 | * |
| 390 | * if quiz id exists, we are sending it to update quiz |
| 391 | */ |
| 392 | |
| 393 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 394 | $.ajax({ |
| 395 | url : ajaxurl, |
| 396 | type : 'POST', |
| 397 | data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'}, |
| 398 | beforeSend: function () { |
| 399 | $that.addClass('tutor-updating-message'); |
| 400 | }, |
| 401 | success: function (data) { |
| 402 | $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row); |
| 403 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 404 | |
| 405 | tutor_slider_init(); |
| 406 | }, |
| 407 | complete: function () { |
| 408 | $that.removeClass('tutor-updating-message'); |
| 409 | } |
| 410 | }); |
| 411 | |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | $.ajax({ |
| 416 | url : ajaxurl, |
| 417 | type : 'POST', |
| 418 | data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'}, |
| 419 | beforeSend: function () { |
| 420 | $that.addClass('tutor-updating-message'); |
| 421 | }, |
| 422 | success: function (data) { |
| 423 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 424 | $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row); |
| 425 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 426 | |
| 427 | tutor_slider_init(); |
| 428 | |
| 429 | $(document).trigger('quiz_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 430 | }, |
| 431 | complete: function () { |
| 432 | $that.removeClass('tutor-updating-message'); |
| 433 | } |
| 434 | }); |
| 435 | |
| 436 | }); |
| 437 | |
| 438 | |
| 439 | /** |
| 440 | * Ope modal for edit quiz |
| 441 | */ |
| 442 | $(document).on('click', '.open-tutor-quiz-modal', function(e){ |
| 443 | e.preventDefault(); |
| 444 | |
| 445 | var $that = $(this); |
| 446 | var quiz_id = $that.attr('data-quiz-id'); |
| 447 | var topic_id = $that.attr('data-topic-id'); |
| 448 | var course_id = $('#post_ID').val(); |
| 449 | |
| 450 | $.ajax({ |
| 451 | url : ajaxurl, |
| 452 | type : 'POST', |
| 453 | data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'}, |
| 454 | beforeSend: function () { |
| 455 | $that.addClass('tutor-updating-message'); |
| 456 | }, |
| 457 | success: function (data) { |
| 458 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 459 | $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).addClass('show'); |
| 460 | |
| 461 | //Back to question Tab if exists |
| 462 | if ($that.attr('data-back-to-tab')){ |
| 463 | var tabSelector = $that.attr('data-back-to-tab'); |
| 464 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 465 | } |
| 466 | |
| 467 | $(document).trigger('quiz_modal_loaded', {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id}); |
| 468 | |
| 469 | tutor_slider_init(); |
| 470 | enable_quiz_questions_sorting(); |
| 471 | }, |
| 472 | complete: function () { |
| 473 | $that.removeClass('tutor-updating-message'); |
| 474 | } |
| 475 | }); |
| 476 | }); |
| 477 | |
| 478 | $(document).on('click', '.quiz-modal-settings-save-btn', function(e){ |
| 479 | e.preventDefault(); |
| 480 | |
| 481 | var $that = $(this); |
| 482 | var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id'); |
| 483 | |
| 484 | var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serialize()+'&quiz_id='+quiz_id+'&action=tutor_quiz_modal_update_settings'; |
| 485 | |
| 486 | $.ajax({ |
| 487 | url : ajaxurl, |
| 488 | type : 'POST', |
| 489 | data : $formInput, |
| 490 | beforeSend: function () { |
| 491 | $that.addClass('tutor-updating-message'); |
| 492 | }, |
| 493 | success: function (data) { |
| 494 | // |
| 495 | }, |
| 496 | complete: function () { |
| 497 | $that.removeClass('tutor-updating-message'); |
| 498 | if ($that.attr('data-action') === 'modal_close'){ |
| 499 | $('.tutor-modal-wrap').removeClass('show'); |
| 500 | } |
| 501 | } |
| 502 | }); |
| 503 | }); |
| 504 | |
| 505 | |
| 506 | /** |
| 507 | * Quiz Question edit save and continue |
| 508 | */ |
| 509 | $(document).on('click', '.quiz-modal-question-save-btn', function(e){ |
| 510 | e.preventDefault(); |
| 511 | |
| 512 | var $that = $(this); |
| 513 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_quiz_modal_update_question'; |
| 514 | $.ajax({ |
| 515 | url : ajaxurl, |
| 516 | type : 'POST', |
| 517 | data : $formInput, |
| 518 | beforeSend: function () { |
| 519 | $that.addClass('tutor-updating-message'); |
| 520 | }, |
| 521 | success: function (data) { |
| 522 | if (data.success){ |
| 523 | //ReOpen questions |
| 524 | $that.closest('.tutor-quiz-builder-modal-contents').find('.open-tutor-quiz-modal').trigger('click'); |
| 525 | }else{ |
| 526 | if (typeof data.data !== 'undefined') { |
| 527 | $('#quiz_validation_msg_wrap').html(data.data.validation_msg); |
| 528 | } |
| 529 | } |
| 530 | }, |
| 531 | complete: function () { |
| 532 | $that.removeClass('tutor-updating-message'); |
| 533 | } |
| 534 | }); |
| 535 | }); |
| 536 | |
| 537 | /** |
| 538 | * Sort quiz questions |
| 539 | */ |
| 540 | function enable_quiz_questions_sorting(){ |
| 541 | if (jQuery().sortable) { |
| 542 | $(".quiz-builder-questions-wrap").sortable({ |
| 543 | handle: ".question-sorting", |
| 544 | start: function (e, ui) { |
| 545 | ui.placeholder.css('visibility', 'visible'); |
| 546 | }, |
| 547 | stop: function (e, ui) { |
| 548 | tutor_save_sorting_quiz_questions_order(); |
| 549 | }, |
| 550 | }); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | function tutor_save_sorting_quiz_questions_order(){ |
| 555 | var questions = {}; |
| 556 | $('.quiz-builder-question-wrap').each(function(index, item){ |
| 557 | var $question = $(this); |
| 558 | var question_id = parseInt($question.attr('data-question-id'), 10); |
| 559 | questions[index] = question_id; |
| 560 | }); |
| 561 | |
| 562 | $.ajax({url : ajaxurl, type : 'POST', |
| 563 | data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'}, |
| 564 | }); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Quiz Modal |
| 569 | */ |
| 570 | |
| 571 | $(document).on('click', '.modal-close-btn', function(e){ |
| 572 | e.preventDefault(); |
| 573 | $('.tutor-modal-wrap').removeClass('show'); |
| 574 | }); |
| 575 | $(document).on('keyup', function(e){ |
| 576 | if (e.keyCode === 27){ |
| 577 | $('.tutor-modal-wrap').removeClass('show'); |
| 578 | } |
| 579 | }); |
| 580 | |
| 581 | $(document).on('click', '.tutor-add-quiz-btn', function(e){ |
| 582 | e.preventDefault(); |
| 583 | |
| 584 | var $that = $(this); |
| 585 | var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under'); |
| 586 | $.ajax({ |
| 587 | url : ajaxurl, |
| 588 | type : 'POST', |
| 589 | data : {quiz_for_post_id : quiz_for_post_id, action: 'tutor_load_quiz_builder_modal'}, |
| 590 | beforeSend: function () { |
| 591 | $that.addClass('tutor-updating-message'); |
| 592 | }, |
| 593 | success: function (data) { |
| 594 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 595 | $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show'); |
| 596 | }, |
| 597 | complete: function () { |
| 598 | $that.removeClass('tutor-updating-message'); |
| 599 | } |
| 600 | }); |
| 601 | }); |
| 602 | |
| 603 | |
| 604 | /** |
| 605 | * Quiz Builder Modal Tabs |
| 606 | */ |
| 607 | $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){ |
| 608 | e.preventDefault(); |
| 609 | |
| 610 | var $that = $(this); |
| 611 | |
| 612 | var $quizTitle = $('[name="quiz_title"]'); |
| 613 | var quiz_title = $quizTitle.val(); |
| 614 | if ( ! quiz_title){ |
| 615 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' + |
| 616 | ' first</p>'); |
| 617 | return; |
| 618 | }else{ |
| 619 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html(''); |
| 620 | } |
| 621 | |
| 622 | var tabSelector = $that.attr('href'); |
| 623 | $('.quiz-builder-tab-container').hide(); |
| 624 | $(tabSelector).show(); |
| 625 | |
| 626 | $('a.tutor-quiz-modal-tab-item').removeClass('active'); |
| 627 | $that.addClass('active'); |
| 628 | }); |
| 629 | |
| 630 | //Next Prev Tab |
| 631 | $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){ |
| 632 | e.preventDefault(); |
| 633 | |
| 634 | var tabSelector = $(this).attr('href'); |
| 635 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 636 | }); |
| 637 | |
| 638 | $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){ |
| 639 | e.preventDefault(); |
| 640 | $('.tutor-modal-wrap').removeClass('show'); |
| 641 | }); |
| 642 | |
| 643 | /** |
| 644 | * Add Question to quiz modal |
| 645 | */ |
| 646 | $(document).on('click', '.tutor-quiz-open-question-form', function(e){ |
| 647 | e.preventDefault(); |
| 648 | |
| 649 | var $that = $(this); |
| 650 | |
| 651 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 652 | var course_id = $('#post_ID').val(); |
| 653 | var question_id = $that.attr('data-question-id'); |
| 654 | |
| 655 | |
| 656 | var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'}; |
| 657 | |
| 658 | if (question_id) { |
| 659 | params.question_id = question_id; |
| 660 | } |
| 661 | |
| 662 | $.ajax({ |
| 663 | url : ajaxurl, |
| 664 | type : 'POST', |
| 665 | data : params, |
| 666 | beforeSend: function () { |
| 667 | $that.addClass('tutor-updating-message'); |
| 668 | }, |
| 669 | success: function (data) { |
| 670 | $('.tutor-quiz-builder-modal-contents').html(data.data.output); |
| 671 | |
| 672 | //Initializing Tutor Select |
| 673 | tutor_select().reInit(); |
| 674 | enable_quiz_answer_sorting(); |
| 675 | }, |
| 676 | complete: function () { |
| 677 | $that.removeClass('tutor-updating-message'); |
| 678 | } |
| 679 | }); |
| 680 | |
| 681 | }); |
| 682 | |
| 683 | $(document).on('click', '.tutor-quiz-question-trash', function(e){ |
| 684 | e.preventDefault(); |
| 685 | |
| 686 | var $that = $(this); |
| 687 | var question_id = $that.attr('data-question-id'); |
| 688 | |
| 689 | $.ajax({ |
| 690 | url : ajaxurl, |
| 691 | type : 'POST', |
| 692 | data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'}, |
| 693 | beforeSend: function () { |
| 694 | $that.closest('.quiz-builder-question-wrap').remove(); |
| 695 | }, |
| 696 | }); |
| 697 | }); |
| 698 | |
| 699 | /** |
| 700 | * Get question answers option form to save multiple/single/true-false options |
| 701 | * |
| 702 | * @since v.1.0.0 |
| 703 | */ |
| 704 | |
| 705 | $(document).on('click', '.add_question_answers_option', function(e){ |
| 706 | e.preventDefault(); |
| 707 | |
| 708 | var $that = $(this); |
| 709 | var question_id = $that.attr('data-question-id'); |
| 710 | var $formInput = $('.quiz_question_form :input').serialize()+'&question_id='+question_id+'&action=tutor_quiz_add_question_answers'; |
| 711 | |
| 712 | $.ajax({ |
| 713 | url : ajaxurl, |
| 714 | type : 'POST', |
| 715 | data : $formInput, |
| 716 | beforeSend: function () { |
| 717 | $that.addClass('tutor-updating-message'); |
| 718 | }, |
| 719 | success: function (data) { |
| 720 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 721 | }, |
| 722 | complete: function () { |
| 723 | $that.removeClass('tutor-updating-message'); |
| 724 | } |
| 725 | }); |
| 726 | }); |
| 727 | |
| 728 | /** |
| 729 | * Get question answers option edit form |
| 730 | * |
| 731 | * @since v.1.0.0 |
| 732 | */ |
| 733 | $(document).on('click', '.tutor-quiz-answer-edit a', function(e){ |
| 734 | e.preventDefault(); |
| 735 | |
| 736 | var $that = $(this); |
| 737 | var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id'); |
| 738 | |
| 739 | $.ajax({ |
| 740 | url : ajaxurl, |
| 741 | type : 'POST', |
| 742 | data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'}, |
| 743 | beforeSend: function () { |
| 744 | $that.addClass('tutor-updating-message'); |
| 745 | }, |
| 746 | success: function (data) { |
| 747 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 748 | }, |
| 749 | complete: function () { |
| 750 | $that.removeClass('tutor-updating-message'); |
| 751 | } |
| 752 | }); |
| 753 | }); |
| 754 | |
| 755 | /** |
| 756 | * Saving question answers options |
| 757 | * Student should select the right answer at quiz attempts |
| 758 | * |
| 759 | * @since v.1.0.0 |
| 760 | */ |
| 761 | |
| 762 | $(document).on('click', '#quiz-answer-save-btn', function(e){ |
| 763 | e.preventDefault(); |
| 764 | |
| 765 | var $that = $(this); |
| 766 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_save_quiz_answer_options'; |
| 767 | |
| 768 | $.ajax({ |
| 769 | url : ajaxurl, |
| 770 | type : 'POST', |
| 771 | data : $formInput, |
| 772 | beforeSend: function () { |
| 773 | $('#quiz_validation_msg_wrap').html(""); |
| 774 | $that.addClass('tutor-updating-message'); |
| 775 | }, |
| 776 | success: function (data) { |
| 777 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 778 | }, |
| 779 | complete: function () { |
| 780 | $that.removeClass('tutor-updating-message'); |
| 781 | } |
| 782 | }); |
| 783 | }); |
| 784 | |
| 785 | /** |
| 786 | * Updating Answer |
| 787 | * |
| 788 | * @since v.1.0.0 |
| 789 | */ |
| 790 | $(document).on('click', '#quiz-answer-edit-btn', function(e){ |
| 791 | e.preventDefault(); |
| 792 | |
| 793 | var $that = $(this); |
| 794 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_update_quiz_answer_options'; |
| 795 | |
| 796 | $.ajax({ |
| 797 | url : ajaxurl, |
| 798 | type : 'POST', |
| 799 | data : $formInput, |
| 800 | beforeSend: function () { |
| 801 | $that.addClass('tutor-updating-message'); |
| 802 | }, |
| 803 | success: function (data) { |
| 804 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 805 | }, |
| 806 | complete: function () { |
| 807 | $that.removeClass('tutor-updating-message'); |
| 808 | } |
| 809 | }); |
| 810 | }); |
| 811 | |
| 812 | $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){ |
| 813 | e.preventDefault(); |
| 814 | |
| 815 | var $that = $(this); |
| 816 | |
| 817 | var answer_id = $that.val(); |
| 818 | var inputValue = 1; |
| 819 | if ( ! $that.prop('checked')) { |
| 820 | inputValue = 0; |
| 821 | } |
| 822 | |
| 823 | $.ajax({ |
| 824 | url : ajaxurl, |
| 825 | type : 'POST', |
| 826 | data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'}, |
| 827 | }); |
| 828 | }); |
| 829 | |
| 830 | |
| 831 | $(document).on('refresh', '#tutor_quiz_question_answers', function(e){ |
| 832 | e.preventDefault(); |
| 833 | |
| 834 | var $that = $(this); |
| 835 | var question_id = $that.attr('data-question-id'); |
| 836 | var question_type = $('.tutor_select_value_holder').val(); |
| 837 | |
| 838 | $.ajax({ |
| 839 | url : ajaxurl, |
| 840 | type : 'POST', |
| 841 | data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'}, |
| 842 | beforeSend: function () { |
| 843 | $that.addClass('tutor-updating-message'); |
| 844 | $('#tutor_quiz_question_answer_form').html(''); |
| 845 | }, |
| 846 | success: function (data) { |
| 847 | if (data.success){ |
| 848 | $that.html(data.data.output); |
| 849 | } |
| 850 | }, |
| 851 | complete: function () { |
| 852 | $that.removeClass('tutor-updating-message'); |
| 853 | } |
| 854 | }); |
| 855 | }); |
| 856 | |
| 857 | |
| 858 | |
| 859 | /** |
| 860 | * Delete answer for a question in quiz builder |
| 861 | * |
| 862 | * @since v.1.0.0 |
| 863 | */ |
| 864 | |
| 865 | $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){ |
| 866 | e.preventDefault(); |
| 867 | |
| 868 | var $that = $(this); |
| 869 | var answer_id = $that.attr('data-answer-id'); |
| 870 | |
| 871 | $.ajax({ |
| 872 | url : ajaxurl, |
| 873 | type : 'POST', |
| 874 | data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'}, |
| 875 | beforeSend: function () { |
| 876 | $that.closest('.tutor-quiz-answer-wrap').remove(); |
| 877 | }, |
| 878 | }); |
| 879 | }); |
| 880 | |
| 881 | |
| 882 | /** |
| 883 | * Delete Quiz |
| 884 | * @since v.1.0.0 |
| 885 | */ |
| 886 | |
| 887 | $(document).on('click', '.tutor-delete-quiz-btn', function(e){ |
| 888 | e.preventDefault(); |
| 889 | |
| 890 | if( ! confirm('Are you sure?')){ |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | var $that = $(this); |
| 895 | var quiz_id = $that.attr('data-quiz-id'); |
| 896 | |
| 897 | $.ajax({ |
| 898 | url : ajaxurl, |
| 899 | type : 'POST', |
| 900 | data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'}, |
| 901 | beforeSend: function () { |
| 902 | $that.closest('.course-content-item').remove(); |
| 903 | } |
| 904 | }); |
| 905 | }); |
| 906 | |
| 907 | /** |
| 908 | * Save answer sorting placement |
| 909 | * |
| 910 | * @since v.1.0.0 |
| 911 | */ |
| 912 | function enable_quiz_answer_sorting(){ |
| 913 | if (jQuery().sortable) { |
| 914 | $("#tutor_quiz_question_answers").sortable({ |
| 915 | handle: ".tutor-quiz-answer-sort-icon", |
| 916 | start: function (e, ui) { |
| 917 | ui.placeholder.css('visibility', 'visible'); |
| 918 | }, |
| 919 | stop: function (e, ui) { |
| 920 | tutor_save_sorting_quiz_answer_order(); |
| 921 | }, |
| 922 | }); |
| 923 | } |
| 924 | } |
| 925 | function tutor_save_sorting_quiz_answer_order(){ |
| 926 | var answers = {}; |
| 927 | $('.tutor-quiz-answer-wrap').each(function(index, item){ |
| 928 | var $answer = $(this); |
| 929 | var answer_id = parseInt($answer.attr('data-answer-id'), 10); |
| 930 | answers[index] = answer_id; |
| 931 | }); |
| 932 | |
| 933 | $.ajax({url : ajaxurl, type : 'POST', |
| 934 | data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'}, |
| 935 | }); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | /** |
| 940 | * Tutor Custom Select |
| 941 | */ |
| 942 | |
| 943 | function tutor_select(){ |
| 944 | var obj = { |
| 945 | init : function(){ |
| 946 | $(document).on('click', '.tutor-select .tutor-select-option', function(e){ |
| 947 | e.preventDefault(); |
| 948 | |
| 949 | var $that = $(this); |
| 950 | if ($that.attr('data-is-pro') !== 'true') { |
| 951 | var $html = $that.html().trim(); |
| 952 | $that.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 953 | $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change'); |
| 954 | $that.closest('.tutor-select-options').hide(); |
| 955 | }else{ |
| 956 | alert('Tutor Pro version required'); |
| 957 | } |
| 958 | }); |
| 959 | $(document).on('click', '.tutor-select .select-header', function(e){ |
| 960 | e.preventDefault(); |
| 961 | |
| 962 | var $that = $(this); |
| 963 | $that.closest('.tutor-select').find('.tutor-select-options').slideToggle(); |
| 964 | }); |
| 965 | |
| 966 | this.setValue(); |
| 967 | this.hideOnOutSideClick(); |
| 968 | }, |
| 969 | setValue : function(){ |
| 970 | $('.tutor-select').each(function(){ |
| 971 | var $that = $(this); |
| 972 | var $option = $that.find('.tutor-select-option'); |
| 973 | |
| 974 | if ($option.length){ |
| 975 | $option.each(function(){ |
| 976 | var $thisOption = $(this); |
| 977 | |
| 978 | if ($thisOption.attr('data-selected') === 'selected'){ |
| 979 | var $html = $thisOption.html().trim(); |
| 980 | $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 981 | $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value')); |
| 982 | } |
| 983 | }); |
| 984 | } |
| 985 | }); |
| 986 | }, |
| 987 | hideOnOutSideClick : function(){ |
| 988 | $(document).mouseup(function(e) { |
| 989 | var $option_wrap = $(".tutor-select-options"); |
| 990 | if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) { |
| 991 | $option_wrap.hide(); |
| 992 | } |
| 993 | }); |
| 994 | }, |
| 995 | reInit : function(){ |
| 996 | this.setValue(); |
| 997 | } |
| 998 | }; |
| 999 | |
| 1000 | return obj; |
| 1001 | } |
| 1002 | tutor_select().init(); |
| 1003 | |
| 1004 | |
| 1005 | /** |
| 1006 | * If change question type from quiz builder question |
| 1007 | * |
| 1008 | * @since v.1.0.0 |
| 1009 | */ |
| 1010 | $(document).on('change', 'input.tutor_select_value_holder', function(e) { |
| 1011 | var $that = $(this); |
| 1012 | //$('#tutor_quiz_question_answer_form').html(''); |
| 1013 | $('.add_question_answers_option').trigger('click'); |
| 1014 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 1015 | }); |
| 1016 | |
| 1017 | $(document).on('click', '.tutor-media-upload-btn', function(e){ |
| 1018 | e.preventDefault(); |
| 1019 | |
| 1020 | var $that = $(this); |
| 1021 | var frame; |
| 1022 | if ( frame ) { |
| 1023 | frame.open(); |
| 1024 | return; |
| 1025 | } |
| 1026 | frame = wp.media({ |
| 1027 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1028 | button: { |
| 1029 | text: 'Use this media' |
| 1030 | }, |
| 1031 | multiple: false |
| 1032 | }); |
| 1033 | frame.on( 'select', function() { |
| 1034 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1035 | $that.html('<img src="'+attachment.url+'" alt="" />'); |
| 1036 | $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id); |
| 1037 | }); |
| 1038 | frame.open(); |
| 1039 | }); |
| 1040 | $(document).on('click', '.tutor-media-upload-trash', function(e){ |
| 1041 | e.preventDefault(); |
| 1042 | |
| 1043 | var $that = $(this); |
| 1044 | $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>'); |
| 1045 | $that.closest('.tutor-media-upload-wrap').find('input').val(''); |
| 1046 | }); |
| 1047 | |
| 1048 | /** |
| 1049 | * Delay Function |
| 1050 | */ |
| 1051 | |
| 1052 | var tutor_delay = (function(){ |
| 1053 | var timer = 0; |
| 1054 | return function(callback, ms){ |
| 1055 | clearTimeout (timer); |
| 1056 | timer = setTimeout(callback, ms); |
| 1057 | }; |
| 1058 | })(); |
| 1059 | |
| 1060 | /** |
| 1061 | * Add instructor modal |
| 1062 | */ |
| 1063 | $(document).on('click', '.tutor-add-instructor-btn', function(e){ |
| 1064 | e.preventDefault(); |
| 1065 | |
| 1066 | var $that = $(this); |
| 1067 | var course_id = $('#post_ID').val(); |
| 1068 | |
| 1069 | $.ajax({ |
| 1070 | url : ajaxurl, |
| 1071 | type : 'POST', |
| 1072 | data : {course_id : course_id, action: 'tutor_load_instructors_modal'}, |
| 1073 | beforeSend: function () { |
| 1074 | $that.addClass('tutor-updating-message'); |
| 1075 | }, |
| 1076 | success: function (data) { |
| 1077 | if (data.success){ |
| 1078 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1079 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1080 | } |
| 1081 | }, |
| 1082 | complete: function () { |
| 1083 | $that.removeClass('tutor-updating-message'); |
| 1084 | } |
| 1085 | }); |
| 1086 | }); |
| 1087 | |
| 1088 | $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){ |
| 1089 | e.preventDefault(); |
| 1090 | |
| 1091 | var $that = $(this); |
| 1092 | var $modal = $('.tutor-modal-wrap'); |
| 1093 | |
| 1094 | tutor_delay(function(){ |
| 1095 | var search_terms = $that.val(); |
| 1096 | var course_id = $('#post_ID').val(); |
| 1097 | |
| 1098 | $.ajax({ |
| 1099 | url : ajaxurl, |
| 1100 | type : 'POST', |
| 1101 | data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'}, |
| 1102 | beforeSend: function () { |
| 1103 | $modal.addClass('loading'); |
| 1104 | }, |
| 1105 | success: function (data) { |
| 1106 | if (data.success){ |
| 1107 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1108 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1109 | } |
| 1110 | }, |
| 1111 | complete: function () { |
| 1112 | $modal.removeClass('loading'); |
| 1113 | } |
| 1114 | }); |
| 1115 | |
| 1116 | }, 1000) |
| 1117 | }); |
| 1118 | $(document).on('click', '.add_instructor_to_course_btn', function(e){ |
| 1119 | e.preventDefault(); |
| 1120 | |
| 1121 | var $that = $(this); |
| 1122 | var $modal = $('.tutor-modal-wrap'); |
| 1123 | var course_id = $('#post_ID').val(); |
| 1124 | var data = $modal.find('input').serialize()+'&course_id='+course_id+'&action=tutor_add_instructors_to_course'; |
| 1125 | |
| 1126 | $.ajax({ |
| 1127 | url : ajaxurl, |
| 1128 | type : 'POST', |
| 1129 | data : data, |
| 1130 | beforeSend: function () { |
| 1131 | $that.addClass('tutor-updating-message'); |
| 1132 | }, |
| 1133 | success: function (data) { |
| 1134 | if (data.success){ |
| 1135 | $('.tutor-course-available-instructors').html(data.data.output); |
| 1136 | $('.tutor-modal-wrap').removeClass('show'); |
| 1137 | } |
| 1138 | }, |
| 1139 | complete: function () { |
| 1140 | $that.removeClass('tutor-updating-message'); |
| 1141 | } |
| 1142 | }); |
| 1143 | }); |
| 1144 | |
| 1145 | $(document).on('click', '.tutor-instructor-delete-btn', function(e){ |
| 1146 | e.preventDefault(); |
| 1147 | |
| 1148 | var $that = $(this); |
| 1149 | var course_id = $('#post_ID').val(); |
| 1150 | var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id'); |
| 1151 | |
| 1152 | $.ajax({ |
| 1153 | url : ajaxurl, |
| 1154 | type : 'POST', |
| 1155 | data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'}, |
| 1156 | success: function (data) { |
| 1157 | if (data.success){ |
| 1158 | $that.closest('.added-instructor-item').remove(); |
| 1159 | } |
| 1160 | } |
| 1161 | }); |
| 1162 | }); |
| 1163 | |
| 1164 | $(document).on('click', '.settings-tabs-navs li', function(e){ |
| 1165 | e.preventDefault(); |
| 1166 | |
| 1167 | var $that = $(this); |
| 1168 | var data_target = $that.find('a').attr('data-target'); |
| 1169 | var url = $that.find('a').attr('href'); |
| 1170 | |
| 1171 | $that.addClass('active').siblings('li.active').removeClass('active'); |
| 1172 | $('.settings-tab-wrap').removeClass('active').hide(); |
| 1173 | $(data_target).addClass('active').show(); |
| 1174 | |
| 1175 | window.history.pushState({}, '', url); |
| 1176 | }); |
| 1177 | |
| 1178 | /** |
| 1179 | * Re init required |
| 1180 | * Modal Loaded... |
| 1181 | */ |
| 1182 | |
| 1183 | $(document).on('lesson_modal_loaded quiz_modal_loaded assignment_modal_loaded', function(e, obj){ |
| 1184 | if (jQuery().select2){ |
| 1185 | $('.select2_multiselect').select2({ |
| 1186 | dropdownCssClass:'increasezindex' |
| 1187 | }); |
| 1188 | } |
| 1189 | if (jQuery.datepicker){ |
| 1190 | $( ".tutor_date_picker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 1191 | } |
| 1192 | }); |
| 1193 | $(document).on('lesson_modal_loaded', function(e, obj){ |
| 1194 | $('.tutor-lesson-modal-wrap .modal-title h1').html('Lesson'); |
| 1195 | }); |
| 1196 | $(document).on('assignment_modal_loaded', function(e, obj){ |
| 1197 | $('.tutor-lesson-modal-wrap .modal-title h1').html('Assignment'); |
| 1198 | }); |
| 1199 | |
| 1200 | }); |