Chart.bundle.min.js
5 years ago
gutenberg_blocks.js
5 years ago
mce-button.js
5 years ago
tutor-admin.js
5 years ago
tutor-front.js
5 years ago
tutor-setup.js
5 years ago
tutor.js
5 years ago
tutor.js
1535 lines
| 1 | function tutor_get_nonce_data() { |
| 2 | |
| 3 | var nonce_data = window.tutor_data || window._tutorobject || {}; |
| 4 | var nonce_key = nonce_data.nonce_key || ''; |
| 5 | var nonce_value = nonce_data[nonce_key] || ''; |
| 6 | |
| 7 | return {[nonce_key]:nonce_value}; |
| 8 | } |
| 9 | |
| 10 | jQuery(document).ready(function($){ |
| 11 | 'use strict'; |
| 12 | |
| 13 | /** |
| 14 | * Slider bar |
| 15 | */ |
| 16 | function tutor_slider_init(){ |
| 17 | $('.tutor-field-slider').each(function(){ |
| 18 | var $slider = $(this); |
| 19 | var $input = $slider.closest('.tutor-field-type-slider').find('input[type="hidden"]'); |
| 20 | var $showVal = $slider.closest('.tutor-field-type-slider').find('.tutor-field-type-slider-value'); |
| 21 | var min = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-min')); |
| 22 | var max = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-max')); |
| 23 | |
| 24 | $slider.slider({ |
| 25 | range: "max", |
| 26 | min: min, |
| 27 | max: max, |
| 28 | value: $input.val(), |
| 29 | slide: function( event, ui ) { |
| 30 | $showVal.text(ui.value); |
| 31 | $input.val(ui.value); |
| 32 | } |
| 33 | }); |
| 34 | }); |
| 35 | } |
| 36 | tutor_slider_init(); |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Video source tabs |
| 41 | */ |
| 42 | |
| 43 | if (jQuery().select2){ |
| 44 | $('.videosource_select2').select2({ |
| 45 | width: "100%", |
| 46 | templateSelection: iformat, |
| 47 | templateResult: iformat, |
| 48 | allowHtml: true |
| 49 | }); |
| 50 | } |
| 51 | //videosource_select2 |
| 52 | |
| 53 | function iformat(icon) { |
| 54 | var originalOption = icon.element; |
| 55 | return $('<span><i class="tutor-icon-' + $(originalOption).data('icon') + '"></i> ' + icon.text + '</span>'); |
| 56 | } |
| 57 | |
| 58 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 59 | var $that = $(this); |
| 60 | var selector = $(this).val(); |
| 61 | |
| 62 | if (selector){ |
| 63 | $('.video-metabox-source-input-wrap').show(); |
| 64 | }else{ |
| 65 | $('.video-metabox-source-input-wrap').hide(); |
| 66 | } |
| 67 | $that.closest('.tutor-option-field').find('.video-metabox-source-item').hide(); |
| 68 | $that.closest('.tutor-option-field').find('.video_source_wrap_'+selector).show(); |
| 69 | }); |
| 70 | |
| 71 | /** |
| 72 | * Course Builder |
| 73 | * |
| 74 | * @since v.1.3.4 |
| 75 | */ |
| 76 | |
| 77 | $(document).on( 'click', '.tutor-course-thumbnail-upload-btn', function( event ){ |
| 78 | event.preventDefault(); |
| 79 | var $that = $(this); |
| 80 | var frame; |
| 81 | if ( frame ) { |
| 82 | frame.open(); |
| 83 | return; |
| 84 | } |
| 85 | frame = wp.media({ |
| 86 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 87 | button: { |
| 88 | text: 'Use this media' |
| 89 | }, |
| 90 | multiple: false |
| 91 | }); |
| 92 | frame.on( 'select', function() { |
| 93 | var attachment = frame.state().get('selection').first().toJSON(); |
| 94 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', attachment.url); |
| 95 | $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id); |
| 96 | $('.tutor-course-thumbnail-delete-btn').show(); |
| 97 | }); |
| 98 | frame.open(); |
| 99 | }); |
| 100 | |
| 101 | //Delete Thumbnail |
| 102 | $(document).on( 'click', '.tutor-course-thumbnail-delete-btn', function( event ){ |
| 103 | event.preventDefault(); |
| 104 | var $that = $(this); |
| 105 | |
| 106 | var placeholder_src = $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('data-placeholder-src'); |
| 107 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', placeholder_src); |
| 108 | $that.closest('.tutor-thumbnail-wrap').find('input').val(''); |
| 109 | $('.tutor-course-thumbnail-delete-btn').hide(); |
| 110 | }); |
| 111 | |
| 112 | /** |
| 113 | * Quiz Builder |
| 114 | */ |
| 115 | |
| 116 | $(document).on('click', '.create_new_topic_btn', function (e) { |
| 117 | e.preventDefault(); |
| 118 | $('.tutor-metabox-add-topics').slideToggle(); |
| 119 | }); |
| 120 | |
| 121 | $(document).on('click', '#tutor-add-topic-btn', function (e) { |
| 122 | e.preventDefault(); |
| 123 | var $that = $(this); |
| 124 | var form_data = $that.closest('.tutor-metabox-add-topics').find('input, textarea').serializeObject(); |
| 125 | form_data.action = 'tutor_add_course_topic'; |
| 126 | |
| 127 | $.ajax({ |
| 128 | url : ajaxurl, |
| 129 | type : 'POST', |
| 130 | data : form_data, |
| 131 | beforeSend: function () { |
| 132 | $that.addClass('tutor-updating-message'); |
| 133 | }, |
| 134 | success: function (data) { |
| 135 | if (data.success){ |
| 136 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 137 | $that.closest('.tutor-metabox-add-topics').find('input[type!="hidden"], textarea').each(function () { |
| 138 | $(this).val(''); |
| 139 | }); |
| 140 | $that.closest('.tutor-metabox-add-topics').slideUp(); |
| 141 | enable_sorting_topic_lesson(); |
| 142 | } |
| 143 | }, |
| 144 | complete: function () { |
| 145 | $that.removeClass('tutor-updating-message'); |
| 146 | } |
| 147 | }); |
| 148 | }); |
| 149 | |
| 150 | /** |
| 151 | * Zoom Meeting js |
| 152 | * here for support enable_sorting_topic_lesson function |
| 153 | * @since 1.7.1 |
| 154 | */ |
| 155 | $('.tutor-zoom-meeting-modal-wrap').on('submit', '.tutor-meeting-modal-form', function (e) { |
| 156 | e.preventDefault(); |
| 157 | var $form = $(this); |
| 158 | var data = $form.serializeObject(); |
| 159 | var $btn = $form.find('button[type="submit"]'); |
| 160 | |
| 161 | $.ajax({ |
| 162 | url: ajaxurl, |
| 163 | type: 'POST', |
| 164 | data: data, |
| 165 | beforeSend: function () { |
| 166 | $btn.addClass('tutor-updating-message'); |
| 167 | }, |
| 168 | success: function (data) { |
| 169 | if(data.course_contents) { |
| 170 | $(data.selector).html(data.course_contents); |
| 171 | if ( data.selector == '#tutor-course-content-wrap') { |
| 172 | enable_sorting_topic_lesson(); |
| 173 | } |
| 174 | //Close the modal |
| 175 | $('.tutor-zoom-meeting-modal-wrap').removeClass('show'); |
| 176 | } else { |
| 177 | location.reload(); |
| 178 | } |
| 179 | }, |
| 180 | complete: function () { |
| 181 | $btn.removeClass('tutor-updating-message'); |
| 182 | } |
| 183 | }); |
| 184 | }); |
| 185 | |
| 186 | /** |
| 187 | * Resorting... |
| 188 | */ |
| 189 | function enable_sorting_topic_lesson(){ |
| 190 | if (jQuery().sortable) { |
| 191 | $(".course-contents").sortable({ |
| 192 | handle: ".course-move-handle", |
| 193 | start: function (e, ui) { |
| 194 | ui.placeholder.css('visibility', 'visible'); |
| 195 | }, |
| 196 | stop: function (e, ui) { |
| 197 | tutor_sorting_topics_and_lesson(); |
| 198 | }, |
| 199 | }); |
| 200 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 201 | connectWith: ".tutor-lessons", |
| 202 | items: "div.course-content-item", |
| 203 | start: function (e, ui) { |
| 204 | ui.placeholder.css('visibility', 'visible'); |
| 205 | }, |
| 206 | stop: function (e, ui) { |
| 207 | tutor_sorting_topics_and_lesson(); |
| 208 | }, |
| 209 | }); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | function tutor_sorting_topics_and_lesson(){ |
| 214 | var topics = {}; |
| 215 | $('.tutor-topics-wrap').each(function(index, item){ |
| 216 | var $topic = $(this); |
| 217 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 218 | var lessons = {}; |
| 219 | |
| 220 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 221 | var $lesson = $(this); |
| 222 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 223 | |
| 224 | lessons[lessonIndex] = lesson_id; |
| 225 | }); |
| 226 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 227 | }); |
| 228 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 229 | } |
| 230 | |
| 231 | $(document).on('change keyup', '.course-edit-topic-title-input', function (e) { |
| 232 | e.preventDefault(); |
| 233 | $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val()); |
| 234 | }); |
| 235 | |
| 236 | $(document).on('click', '.topic-edit-icon', function (e) { |
| 237 | e.preventDefault(); |
| 238 | $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle(); |
| 239 | }); |
| 240 | |
| 241 | $(document).on('click', '.tutor-topics-edit-button', function(e){ |
| 242 | e.preventDefault(); |
| 243 | var $button = $(this); |
| 244 | var $topic = $button.closest('.tutor-topics-wrap'); |
| 245 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 246 | var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val(); |
| 247 | var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val(); |
| 248 | |
| 249 | var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'}; |
| 250 | $.ajax({ |
| 251 | url : ajaxurl, |
| 252 | type : 'POST', |
| 253 | data : data, |
| 254 | beforeSend: function () { |
| 255 | $button.addClass('tutor-updating-message'); |
| 256 | }, |
| 257 | success: function (data) { |
| 258 | if (data.success){ |
| 259 | $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title); |
| 260 | $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp(); |
| 261 | } |
| 262 | }, |
| 263 | complete: function () { |
| 264 | $button.removeClass('tutor-updating-message'); |
| 265 | } |
| 266 | }); |
| 267 | }); |
| 268 | |
| 269 | /** |
| 270 | * Update Lesson Modal |
| 271 | */ |
| 272 | $(document).on('click', '.open-tutor-lesson-modal', function(e){ |
| 273 | e.preventDefault(); |
| 274 | |
| 275 | var $that = $(this); |
| 276 | var lesson_id = $that.attr('data-lesson-id'); |
| 277 | var topic_id = $that.attr('data-topic-id'); |
| 278 | var course_id = $('#post_ID').val(); |
| 279 | |
| 280 | $.ajax({ |
| 281 | url : ajaxurl, |
| 282 | type : 'POST', |
| 283 | data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'}, |
| 284 | beforeSend: function () { |
| 285 | $that.addClass('tutor-updating-message'); |
| 286 | }, |
| 287 | success: function (data) { |
| 288 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 289 | $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show'); |
| 290 | |
| 291 | var tinymceConfig = tinyMCEPreInit.mceInit.tutor_editor_config; |
| 292 | if ( ! tinymceConfig){ |
| 293 | tinymceConfig = tinyMCEPreInit.mceInit.course_description; |
| 294 | } |
| 295 | tinymce.init(tinymceConfig); |
| 296 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' ); |
| 297 | tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor"); |
| 298 | |
| 299 | $(document).trigger('lesson_modal_loaded', {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id}); |
| 300 | }, |
| 301 | complete: function () { |
| 302 | quicktags({id : "tutor_lesson_modal_editor"}); |
| 303 | $that.removeClass('tutor-updating-message'); |
| 304 | } |
| 305 | }); |
| 306 | }); |
| 307 | |
| 308 | /** |
| 309 | * Lesson upload thumbnail |
| 310 | */ |
| 311 | $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){ |
| 312 | event.preventDefault(); |
| 313 | var $that = $(this); |
| 314 | var frame; |
| 315 | if ( frame ) { |
| 316 | frame.open(); |
| 317 | return; |
| 318 | } |
| 319 | frame = wp.media({ |
| 320 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 321 | button: { |
| 322 | text: 'Use this media' |
| 323 | }, |
| 324 | multiple: false |
| 325 | }); |
| 326 | frame.on( 'select', function() { |
| 327 | var attachment = frame.state().get('selection').first().toJSON(); |
| 328 | $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>'); |
| 329 | $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id); |
| 330 | $('.tutor-lesson-thumbnail-delete-btn').show(); |
| 331 | }); |
| 332 | frame.open(); |
| 333 | }); |
| 334 | |
| 335 | /** |
| 336 | * Lesson Feature Image Delete |
| 337 | * @since v.1.5.6 |
| 338 | */ |
| 339 | $(document).on('click', '.tutor-lesson-thumbnail-delete-btn', function(e){ |
| 340 | e.preventDefault(); |
| 341 | |
| 342 | var $that = $(this); |
| 343 | |
| 344 | $that.closest('.tutor-thumbnail-wrap').find('._lesson_thumbnail_id').val(''); |
| 345 | $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html(''); |
| 346 | $that.hide(); |
| 347 | |
| 348 | }); |
| 349 | |
| 350 | /** |
| 351 | * Delete Lesson from course builder |
| 352 | */ |
| 353 | $(document).on('click', '.tutor-delete-lesson-btn', function(e){ |
| 354 | e.preventDefault(); |
| 355 | |
| 356 | if( ! confirm('Are you sure?')){ |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | var $that = $(this); |
| 361 | var lesson_id = $that.attr('data-lesson-id'); |
| 362 | |
| 363 | $.ajax({ |
| 364 | url : ajaxurl, |
| 365 | type : 'POST', |
| 366 | data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'}, |
| 367 | beforeSend: function () { |
| 368 | $that.addClass('tutor-updating-message'); |
| 369 | }, |
| 370 | success: function (data) { |
| 371 | if (data.success){ |
| 372 | $that.closest('.course-content-item').remove(); |
| 373 | } |
| 374 | }, |
| 375 | complete: function () { |
| 376 | $that.removeClass('tutor-updating-message'); |
| 377 | } |
| 378 | }); |
| 379 | }); |
| 380 | |
| 381 | /** |
| 382 | * Confirmation for deleting Topic |
| 383 | */ |
| 384 | $(document).on('click', '.topic-delete-btn a', function(e){ |
| 385 | var topic_id = $(this).attr('data-topic-id'); |
| 386 | |
| 387 | if ( ! confirm('Are you sure to delete?')){ |
| 388 | e.preventDefault(); |
| 389 | } |
| 390 | }); |
| 391 | |
| 392 | $(document).on('click', '.tutor-expand-all-topic', function (e) { |
| 393 | e.preventDefault(); |
| 394 | $('.tutor-topics-body').slideDown(); |
| 395 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up'); |
| 396 | }); |
| 397 | $(document).on('click', '.tutor-collapse-all-topic', function (e) { |
| 398 | e.preventDefault(); |
| 399 | $('.tutor-topics-body').slideUp(); |
| 400 | $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down'); |
| 401 | }); |
| 402 | $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) { |
| 403 | e.preventDefault(); |
| 404 | var $that = $(this); |
| 405 | $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle(); |
| 406 | $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up'); |
| 407 | }); |
| 408 | |
| 409 | /** |
| 410 | * Create new quiz |
| 411 | */ |
| 412 | |
| 413 | $(document).on('click', '.quiz-modal-btn-first-step', function(e){ |
| 414 | e.preventDefault(); |
| 415 | |
| 416 | var $that = $(this); |
| 417 | var $quizTitle = $('[name="quiz_title"]'); |
| 418 | var quiz_title = $quizTitle.val(); |
| 419 | var quiz_description = $('[name="quiz_description"]').val(); |
| 420 | |
| 421 | if ( ! quiz_title){ |
| 422 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title'); |
| 423 | return; |
| 424 | }else{ |
| 425 | $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html(''); |
| 426 | } |
| 427 | |
| 428 | var course_id = $('#post_ID').val(); |
| 429 | var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id'); |
| 430 | |
| 431 | if ($('#tutor_quiz_builder_quiz_id').length) { |
| 432 | /** |
| 433 | * |
| 434 | * @type {jQuery} |
| 435 | * |
| 436 | * if quiz id exists, we are sending it to update quiz |
| 437 | */ |
| 438 | |
| 439 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 440 | $.ajax({ |
| 441 | url : ajaxurl, |
| 442 | type : 'POST', |
| 443 | data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'}, |
| 444 | beforeSend: function () { |
| 445 | $that.addClass('tutor-updating-message'); |
| 446 | }, |
| 447 | success: function (data) { |
| 448 | $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row); |
| 449 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 450 | |
| 451 | tutor_slider_init(); |
| 452 | }, |
| 453 | complete: function () { |
| 454 | $that.removeClass('tutor-updating-message'); |
| 455 | } |
| 456 | }); |
| 457 | |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | $.ajax({ |
| 462 | url : ajaxurl, |
| 463 | type : 'POST', |
| 464 | data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'}, |
| 465 | beforeSend: function () { |
| 466 | $that.addClass('tutor-updating-message'); |
| 467 | }, |
| 468 | success: function (data) { |
| 469 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 470 | $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row); |
| 471 | $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click'); |
| 472 | |
| 473 | tutor_slider_init(); |
| 474 | |
| 475 | $(document).trigger('quiz_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 476 | }, |
| 477 | complete: function () { |
| 478 | $that.removeClass('tutor-updating-message'); |
| 479 | } |
| 480 | }); |
| 481 | |
| 482 | }); |
| 483 | |
| 484 | |
| 485 | /** |
| 486 | * Ope modal for edit quiz |
| 487 | */ |
| 488 | $(document).on('click', '.open-tutor-quiz-modal', function(e){ |
| 489 | e.preventDefault(); |
| 490 | |
| 491 | var $that = $(this); |
| 492 | var quiz_id = $that.attr('data-quiz-id'); |
| 493 | var topic_id = $that.attr('data-topic-id'); |
| 494 | var course_id = $('#post_ID').val(); |
| 495 | |
| 496 | $.ajax({ |
| 497 | url : ajaxurl, |
| 498 | type : 'POST', |
| 499 | data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'}, |
| 500 | beforeSend: function () { |
| 501 | $that.addClass('tutor-updating-message'); |
| 502 | }, |
| 503 | success: function (data) { |
| 504 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 505 | $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).attr('quiz-for-post-id', topic_id).addClass('show'); |
| 506 | |
| 507 | //Back to question Tab if exists |
| 508 | if ($that.attr('data-back-to-tab')){ |
| 509 | var tabSelector = $that.attr('data-back-to-tab'); |
| 510 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 511 | } |
| 512 | |
| 513 | $(document).trigger('quiz_modal_loaded', {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id}); |
| 514 | |
| 515 | tutor_slider_init(); |
| 516 | enable_quiz_questions_sorting(); |
| 517 | }, |
| 518 | complete: function () { |
| 519 | $that.removeClass('tutor-updating-message'); |
| 520 | } |
| 521 | }); |
| 522 | }); |
| 523 | |
| 524 | $(document).on('click', '.quiz-modal-settings-save-btn', function(e){ |
| 525 | e.preventDefault(); |
| 526 | |
| 527 | var $that = $(this); |
| 528 | var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id'); |
| 529 | |
| 530 | var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serializeObject(); |
| 531 | $formInput.quiz_id = quiz_id; |
| 532 | $formInput.action = 'tutor_quiz_modal_update_settings'; |
| 533 | |
| 534 | $.ajax({ |
| 535 | url : ajaxurl, |
| 536 | type : 'POST', |
| 537 | data : $formInput, |
| 538 | beforeSend: function () { |
| 539 | $that.addClass('tutor-updating-message'); |
| 540 | }, |
| 541 | success: function (data) { |
| 542 | // |
| 543 | }, |
| 544 | complete: function () { |
| 545 | $that.removeClass('tutor-updating-message'); |
| 546 | if ($that.attr('data-action') === 'modal_close'){ |
| 547 | $('.tutor-modal-wrap').removeClass('show'); |
| 548 | } |
| 549 | } |
| 550 | }); |
| 551 | }); |
| 552 | |
| 553 | |
| 554 | /** |
| 555 | * Quiz Question edit save and continue |
| 556 | */ |
| 557 | $(document).on('click', '.quiz-modal-question-save-btn', function(e){ |
| 558 | e.preventDefault(); |
| 559 | |
| 560 | var $that = $(this); |
| 561 | var $formInput = $('.quiz_question_form :input').serializeObject(); |
| 562 | $formInput.action = 'tutor_quiz_modal_update_question'; |
| 563 | |
| 564 | $.ajax({ |
| 565 | url : ajaxurl, |
| 566 | type : 'POST', |
| 567 | data : $formInput, |
| 568 | beforeSend: function () { |
| 569 | $that.addClass('tutor-updating-message'); |
| 570 | }, |
| 571 | success: function (data) { |
| 572 | if (data.success){ |
| 573 | //ReOpen questions |
| 574 | $that.closest('.tutor-quiz-builder-modal-contents').find('.open-tutor-quiz-modal').trigger('click'); |
| 575 | }else{ |
| 576 | if (typeof data.data !== 'undefined') { |
| 577 | $('#quiz_validation_msg_wrap').html(data.data.validation_msg); |
| 578 | } |
| 579 | } |
| 580 | }, |
| 581 | complete: function () { |
| 582 | $that.removeClass('tutor-updating-message'); |
| 583 | } |
| 584 | }); |
| 585 | }); |
| 586 | |
| 587 | /** |
| 588 | * Sort quiz questions |
| 589 | */ |
| 590 | function enable_quiz_questions_sorting(){ |
| 591 | if (jQuery().sortable) { |
| 592 | $(".quiz-builder-questions-wrap").sortable({ |
| 593 | handle: ".question-sorting", |
| 594 | start: function (e, ui) { |
| 595 | ui.placeholder.css('visibility', 'visible'); |
| 596 | }, |
| 597 | stop: function (e, ui) { |
| 598 | tutor_save_sorting_quiz_questions_order(); |
| 599 | }, |
| 600 | }); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | function tutor_save_sorting_quiz_questions_order(){ |
| 605 | var questions = {}; |
| 606 | $('.quiz-builder-question-wrap').each(function(index, item){ |
| 607 | var $question = $(this); |
| 608 | var question_id = parseInt($question.attr('data-question-id'), 10); |
| 609 | questions[index] = question_id; |
| 610 | }); |
| 611 | |
| 612 | $.ajax({url : ajaxurl, type : 'POST', |
| 613 | data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'}, |
| 614 | }); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Quiz Modal |
| 619 | */ |
| 620 | |
| 621 | $(document).on('click', '.modal-close-btn', function(e){ |
| 622 | e.preventDefault(); |
| 623 | $('.tutor-modal-wrap').removeClass('show'); |
| 624 | }); |
| 625 | $(document).on('keyup', function(e){ |
| 626 | if (e.keyCode === 27){ |
| 627 | $('.tutor-modal-wrap').removeClass('show'); |
| 628 | } |
| 629 | }); |
| 630 | |
| 631 | $(document).on('click', '.tutor-add-quiz-btn', function(e){ |
| 632 | e.preventDefault(); |
| 633 | |
| 634 | var $that = $(this); |
| 635 | var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under'); |
| 636 | $.ajax({ |
| 637 | url : ajaxurl, |
| 638 | type : 'POST', |
| 639 | data : {quiz_for_post_id : quiz_for_post_id, action: 'tutor_load_quiz_builder_modal'}, |
| 640 | beforeSend: function () { |
| 641 | $that.addClass('tutor-updating-message'); |
| 642 | }, |
| 643 | success: function (data) { |
| 644 | $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output); |
| 645 | $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show'); |
| 646 | }, |
| 647 | complete: function () { |
| 648 | $that.removeClass('tutor-updating-message'); |
| 649 | } |
| 650 | }); |
| 651 | }); |
| 652 | |
| 653 | |
| 654 | /** |
| 655 | * Quiz Builder Modal Tabs |
| 656 | */ |
| 657 | $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){ |
| 658 | e.preventDefault(); |
| 659 | |
| 660 | var $that = $(this); |
| 661 | |
| 662 | var $quizTitle = $('[name="quiz_title"]'); |
| 663 | var quiz_title = $quizTitle.val(); |
| 664 | if ( ! quiz_title){ |
| 665 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' + |
| 666 | ' first</p>'); |
| 667 | return; |
| 668 | }else{ |
| 669 | $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html(''); |
| 670 | } |
| 671 | |
| 672 | var tabSelector = $that.attr('href'); |
| 673 | $('.quiz-builder-tab-container').hide(); |
| 674 | $(tabSelector).show(); |
| 675 | |
| 676 | $('a.tutor-quiz-modal-tab-item').removeClass('active'); |
| 677 | $that.addClass('active'); |
| 678 | }); |
| 679 | |
| 680 | //Next Prev Tab |
| 681 | $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){ |
| 682 | e.preventDefault(); |
| 683 | |
| 684 | var tabSelector = $(this).attr('href'); |
| 685 | $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click'); |
| 686 | }); |
| 687 | |
| 688 | $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){ |
| 689 | e.preventDefault(); |
| 690 | $('.tutor-modal-wrap').removeClass('show'); |
| 691 | }); |
| 692 | |
| 693 | /** |
| 694 | * Add Question to quiz modal |
| 695 | */ |
| 696 | $(document).on('click', '.tutor-quiz-open-question-form', function(e){ |
| 697 | e.preventDefault(); |
| 698 | |
| 699 | var $that = $(this); |
| 700 | |
| 701 | var quiz_id = $('#tutor_quiz_builder_quiz_id').val(); |
| 702 | var course_id = $('#post_ID').val(); |
| 703 | var question_id = $that.attr('data-question-id'); |
| 704 | |
| 705 | |
| 706 | var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'}; |
| 707 | |
| 708 | if (question_id) { |
| 709 | params.question_id = question_id; |
| 710 | } |
| 711 | |
| 712 | $.ajax({ |
| 713 | url : ajaxurl, |
| 714 | type : 'POST', |
| 715 | data : params, |
| 716 | beforeSend: function () { |
| 717 | $that.addClass('tutor-updating-message'); |
| 718 | }, |
| 719 | success: function (data) { |
| 720 | $('.tutor-quiz-builder-modal-contents').html(data.data.output); |
| 721 | |
| 722 | //Initializing Tutor Select |
| 723 | tutor_select().reInit(); |
| 724 | enable_quiz_answer_sorting(); |
| 725 | }, |
| 726 | complete: function () { |
| 727 | $that.removeClass('tutor-updating-message'); |
| 728 | } |
| 729 | }); |
| 730 | |
| 731 | }); |
| 732 | |
| 733 | $(document).on('click', '.tutor-quiz-question-trash', function(e){ |
| 734 | e.preventDefault(); |
| 735 | |
| 736 | var $that = $(this); |
| 737 | var question_id = $that.attr('data-question-id'); |
| 738 | |
| 739 | $.ajax({ |
| 740 | url : ajaxurl, |
| 741 | type : 'POST', |
| 742 | data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'}, |
| 743 | beforeSend: function () { |
| 744 | $that.closest('.quiz-builder-question-wrap').remove(); |
| 745 | }, |
| 746 | }); |
| 747 | }); |
| 748 | |
| 749 | /** |
| 750 | * Get question answers option form to save multiple/single/true-false options |
| 751 | * |
| 752 | * @since v.1.0.0 |
| 753 | */ |
| 754 | |
| 755 | $(document).on('click', '.add_question_answers_option', function(e){ |
| 756 | e.preventDefault(); |
| 757 | |
| 758 | var $that = $(this); |
| 759 | var question_id = $that.attr('data-question-id'); |
| 760 | |
| 761 | var $formInput = $('.quiz_question_form :input').serializeObject(); |
| 762 | $formInput.question_id = question_id; |
| 763 | $formInput.action = 'tutor_quiz_add_question_answers'; |
| 764 | |
| 765 | $.ajax({ |
| 766 | url : ajaxurl, |
| 767 | type : 'POST', |
| 768 | data : $formInput, |
| 769 | beforeSend: function () { |
| 770 | $that.addClass('tutor-updating-message'); |
| 771 | }, |
| 772 | success: function (data) { |
| 773 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 774 | }, |
| 775 | complete: function () { |
| 776 | $that.removeClass('tutor-updating-message'); |
| 777 | } |
| 778 | }); |
| 779 | }); |
| 780 | |
| 781 | /** |
| 782 | * Get question answers option edit form |
| 783 | * |
| 784 | * @since v.1.0.0 |
| 785 | */ |
| 786 | $(document).on('click', '.tutor-quiz-answer-edit a', function(e){ |
| 787 | e.preventDefault(); |
| 788 | |
| 789 | var $that = $(this); |
| 790 | var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id'); |
| 791 | |
| 792 | $.ajax({ |
| 793 | url : ajaxurl, |
| 794 | type : 'POST', |
| 795 | data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'}, |
| 796 | beforeSend: function () { |
| 797 | $that.addClass('tutor-updating-message'); |
| 798 | }, |
| 799 | success: function (data) { |
| 800 | $('#tutor_quiz_question_answer_form').html(data.data.output); |
| 801 | }, |
| 802 | complete: function () { |
| 803 | $that.removeClass('tutor-updating-message'); |
| 804 | } |
| 805 | }); |
| 806 | }); |
| 807 | |
| 808 | /** |
| 809 | * Saving question answers options |
| 810 | * Student should select the right answer at quiz attempts |
| 811 | * |
| 812 | * @since v.1.0.0 |
| 813 | */ |
| 814 | |
| 815 | $(document).on('click', '#quiz-answer-save-btn', function(e){ |
| 816 | e.preventDefault(); |
| 817 | |
| 818 | var $that = $(this); |
| 819 | var $formInput = $('.quiz_question_form :input').serializeObject(); |
| 820 | $formInput.action = 'tutor_save_quiz_answer_options'; |
| 821 | |
| 822 | $.ajax({ |
| 823 | url : ajaxurl, |
| 824 | type : 'POST', |
| 825 | data : $formInput, |
| 826 | beforeSend: function () { |
| 827 | $('#quiz_validation_msg_wrap').html(""); |
| 828 | $that.addClass('tutor-updating-message'); |
| 829 | }, |
| 830 | success: function (data) { |
| 831 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 832 | }, |
| 833 | complete: function () { |
| 834 | $that.removeClass('tutor-updating-message'); |
| 835 | } |
| 836 | }); |
| 837 | }); |
| 838 | |
| 839 | /** |
| 840 | * Updating Answer |
| 841 | * |
| 842 | * @since v.1.0.0 |
| 843 | */ |
| 844 | $(document).on('click', '#quiz-answer-edit-btn', function(e){ |
| 845 | e.preventDefault(); |
| 846 | |
| 847 | var $that = $(this); |
| 848 | var $formInput = $('.quiz_question_form :input').serializeObject(); |
| 849 | $formInput.action = 'tutor_update_quiz_answer_options'; |
| 850 | |
| 851 | $.ajax({ |
| 852 | url : ajaxurl, |
| 853 | type : 'POST', |
| 854 | data : $formInput, |
| 855 | beforeSend: function () { |
| 856 | $that.addClass('tutor-updating-message'); |
| 857 | }, |
| 858 | success: function (data) { |
| 859 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 860 | }, |
| 861 | complete: function () { |
| 862 | $that.removeClass('tutor-updating-message'); |
| 863 | } |
| 864 | }); |
| 865 | }); |
| 866 | |
| 867 | $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){ |
| 868 | e.preventDefault(); |
| 869 | |
| 870 | var $that = $(this); |
| 871 | |
| 872 | var answer_id = $that.val(); |
| 873 | var inputValue = 1; |
| 874 | if ( ! $that.prop('checked')) { |
| 875 | inputValue = 0; |
| 876 | } |
| 877 | |
| 878 | $.ajax({ |
| 879 | url : ajaxurl, |
| 880 | type : 'POST', |
| 881 | data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'}, |
| 882 | }); |
| 883 | }); |
| 884 | |
| 885 | |
| 886 | $(document).on('refresh', '#tutor_quiz_question_answers', function(e){ |
| 887 | e.preventDefault(); |
| 888 | |
| 889 | var $that = $(this); |
| 890 | var question_id = $that.attr('data-question-id'); |
| 891 | var question_type = $('.tutor_select_value_holder').val(); |
| 892 | |
| 893 | $.ajax({ |
| 894 | url : ajaxurl, |
| 895 | type : 'POST', |
| 896 | data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'}, |
| 897 | beforeSend: function () { |
| 898 | $that.addClass('tutor-updating-message'); |
| 899 | $('#tutor_quiz_question_answer_form').html(''); |
| 900 | }, |
| 901 | success: function (data) { |
| 902 | if (data.success){ |
| 903 | $that.html(data.data.output); |
| 904 | } |
| 905 | }, |
| 906 | complete: function () { |
| 907 | $that.removeClass('tutor-updating-message'); |
| 908 | } |
| 909 | }); |
| 910 | }); |
| 911 | |
| 912 | |
| 913 | |
| 914 | /** |
| 915 | * Delete answer for a question in quiz builder |
| 916 | * |
| 917 | * @since v.1.0.0 |
| 918 | */ |
| 919 | |
| 920 | $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){ |
| 921 | e.preventDefault(); |
| 922 | |
| 923 | var $that = $(this); |
| 924 | var answer_id = $that.attr('data-answer-id'); |
| 925 | |
| 926 | $.ajax({ |
| 927 | url : ajaxurl, |
| 928 | type : 'POST', |
| 929 | data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'}, |
| 930 | beforeSend: function () { |
| 931 | $that.closest('.tutor-quiz-answer-wrap').remove(); |
| 932 | }, |
| 933 | }); |
| 934 | }); |
| 935 | |
| 936 | |
| 937 | /** |
| 938 | * Delete Quiz |
| 939 | * @since v.1.0.0 |
| 940 | */ |
| 941 | |
| 942 | $(document).on('click', '.tutor-delete-quiz-btn', function(e){ |
| 943 | e.preventDefault(); |
| 944 | |
| 945 | if( ! confirm('Are you sure?')){ |
| 946 | return; |
| 947 | } |
| 948 | |
| 949 | var $that = $(this); |
| 950 | var quiz_id = $that.attr('data-quiz-id'); |
| 951 | |
| 952 | $.ajax({ |
| 953 | url : ajaxurl, |
| 954 | type : 'POST', |
| 955 | data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'}, |
| 956 | beforeSend: function () { |
| 957 | $that.closest('.course-content-item').remove(); |
| 958 | } |
| 959 | }); |
| 960 | }); |
| 961 | |
| 962 | /** |
| 963 | * Save answer sorting placement |
| 964 | * |
| 965 | * @since v.1.0.0 |
| 966 | */ |
| 967 | function enable_quiz_answer_sorting(){ |
| 968 | if (jQuery().sortable) { |
| 969 | $("#tutor_quiz_question_answers").sortable({ |
| 970 | handle: ".tutor-quiz-answer-sort-icon", |
| 971 | start: function (e, ui) { |
| 972 | ui.placeholder.css('visibility', 'visible'); |
| 973 | }, |
| 974 | stop: function (e, ui) { |
| 975 | tutor_save_sorting_quiz_answer_order(); |
| 976 | }, |
| 977 | }); |
| 978 | } |
| 979 | } |
| 980 | function tutor_save_sorting_quiz_answer_order(){ |
| 981 | var answers = {}; |
| 982 | $('.tutor-quiz-answer-wrap').each(function(index, item){ |
| 983 | var $answer = $(this); |
| 984 | var answer_id = parseInt($answer.attr('data-answer-id'), 10); |
| 985 | answers[index] = answer_id; |
| 986 | }); |
| 987 | |
| 988 | $.ajax({url : ajaxurl, type : 'POST', |
| 989 | data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'}, |
| 990 | }); |
| 991 | } |
| 992 | |
| 993 | |
| 994 | /** |
| 995 | * Tutor Custom Select |
| 996 | */ |
| 997 | |
| 998 | function tutor_select(){ |
| 999 | var obj = { |
| 1000 | init : function(){ |
| 1001 | $(document).on('click', '.tutor-select .tutor-select-option', function(e){ |
| 1002 | e.preventDefault(); |
| 1003 | |
| 1004 | var $that = $(this); |
| 1005 | if ($that.attr('data-is-pro') !== 'true') { |
| 1006 | var $html = $that.html().trim(); |
| 1007 | $that.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 1008 | $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change'); |
| 1009 | $that.closest('.tutor-select-options').hide(); |
| 1010 | }else{ |
| 1011 | alert('Tutor Pro version required'); |
| 1012 | } |
| 1013 | }); |
| 1014 | $(document).on('click', '.tutor-select .select-header', function(e){ |
| 1015 | e.preventDefault(); |
| 1016 | |
| 1017 | var $that = $(this); |
| 1018 | $that.closest('.tutor-select').find('.tutor-select-options').slideToggle(); |
| 1019 | }); |
| 1020 | |
| 1021 | this.setValue(); |
| 1022 | this.hideOnOutSideClick(); |
| 1023 | }, |
| 1024 | setValue : function(){ |
| 1025 | $('.tutor-select').each(function(){ |
| 1026 | var $that = $(this); |
| 1027 | var $option = $that.find('.tutor-select-option'); |
| 1028 | |
| 1029 | if ($option.length){ |
| 1030 | $option.each(function(){ |
| 1031 | var $thisOption = $(this); |
| 1032 | |
| 1033 | if ($thisOption.attr('data-selected') === 'selected'){ |
| 1034 | var $html = $thisOption.html().trim(); |
| 1035 | $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html); |
| 1036 | $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value')); |
| 1037 | } |
| 1038 | }); |
| 1039 | } |
| 1040 | }); |
| 1041 | }, |
| 1042 | hideOnOutSideClick : function(){ |
| 1043 | $(document).mouseup(function(e) { |
| 1044 | var $option_wrap = $(".tutor-select-options"); |
| 1045 | if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) { |
| 1046 | $option_wrap.hide(); |
| 1047 | } |
| 1048 | }); |
| 1049 | }, |
| 1050 | reInit : function(){ |
| 1051 | this.setValue(); |
| 1052 | } |
| 1053 | }; |
| 1054 | |
| 1055 | return obj; |
| 1056 | } |
| 1057 | tutor_select().init(); |
| 1058 | |
| 1059 | |
| 1060 | /** |
| 1061 | * If change question type from quiz builder question |
| 1062 | * |
| 1063 | * @since v.1.0.0 |
| 1064 | */ |
| 1065 | $(document).on('change', 'input.tutor_select_value_holder', function(e) { |
| 1066 | var $that = $(this); |
| 1067 | //$('#tutor_quiz_question_answer_form').html(''); |
| 1068 | $('.add_question_answers_option').trigger('click'); |
| 1069 | $('#tutor_quiz_question_answers').trigger('refresh'); |
| 1070 | }); |
| 1071 | |
| 1072 | $(document).on('click', '.tutor-media-upload-btn', function(e){ |
| 1073 | e.preventDefault(); |
| 1074 | |
| 1075 | var $that = $(this); |
| 1076 | var frame; |
| 1077 | if ( frame ) { |
| 1078 | frame.open(); |
| 1079 | return; |
| 1080 | } |
| 1081 | frame = wp.media({ |
| 1082 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1083 | button: { |
| 1084 | text: 'Use this media' |
| 1085 | }, |
| 1086 | multiple: false |
| 1087 | }); |
| 1088 | frame.on( 'select', function() { |
| 1089 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1090 | $that.html('<img src="'+attachment.url+'" alt="" />'); |
| 1091 | $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id); |
| 1092 | }); |
| 1093 | frame.open(); |
| 1094 | }); |
| 1095 | $(document).on('click', '.tutor-media-upload-trash', function(e){ |
| 1096 | e.preventDefault(); |
| 1097 | |
| 1098 | var $that = $(this); |
| 1099 | $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>'); |
| 1100 | $that.closest('.tutor-media-upload-wrap').find('input').val(''); |
| 1101 | }); |
| 1102 | |
| 1103 | /** |
| 1104 | * Delay Function |
| 1105 | */ |
| 1106 | |
| 1107 | var tutor_delay = (function(){ |
| 1108 | var timer = 0; |
| 1109 | return function(callback, ms){ |
| 1110 | clearTimeout (timer); |
| 1111 | timer = setTimeout(callback, ms); |
| 1112 | }; |
| 1113 | })(); |
| 1114 | |
| 1115 | /** |
| 1116 | * Add instructor modal |
| 1117 | */ |
| 1118 | $(document).on('click', '.tutor-add-instructor-btn', function(e){ |
| 1119 | e.preventDefault(); |
| 1120 | |
| 1121 | var $that = $(this); |
| 1122 | var course_id = $('#post_ID').val(); |
| 1123 | |
| 1124 | $.ajax({ |
| 1125 | url : ajaxurl, |
| 1126 | type : 'POST', |
| 1127 | data : {course_id : course_id, action: 'tutor_load_instructors_modal'}, |
| 1128 | beforeSend: function () { |
| 1129 | $that.addClass('tutor-updating-message'); |
| 1130 | }, |
| 1131 | success: function (data) { |
| 1132 | if (data.success){ |
| 1133 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1134 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1135 | } |
| 1136 | }, |
| 1137 | complete: function () { |
| 1138 | $that.removeClass('tutor-updating-message'); |
| 1139 | } |
| 1140 | }); |
| 1141 | }); |
| 1142 | |
| 1143 | $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){ |
| 1144 | e.preventDefault(); |
| 1145 | |
| 1146 | var $that = $(this); |
| 1147 | var $modal = $('.tutor-modal-wrap'); |
| 1148 | |
| 1149 | tutor_delay(function(){ |
| 1150 | var search_terms = $that.val(); |
| 1151 | var course_id = $('#post_ID').val(); |
| 1152 | |
| 1153 | $.ajax({ |
| 1154 | url : ajaxurl, |
| 1155 | type : 'POST', |
| 1156 | data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'}, |
| 1157 | beforeSend: function () { |
| 1158 | $modal.addClass('loading'); |
| 1159 | }, |
| 1160 | success: function (data) { |
| 1161 | if (data.success){ |
| 1162 | $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output); |
| 1163 | $('.tutor-instructors-modal-wrap').addClass('show'); |
| 1164 | } |
| 1165 | }, |
| 1166 | complete: function () { |
| 1167 | $modal.removeClass('loading'); |
| 1168 | } |
| 1169 | }); |
| 1170 | |
| 1171 | }, 1000) |
| 1172 | }); |
| 1173 | $(document).on('click', '.add_instructor_to_course_btn', function(e){ |
| 1174 | e.preventDefault(); |
| 1175 | |
| 1176 | var $that = $(this); |
| 1177 | var $modal = $('.tutor-modal-wrap'); |
| 1178 | var course_id = $('#post_ID').val(); |
| 1179 | |
| 1180 | var data = $modal.find('input').serializeObject(); |
| 1181 | data.course_id = course_id; |
| 1182 | data.action = 'tutor_add_instructors_to_course'; |
| 1183 | |
| 1184 | $.ajax({ |
| 1185 | url : ajaxurl, |
| 1186 | type : 'POST', |
| 1187 | data : data, |
| 1188 | beforeSend: function () { |
| 1189 | $that.addClass('tutor-updating-message'); |
| 1190 | }, |
| 1191 | success: function (data) { |
| 1192 | if (data.success){ |
| 1193 | $('.tutor-course-available-instructors').html(data.data.output); |
| 1194 | $('.tutor-modal-wrap').removeClass('show'); |
| 1195 | } |
| 1196 | }, |
| 1197 | complete: function () { |
| 1198 | $that.removeClass('tutor-updating-message'); |
| 1199 | } |
| 1200 | }); |
| 1201 | }); |
| 1202 | |
| 1203 | $(document).on('click', '.tutor-instructor-delete-btn', function(e){ |
| 1204 | e.preventDefault(); |
| 1205 | |
| 1206 | var $that = $(this); |
| 1207 | var course_id = $('#post_ID').val(); |
| 1208 | var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id'); |
| 1209 | |
| 1210 | $.ajax({ |
| 1211 | url : ajaxurl, |
| 1212 | type : 'POST', |
| 1213 | data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'}, |
| 1214 | success: function (data) { |
| 1215 | if (data.success){ |
| 1216 | $that.closest('.added-instructor-item').remove(); |
| 1217 | } |
| 1218 | } |
| 1219 | }); |
| 1220 | }); |
| 1221 | |
| 1222 | $(document).on('click', '.settings-tabs-navs li', function(e){ |
| 1223 | e.preventDefault(); |
| 1224 | |
| 1225 | var $that = $(this); |
| 1226 | var data_target = $that.find('a').attr('data-target'); |
| 1227 | var url = $that.find('a').attr('href'); |
| 1228 | |
| 1229 | $that.addClass('active').siblings('li.active').removeClass('active'); |
| 1230 | $('.settings-tab-wrap').removeClass('active').hide(); |
| 1231 | $(data_target).addClass('active').show(); |
| 1232 | |
| 1233 | window.history.pushState({}, '', url); |
| 1234 | }); |
| 1235 | |
| 1236 | /** |
| 1237 | * Re init required |
| 1238 | * Modal Loaded... |
| 1239 | */ |
| 1240 | |
| 1241 | $(document).on('lesson_modal_loaded quiz_modal_loaded assignment_modal_loaded', function(e, obj){ |
| 1242 | if (jQuery().select2){ |
| 1243 | $('.select2_multiselect').select2({ |
| 1244 | dropdownCssClass:'increasezindex' |
| 1245 | }); |
| 1246 | } |
| 1247 | if (jQuery.datepicker){ |
| 1248 | $( ".tutor_date_picker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 1249 | } |
| 1250 | }); |
| 1251 | $(document).on('lesson_modal_loaded', function(e, obj){ |
| 1252 | $('.tutor-lesson-modal-wrap .modal-title h1').html('Lesson'); |
| 1253 | }); |
| 1254 | $(document).on('assignment_modal_loaded', function(e, obj){ |
| 1255 | $('.tutor-lesson-modal-wrap .modal-title h1').html('Assignment'); |
| 1256 | }); |
| 1257 | |
| 1258 | /** |
| 1259 | * Tutor number validation |
| 1260 | * |
| 1261 | * @since v.1.6.3 |
| 1262 | */ |
| 1263 | $(document).on('keyup change', '.tutor-number-validation', function(e) { |
| 1264 | var input = $(this); |
| 1265 | var val = parseInt(input.val()); |
| 1266 | var min = parseInt(input.attr('data-min')); |
| 1267 | var max = parseInt(input.attr('data-max')); |
| 1268 | if ( val < min ) { |
| 1269 | input.val(min); |
| 1270 | } else if ( val > max ) { |
| 1271 | input.val(max); |
| 1272 | } |
| 1273 | }); |
| 1274 | |
| 1275 | /* |
| 1276 | * @since v.1.6.4 |
| 1277 | * Quiz Attempts Instructor Feedback |
| 1278 | */ |
| 1279 | $(document).on('click', '.tutor-instructor-feedback', function(e){ |
| 1280 | e.preventDefault(); |
| 1281 | var $that = $(this); |
| 1282 | console.log('Here->', $that.data('attemptid'), $('.tutor-instructor-feedback-content').val()); |
| 1283 | $.ajax({ |
| 1284 | url : ajaxurl, |
| 1285 | type : 'POST', |
| 1286 | data : {attempts_id: $that.data('attemptid'), feedback: $('.tutor-instructor-feedback-content').val() , action: 'tutor_instructor_feedback'}, |
| 1287 | beforeSend: function () { |
| 1288 | $that.addClass('tutor-updating-message'); |
| 1289 | }, |
| 1290 | success: function (data) { |
| 1291 | if (data.success){ |
| 1292 | $that.closest('.course-content-item').remove(); |
| 1293 | alert('Done'); |
| 1294 | } |
| 1295 | }, |
| 1296 | complete: function () { |
| 1297 | $that.removeClass('tutor-updating-message'); |
| 1298 | } |
| 1299 | }); |
| 1300 | }); |
| 1301 | |
| 1302 | /** |
| 1303 | * Since 1.7.9 |
| 1304 | * Announcements scripts |
| 1305 | */ |
| 1306 | |
| 1307 | if(window._tutorobject != undefined){ |
| 1308 | var announcement_url = window._tutorobject.ajaxurl; |
| 1309 | } |
| 1310 | var add_new_button = $(".tutor-announcement-add-new"); |
| 1311 | var update_button = $(".tutor-announcement-edit"); |
| 1312 | var delete_button = $(".tutor-announcement-delete"); |
| 1313 | var details_button = $(".tutor-announcement-details"); |
| 1314 | var close_button = $(".tutor-announcement-close-btn"); |
| 1315 | var create_modal = $(".tutor-accouncement-create-modal"); |
| 1316 | var update_modal = $(".tutor-accouncement-update-modal"); |
| 1317 | var details_modal = $(".tutor-accouncement-details-modal"); |
| 1318 | //open create modal |
| 1319 | $(add_new_button).click(function(){ |
| 1320 | create_modal.addClass("show"); |
| 1321 | $("#tutor-annoucement-backend-create-modal").addClass('show'); |
| 1322 | }) |
| 1323 | |
| 1324 | $(details_button).click(function(){ |
| 1325 | var announcement_date = $(this).attr('announcement-date'); |
| 1326 | var announcement_id = $(this).attr('announcement-id'); |
| 1327 | var course_id = $(this).attr('course-id'); |
| 1328 | var course_name = $(this).attr('course-name'); |
| 1329 | var announcement_title = $(this).attr('announcement-title'); |
| 1330 | var announcement_summary = $(this).attr('announcement-summary'); |
| 1331 | |
| 1332 | $(".tutor-announcement-detail-content").html(`<h3>${announcement_title}</h3><p>${announcement_summary}</p>`); |
| 1333 | $(".tutor-announcement-detail-course-info p").html(`${course_name}`); |
| 1334 | $(".tutor-announcement-detail-date-info p").html(`${announcement_date}`); |
| 1335 | //set attr on edit button |
| 1336 | $("#tutor-announcement-edit-from-detail").attr('announcement-id',announcement_id); |
| 1337 | $("#tutor-announcement-edit-from-detail").attr('course-id',course_id); |
| 1338 | $("#tutor-announcement-edit-from-detail").attr('announcement-title',announcement_title); |
| 1339 | $("#tutor-announcement-edit-from-detail").attr('announcement-summary',announcement_summary); |
| 1340 | $("#tutor-announcement-delete-from-detail").attr('announcement-id',announcement_id); |
| 1341 | details_modal.addClass("show"); |
| 1342 | }) |
| 1343 | |
| 1344 | //open update modal |
| 1345 | $(update_button).click(function(){ |
| 1346 | if(details_modal){ |
| 1347 | details_modal.removeClass('show'); |
| 1348 | } |
| 1349 | var announcement_id = $(this).attr('announcement-id'); |
| 1350 | var course_id = $(this).attr('course-id'); |
| 1351 | var announcement_title = $(this).attr('announcement-title'); |
| 1352 | var announcement_summary = $(this).attr('announcement-summary'); |
| 1353 | |
| 1354 | $("#tutor-announcement-course-id").val(course_id); |
| 1355 | $("#announcement_id").val(announcement_id); |
| 1356 | $("#tutor-announcement-title").val(announcement_title); |
| 1357 | $("#tutor-announcement-summary").val(announcement_summary); |
| 1358 | |
| 1359 | update_modal.addClass("show"); |
| 1360 | }) |
| 1361 | |
| 1362 | //close create and update modal |
| 1363 | $(close_button).click(function(){ |
| 1364 | create_modal.removeClass("show"); |
| 1365 | update_modal.removeClass("show"); |
| 1366 | details_modal.removeClass("show"); |
| 1367 | $("#tutor-annoucement-backend-create-modal").removeClass('show'); |
| 1368 | }) |
| 1369 | |
| 1370 | //create announcement |
| 1371 | $(".tutor-announcements-form").on('submit',function(e){ |
| 1372 | e.preventDefault(); |
| 1373 | var $btn = $(this).find('button[type="submit"]'); |
| 1374 | var formData = $(".tutor-announcements-form").serialize() + '&action=tutor_announcement_create' + '&action_type=create'; |
| 1375 | |
| 1376 | $.ajax({ |
| 1377 | url : window._tutorobject ? announcement_url : ajaxurl, |
| 1378 | type : 'POST', |
| 1379 | data : formData, |
| 1380 | beforeSend: function() { |
| 1381 | $btn.addClass('tutor-updating-message'); |
| 1382 | }, |
| 1383 | success: function(data) { |
| 1384 | |
| 1385 | $(".tutor-alert").remove(); |
| 1386 | |
| 1387 | if(data.status=="success") { |
| 1388 | location.reload(); |
| 1389 | } |
| 1390 | |
| 1391 | if(data.status=="validation_error"){ |
| 1392 | $(".tutor-announcements-create-alert").append(`<div class="tutor-alert alert-warning"></div>`); |
| 1393 | for(let [key,value] of Object.entries(data.message)){ |
| 1394 | |
| 1395 | $(".tutor-announcements-create-alert .tutor-alert").append(`<li>${value}</li>`); |
| 1396 | } |
| 1397 | } |
| 1398 | if(data.status=="fail"){ |
| 1399 | |
| 1400 | $(".tutor-announcements-create-alert").html(`<li>${data.message}</li>`); |
| 1401 | |
| 1402 | } |
| 1403 | }, |
| 1404 | error: function(data){ |
| 1405 | console.log(data); |
| 1406 | } |
| 1407 | }) |
| 1408 | }) |
| 1409 | //update announcement |
| 1410 | $(".tutor-announcements-update-form").on('submit',function(e){ |
| 1411 | e.preventDefault(); |
| 1412 | var $btn = $(this).find('button[type="submit"]'); |
| 1413 | var formData = $(".tutor-announcements-update-form").serialize() + '&action=tutor_announcement_create' + '&action_type=update'; |
| 1414 | |
| 1415 | $.ajax({ |
| 1416 | url : window._tutorobject ? announcement_url : ajaxurl, |
| 1417 | type : 'POST', |
| 1418 | data : formData, |
| 1419 | beforeSend: function() { |
| 1420 | $btn.addClass('tutor-updating-message'); |
| 1421 | }, |
| 1422 | success: function(data) { |
| 1423 | |
| 1424 | $(".tutor-alert").remove(); |
| 1425 | if(data.status=="success"){ |
| 1426 | location.reload(); |
| 1427 | } |
| 1428 | if(data.status=="validation_error"){ |
| 1429 | $(".tutor-announcements-update-alert").append(`<div class="tutor-alert alert-warning"></div>`); |
| 1430 | for(let [key,value] of Object.entries(data.message)){ |
| 1431 | $(".tutor-announcements-update-alert > .tutor-alert").append(`<li>${value}</li>`); |
| 1432 | } |
| 1433 | } |
| 1434 | if(data.status=="fail"){ |
| 1435 | |
| 1436 | $(".tutor-announcements-create-alert").html(`<li>${data.message}</li>`); |
| 1437 | |
| 1438 | } |
| 1439 | }, |
| 1440 | error: function(){ |
| 1441 | |
| 1442 | } |
| 1443 | }) |
| 1444 | }); |
| 1445 | |
| 1446 | $(delete_button).click(function(){ |
| 1447 | var announcement_id = $(this).attr('announcement-id'); |
| 1448 | var whichtr = $("#tutor-announcement-tr-"+announcement_id); |
| 1449 | if(confirm("Do you want to delete?")){ |
| 1450 | $.ajax({ |
| 1451 | url : window._tutorobject ? announcement_url : ajaxurl, |
| 1452 | type : 'POST', |
| 1453 | data : {action:'tutor_announcement_delete',announcement_id:announcement_id}, |
| 1454 | beforeSend: function() { |
| 1455 | |
| 1456 | }, |
| 1457 | success: function(data) { |
| 1458 | |
| 1459 | whichtr.remove(); |
| 1460 | if(details_modal.length){ |
| 1461 | details_modal.removeClass('show'); |
| 1462 | } |
| 1463 | if(data.status == "fail"){ |
| 1464 | console.log(data.message); |
| 1465 | } |
| 1466 | }, |
| 1467 | error: function(){ |
| 1468 | |
| 1469 | } |
| 1470 | }) |
| 1471 | } |
| 1472 | }) |
| 1473 | //sorting |
| 1474 | if (jQuery.datepicker){ |
| 1475 | $( "#tutor-announcement-datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 1476 | } |
| 1477 | function urlPrams(type, val){ |
| 1478 | var url = new URL(window.location.href); |
| 1479 | var search_params = url.searchParams; |
| 1480 | search_params.set(type, val); |
| 1481 | |
| 1482 | url.search = search_params.toString(); |
| 1483 | |
| 1484 | search_params.set('paged', 1); |
| 1485 | url.search = search_params.toString(); |
| 1486 | |
| 1487 | return url.toString(); |
| 1488 | } |
| 1489 | $('.tutor-announcement-course-sorting').on('change', function(e){ |
| 1490 | window.location = urlPrams( 'course-id', $(this).val() ); |
| 1491 | }); |
| 1492 | $('.tutor-announcement-order-sorting').on('change', function(e){ |
| 1493 | window.location = urlPrams( 'order', $(this).val() ); |
| 1494 | }); |
| 1495 | $('.tutor-announcement-date-sorting').on('change', function(e){ |
| 1496 | window.location = urlPrams( 'date', $(this).val() ); |
| 1497 | }); |
| 1498 | $('.tutor-announcement-search-sorting').on('click', function(e){ |
| 1499 | window.location = urlPrams( 'search', $(".tutor-announcement-search-field").val() ); |
| 1500 | }); |
| 1501 | //dropdown toggle |
| 1502 | $(document).click(function(){ |
| 1503 | $(".tutor-dropdown").removeClass('show'); |
| 1504 | }); |
| 1505 | |
| 1506 | $(".tutor-dropdown").click(function(e){ |
| 1507 | e.stopPropagation(); |
| 1508 | $(this).addClass('show'); |
| 1509 | }); |
| 1510 | //announcement end |
| 1511 | /* |
| 1512 | * @since v.1.7.9 |
| 1513 | * Send wp nonce to every ajax request |
| 1514 | */ |
| 1515 | $.ajaxSetup({data : tutor_get_nonce_data()}); |
| 1516 | }); |
| 1517 | |
| 1518 | jQuery.fn.serializeObject = function() |
| 1519 | { |
| 1520 | var values = {}; |
| 1521 | var array = this.serializeArray(); |
| 1522 | |
| 1523 | jQuery.each(array, function() { |
| 1524 | if (values[this.name]) { |
| 1525 | if (!values[this.name].push) { |
| 1526 | values[this.name] = [values[this.name]]; |
| 1527 | } |
| 1528 | values[this.name].push(this.value || ''); |
| 1529 | } else { |
| 1530 | values[this.name] = this.value || ''; |
| 1531 | } |
| 1532 | }); |
| 1533 | |
| 1534 | return values; |
| 1535 | }; |