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
888 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 | /** |
| 72 | * Don't move it to anywhere? |
| 73 | */ |
| 74 | function enable_sorting_topic_lesson(){ |
| 75 | if (jQuery().sortable) { |
| 76 | $(".course-contents").sortable({ |
| 77 | handle: ".course-move-handle", |
| 78 | start: function (e, ui) { |
| 79 | ui.placeholder.css('visibility', 'visible'); |
| 80 | }, |
| 81 | stop: function (e, ui) { |
| 82 | tutor_sorting_topics_and_lesson(); |
| 83 | }, |
| 84 | }); |
| 85 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 86 | connectWith: ".tutor-lessons", |
| 87 | items: "div.course-content-item", |
| 88 | start: function (e, ui) { |
| 89 | ui.placeholder.css('visibility', 'visible'); |
| 90 | }, |
| 91 | stop: function (e, ui) { |
| 92 | tutor_sorting_topics_and_lesson(); |
| 93 | }, |
| 94 | }); |
| 95 | } |
| 96 | } |
| 97 | enable_sorting_topic_lesson(); |
| 98 | function tutor_sorting_topics_and_lesson(){ |
| 99 | var topics = {}; |
| 100 | $('.tutor-topics-wrap').each(function(index, item){ |
| 101 | var $topic = $(this); |
| 102 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 103 | var lessons = {}; |
| 104 | |
| 105 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 106 | var $lesson = $(this); |
| 107 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 108 | |
| 109 | lessons[lessonIndex] = lesson_id; |
| 110 | }); |
| 111 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 112 | }); |
| 113 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Lesson Update or Create Modal |
| 118 | */ |
| 119 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 120 | event.preventDefault(); |
| 121 | |
| 122 | var $that = $(this); |
| 123 | var content; |
| 124 | var inputid = 'tutor_lesson_modal_editor'; |
| 125 | var editor = tinyMCE.get(inputid); |
| 126 | if (editor) { |
| 127 | content = editor.getContent(); |
| 128 | } else { |
| 129 | content = $('#'+inputid).val(); |
| 130 | } |
| 131 | |
| 132 | var form_data = $(this).closest('form').serialize(); |
| 133 | form_data += '&lesson_content='+content; |
| 134 | |
| 135 | $.ajax({ |
| 136 | url : ajaxurl, |
| 137 | type : 'POST', |
| 138 | data : form_data, |
| 139 | beforeSend: function () { |
| 140 | $that.addClass('tutor-updating-message'); |
| 141 | }, |
| 142 | success: function (data) { |
| 143 | if (data.success){ |
| 144 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 145 | enable_sorting_topic_lesson(); |
| 146 | |
| 147 | //Close the modal |
| 148 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 149 | } |
| 150 | }, |
| 151 | complete: function () { |
| 152 | $that.removeClass('tutor-updating-message'); |
| 153 | } |
| 154 | }); |
| 155 | }); |
| 156 | |
| 157 | /** |
| 158 | * Lesson Video |
| 159 | */ |
| 160 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 161 | var selector = $(this).val(); |
| 162 | $('[class^="video_source_wrap"]').hide(); |
| 163 | $('.video_source_wrap_'+selector).show(); |
| 164 | |
| 165 | if (selector === 'html5'){ |
| 166 | $('.tutor-video-poster-field').show(); |
| 167 | } else{ |
| 168 | $('.tutor-video-poster-field').hide(); |
| 169 | } |
| 170 | }); |
| 171 | |
| 172 | $(document).on( 'click', '.video_source_wrap_html5 .video_upload_btn', function( event ){ |
| 173 | event.preventDefault(); |
| 174 | |
| 175 | var $that = $(this); |
| 176 | var frame; |
| 177 | // If the media frame already exists, reopen it. |
| 178 | if ( frame ) { |
| 179 | frame.open(); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | // Create a new media frame |
| 184 | frame = wp.media({ |
| 185 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 186 | button: { |
| 187 | text: 'Use this media' |
| 188 | }, |
| 189 | multiple: false // Set to true to allow multiple files to be selected |
| 190 | }); |
| 191 | |
| 192 | // When an image is selected in the media frame... |
| 193 | frame.on( 'select', function() { |
| 194 | // Get media attachment details from the frame state |
| 195 | var attachment = frame.state().get('selection').first().toJSON(); |
| 196 | $that.closest('.video_source_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 197 | $that.closest('.video_source_wrap_html5').find('input.input_source_video_id').val(attachment.id); |
| 198 | }); |
| 199 | // Finally, open the modal on click |
| 200 | frame.open(); |
| 201 | }); |
| 202 | |
| 203 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 204 | e.preventDefault(); |
| 205 | $(this).closest('.tutor-added-attachment').remove(); |
| 206 | }); |
| 207 | |
| 208 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 209 | e.preventDefault(); |
| 210 | |
| 211 | var $that = $(this); |
| 212 | var frame; |
| 213 | // If the media frame already exists, reopen it. |
| 214 | if ( frame ) { |
| 215 | frame.open(); |
| 216 | return; |
| 217 | } |
| 218 | // Create a new media frame |
| 219 | frame = wp.media({ |
| 220 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 221 | button: { |
| 222 | text: 'Use this media' |
| 223 | }, |
| 224 | multiple: true // Set to true to allow multiple files to be selected |
| 225 | }); |
| 226 | // When an image is selected in the media frame... |
| 227 | frame.on( 'select', function() { |
| 228 | // Get media attachment details from the frame state |
| 229 | var attachments = frame.state().get('selection').toJSON(); |
| 230 | if (attachments.length){ |
| 231 | for (var i=0; i < attachments.length; i++){ |
| 232 | var attachment = attachments[i]; |
| 233 | |
| 234 | 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>'; |
| 235 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 236 | } |
| 237 | } |
| 238 | }); |
| 239 | // Finally, open the modal on click |
| 240 | frame.open(); |
| 241 | }); |
| 242 | |
| 243 | /** |
| 244 | * Open Sidebar Menu |
| 245 | */ |
| 246 | if (tutor_data.open_tutor_admin_menu){ |
| 247 | var $adminMenu = $('#adminmenu'); |
| 248 | $adminMenu.find('[href="admin.php?page=tutor"]').closest('li.wp-has-submenu').addClass('wp-has-current-submenu'); |
| 249 | $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'); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Add question answer for quiz |
| 254 | */ |
| 255 | |
| 256 | $(document).on('change keyup paste', '.question_field_title', function(){ |
| 257 | var $that = $(this); |
| 258 | $that.closest('.single-question-item').find('.tutor-question-item-head').find('.question-title').text($that.val()); |
| 259 | }); |
| 260 | |
| 261 | $(document).on('change', '.question_type_field', function(){ |
| 262 | var $that = $(this); |
| 263 | var question_type = $that.val(); |
| 264 | |
| 265 | var option_text = $that.find('option[value="'+question_type+'"]').text(); |
| 266 | $that.closest('.single-question-item').find('.tutor-question-item-head').find('.question-type').text(option_text); |
| 267 | |
| 268 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 269 | var data = {question_id: question_id, question_type : question_type, action: 'quiz_question_type_changed'}; |
| 270 | |
| 271 | $.ajax({ |
| 272 | url : ajaxurl, |
| 273 | type : 'POST', |
| 274 | data : data, |
| 275 | beforeSend: function () { |
| 276 | $that.closest('.single-question-item').find('.tutor-loading-icon-wrap').addClass('tutor-updating-message'); |
| 277 | }, |
| 278 | success: function (data) { |
| 279 | if (data.success){ |
| 280 | $that.closest('.quiz-question-form-wrap').find('.answer-entry-wrap').html(data.data.multi_answer_options); |
| 281 | |
| 282 | if (question_type === 'true_false' && $('.answer-option-row').length >= 2){ |
| 283 | $('.add_answer_option_wrap').hide(); |
| 284 | }else{ |
| 285 | $('.add_answer_option_wrap').show(); |
| 286 | } |
| 287 | } |
| 288 | }, |
| 289 | complete: function () { |
| 290 | $that.closest('.single-question-item').find('.tutor-loading-icon-wrap').removeClass('tutor-updating-message'); |
| 291 | } |
| 292 | }); |
| 293 | }); |
| 294 | |
| 295 | $(document).on('click', '.add_answer_option_btn', function(e){ |
| 296 | e.preventDefault(); |
| 297 | |
| 298 | var $that = $(this); |
| 299 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 300 | var question_type = $that.closest('.quiz-question-form-wrap').find('select.question_type_field').val(); |
| 301 | var data = {question_id: question_id, action: 'quiz_add_answer_to_question'}; |
| 302 | |
| 303 | $.ajax({ |
| 304 | url : ajaxurl, |
| 305 | type : 'POST', |
| 306 | data : data, |
| 307 | beforeSend: function () { |
| 308 | $that.removeClass('updated-message').addClass('tutor-updating-message'); |
| 309 | }, |
| 310 | success: function (data) { |
| 311 | if (data.success){ |
| 312 | $that.closest('.answer-entry-wrap').find('table.multi-answers-options').append(data.data.data_tr); |
| 313 | |
| 314 | //Hide add answer button if true false and 2 option exists |
| 315 | if (question_type === 'true_false' && $that.closest('.answer-entry-wrap').find('tr.answer-option-row').length >= 2){ |
| 316 | $that.closest('.add_answer_option_wrap').hide(); |
| 317 | }else{ |
| 318 | $that.closest('.add_answer_option_wrap').show(); |
| 319 | } |
| 320 | } |
| 321 | }, |
| 322 | complete: function () { |
| 323 | $that.removeClass('tutor-updating-message').addClass('updated-message'); |
| 324 | } |
| 325 | }); |
| 326 | }); |
| 327 | |
| 328 | $(document).on('click', '.add_question_btn', function(e){ |
| 329 | e.preventDefault(); |
| 330 | |
| 331 | var $that = $(this); |
| 332 | var $title = $('[name="new_question_title"]'); |
| 333 | var question_title = $title.val(); |
| 334 | var question_type = $('[name="new_question_type"]').val(); |
| 335 | var quiz_id = $('#post_ID').val(); |
| 336 | |
| 337 | //If no question title, stop here |
| 338 | if ( ! question_title.length){ |
| 339 | $title.addClass('tutor-input-text-error'); |
| 340 | return; |
| 341 | }else{ |
| 342 | $title.removeClass('tutor-input-text-error'); |
| 343 | } |
| 344 | |
| 345 | var data = {question_title : question_title, question_type:question_type, quiz_id : quiz_id, action: 'quiz_page_add_new_question' }; |
| 346 | $.ajax({ |
| 347 | url : ajaxurl, |
| 348 | type : 'POST', |
| 349 | data : data, |
| 350 | beforeSend: function () { |
| 351 | $that.removeClass('updated-message').addClass('tutor-updating-message'); |
| 352 | }, |
| 353 | success: function (data) { |
| 354 | if (data.success){ |
| 355 | $('.single-question-item .quiz-question-form-wrap').hide(); |
| 356 | $('.tutor-quiz-questions-wrap').append(data.data.question_html); |
| 357 | $('.single-question-item:last-child .quiz-question-form-wrap').show(); |
| 358 | $title.val(''); |
| 359 | } |
| 360 | }, |
| 361 | complete: function () { |
| 362 | $that.removeClass('tutor-updating-message').addClass('updated-message'); |
| 363 | } |
| 364 | }); |
| 365 | }); |
| 366 | |
| 367 | //Show hide question settings |
| 368 | $(document).on('click', '.question-action-btn.down', function(e){ |
| 369 | e.preventDefault(); |
| 370 | $(this).closest('.single-question-item').find('.quiz-question-form-wrap').toggle(); |
| 371 | $(this).find('i.dashicons').toggleClass('dashicons-arrow-up-alt2 dashicons-arrow-down-alt2'); |
| 372 | }); |
| 373 | |
| 374 | $(document).on('change', '.single-question-item', function(e){ |
| 375 | e.preventDefault(); |
| 376 | |
| 377 | var $that = $(this); |
| 378 | var data = $(this).find("select, textarea, input").serialize()+'&action=update_tutor_question'; |
| 379 | $.ajax({ |
| 380 | url : ajaxurl, |
| 381 | type : 'POST', |
| 382 | data : data, |
| 383 | beforeSend: function () { |
| 384 | $that.find('.tutor-loading-icon-wrap').addClass('tutor-updating-message'); |
| 385 | }, |
| 386 | success: function (data) { |
| 387 | if (data.success){ |
| 388 | |
| 389 | } |
| 390 | }, |
| 391 | complete: function () { |
| 392 | $that.find('.tutor-loading-icon-wrap').removeClass('tutor-updating-message'); |
| 393 | } |
| 394 | }); |
| 395 | }); |
| 396 | |
| 397 | $(document).on('click', '.quiz-answer-option-delete-btn', function(e){ |
| 398 | e.preventDefault(); |
| 399 | var $that = $(this); |
| 400 | var $closestTable = $that.closest('table'); |
| 401 | var $loadingIcon = $that.closest('.single-question-item').find('.tutor-loading-icon-wrap'); |
| 402 | |
| 403 | var question_type = $that.closest('.quiz-question-form-wrap').find('select.question_type_field').val(); |
| 404 | var answer_option_id = $that.closest('tr').attr('data-answer-option-id'); |
| 405 | |
| 406 | $.ajax({ |
| 407 | url : ajaxurl, |
| 408 | type : 'POST', |
| 409 | data : {answer_option_id:answer_option_id, action: 'quiz_delete_answer_option'}, |
| 410 | beforeSend: function () { |
| 411 | $loadingIcon.addClass('tutor-updating-message'); |
| 412 | }, |
| 413 | success: function (data) { |
| 414 | if (data.success){ |
| 415 | $that.closest('tr').remove(); |
| 416 | //Hide add answer button if true false and 2 option exists |
| 417 | if (question_type === 'true_false' && $closestTable.find('tr.answer-option-row').length >= 2){ |
| 418 | $closestTable.closest('.answer-entry-wrap').find('.add_answer_option_wrap').hide(); |
| 419 | }else{ |
| 420 | $closestTable.closest('.answer-entry-wrap').find('.add_answer_option_wrap').show(); |
| 421 | } |
| 422 | } |
| 423 | }, |
| 424 | complete: function () { |
| 425 | $loadingIcon.removeClass('tutor-updating-message'); |
| 426 | } |
| 427 | }); |
| 428 | }); |
| 429 | |
| 430 | $(document).on('click', '.question-action-btn.trash', function(e){ |
| 431 | e.preventDefault(); |
| 432 | |
| 433 | var $that = $(this); |
| 434 | var question_id = $that.closest('.single-question-item').attr('data-question-id'); |
| 435 | var $loadingIcon = $that.closest('.single-question-item').find('.tutor-loading-icon-wrap'); |
| 436 | |
| 437 | $.ajax({ |
| 438 | url : ajaxurl, |
| 439 | type : 'POST', |
| 440 | data : {question_id:question_id, action: 'quiz_question_delete'}, |
| 441 | beforeSend: function () { |
| 442 | $loadingIcon.addClass('tutor-updating-message'); |
| 443 | }, |
| 444 | success: function (data) { |
| 445 | if (data.success){ |
| 446 | $that.closest('.single-question-item').remove(); |
| 447 | } |
| 448 | }, |
| 449 | complete: function () { |
| 450 | $loadingIcon.removeClass('tutor-updating-message'); |
| 451 | } |
| 452 | }); |
| 453 | }); |
| 454 | |
| 455 | /** |
| 456 | * Sort quiz questions |
| 457 | */ |
| 458 | |
| 459 | if (jQuery().sortable) { |
| 460 | $(".tutor-quiz-questions-wrap").sortable({ |
| 461 | handle: ".question-short", |
| 462 | start: function (e, ui) { |
| 463 | ui.placeholder.css('visibility', 'visible'); |
| 464 | }, |
| 465 | stop: function (e, ui) { |
| 466 | var questions = {}; |
| 467 | $('.single-question-item').each(function(index, item){ |
| 468 | var $question = $(this); |
| 469 | var question_id = parseInt($question.attr('data-question-id').match(/\d+/)[0], 10); |
| 470 | questions[index] = { 'question_id' : question_id }; |
| 471 | }); |
| 472 | |
| 473 | $.post(ajaxurl, {questions : questions, action: 'sorting_quiz_questions'}); |
| 474 | }, |
| 475 | }); |
| 476 | } |
| 477 | |
| 478 | $(document).on('change keyup', '.tutor-quiz-modal-wrap .tutor-modal-search-input', function(e){ |
| 479 | e.preventDefault(); |
| 480 | |
| 481 | var $that = $(this); |
| 482 | var $modal = $('.tutor-modal-wrap'); |
| 483 | |
| 484 | tutor_delay(function(){ |
| 485 | var search_terms = $that.val(); |
| 486 | var quiz_for_post_id = $modal.attr('quiz-for-post-id'); |
| 487 | |
| 488 | $.ajax({ |
| 489 | url : ajaxurl, |
| 490 | type : 'POST', |
| 491 | data : {quiz_for_post_id : quiz_for_post_id, search_terms : search_terms, action: 'tutor_load_quiz_modal'}, |
| 492 | beforeSend: function () { |
| 493 | $modal.addClass('loading'); |
| 494 | }, |
| 495 | success: function (data) { |
| 496 | if (data.success){ |
| 497 | $('.tutor-modal-wrap .modal-container').html(data.data.output); |
| 498 | } |
| 499 | }, |
| 500 | complete: function () { |
| 501 | $modal.removeClass('loading'); |
| 502 | } |
| 503 | }); |
| 504 | |
| 505 | }, 1000) |
| 506 | }); |
| 507 | |
| 508 | var tutor_delay = (function(){ |
| 509 | var timer = 0; |
| 510 | return function(callback, ms){ |
| 511 | clearTimeout (timer); |
| 512 | timer = setTimeout(callback, ms); |
| 513 | }; |
| 514 | })(); |
| 515 | |
| 516 | $(document).on('click', '.tutor-quiz-delete-btn', function(e){ |
| 517 | e.preventDefault(); |
| 518 | |
| 519 | var $that = $(this); |
| 520 | var quiz_id = $that.closest('.added-quiz-item').attr('data-quiz-id'); |
| 521 | |
| 522 | $.ajax({ |
| 523 | url : ajaxurl, |
| 524 | type : 'POST', |
| 525 | data : {quiz_id:quiz_id, action: 'remove_quiz_from_post'}, |
| 526 | success: function (data) { |
| 527 | if (data.success){ |
| 528 | $that.closest('.added-quiz-item').remove(); |
| 529 | } |
| 530 | } |
| 531 | }); |
| 532 | }); |
| 533 | |
| 534 | $(document).on('click', '.tutor-option-media-upload-btn', function(e){ |
| 535 | e.preventDefault(); |
| 536 | |
| 537 | var $that = $(this); |
| 538 | var frame; |
| 539 | if ( frame ) { |
| 540 | frame.open(); |
| 541 | return; |
| 542 | } |
| 543 | frame = wp.media({ |
| 544 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 545 | button: { |
| 546 | text: 'Use this media' |
| 547 | }, |
| 548 | multiple: false |
| 549 | }); |
| 550 | frame.on( 'select', function() { |
| 551 | var attachment = frame.state().get('selection').first().toJSON(); |
| 552 | $that.closest('.option-media-wrap').find('.option-media-preview').html('<img src="'+attachment.url+'" alt="" />'); |
| 553 | $that.closest('.option-media-wrap').find('input').val(attachment.id); |
| 554 | }); |
| 555 | frame.open(); |
| 556 | }); |
| 557 | |
| 558 | $(document).on('change', '.tutor_addons_list_item', function(e) { |
| 559 | var $that = $(this); |
| 560 | |
| 561 | var isEnable = $that.prop('checked') ? 1 : 0; |
| 562 | var addonFieldName = $that.attr('name'); |
| 563 | |
| 564 | $.ajax({ |
| 565 | url : ajaxurl, |
| 566 | type : 'POST', |
| 567 | data : {isEnable:isEnable, addonFieldName:addonFieldName, action : 'addon_enable_disable'}, |
| 568 | success: function (data) { |
| 569 | if (data.success){ |
| 570 | //Success |
| 571 | } |
| 572 | } |
| 573 | }); |
| 574 | }); |
| 575 | |
| 576 | /** |
| 577 | * Add instructor |
| 578 | * @since v.1.0.3 |
| 579 | */ |
| 580 | $(document).on('submit', '#new-instructor-form', function(e){ |
| 581 | e.preventDefault(); |
| 582 | |
| 583 | var $that = $(this); |
| 584 | var formData = $that.serialize()+'&action=tutor_add_instructor'; |
| 585 | |
| 586 | $.ajax({ |
| 587 | url : ajaxurl, |
| 588 | type : 'POST', |
| 589 | data : formData, |
| 590 | success: function (data) { |
| 591 | if (data.success){ |
| 592 | $that.trigger("reset"); |
| 593 | $('#form-response').html('<p class="tutor-status-approved-context">'+data.data.msg+'</p>'); |
| 594 | }else{ |
| 595 | var errorMsg = ''; |
| 596 | |
| 597 | var errors = data.data.errors; |
| 598 | if (errors && Object.keys(errors).length){ |
| 599 | $.each(data.data.errors, function( index, value ) { |
| 600 | if (isObject(value)){ |
| 601 | |
| 602 | $.each(value, function( key, value1 ) { |
| 603 | errorMsg += '<p class="tutor-required-fields">'+value1[0]+'</p>'; |
| 604 | }); |
| 605 | } else{ |
| 606 | errorMsg += '<p class="tutor-required-fields">'+value+'</p>'; |
| 607 | } |
| 608 | }); |
| 609 | $('#form-response').html(errorMsg); |
| 610 | } |
| 611 | |
| 612 | } |
| 613 | } |
| 614 | }); |
| 615 | }); |
| 616 | |
| 617 | function isObject (value) { |
| 618 | return value && typeof value === 'object' && value.constructor === Object; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /** |
| 623 | * Tutor Assignments JS |
| 624 | * @since v.1.3.3 |
| 625 | */ |
| 626 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 627 | e.preventDefault(); |
| 628 | |
| 629 | var $that = $(this); |
| 630 | var topic_id = $(this).attr('data-topic-id'); |
| 631 | var course_id = $('#post_ID').val(); |
| 632 | |
| 633 | $.ajax({ |
| 634 | url : ajaxurl, |
| 635 | type : 'POST', |
| 636 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 637 | beforeSend: function () { |
| 638 | $that.addClass('tutor-updating-message'); |
| 639 | }, |
| 640 | success: function (data) { |
| 641 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 642 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 643 | |
| 644 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 645 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 646 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 647 | }, |
| 648 | complete: function () { |
| 649 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 650 | $that.removeClass('tutor-updating-message'); |
| 651 | } |
| 652 | }); |
| 653 | }); |
| 654 | |
| 655 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 656 | e.preventDefault(); |
| 657 | |
| 658 | var $that = $(this); |
| 659 | var assignment_id = $that.attr('data-assignment-id'); |
| 660 | var topic_id = $that.attr('data-topic-id'); |
| 661 | var course_id = $('#post_ID').val(); |
| 662 | |
| 663 | $.ajax({ |
| 664 | url : ajaxurl, |
| 665 | type : 'POST', |
| 666 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 667 | beforeSend: function () { |
| 668 | $that.addClass('tutor-updating-message'); |
| 669 | }, |
| 670 | success: function (data) { |
| 671 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 672 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 673 | |
| 674 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 675 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 676 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 677 | }, |
| 678 | complete: function () { |
| 679 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 680 | $that.removeClass('tutor-updating-message'); |
| 681 | } |
| 682 | }); |
| 683 | }); |
| 684 | |
| 685 | /** |
| 686 | * Update Assignment Data |
| 687 | */ |
| 688 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 689 | event.preventDefault(); |
| 690 | |
| 691 | var $that = $(this); |
| 692 | var content; |
| 693 | var inputid = 'tutor_assignments_modal_editor'; |
| 694 | var editor = tinyMCE.get(inputid); |
| 695 | if (editor) { |
| 696 | content = editor.getContent(); |
| 697 | } else { |
| 698 | content = $('#'+inputid).val(); |
| 699 | } |
| 700 | |
| 701 | var form_data = $(this).closest('form').serialize(); |
| 702 | form_data += '&assignment_content='+content; |
| 703 | |
| 704 | $.ajax({ |
| 705 | url : ajaxurl, |
| 706 | type : 'POST', |
| 707 | data : form_data, |
| 708 | beforeSend: function () { |
| 709 | $that.addClass('tutor-updating-message'); |
| 710 | }, |
| 711 | success: function (data) { |
| 712 | if (data.success){ |
| 713 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 714 | enable_sorting_topic_lesson(); |
| 715 | |
| 716 | //Close the modal |
| 717 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 718 | } |
| 719 | }, |
| 720 | complete: function () { |
| 721 | $that.removeClass('tutor-updating-message'); |
| 722 | } |
| 723 | }); |
| 724 | }); |
| 725 | |
| 726 | /** |
| 727 | * Add Assignment |
| 728 | */ |
| 729 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 730 | event.preventDefault(); |
| 731 | |
| 732 | var $that = $(this); |
| 733 | var frame; |
| 734 | // If the media frame already exists, reopen it. |
| 735 | if ( frame ) { |
| 736 | frame.open(); |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | // Create a new media frame |
| 741 | frame = wp.media({ |
| 742 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 743 | button: { |
| 744 | text: 'Use this media' |
| 745 | }, |
| 746 | multiple: false // Set to true to allow multiple files to be selected |
| 747 | }); |
| 748 | |
| 749 | // When an image is selected in the media frame... |
| 750 | frame.on( 'select', function() { |
| 751 | // Get media attachment details from the frame state |
| 752 | var attachment = frame.state().get('selection').first().toJSON(); |
| 753 | |
| 754 | 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>'; |
| 755 | |
| 756 | $('#assignment-attached-file').append(field_markup); |
| 757 | $that.closest('.video_source_wrap_html5').find('input').val(attachment.id); |
| 758 | }); |
| 759 | // Finally, open the modal on click |
| 760 | frame.open(); |
| 761 | }); |
| 762 | |
| 763 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 764 | event.preventDefault(); |
| 765 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 766 | }); |
| 767 | |
| 768 | /** |
| 769 | * Used for backend profile photo upload. |
| 770 | */ |
| 771 | |
| 772 | //tutor_video_poster_upload_btn |
| 773 | $(document).on( 'click', '.tutor_video_poster_upload_btn', function( event ){ |
| 774 | event.preventDefault(); |
| 775 | |
| 776 | var $that = $(this); |
| 777 | var frame; |
| 778 | // If the media frame already exists, reopen it. |
| 779 | if ( frame ) { |
| 780 | frame.open(); |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | // Create a new media frame |
| 785 | frame = wp.media({ |
| 786 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 787 | button: { |
| 788 | text: 'Use this media' |
| 789 | }, |
| 790 | multiple: false // Set to true to allow multiple files to be selected |
| 791 | }); |
| 792 | |
| 793 | // When an image is selected in the media frame... |
| 794 | frame.on( 'select', function() { |
| 795 | // Get media attachment details from the frame state |
| 796 | var attachment = frame.state().get('selection').first().toJSON(); |
| 797 | $that.closest('.tutor-video-poster-wrap').find('.video-poster-img').html('<img src="'+attachment.url+'" alt="" />'); |
| 798 | $that.closest('.tutor-video-poster-wrap').find('input').val(attachment.id); |
| 799 | }); |
| 800 | // Finally, open the modal on click |
| 801 | frame.open(); |
| 802 | }); |
| 803 | |
| 804 | |
| 805 | /** |
| 806 | * Tutor Memberships toggle in Paid Membership Pro panel |
| 807 | * @since v.1.3.6 |
| 808 | */ |
| 809 | |
| 810 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 811 | e.preventDefault(); |
| 812 | |
| 813 | var $that = $(this); |
| 814 | |
| 815 | if ($that.val() === 'category_wise_membership'){ |
| 816 | $('.membership_course_categories').show(); |
| 817 | } else{ |
| 818 | $('.membership_course_categories').hide(); |
| 819 | } |
| 820 | }); |
| 821 | |
| 822 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 823 | e.preventDefault(); |
| 824 | |
| 825 | var $that = $(this); |
| 826 | |
| 827 | if ($that.val() === 'category_wise_membership'){ |
| 828 | $('.membership_course_categories').show(); |
| 829 | } else{ |
| 830 | $('.membership_course_categories').hide(); |
| 831 | } |
| 832 | }); |
| 833 | |
| 834 | /** |
| 835 | * Find user/student from select2 |
| 836 | * @since v.1.4.0 |
| 837 | */ |
| 838 | |
| 839 | $('#select2_search_user_ajax').select2({ |
| 840 | allowClear: true, |
| 841 | placeholder: "Search students", |
| 842 | minimumInputLength: '1', |
| 843 | escapeMarkup: function( m ) { |
| 844 | return m; |
| 845 | }, |
| 846 | ajax: { |
| 847 | url : ajaxurl, |
| 848 | type : 'POST', |
| 849 | dataType: 'json', |
| 850 | delay: 1000, |
| 851 | data: function( params ) { |
| 852 | return { |
| 853 | term: params.term, |
| 854 | action: 'tutor_json_search_students' |
| 855 | }; |
| 856 | }, |
| 857 | processResults: function( data ) { |
| 858 | var terms = []; |
| 859 | if ( data ) { |
| 860 | $.each( data, function( id, text ) { |
| 861 | terms.push({ |
| 862 | id: id, |
| 863 | text: text |
| 864 | }); |
| 865 | }); |
| 866 | } |
| 867 | return { |
| 868 | results: terms |
| 869 | }; |
| 870 | |
| 871 | }, |
| 872 | cache: true |
| 873 | } |
| 874 | }); |
| 875 | |
| 876 | /** |
| 877 | * Confirm Alert for deleting enrollments data |
| 878 | * |
| 879 | * @since v.1.4.0 |
| 880 | */ |
| 881 | $(document).on( 'click', 'table.enrolments .delete a', function( e ){ |
| 882 | if (! confirm(tutor_data.delete_confirm_text)) { |
| 883 | e.preventDefault(); |
| 884 | } |
| 885 | }); |
| 886 | |
| 887 | }); |
| 888 |