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.js
6 years ago
tutor-admin.js
1797 lines
| 1 | jQuery(document).ready(function($){ |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * Color Picker |
| 6 | * @since v.1.2.21 |
| 7 | */ |
| 8 | if (jQuery().wpColorPicker) { |
| 9 | $('.tutor_colorpicker').wpColorPicker(); |
| 10 | } |
| 11 | |
| 12 | if (jQuery().select2){ |
| 13 | $('.tutor_select2').select2(); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Option Settings Nav Tab |
| 18 | */ |
| 19 | $('.tutor-option-nav-tabs li a').click(function(e){ |
| 20 | e.preventDefault(); |
| 21 | var tab_page_id = $(this).attr('href'); |
| 22 | $('.option-nav-item').removeClass('current'); |
| 23 | $(this).closest('li').addClass('current'); |
| 24 | $('.tutor-option-nav-page').hide(); |
| 25 | $(tab_page_id).addClass('current-page').show(); |
| 26 | }); |
| 27 | |
| 28 | $('#save_tutor_option').click(function (e) { |
| 29 | e.preventDefault(); |
| 30 | $(this).closest('form').submit(); |
| 31 | }); |
| 32 | $('#tutor-option-form').submit(function(e){ |
| 33 | e.preventDefault(); |
| 34 | |
| 35 | var $form = $(this); |
| 36 | var data = $form.serialize(); |
| 37 | |
| 38 | $.ajax({ |
| 39 | url : ajaxurl, |
| 40 | type : 'POST', |
| 41 | data : data, |
| 42 | beforeSend: function () { |
| 43 | $form.find('.button').addClass('tutor-updating-message'); |
| 44 | }, |
| 45 | success: function (data) { |
| 46 | if (data.success) { |
| 47 | window.location.reload(); |
| 48 | } |
| 49 | }, |
| 50 | complete: function () { |
| 51 | $form.find('.button').removeClass('tutor-updating-message'); |
| 52 | } |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | /** |
| 57 | * Withdraw nav tabs |
| 58 | * @since v.1.1.2 |
| 59 | */ |
| 60 | $(document).on('click', '.withdraw-method-nav li a', function(e){ |
| 61 | e.preventDefault(); |
| 62 | var tab_page_id = $(this).attr('data-target-id'); |
| 63 | $('.withdraw-method-form-wrap').hide(); |
| 64 | $('#'+tab_page_id).show(); |
| 65 | }); |
| 66 | |
| 67 | /** |
| 68 | * End Withdraw nav tabs |
| 69 | */ |
| 70 | |
| 71 | function tutor_slider_init(){ |
| 72 | $('.tutor-field-slider').each(function(){ |
| 73 | var $slider = $(this); |
| 74 | var $input = $slider.closest('.tutor-field-type-slider').find('input[type="hidden"]'); |
| 75 | var $showVal = $slider.closest('.tutor-field-type-slider').find('.tutor-field-type-slider-value'); |
| 76 | var min = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-min')); |
| 77 | var max = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-max')); |
| 78 | |
| 79 | $slider.slider({ |
| 80 | range: "max", |
| 81 | min: min, |
| 82 | max: max, |
| 83 | value: $input.val(), |
| 84 | slide: function( event, ui ) { |
| 85 | $showVal.text(ui.value); |
| 86 | $input.val(ui.value); |
| 87 | } |
| 88 | }); |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | tutor_slider_init(); |
| 93 | |
| 94 | /** |
| 95 | * Course and lesson sorting |
| 96 | */ |
| 97 | function enable_sorting_topic_lesson(){ |
| 98 | if (jQuery().sortable) { |
| 99 | $(".course-contents").sortable({ |
| 100 | handle: ".course-move-handle", |
| 101 | start: function (e, ui) { |
| 102 | ui.placeholder.css('visibility', 'visible'); |
| 103 | }, |
| 104 | stop: function (e, ui) { |
| 105 | tutor_sorting_topics_and_lesson(); |
| 106 | }, |
| 107 | }); |
| 108 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 109 | connectWith: ".tutor-lessons", |
| 110 | items: "div.course-content-item", |
| 111 | start: function (e, ui) { |
| 112 | ui.placeholder.css('visibility', 'visible'); |
| 113 | }, |
| 114 | stop: function (e, ui) { |
| 115 | tutor_sorting_topics_and_lesson(); |
| 116 | }, |
| 117 | }); |
| 118 | } |
| 119 | } |
| 120 | enable_sorting_topic_lesson(); |
| 121 | function tutor_sorting_topics_and_lesson(){ |
| 122 | var topics = {}; |
| 123 | $('.tutor-topics-wrap').each(function(index, item){ |
| 124 | var $topic = $(this); |
| 125 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 126 | var lessons = {}; |
| 127 | |
| 128 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 129 | var $lesson = $(this); |
| 130 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 131 | |
| 132 | lessons[lessonIndex] = lesson_id; |
| 133 | }); |
| 134 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 135 | }); |
| 136 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 137 | } |
| 138 | |
| 139 | $(document).on('click', '.create_new_topic_btn', function (e) { |
| 140 | e.preventDefault(); |
| 141 | $('.tutor-metabox-add-topics').slideToggle(); |
| 142 | }); |
| 143 | |
| 144 | $(document).on('click', '#tutor-add-topic-btn', function (e) { |
| 145 | e.preventDefault(); |
| 146 | var $that = $(this); |
| 147 | var form_data = $that.closest('.tutor-metabox-add-topics').find('input, textarea').serialize()+'&action=tutor_add_course_topic'; |
| 148 | |
| 149 | $.ajax({ |
| 150 | url : ajaxurl, |
| 151 | type : 'POST', |
| 152 | data : form_data, |
| 153 | beforeSend: function () { |
| 154 | $that.addClass('tutor-updating-message'); |
| 155 | }, |
| 156 | success: function (data) { |
| 157 | if (data.success){ |
| 158 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 159 | $that.closest('.tutor-metabox-add-topics').find('input[type!="hidden"], textarea').each(function () { |
| 160 | $(this).val(''); |
| 161 | }); |
| 162 | $that.closest('.tutor-metabox-add-topics').slideUp(); |
| 163 | enable_sorting_topic_lesson(); |
| 164 | } |
| 165 | }, |
| 166 | complete: function () { |
| 167 | $that.removeClass('tutor-updating-message'); |
| 168 | } |
| 169 | }); |
| 170 | }); |
| 171 | |
| 172 | $(document).on('change keyup', '.course-edit-topic-title-input', function (e) { |
| 173 | e.preventDefault(); |
| 174 | $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val()); |
| 175 | }); |
| 176 | |
| 177 | $(document).on('click', '.topic-edit-icon', function (e) { |
| 178 | e.preventDefault(); |
| 179 | $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle(); |
| 180 | }); |
| 181 | |
| 182 | $(document).on('click', '.tutor-topics-edit-button', function(e){ |
| 183 | e.preventDefault(); |
| 184 | var $button = $(this); |
| 185 | var $topic = $button.closest('.tutor-topics-wrap'); |
| 186 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 187 | var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val(); |
| 188 | var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val(); |
| 189 | |
| 190 | var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'}; |
| 191 | $.ajax({ |
| 192 | url : ajaxurl, |
| 193 | type : 'POST', |
| 194 | data : data, |
| 195 | beforeSend: function () { |
| 196 | $button.addClass('tutor-updating-message'); |
| 197 | }, |
| 198 | success: function (data) { |
| 199 | if (data.success){ |
| 200 | $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title); |
| 201 | $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp(); |
| 202 | } |
| 203 | }, |
| 204 | complete: function () { |
| 205 | $button.removeClass('tutor-updating-message'); |
| 206 | } |
| 207 | }); |
| 208 | }); |
| 209 | |
| 210 | /** |
| 211 | * Confirmation for deleting Topic |
| 212 | */ |
| 213 | $(document).on('click', '.topic-delete-btn a', function(e){ |
| 214 | var topic_id = $(this).attr('data-topic-id'); |
| 215 | |
| 216 | if ( ! confirm('Are you sure to delete?')){ |
| 217 | e.preventDefault(); |
| 218 | } |
| 219 | }); |
| 220 | |
| 221 | $(document).on('click', '.tutor-expand-all-topic', function (e) { |
| 222 | e.preventDefault(); |
| 223 | $('.tutor-topics-body').slideDown(); |
| 224 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up'); |
| 225 | }); |
| 226 | $(document).on('click', '.tutor-collapse-all-topic', function (e) { |
| 227 | e.preventDefault(); |
| 228 | $('.tutor-topics-body').slideUp(); |
| 229 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down'); |
| 230 | }); |
| 231 | $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) { |
| 232 | e.preventDefault(); |
| 233 | var $that = $(this); |
| 234 | $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle(); |
| 235 | $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up'); |
| 236 | }); |
| 237 | |
| 238 | /** |
| 239 | * Update Lesson Modal |
| 240 | */ |
| 241 | $(document).on('click', '.open-tutor-lesson-modal', function(e){ |
| 242 | e.preventDefault(); |
| 243 | |
| 244 | var $that = $(this); |
| 245 | var lesson_id = $that.attr('data-lesson-id'); |
| 246 | var topic_id = $that.attr('data-topic-id'); |
| 247 | var course_id = $('#post_ID').val(); |
| 248 | |
| 249 | $.ajax({ |
| 250 | url : ajaxurl, |
| 251 | type : 'POST', |
| 252 | data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'}, |
| 253 | beforeSend: function () { |
| 254 | $that.addClass('tutor-updating-message'); |
| 255 | }, |
| 256 | success: function (data) { |
| 257 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 258 | $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show'); |
| 259 | |
| 260 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 261 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' ); |
| 262 | tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor"); |
| 263 | }, |
| 264 | complete: function () { |
| 265 | quicktags({id : "tutor_lesson_modal_editor"}); |
| 266 | $that.removeClass('tutor-updating-message'); |
| 267 | } |
| 268 | }); |
| 269 | }); |
| 270 | |
| 271 | $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){ |
| 272 | event.preventDefault(); |
| 273 | var $that = $(this); |
| 274 | var frame; |
| 275 | if ( frame ) { |
| 276 | frame.open(); |
| 277 | return; |
| 278 | } |
| 279 | frame = wp.media({ |
| 280 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 281 | button: { |
| 282 | text: 'Use this media' |
| 283 | }, |
| 284 | multiple: false |
| 285 | }); |
| 286 | frame.on( 'select', function() { |
| 287 | var attachment = frame.state().get('selection').first().toJSON(); |
| 288 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html('<img src="'+attachment.url+'" alt="" />'); |
| 289 | $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id); |
| 290 | }); |
| 291 | frame.open(); |
| 292 | }); |
| 293 | |
| 294 | /** |
| 295 | * Delete Lesson from course builder |
| 296 | */ |
| 297 | $(document).on('click', '.tutor-delete-lesson-btn', function(e){ |
| 298 | e.preventDefault(); |
| 299 | |
| 300 | if( ! confirm('Are you sure?')){ |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | var $that = $(this); |
| 305 | var lesson_id = $that.attr('data-lesson-id'); |
| 306 | |
| 307 | $.ajax({ |
| 308 | url : ajaxurl, |
| 309 | type : 'POST', |
| 310 | data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'}, |
| 311 | beforeSend: function () { |
| 312 | $that.addClass('tutor-updating-message'); |
| 313 | }, |
| 314 | success: function (data) { |
| 315 | if (data.success){ |
| 316 | $that.closest('.tutor-lesson').remove(); |
| 317 | } |
| 318 | }, |
| 319 | complete: function () { |
| 320 | $that.removeClass('tutor-updating-message'); |
| 321 | } |
| 322 | }); |
| 323 | }); |
| 324 | |
| 325 | /** |
| 326 | * Delete quiz |
| 327 | */ |
| 328 | $(document).on('click', '.tutor-delete-quiz-btn', function(e){ |
| 329 | e.preventDefault(); |
| 330 | |
| 331 | if( ! confirm('Are you sure?')){ |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | var $that = $(this); |
| 336 | var quiz_id = $that.attr('data-quiz-id'); |
| 337 | |
| 338 | $.ajax({ |
| 339 | url : ajaxurl, |
| 340 | type : 'POST', |
| 341 | data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'}, |
| 342 | beforeSend: function () { |
| 343 | $that.closest('.course-content-item').remove(); |
| 344 | } |
| 345 | }); |
| 346 | }); |
| 347 | |
| 348 | /** |
| 349 | * Lesson Update or Create Modal |
| 350 | */ |
| 351 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 352 | event.preventDefault(); |
| 353 | |
| 354 | var $that = $(this); |
| 355 | var content; |
| 356 | var inputid = 'tutor_lesson_modal_editor'; |
| 357 | var editor = tinyMCE.get(inputid); |
| 358 | if (editor) { |
| 359 | content = editor.getContent(); |
| 360 | } else { |
| 361 | content = $('#'+inputid).val(); |
| 362 | } |
| 363 | |
| 364 | var form_data = $(this).closest('form').serialize(); |
| 365 | form_data += '&lesson_content='+content; |
| 366 | |
| 367 | $.ajax({ |
| 368 | url : ajaxurl, |
| 369 | type : 'POST', |
| 370 | data : form_data, |
| 371 | beforeSend: function () { |
| 372 | $that.addClass('tutor-updating-message'); |
| 373 | }, |
| 374 | success: function (data) { |
| 375 | if (data.success){ |
| 376 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 377 | enable_sorting_topic_lesson(); |
| 378 | |
| 379 | //Close the modal |
| 380 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 381 | } |
| 382 | }, |
| 383 | complete: function () { |
| 384 | $that.removeClass('tutor-updating-message'); |
| 385 | } |
| 386 | }); |
| 387 | }); |
| 388 | |
| 389 | /** |
| 390 | * Lesson Video |
| 391 | */ |
| 392 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 393 | var selector = $(this).val(); |
| 394 | $('[class^="video_source_wrap"]').hide(); |
| 395 | $('.video_source_wrap_'+selector).show(); |
| 396 | |
| 397 | if (selector === 'html5'){ |
| 398 | $('.tutor-video-poster-field').show(); |
| 399 | } else{ |
| 400 | $('.tutor-video-poster-field').hide(); |
| 401 | } |
| 402 | }); |
| 403 | |
| 404 | $(document).on( 'click', '.video_source_wrap_html5 .video_upload_btn', function( event ){ |
| 405 | event.preventDefault(); |
| 406 | |
| 407 | var $that = $(this); |
| 408 | var frame; |
| 409 | // If the media frame already exists, reopen it. |
| 410 | if ( frame ) { |
| 411 | frame.open(); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | // Create a new media frame |
| 416 | frame = wp.media({ |
| 417 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 418 | button: { |
| 419 | text: 'Use this media' |
| 420 | }, |
| 421 | multiple: false // Set to true to allow multiple files to be selected |
| 422 | }); |
| 423 | |
| 424 | // When an image is selected in the media frame... |
| 425 | frame.on( 'select', function() { |
| 426 | // Get media attachment details from the frame state |
| 427 | var attachment = frame.state().get('selection').first().toJSON(); |
| 428 | $that.closest('.video_source_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 429 | $that.closest('.video_source_wrap_html5').find('input').val(attachment.id); |
| 430 | }); |
| 431 | // Finally, open the modal on click |
| 432 | frame.open(); |
| 433 | }); |
| 434 | |
| 435 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 436 | e.preventDefault(); |
| 437 | $(this).closest('.tutor-added-attachment').remove(); |
| 438 | }); |
| 439 | |
| 440 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 441 | e.preventDefault(); |
| 442 | |
| 443 | var $that = $(this); |
| 444 | var frame; |
| 445 | // If the media frame already exists, reopen it. |
| 446 | if ( frame ) { |
| 447 | frame.open(); |
| 448 | return; |
| 449 | } |
| 450 | // Create a new media frame |
| 451 | frame = wp.media({ |
| 452 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 453 | button: { |
| 454 | text: 'Use this media' |
| 455 | }, |
| 456 | multiple: true // Set to true to allow multiple files to be selected |
| 457 | }); |
| 458 | // When an image is selected in the media frame... |
| 459 | frame.on( 'select', function() { |
| 460 | // Get media attachment details from the frame state |
| 461 | var attachments = frame.state().get('selection').toJSON(); |
| 462 | if (attachments.length){ |
| 463 | for (var i=0; i < attachments.length; i++){ |
| 464 | var attachment = attachments[i]; |
| 465 | |
| 466 | var inputHtml = '<div class="tutor-added-attachment"><i class="tutor-icon-archive"></i> <a href="javascript:;" class="tutor-delete-attachment tutor-icon-line-cross"></a> <span> <a href="'+attachment.url+'">'+attachment.filename+'</a> </span><input type="hidden" name="tutor_attachments[]" value="'+attachment.id+'"></div>'; |
| 467 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 468 | } |
| 469 | } |
| 470 | }); |
| 471 | // Finally, open the modal on click |
| 472 | frame.open(); |
| 473 | }); |
| 474 | |
| 475 | /** |
| 476 | * Open Sidebar Menu |
| 477 | */ |
| 478 | if (tutor_data.open_tutor_admin_menu){ |
| 479 | var $adminMenu = $('#adminmenu'); |
| 480 | $adminMenu.find('[href="admin.php?page=tutor"]').closest('li.wp-has-submenu').addClass('wp-has-current-submenu'); |
| 481 | $adminMenu.find('[href="admin.php?page=tutor"]').closest('li.wp-has-submenu').find('a.wp-has-submenu').removeClass('wp-has-current-submenu').addClass('wp-has-current-submenu'); |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Add question answer for quiz |
| 486 | */ |
| 487 | |
| 488 | $(document).on('change keyup paste', '.question_field_title', function(){ |
| 489 | var $that = $(this); |
| 490 | $that.closest('.single-question-item').find('.tutor-question-item-head').find('.question-title').text($that.val()); |
| 491 | }); |
| 492 | |
| 493 | $(document).on('change', '.question_type_field', function(){ |
| 494 | var $that = $(this); |
| 495 | var question_type = $that.val(); |
| 496 | |
| 497 | var option_text = $that.find('option[value="'+question_type+'"]').text(); |
| 498 | $that.closest('.single-question-item').find('.tutor-question-item-head').find('.question-type').text(option_text); |
| 499 | |
| 500 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 501 | var data = {question_id: question_id, question_type : question_type, action: 'quiz_question_type_changed'}; |
| 502 | |
| 503 | $.ajax({ |
| 504 | url : ajaxurl, |
| 505 | type : 'POST', |
| 506 | data : data, |
| 507 | beforeSend: function () { |
| 508 | $that.closest('.single-question-item').find('.tutor-loading-icon-wrap').addClass('tutor-updating-message'); |
| 509 | }, |
| 510 | success: function (data) { |
| 511 | if (data.success){ |
| 512 | $that.closest('.quiz-question-form-wrap').find('.answer-entry-wrap').html(data.data.multi_answer_options); |
| 513 | |
| 514 | if (question_type === 'true_false' && $('.answer-option-row').length >= 2){ |
| 515 | $('.add_answer_option_wrap').hide(); |
| 516 | }else{ |
| 517 | $('.add_answer_option_wrap').show(); |
| 518 | } |
| 519 | } |
| 520 | }, |
| 521 | complete: function () { |
| 522 | $that.closest('.single-question-item').find('.tutor-loading-icon-wrap').removeClass('tutor-updating-message'); |
| 523 | } |
| 524 | }); |
| 525 | }); |
| 526 | |
| 527 | $(document).on('click', '.add_answer_option_btn', function(e){ |
| 528 | e.preventDefault(); |
| 529 | |
| 530 | var $that = $(this); |
| 531 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 532 | var question_type = $that.closest('.quiz-question-form-wrap').find('select.question_type_field').val(); |
| 533 | var data = {question_id: question_id, action: 'quiz_add_answer_to_question'}; |
| 534 | |
| 535 | $.ajax({ |
| 536 | url : ajaxurl, |
| 537 | type : 'POST', |
| 538 | data : data, |
| 539 | beforeSend: function () { |
| 540 | $that.removeClass('updated-message').addClass('tutor-updating-message'); |
| 541 | }, |
| 542 | success: function (data) { |
| 543 | if (data.success){ |
| 544 | $that.closest('.answer-entry-wrap').find('table.multi-answers-options').append(data.data.data_tr); |
| 545 | |
| 546 | //Hide add answer button if true false and 2 option exists |
| 547 | if (question_type === 'true_false' && $that.closest('.answer-entry-wrap').find('tr.answer-option-row').length >= 2){ |
| 548 | $that.closest('.add_answer_option_wrap').hide(); |
| 549 | }else{ |
| 550 | $that.closest('.add_answer_option_wrap').show(); |
| 551 | } |
| 552 | } |
| 553 | }, |
| 554 | complete: function () { |
| 555 | $that.removeClass('tutor-updating-message').addClass('updated-message'); |
| 556 | } |
| 557 | }); |
| 558 | }); |
| 559 | |
| 560 | $(document).on('click', '.add_question_btn', function(e){ |
| 561 | e.preventDefault(); |
| 562 | |
| 563 | var $that = $(this); |
| 564 | var $title = $('[name="new_question_title"]'); |
| 565 | var question_title = $title.val(); |
| 566 | var question_type = $('[name="new_question_type"]').val(); |
| 567 | var quiz_id = $('#post_ID').val(); |
| 568 | |
| 569 | //If no question title, stop here |
| 570 | if ( ! question_title.length){ |
| 571 | $title.addClass('tutor-input-text-error'); |
| 572 | return; |
| 573 | }else{ |
| 574 | $title.removeClass('tutor-input-text-error'); |
| 575 | } |
| 576 | |
| 577 | var data = {question_title : question_title, question_type:question_type, quiz_id : quiz_id, action: 'quiz_page_add_new_question' }; |
| 578 | $.ajax({ |
| 579 | url : ajaxurl, |
| 580 | type : 'POST', |
| 581 | data : data, |
| 582 | beforeSend: function () { |
| 583 | $that.removeClass('updated-message').addClass('tutor-updating-message'); |
| 584 | }, |
| 585 | success: function (data) { |
| 586 | if (data.success){ |
| 587 | $('.single-question-item .quiz-question-form-wrap').hide(); |
| 588 | $('.tutor-quiz-questions-wrap').append(data.data.question_html); |
| 589 | $('.single-question-item:last-child .quiz-question-form-wrap').show(); |
| 590 | $title.val(''); |
| 591 | } |
| 592 | }, |
| 593 | complete: function () { |
| 594 | $that.removeClass('tutor-updating-message').addClass('updated-message'); |
| 595 | } |
| 596 | }); |
| 597 | }); |
| 598 | |
| 599 | //Show hide question settings |
| 600 | $(document).on('click', '.question-action-btn.down', function(e){ |
| 601 | e.preventDefault(); |
| 602 | $(this).closest('.single-question-item').find('.quiz-question-form-wrap').toggle(); |
| 603 | $(this).find('i.dashicons').toggleClass('dashicons-arrow-up-alt2 dashicons-arrow-down-alt2'); |
| 604 | }); |
| 605 | |
| 606 | $(document).on('change', '.single-question-item', function(e){ |
| 607 | e.preventDefault(); |
| 608 | |
| 609 | var $that = $(this); |
| 610 | var data = $(this).find("select, textarea, input").serialize()+'&action=update_tutor_question'; |
| 611 | $.ajax({ |
| 612 | url : ajaxurl, |
| 613 | type : 'POST', |
| 614 | data : data, |
| 615 | beforeSend: function () { |
| 616 | $that.find('.tutor-loading-icon-wrap').addClass('tutor-updating-message'); |
| 617 | }, |
| 618 | success: function (data) { |
| 619 | if (data.success){ |
| 620 | |
| 621 | } |
| 622 | }, |
| 623 | complete: function () { |
| 624 | $that.find('.tutor-loading-icon-wrap').removeClass('tutor-updating-message'); |
| 625 | } |
| 626 | }); |
| 627 | }); |
| 628 | |
| 629 | $(document).on('click', '.quiz-answer-option-delete-btn', function(e){ |
| 630 | e.preventDefault(); |
| 631 | var $that = $(this); |
| 632 | var $closestTable = $that.closest('table'); |
| 633 | var $loadingIcon = $that.closest('.single-question-item').find('.tutor-loading-icon-wrap'); |
| 634 | |
| 635 | var question_type = $that.closest('.quiz-question-form-wrap').find('select.question_type_field').val(); |
| 636 | var answer_option_id = $that.closest('tr').attr('data-answer-option-id'); |
| 637 | |
| 638 | $.ajax({ |
| 639 | url : ajaxurl, |
| 640 | type : 'POST', |
| 641 | data : {answer_option_id:answer_option_id, action: 'quiz_delete_answer_option'}, |
| 642 | beforeSend: function () { |
| 643 | $loadingIcon.addClass('tutor-updating-message'); |
| 644 | }, |
| 645 | success: function (data) { |
| 646 | if (data.success){ |
| 647 | $that.closest('tr').remove(); |
| 648 | //Hide add answer button if true false and 2 option exists |
| 649 | if (question_type === 'true_false' && $closestTable.find('tr.answer-option-row').length >= 2){ |
| 650 | $closestTable.closest('.answer-entry-wrap').find('.add_answer_option_wrap').hide(); |
| 651 | }else{ |
| 652 | $closestTable.closest('.answer-entry-wrap').find('.add_answer_option_wrap').show(); |
| 653 | } |
| 654 | } |
| 655 | }, |
| 656 | complete: function () { |
| 657 | $loadingIcon.removeClass('tutor-updating-message'); |
| 658 | } |
| 659 | }); |
| 660 | }); |
| 661 | |
| 662 | $(document).on('click', '.question-action-btn.trash', function(e){ |
| 663 | e.preventDefault(); |
| 664 | |
| 665 | var $that = $(this); |
| 666 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 667 | var $loadingIcon = $that.closest('.single-question-item').find('.tutor-loading-icon-wrap'); |
| 668 | |
| 669 | $.ajax({ |
| 670 | url : ajaxurl, |
| 671 | type : 'POST', |
| 672 | data : {question_id:question_id, action: 'quiz_question_delete'}, |
| 673 | beforeSend: function () { |
| 674 | $loadingIcon.addClass('tutor-updating-message'); |
| 675 | }, |
| 676 | success: function (data) { |
| 677 | if (data.success){ |
| 678 | $that.closest('.single-question-item').remove(); |
| 679 | } |
| 680 | }, |
| 681 | complete: function () { |
| 682 | $loadingIcon.removeClass('tutor-updating-message'); |
| 683 | } |
| 684 | }); |
| 685 | }); |
| 686 | |
| 687 | /** |
| 688 | * Sort quiz questions |
| 689 | */ |
| 690 | |
| 691 | if (jQuery().sortable) { |
| 692 | $(".tutor-quiz-questions-wrap").sortable({ |
| 693 | handle: ".question-short", |
| 694 | start: function (e, ui) { |
| 695 | ui.placeholder.css('visibility', 'visible'); |
| 696 | }, |
| 697 | stop: function (e, ui) { |
| 698 | var questions = {}; |
| 699 | $('.single-question-item').each(function(index, item){ |
| 700 | var $question = $(this); |
| 701 | var question_id = parseInt($question.attr('data-question-id').match(/\d+/)[0], 10); |
| 702 | questions[index] = { 'question_id' : question_id }; |
| 703 | }); |
| 704 | |
| 705 | $.post(ajaxurl, {questions : questions, action: 'sorting_quiz_questions'}); |
| 706 | }, |
| 707 | }); |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * Quiz Modal |
| 712 | */ |
| 713 | |
| 714 | $(document).on('click', '.modal-close-btn', function(e){ |
| 715 | e.preventDefault(); |
| 716 | $('.tutor-modal-wrap').removeClass('show'); |
| 717 | }); |
| 718 | $(document).on('keyup', function(e){ |
| 719 | if (e.keyCode === 27){ |
| 720 | $('.tutor-modal-wrap').removeClass('show'); |
| 721 | } |
| 722 | }); |
| 723 | |
| 724 | $(document).on('click', '.tutor-add-quiz-btn', function(e){ |
| 725 | e.preventDefault(); |
| 726 | |
| 727 | var $that = $(this); |
| 728 | var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under'); |
| 729 | $.ajax({ |
| 730 | url : ajaxurl, |
| 731 | type : 'POST', |
| 732 | data : {quiz_for_post_id : quiz_for_post_id, action: 'tutor_load_quiz_builder_modal'}, |
| 733 | beforeSend: function () { |
| 734 | $that.addClass('tutor-updating-message'); |
| 735 | }, |
| 736 | success: function (data) { |
| 737 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 738 | $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show'); |
| 739 | }, |
| 740 | complete: function () { |
| 741 | $that.removeClass('tutor-updating-message'); |
| 742 | } |
| 743 | }); |
| 744 | }); |
| 745 | |
| 746 | /** |
| 747 | * Quiz Builder Modal Tabs |
| 748 | */ |
| 749 | $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){ |
| 750 | e.preventDefault(); |
| 751 | |
| 752 | var $that = $(this); |
| 753 | |
| 754 | var $quizTitle = $('[name="quiz_title"]'); |
| 755 | var quiz_title = $quizTitle.val(); |
| 756 | if ( ! quiz_title){ |
| 757 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' + |
| 758 | ' first</p>'); |
| 759 | return; |
| 760 | }else{ |
| 761 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html(''); |
| 762 | } |
| 763 | |
| 764 | var tabSelector = $that.attr('href'); |
| 765 | $('.quiz-builder-tab-container').hide(); |
| 766 | $(tabSelector).show(); |
| 767 | |
| 768 | $('a.tutor-quiz-modal-tab-item').removeClass('active'); |
| 769 | $that.addClass('active'); |
| 770 | }); |
| 771 | |
| 772 | //Next Prev Tab |
| 773 | $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){ |
| 774 | e.preventDefault(); |
| 775 | |
| 776 | var tabSelector = $(this).attr('href'); |
| 777 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 778 | }); |
| 779 | |
| 780 | $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){ |
| 781 | e.preventDefault(); |
| 782 | $('.tutor-modal-wrap').removeClass('show'); |
| 783 | }); |
| 784 | |
| 785 | $(document).on('click', '.quiz-modal-btn-first-step', function(e){ |
| 786 | e.preventDefault(); |
| 787 | |
| 788 | var $that = $(this); |
| 789 | var $quizTitle = $('[name="quiz_title"]'); |
| 790 | var quiz_title = $quizTitle.val(); |
| 791 | var quiz_description = $('[name="quiz_description"]').val(); |
| 792 | |
| 793 | if ( ! quiz_title){ |
| 794 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title'); |
| 795 | return; |
| 796 | }else{ |
| 797 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html(''); |
| 798 | } |
| 799 | |
| 800 | |
| 801 | |
| 802 | var course_id = $('#post_ID').val(); |
| 803 | var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id'); |
| 804 | |
| 805 | |
| 806 | if ($('#tutor_quiz_builder_quiz_id').length) { |
| 807 | /** |
| 808 | * |
| 809 | * @type {jQuery} |
| 810 | * |
| 811 | * if quiz id exists, we are sending it to update quiz |
| 812 | */ |
| 813 | |
| 814 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 815 | $.ajax({ |
| 816 | url : ajaxurl, |
| 817 | type : 'POST', |
| 818 | data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'}, |
| 819 | beforeSend: function () { |
| 820 | $that.addClass('tutor-updating-message'); |
| 821 | }, |
| 822 | success: function (data) { |
| 823 | $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row); |
| 824 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 825 | }, |
| 826 | complete: function () { |
| 827 | $that.removeClass('tutor-updating-message'); |
| 828 | } |
| 829 | }); |
| 830 | |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | $.ajax({ |
| 835 | url : ajaxurl, |
| 836 | type : 'POST', |
| 837 | data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'}, |
| 838 | beforeSend: function () { |
| 839 | $that.addClass('tutor-updating-message'); |
| 840 | }, |
| 841 | success: function (data) { |
| 842 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 843 | $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row); |
| 844 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 845 | }, |
| 846 | complete: function () { |
| 847 | $that.removeClass('tutor-updating-message'); |
| 848 | } |
| 849 | }); |
| 850 | |
| 851 | }); |
| 852 | |
| 853 | /** |
| 854 | * Ope modal for edit quiz |
| 855 | */ |
| 856 | $(document).on('click', '.open-tutor-quiz-modal', function(e){ |
| 857 | e.preventDefault(); |
| 858 | |
| 859 | var $that = $(this); |
| 860 | var quiz_id = $that.attr('data-quiz-id'); |
| 861 | var topic_id = $that.attr('data-topic-id'); |
| 862 | var course_id = $('#post_ID').val(); |
| 863 | |
| 864 | $.ajax({ |
| 865 | url : ajaxurl, |
| 866 | type : 'POST', |
| 867 | data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'}, |
| 868 | beforeSend: function () { |
| 869 | $that.addClass('tutor-updating-message'); |
| 870 | }, |
| 871 | success: function (data) { |
| 872 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 873 | $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).addClass('show'); |
| 874 | |
| 875 | //Back to question Tab if exists |
| 876 | if ($that.attr('data-back-to-tab')){ |
| 877 | var tabSelector = $that.attr('data-back-to-tab'); |
| 878 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 879 | } |
| 880 | tutor_slider_init(); |
| 881 | enable_quiz_questions_sorting(); |
| 882 | }, |
| 883 | complete: function () { |
| 884 | $that.removeClass('tutor-updating-message'); |
| 885 | } |
| 886 | }); |
| 887 | }); |
| 888 | |
| 889 | |
| 890 | $(document).on('click', '.quiz-modal-settings-save-btn', function(e){ |
| 891 | e.preventDefault(); |
| 892 | |
| 893 | var $that = $(this); |
| 894 | var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id'); |
| 895 | |
| 896 | var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serialize()+'&quiz_id='+quiz_id+'&action=tutor_quiz_modal_update_settings'; |
| 897 | |
| 898 | $.ajax({ |
| 899 | url : ajaxurl, |
| 900 | type : 'POST', |
| 901 | data : $formInput, |
| 902 | beforeSend: function () { |
| 903 | $that.addClass('tutor-updating-message'); |
| 904 | }, |
| 905 | success: function (data) { |
| 906 | // |
| 907 | }, |
| 908 | complete: function () { |
| 909 | $that.removeClass('tutor-updating-message'); |
| 910 | if ($that.attr('data-action') === 'modal_close'){ |
| 911 | $('.tutor-modal-wrap').removeClass('show'); |
| 912 | } |
| 913 | } |
| 914 | }); |
| 915 | }); |
| 916 | |
| 917 | |
| 918 | /** |
| 919 | * Add Question to quiz modal |
| 920 | */ |
| 921 | $(document).on('click', '.tutor-quiz-open-question-form', function(e){ |
| 922 | e.preventDefault(); |
| 923 | |
| 924 | var $that = $(this); |
| 925 | |
| 926 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 927 | var course_id = $('#post_ID').val(); |
| 928 | var question_id = $that.attr('data-question-id'); |
| 929 | |
| 930 | |
| 931 | var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'}; |
| 932 | |
| 933 | if (question_id) { |
| 934 | params.question_id = question_id; |
| 935 | } |
| 936 | |
| 937 | $.ajax({ |
| 938 | url : ajaxurl, |
| 939 | type : 'POST', |
| 940 | data : params, |
| 941 | beforeSend: function () { |
| 942 | $that.addClass('tutor-updating-message'); |
| 943 | }, |
| 944 | success: function (data) { |
| 945 | $('.tutor-quiz-builder-modal-contents').html(data.data.output); |
| 946 | |
| 947 | //Initializing Tutor Select |
| 948 | tutor_select().reInit(); |
| 949 | enable_quiz_answer_sorting(); |
| 950 | }, |
| 951 | complete: function () { |
| 952 | $that.removeClass('tutor-updating-message'); |
| 953 | } |
| 954 | }); |
| 955 | |
| 956 | }); |
| 957 | |
| 958 | $(document).on('click', '.quiz-modal-question-save-btn', function(e){ |
| 959 | e.preventDefault(); |
| 960 | |
| 961 | var $that = $(this); |
| 962 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_quiz_modal_update_question'; |
| 963 | $.ajax({ |
| 964 | url : ajaxurl, |
| 965 | type : 'POST', |
| 966 | data : $formInput, |
| 967 | beforeSend: function () { |
| 968 | $that.addClass('tutor-updating-message'); |
| 969 | }, |
| 970 | success: function (data) { |
| 971 | //ReOpen questions |
| 972 | $that.closest('.quiz-questions-form').find('.open-tutor-quiz-modal').trigger('click'); |
| 973 | }, |
| 974 | complete: function () { |
| 975 | $that.removeClass('tutor-updating-message'); |
| 976 | } |
| 977 | }); |
| 978 | }); |
| 979 | |
| 980 | $(document).on('click', '.tutor-quiz-question-trash', function(e){ |
| 981 | e.preventDefault(); |
| 982 | |
| 983 | var $that = $(this); |
| 984 | var question_id = $that.attr('data-question-id'); |
| 985 | |
| 986 | $.ajax({ |
| 987 | url : ajaxurl, |
| 988 | type : 'POST', |
| 989 | data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'}, |
| 990 | beforeSend: function () { |
| 991 | $that.closest('.quiz-builder-question-wrap').remove(); |
| 992 | }, |
| 993 | }); |
| 994 | }); |
| 995 | |
| 996 | /** |
| 997 | * Get question answers option form to save multiple/single/true-false options |
| 998 | * |
| 999 | * @since v.1.0.0 |
| 1000 | */ |
| 1001 | |
| 1002 | $(document).on('click', '.add_question_answers_option', function(e){ |
| 1003 | e.preventDefault(); |
| 1004 | |
| 1005 | var $that = $(this); |
| 1006 | var question_id = $that.attr('data-question-id'); |
| 1007 | var $formInput = $('.quiz_question_form :input').serialize()+'&question_id='+question_id+'&action=tutor_quiz_add_question_answers'; |
| 1008 | |
| 1009 | $.ajax({ |
| 1010 | url : ajaxurl, |
| 1011 | type : 'POST', |
| 1012 | data : $formInput, |
| 1013 | beforeSend: function () { |
| 1014 | $that.addClass('tutor-updating-message'); |
| 1015 | }, |
| 1016 | success: function (data) { |
| 1017 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 1018 | }, |
| 1019 | complete: function () { |
| 1020 | $that.removeClass('tutor-updating-message'); |
| 1021 | } |
| 1022 | }); |
| 1023 | }); |
| 1024 | |
| 1025 | /** |
| 1026 | * Get question answers option edit form |
| 1027 | * |
| 1028 | * @since v.1.0.0 |
| 1029 | */ |
| 1030 | $(document).on('click', '.tutor-quiz-answer-edit a', function(e){ |
| 1031 | e.preventDefault(); |
| 1032 | |
| 1033 | var $that = $(this); |
| 1034 | var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id'); |
| 1035 | |
| 1036 | $.ajax({ |
| 1037 | url : ajaxurl, |
| 1038 | type : 'POST', |
| 1039 | data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'}, |
| 1040 | beforeSend: function () { |
| 1041 | $that.addClass('tutor-updating-message'); |
| 1042 | }, |
| 1043 | success: function (data) { |
| 1044 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 1045 | }, |
| 1046 | complete: function () { |
| 1047 | $that.removeClass('tutor-updating-message'); |
| 1048 | } |
| 1049 | }); |
| 1050 | }); |
| 1051 | |
| 1052 | |
| 1053 | /** |
| 1054 | * Saving question answers options |
| 1055 | * Student should select the right answer at quiz attempts |
| 1056 | * |
| 1057 | * @since v.1.0.0 |
| 1058 | */ |
| 1059 | |
| 1060 | $(document).on('click', '#quiz-answer-save-btn', function(e){ |
| 1061 | e.preventDefault(); |
| 1062 | |
| 1063 | var $that = $(this); |
| 1064 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_save_quiz_answer_options'; |
| 1065 | |
| 1066 | $.ajax({ |
| 1067 | url : ajaxurl, |
| 1068 | type : 'POST', |
| 1069 | data : $formInput, |
| 1070 | beforeSend: function () { |
| 1071 | $that.addClass('tutor-updating-message'); |
| 1072 | }, |
| 1073 | success: function (data) { |
| 1074 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 1075 | }, |
| 1076 | complete: function () { |
| 1077 | $that.removeClass('tutor-updating-message'); |
| 1078 | } |
| 1079 | }); |
| 1080 | }); |
| 1081 | |
| 1082 | /** |
| 1083 | * Updating Answer |
| 1084 | * |
| 1085 | * @since v.1.0.0 |
| 1086 | */ |
| 1087 | $(document).on('click', '#quiz-answer-edit-btn', function(e){ |
| 1088 | e.preventDefault(); |
| 1089 | |
| 1090 | var $that = $(this); |
| 1091 | var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_update_quiz_answer_options'; |
| 1092 | |
| 1093 | $.ajax({ |
| 1094 | url : ajaxurl, |
| 1095 | type : 'POST', |
| 1096 | data : $formInput, |
| 1097 | beforeSend: function () { |
| 1098 | $that.addClass('tutor-updating-message'); |
| 1099 | }, |
| 1100 | success: function (data) { |
| 1101 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 1102 | }, |
| 1103 | complete: function () { |
| 1104 | $that.removeClass('tutor-updating-message'); |
| 1105 | } |
| 1106 | }); |
| 1107 | }); |
| 1108 | |
| 1109 | $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){ |
| 1110 | e.preventDefault(); |
| 1111 | |
| 1112 | var $that = $(this); |
| 1113 | |
| 1114 | var answer_id = $that.val(); |
| 1115 | var inputValue = 1; |
| 1116 | if ( ! $that.prop('checked')) { |
| 1117 | inputValue = 0; |
| 1118 | } |
| 1119 | |
| 1120 | $.ajax({ |
| 1121 | url : ajaxurl, |
| 1122 | type : 'POST', |
| 1123 | data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'}, |
| 1124 | }); |
| 1125 | }); |
| 1126 | |
| 1127 | |
| 1128 | $(document).on('refresh', '#tutor_quiz_question_answers', function(e){ |
| 1129 | e.preventDefault(); |
| 1130 | |
| 1131 | var $that = $(this); |
| 1132 | var question_id = $that.attr('data-question-id'); |
| 1133 | var question_type = $('.tutor_select_value_holder').val(); |
| 1134 | |
| 1135 | $.ajax({ |
| 1136 | url : ajaxurl, |
| 1137 | type : 'POST', |
| 1138 | data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'}, |
| 1139 | beforeSend: function () { |
| 1140 | $that.addClass('tutor-updating-message'); |
| 1141 | $('#tutor_quiz_question_answer_form').html(''); |
| 1142 | }, |
| 1143 | success: function (data) { |
| 1144 | if (data.success){ |
| 1145 | $that.html(data.data.output); |
| 1146 | } |
| 1147 | }, |
| 1148 | complete: function () { |
| 1149 | $that.removeClass('tutor-updating-message'); |
| 1150 | } |
| 1151 | }); |
| 1152 | }); |
| 1153 | |
| 1154 | /** |
| 1155 | * Delete answer for a question in quiz builder |
| 1156 | * |
| 1157 | * @since v.1.0.0 |
| 1158 | */ |
| 1159 | |
| 1160 | $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){ |
| 1161 | e.preventDefault(); |
| 1162 | |
| 1163 | var $that = $(this); |
| 1164 | var answer_id = $that.attr('data-answer-id'); |
| 1165 | |
| 1166 | $.ajax({ |
| 1167 | url : ajaxurl, |
| 1168 | type : 'POST', |
| 1169 | data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'}, |
| 1170 | beforeSend: function () { |
| 1171 | $that.closest('.tutor-quiz-answer-wrap').remove(); |
| 1172 | }, |
| 1173 | }); |
| 1174 | }); |
| 1175 | |
| 1176 | /** |
| 1177 | * Sort quiz questions |
| 1178 | */ |
| 1179 | function enable_quiz_questions_sorting(){ |
| 1180 | if (jQuery().sortable) { |
| 1181 | $(".quiz-builder-questions-wrap").sortable({ |
| 1182 | handle: ".question-sorting", |
| 1183 | start: function (e, ui) { |
| 1184 | ui.placeholder.css('visibility', 'visible'); |
| 1185 | }, |
| 1186 | stop: function (e, ui) { |
| 1187 | tutor_save_sorting_quiz_questions_order(); |
| 1188 | }, |
| 1189 | }); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | function tutor_save_sorting_quiz_questions_order(){ |
| 1194 | var questions = {}; |
| 1195 | $('.quiz-builder-question-wrap').each(function(index, item){ |
| 1196 | var $question = $(this); |
| 1197 | var question_id = parseInt($question.attr('data-question-id'), 10); |
| 1198 | questions[index] = question_id; |
| 1199 | }); |
| 1200 | |
| 1201 | $.ajax({url : ajaxurl, type : 'POST', |
| 1202 | data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'}, |
| 1203 | }); |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Save answer sorting placement |
| 1208 | * |
| 1209 | * @since v.1.0.0 |
| 1210 | */ |
| 1211 | function enable_quiz_answer_sorting(){ |
| 1212 | if (jQuery().sortable) { |
| 1213 | $("#tutor_quiz_question_answers").sortable({ |
| 1214 | handle: ".tutor-quiz-answer-sort-icon", |
| 1215 | start: function (e, ui) { |
| 1216 | ui.placeholder.css('visibility', 'visible'); |
| 1217 | }, |
| 1218 | stop: function (e, ui) { |
| 1219 | tutor_save_sorting_quiz_answer_order(); |
| 1220 | }, |
| 1221 | }); |
| 1222 | } |
| 1223 | } |
| 1224 | function tutor_save_sorting_quiz_answer_order(){ |
| 1225 | var answers = {}; |
| 1226 | $('.tutor-quiz-answer-wrap').each(function(index, item){ |
| 1227 | var $answer = $(this); |
| 1228 | var answer_id = parseInt($answer.attr('data-answer-id'), 10); |
| 1229 | answers[index] = answer_id; |
| 1230 | }); |
| 1231 | |
| 1232 | $.ajax({url : ajaxurl, type : 'POST', |
| 1233 | data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'}, |
| 1234 | }); |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | $(document).on('change keyup', '.tutor-quiz-modal-wrap .tutor-modal-search-input', function(e){ |
| 1239 | e.preventDefault(); |
| 1240 | |
| 1241 | var $that = $(this); |
| 1242 | var $modal = $('.tutor-modal-wrap'); |
| 1243 | |
| 1244 | tutor_delay(function(){ |
| 1245 | var search_terms = $that.val(); |
| 1246 | var quiz_for_post_id = $modal.attr('quiz-for-post-id'); |
| 1247 | |
| 1248 | $.ajax({ |
| 1249 | url : ajaxurl, |
| 1250 | type : 'POST', |
| 1251 | data : {quiz_for_post_id : quiz_for_post_id, search_terms : search_terms, action: 'tutor_load_quiz_modal'}, |
| 1252 | beforeSend: function () { |
| 1253 | $modal.addClass('loading'); |
| 1254 | }, |
| 1255 | success: function (data) { |
| 1256 | if (data.success){ |
| 1257 | $('.tutor-modal-wrap .modal-container').html(data.data.output); |
| 1258 | } |
| 1259 | }, |
| 1260 | complete: function () { |
| 1261 | $modal.removeClass('loading'); |
| 1262 | } |
| 1263 | }); |
| 1264 | |
| 1265 | }, 1000) |
| 1266 | }); |
| 1267 | |
| 1268 | var tutor_delay = (function(){ |
| 1269 | var timer = 0; |
| 1270 | return function(callback, ms){ |
| 1271 | clearTimeout (timer); |
| 1272 | timer = setTimeout(callback, ms); |
| 1273 | }; |
| 1274 | })(); |
| 1275 | |
| 1276 | $(document).on('click', '.tutor-quiz-delete-btn', function(e){ |
| 1277 | e.preventDefault(); |
| 1278 | |
| 1279 | var $that = $(this); |
| 1280 | var quiz_id = $that.closest('.added-quiz-item').attr('data-quiz-id'); |
| 1281 | |
| 1282 | $.ajax({ |
| 1283 | url : ajaxurl, |
| 1284 | type : 'POST', |
| 1285 | data : {quiz_id:quiz_id, action: 'remove_quiz_from_post'}, |
| 1286 | success: function (data) { |
| 1287 | if (data.success){ |
| 1288 | $that.closest('.added-quiz-item').remove(); |
| 1289 | } |
| 1290 | } |
| 1291 | }); |
| 1292 | }); |
| 1293 | |
| 1294 | /** |
| 1295 | * Add instructor modal |
| 1296 | */ |
| 1297 | $(document).on('click', '.tutor-add-instructor-btn', function(e){ |
| 1298 | e.preventDefault(); |
| 1299 | |
| 1300 | var $that = $(this); |
| 1301 | var course_id = $('#post_ID').val(); |
| 1302 | |
| 1303 | $.ajax({ |
| 1304 | url : ajaxurl, |
| 1305 | type : 'POST', |
| 1306 | data : {course_id : course_id, action: 'tutor_load_instructors_modal'}, |
| 1307 | beforeSend: function () { |
| 1308 | $that.addClass('tutor-updating-message'); |
| 1309 | }, |
| 1310 | success: function (data) { |
| 1311 | if (data.success){ |
| 1312 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1313 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1314 | } |
| 1315 | }, |
| 1316 | complete: function () { |
| 1317 | $that.removeClass('tutor-updating-message'); |
| 1318 | } |
| 1319 | }); |
| 1320 | }); |
| 1321 | |
| 1322 | $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){ |
| 1323 | e.preventDefault(); |
| 1324 | |
| 1325 | var $that = $(this); |
| 1326 | var $modal = $('.tutor-modal-wrap'); |
| 1327 | |
| 1328 | tutor_delay(function(){ |
| 1329 | var search_terms = $that.val(); |
| 1330 | var course_id = $('#post_ID').val(); |
| 1331 | |
| 1332 | $.ajax({ |
| 1333 | url : ajaxurl, |
| 1334 | type : 'POST', |
| 1335 | data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'}, |
| 1336 | beforeSend: function () { |
| 1337 | $modal.addClass('loading'); |
| 1338 | }, |
| 1339 | success: function (data) { |
| 1340 | if (data.success){ |
| 1341 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1342 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1343 | } |
| 1344 | }, |
| 1345 | complete: function () { |
| 1346 | $modal.removeClass('loading'); |
| 1347 | } |
| 1348 | }); |
| 1349 | |
| 1350 | }, 1000) |
| 1351 | }); |
| 1352 | $(document).on('click', '.add_instructor_to_course_btn', function(e){ |
| 1353 | e.preventDefault(); |
| 1354 | |
| 1355 | var $that = $(this); |
| 1356 | var $modal = $('.tutor-modal-wrap'); |
| 1357 | var course_id = $('#post_ID').val(); |
| 1358 | var data = $modal.find('input').serialize()+'&course_id='+course_id+'&action=tutor_add_instructors_to_course'; |
| 1359 | |
| 1360 | $.ajax({ |
| 1361 | url : ajaxurl, |
| 1362 | type : 'POST', |
| 1363 | data : data, |
| 1364 | beforeSend: function () { |
| 1365 | $that.addClass('tutor-updating-message'); |
| 1366 | }, |
| 1367 | success: function (data) { |
| 1368 | if (data.success){ |
| 1369 | $('.tutor-course-available-instructors').html(data.data.output); |
| 1370 | $('.tutor-modal-wrap').removeClass('show'); |
| 1371 | } |
| 1372 | }, |
| 1373 | complete: function () { |
| 1374 | $that.removeClass('tutor-updating-message'); |
| 1375 | } |
| 1376 | }); |
| 1377 | }); |
| 1378 | |
| 1379 | $(document).on('click', '.tutor-instructor-delete-btn', function(e){ |
| 1380 | e.preventDefault(); |
| 1381 | |
| 1382 | var $that = $(this); |
| 1383 | var course_id = $('#post_ID').val(); |
| 1384 | var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id'); |
| 1385 | |
| 1386 | $.ajax({ |
| 1387 | url : ajaxurl, |
| 1388 | type : 'POST', |
| 1389 | data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'}, |
| 1390 | success: function (data) { |
| 1391 | if (data.success){ |
| 1392 | $that.closest('.added-instructor-item').remove(); |
| 1393 | } |
| 1394 | } |
| 1395 | }); |
| 1396 | }); |
| 1397 | |
| 1398 | $(document).on('click', '.tutor-option-media-upload-btn', function(e){ |
| 1399 | e.preventDefault(); |
| 1400 | |
| 1401 | var $that = $(this); |
| 1402 | var frame; |
| 1403 | if ( frame ) { |
| 1404 | frame.open(); |
| 1405 | return; |
| 1406 | } |
| 1407 | frame = wp.media({ |
| 1408 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1409 | button: { |
| 1410 | text: 'Use this media' |
| 1411 | }, |
| 1412 | multiple: false |
| 1413 | }); |
| 1414 | frame.on( 'select', function() { |
| 1415 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1416 | $that.closest('.option-media-wrap').find('.option-media-preview').html('<img src="'+attachment.url+'" alt="" />'); |
| 1417 | $that.closest('.option-media-wrap').find('input').val(attachment.id); |
| 1418 | }); |
| 1419 | frame.open(); |
| 1420 | }); |
| 1421 | |
| 1422 | $(document).on('change', '.tutor_addons_list_item', function(e) { |
| 1423 | var $that = $(this); |
| 1424 | |
| 1425 | var isEnable = $that.prop('checked') ? 1 : 0; |
| 1426 | var addonFieldName = $that.attr('name'); |
| 1427 | |
| 1428 | $.ajax({ |
| 1429 | url : ajaxurl, |
| 1430 | type : 'POST', |
| 1431 | data : {isEnable:isEnable, addonFieldName:addonFieldName, action : 'addon_enable_disable'}, |
| 1432 | success: function (data) { |
| 1433 | if (data.success){ |
| 1434 | //Success |
| 1435 | } |
| 1436 | } |
| 1437 | }); |
| 1438 | }); |
| 1439 | |
| 1440 | /** |
| 1441 | * Tutor Custom Select |
| 1442 | */ |
| 1443 | |
| 1444 | function tutor_select(){ |
| 1445 | var obj = { |
| 1446 | init : function(){ |
| 1447 | $(document).on('click', '.tutor-select .tutor-select-option', function(e){ |
| 1448 | e.preventDefault(); |
| 1449 | |
| 1450 | var $that = $(this); |
| 1451 | if ($that.attr('data-is-pro') !== 'true') { |
| 1452 | var $html = $that.html().trim(); |
| 1453 | $that.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 1454 | $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change'); |
| 1455 | $that.closest('.tutor-select-options').hide(); |
| 1456 | }else{ |
| 1457 | alert('Tutor Pro version required'); |
| 1458 | } |
| 1459 | }); |
| 1460 | $(document).on('click', '.tutor-select .select-header', function(e){ |
| 1461 | e.preventDefault(); |
| 1462 | |
| 1463 | var $that = $(this); |
| 1464 | $that.closest('.tutor-select').find('.tutor-select-options').slideToggle(); |
| 1465 | }); |
| 1466 | |
| 1467 | this.setValue(); |
| 1468 | this.hideOnOutSideClick(); |
| 1469 | }, |
| 1470 | setValue : function(){ |
| 1471 | $('.tutor-select').each(function(){ |
| 1472 | var $that = $(this); |
| 1473 | var $option = $that.find('.tutor-select-option'); |
| 1474 | |
| 1475 | if ($option.length){ |
| 1476 | $option.each(function(){ |
| 1477 | var $thisOption = $(this); |
| 1478 | |
| 1479 | if ($thisOption.attr('data-selected') === 'selected'){ |
| 1480 | var $html = $thisOption.html().trim(); |
| 1481 | $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 1482 | $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value')); |
| 1483 | } |
| 1484 | }); |
| 1485 | } |
| 1486 | }); |
| 1487 | }, |
| 1488 | hideOnOutSideClick : function(){ |
| 1489 | $(document).mouseup(function(e) { |
| 1490 | var $option_wrap = $(".tutor-select-options"); |
| 1491 | if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) { |
| 1492 | $option_wrap.hide(); |
| 1493 | } |
| 1494 | }); |
| 1495 | }, |
| 1496 | reInit : function(){ |
| 1497 | this.setValue(); |
| 1498 | } |
| 1499 | }; |
| 1500 | |
| 1501 | return obj; |
| 1502 | } |
| 1503 | tutor_select().init(); |
| 1504 | |
| 1505 | /** |
| 1506 | * If change question type from quiz builder question |
| 1507 | * |
| 1508 | * @since v.1.0.0 |
| 1509 | */ |
| 1510 | $(document).on('change', 'input.tutor_select_value_holder', function(e) { |
| 1511 | var $that = $(this); |
| 1512 | //$('#tutor_quiz_question_answer_form').html(''); |
| 1513 | $('.add_question_answers_option').trigger('click'); |
| 1514 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 1515 | }); |
| 1516 | |
| 1517 | $(document).on('click', '.tutor-media-upload-btn', function(e){ |
| 1518 | e.preventDefault(); |
| 1519 | |
| 1520 | var $that = $(this); |
| 1521 | var frame; |
| 1522 | if ( frame ) { |
| 1523 | frame.open(); |
| 1524 | return; |
| 1525 | } |
| 1526 | frame = wp.media({ |
| 1527 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1528 | button: { |
| 1529 | text: 'Use this media' |
| 1530 | }, |
| 1531 | multiple: false |
| 1532 | }); |
| 1533 | frame.on( 'select', function() { |
| 1534 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1535 | $that.html('<img src="'+attachment.url+'" alt="" />'); |
| 1536 | $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id); |
| 1537 | }); |
| 1538 | frame.open(); |
| 1539 | }); |
| 1540 | $(document).on('click', '.tutor-media-upload-trash', function(e){ |
| 1541 | e.preventDefault(); |
| 1542 | |
| 1543 | var $that = $(this); |
| 1544 | $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>'); |
| 1545 | $that.closest('.tutor-media-upload-wrap').find('input').val(''); |
| 1546 | }); |
| 1547 | |
| 1548 | /** |
| 1549 | * Add instructor |
| 1550 | * @since v.1.0.3 |
| 1551 | */ |
| 1552 | $(document).on('submit', '#new-instructor-form', function(e){ |
| 1553 | e.preventDefault(); |
| 1554 | |
| 1555 | var $that = $(this); |
| 1556 | var formData = $that.serialize()+'&action=tutor_add_instructor'; |
| 1557 | |
| 1558 | $.ajax({ |
| 1559 | url : ajaxurl, |
| 1560 | type : 'POST', |
| 1561 | data : formData, |
| 1562 | success: function (data) { |
| 1563 | if (data.success){ |
| 1564 | $that.trigger("reset"); |
| 1565 | $('#form-response').html('<p class="tutor-status-approved-context">'+data.data.msg+'</p>'); |
| 1566 | }else{ |
| 1567 | var errorMsg = ''; |
| 1568 | |
| 1569 | var errors = data.data.errors; |
| 1570 | if (errors && Object.keys(errors).length){ |
| 1571 | $.each(data.data.errors, function( index, value ) { |
| 1572 | if (isObject(value)){ |
| 1573 | |
| 1574 | $.each(value, function( key, value1 ) { |
| 1575 | errorMsg += '<p class="tutor-required-fields">'+value1[0]+'</p>'; |
| 1576 | }); |
| 1577 | } else{ |
| 1578 | errorMsg += '<p class="tutor-required-fields">'+value+'</p>'; |
| 1579 | } |
| 1580 | }); |
| 1581 | $('#form-response').html(errorMsg); |
| 1582 | } |
| 1583 | |
| 1584 | } |
| 1585 | } |
| 1586 | }); |
| 1587 | }); |
| 1588 | |
| 1589 | function isObject (value) { |
| 1590 | return value && typeof value === 'object' && value.constructor === Object; |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | /** |
| 1595 | * Tutor Assignments JS |
| 1596 | * @since v.1.3.3 |
| 1597 | */ |
| 1598 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 1599 | e.preventDefault(); |
| 1600 | |
| 1601 | var $that = $(this); |
| 1602 | var topic_id = $(this).attr('data-topic-id'); |
| 1603 | var course_id = $('#post_ID').val(); |
| 1604 | |
| 1605 | $.ajax({ |
| 1606 | url : ajaxurl, |
| 1607 | type : 'POST', |
| 1608 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1609 | beforeSend: function () { |
| 1610 | $that.addClass('tutor-updating-message'); |
| 1611 | }, |
| 1612 | success: function (data) { |
| 1613 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1614 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 1615 | |
| 1616 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 1617 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1618 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1619 | }, |
| 1620 | complete: function () { |
| 1621 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1622 | |
| 1623 | $that.removeClass('tutor-updating-message'); |
| 1624 | } |
| 1625 | }); |
| 1626 | }); |
| 1627 | |
| 1628 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 1629 | e.preventDefault(); |
| 1630 | |
| 1631 | var $that = $(this); |
| 1632 | var assignment_id = $that.attr('data-assignment-id'); |
| 1633 | var topic_id = $that.attr('data-topic-id'); |
| 1634 | var course_id = $('#post_ID').val(); |
| 1635 | |
| 1636 | $.ajax({ |
| 1637 | url : ajaxurl, |
| 1638 | type : 'POST', |
| 1639 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1640 | beforeSend: function () { |
| 1641 | $that.addClass('tutor-updating-message'); |
| 1642 | }, |
| 1643 | success: function (data) { |
| 1644 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1645 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 1646 | |
| 1647 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 1648 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1649 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1650 | }, |
| 1651 | complete: function () { |
| 1652 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1653 | $that.removeClass('tutor-updating-message'); |
| 1654 | } |
| 1655 | }); |
| 1656 | }); |
| 1657 | |
| 1658 | /** |
| 1659 | * Update Assignment Data |
| 1660 | */ |
| 1661 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 1662 | event.preventDefault(); |
| 1663 | |
| 1664 | var $that = $(this); |
| 1665 | var content; |
| 1666 | var inputid = 'tutor_assignments_modal_editor'; |
| 1667 | var editor = tinyMCE.get(inputid); |
| 1668 | if (editor) { |
| 1669 | content = editor.getContent(); |
| 1670 | } else { |
| 1671 | content = $('#'+inputid).val(); |
| 1672 | } |
| 1673 | |
| 1674 | var form_data = $(this).closest('form').serialize(); |
| 1675 | form_data += '&assignment_content='+content; |
| 1676 | |
| 1677 | $.ajax({ |
| 1678 | url : ajaxurl, |
| 1679 | type : 'POST', |
| 1680 | data : form_data, |
| 1681 | beforeSend: function () { |
| 1682 | $that.addClass('tutor-updating-message'); |
| 1683 | }, |
| 1684 | success: function (data) { |
| 1685 | if (data.success){ |
| 1686 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1687 | enable_sorting_topic_lesson(); |
| 1688 | |
| 1689 | //Close the modal |
| 1690 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1691 | } |
| 1692 | }, |
| 1693 | complete: function () { |
| 1694 | $that.removeClass('tutor-updating-message'); |
| 1695 | } |
| 1696 | }); |
| 1697 | }); |
| 1698 | |
| 1699 | /** |
| 1700 | * Add Assignment |
| 1701 | */ |
| 1702 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 1703 | event.preventDefault(); |
| 1704 | |
| 1705 | var $that = $(this); |
| 1706 | var frame; |
| 1707 | // If the media frame already exists, reopen it. |
| 1708 | if ( frame ) { |
| 1709 | frame.open(); |
| 1710 | return; |
| 1711 | } |
| 1712 | |
| 1713 | // Create a new media frame |
| 1714 | frame = wp.media({ |
| 1715 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1716 | button: { |
| 1717 | text: 'Use this media' |
| 1718 | }, |
| 1719 | multiple: false // Set to true to allow multiple files to be selected |
| 1720 | }); |
| 1721 | |
| 1722 | // When an image is selected in the media frame... |
| 1723 | frame.on( 'select', function() { |
| 1724 | // Get media attachment details from the frame state |
| 1725 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1726 | |
| 1727 | var field_markup = '<div class="tutor-individual-attachment-file"><p class="attachment-file-name">'+attachment.filename+'</p><input type="hidden" name="tutor_assignment_attachments[]" value="'+attachment.id+'"><a href="javascript:;" class="remove-assignment-attachment-a text-muted"> × Remove</a></div>'; |
| 1728 | |
| 1729 | $('#assignment-attached-file').append(field_markup); |
| 1730 | $that.closest('.video_source_wrap_html5').find('input').val(attachment.id); |
| 1731 | }); |
| 1732 | // Finally, open the modal on click |
| 1733 | frame.open(); |
| 1734 | }); |
| 1735 | |
| 1736 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 1737 | event.preventDefault(); |
| 1738 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 1739 | }); |
| 1740 | |
| 1741 | /** |
| 1742 | * Used for backend profile photo upload. |
| 1743 | */ |
| 1744 | |
| 1745 | //tutor_video_poster_upload_btn |
| 1746 | $(document).on( 'click', '.tutor_video_poster_upload_btn', function( event ){ |
| 1747 | event.preventDefault(); |
| 1748 | |
| 1749 | var $that = $(this); |
| 1750 | var frame; |
| 1751 | // If the media frame already exists, reopen it. |
| 1752 | if ( frame ) { |
| 1753 | frame.open(); |
| 1754 | return; |
| 1755 | } |
| 1756 | |
| 1757 | // Create a new media frame |
| 1758 | frame = wp.media({ |
| 1759 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1760 | button: { |
| 1761 | text: 'Use this media' |
| 1762 | }, |
| 1763 | multiple: false // Set to true to allow multiple files to be selected |
| 1764 | }); |
| 1765 | |
| 1766 | // When an image is selected in the media frame... |
| 1767 | frame.on( 'select', function() { |
| 1768 | // Get media attachment details from the frame state |
| 1769 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1770 | $that.closest('.tutor-video-poster-wrap').find('.video-poster-img').html('<img src="'+attachment.url+'" alt="" />'); |
| 1771 | $that.closest('.tutor-video-poster-wrap').find('input').val(attachment.id); |
| 1772 | }); |
| 1773 | // Finally, open the modal on click |
| 1774 | frame.open(); |
| 1775 | }); |
| 1776 | |
| 1777 | |
| 1778 | /** |
| 1779 | * Tutor Memberships toggle in Paid Membership Pro panel |
| 1780 | * @since v.1.3.6 |
| 1781 | */ |
| 1782 | |
| 1783 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 1784 | e.preventDefault(); |
| 1785 | |
| 1786 | var $that = $(this); |
| 1787 | |
| 1788 | if ($that.val() === 'category_wise_membership'){ |
| 1789 | $('.membership_course_categories').show(); |
| 1790 | } else{ |
| 1791 | $('.membership_course_categories').hide(); |
| 1792 | } |
| 1793 | }); |
| 1794 | |
| 1795 | |
| 1796 | }); |
| 1797 |