Chart.bundle.min.js
6 years ago
gutenberg_blocks.js
6 years ago
mce-button.js
6 years ago
tutor-admin.js
6 years ago
tutor-front.js
6 years ago
tutor-setup.js
6 years ago
tutor.js
6 years ago
tutor-admin.js
657 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('data-tab'); |
| 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 | window.history.pushState('obj', '', $(this).attr('href')); |
| 27 | }); |
| 28 | |
| 29 | $('#save_tutor_option').click(function (e) { |
| 30 | e.preventDefault(); |
| 31 | $(this).closest('form').submit(); |
| 32 | }); |
| 33 | $('#tutor-option-form').submit(function(e){ |
| 34 | e.preventDefault(); |
| 35 | |
| 36 | var $form = $(this); |
| 37 | var data = $form.serialize(); |
| 38 | |
| 39 | $.ajax({ |
| 40 | url : ajaxurl, |
| 41 | type : 'POST', |
| 42 | data : data, |
| 43 | beforeSend: function () { |
| 44 | $form.find('.button').addClass('tutor-updating-message'); |
| 45 | }, |
| 46 | success: function (data) { |
| 47 | if (data.success) { |
| 48 | //window.location.reload(); |
| 49 | } |
| 50 | }, |
| 51 | complete: function () { |
| 52 | $form.find('.button').removeClass('tutor-updating-message'); |
| 53 | } |
| 54 | }); |
| 55 | }); |
| 56 | |
| 57 | /** |
| 58 | * Withdraw nav tabs |
| 59 | * @since v.1.1.2 |
| 60 | */ |
| 61 | $(document).on('click', '.withdraw-method-nav li a', function(e){ |
| 62 | e.preventDefault(); |
| 63 | var tab_page_id = $(this).attr('data-target-id'); |
| 64 | $('.withdraw-method-form-wrap').hide(); |
| 65 | $('#'+tab_page_id).show(); |
| 66 | }); |
| 67 | |
| 68 | /** |
| 69 | * End Withdraw nav tabs |
| 70 | */ |
| 71 | |
| 72 | /** |
| 73 | * Don't move it to anywhere? |
| 74 | */ |
| 75 | function enable_sorting_topic_lesson(){ |
| 76 | if (jQuery().sortable) { |
| 77 | $(".course-contents").sortable({ |
| 78 | handle: ".course-move-handle", |
| 79 | start: function (e, ui) { |
| 80 | ui.placeholder.css('visibility', 'visible'); |
| 81 | }, |
| 82 | stop: function (e, ui) { |
| 83 | tutor_sorting_topics_and_lesson(); |
| 84 | }, |
| 85 | }); |
| 86 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 87 | connectWith: ".tutor-lessons", |
| 88 | items: "div.course-content-item", |
| 89 | start: function (e, ui) { |
| 90 | ui.placeholder.css('visibility', 'visible'); |
| 91 | }, |
| 92 | stop: function (e, ui) { |
| 93 | tutor_sorting_topics_and_lesson(); |
| 94 | }, |
| 95 | }); |
| 96 | } |
| 97 | } |
| 98 | enable_sorting_topic_lesson(); |
| 99 | function tutor_sorting_topics_and_lesson(){ |
| 100 | var topics = {}; |
| 101 | $('.tutor-topics-wrap').each(function(index, item){ |
| 102 | var $topic = $(this); |
| 103 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 104 | var lessons = {}; |
| 105 | |
| 106 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 107 | var $lesson = $(this); |
| 108 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 109 | |
| 110 | lessons[lessonIndex] = lesson_id; |
| 111 | }); |
| 112 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 113 | }); |
| 114 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Lesson Update or Create Modal |
| 119 | */ |
| 120 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 121 | event.preventDefault(); |
| 122 | |
| 123 | var $that = $(this); |
| 124 | var content; |
| 125 | var inputid = 'tutor_lesson_modal_editor'; |
| 126 | var editor = tinyMCE.get(inputid); |
| 127 | if (editor) { |
| 128 | content = editor.getContent(); |
| 129 | } else { |
| 130 | content = $('#'+inputid).val(); |
| 131 | } |
| 132 | |
| 133 | var form_data = $(this).closest('form').serialize(); |
| 134 | form_data += '&lesson_content='+encodeURIComponent(content); |
| 135 | |
| 136 | $.ajax({ |
| 137 | url : ajaxurl, |
| 138 | type : 'POST', |
| 139 | data : form_data, |
| 140 | beforeSend: function () { |
| 141 | $that.addClass('tutor-updating-message'); |
| 142 | }, |
| 143 | success: function (data) { |
| 144 | if (data.success){ |
| 145 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 146 | enable_sorting_topic_lesson(); |
| 147 | |
| 148 | //Close the modal |
| 149 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 150 | } |
| 151 | }, |
| 152 | complete: function () { |
| 153 | $that.removeClass('tutor-updating-message'); |
| 154 | } |
| 155 | }); |
| 156 | }); |
| 157 | |
| 158 | /** |
| 159 | * Lesson Video |
| 160 | */ |
| 161 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 162 | var selector = $(this).val(); |
| 163 | $('[class^="video_source_wrap"]').hide(); |
| 164 | $('.video_source_wrap_'+selector).show(); |
| 165 | |
| 166 | if (selector === 'html5'){ |
| 167 | $('.tutor-video-poster-field').show(); |
| 168 | } else{ |
| 169 | $('.tutor-video-poster-field').hide(); |
| 170 | } |
| 171 | }); |
| 172 | |
| 173 | $(document).on( 'click', '.video_source_wrap_html5 .video_upload_btn', function( event ){ |
| 174 | event.preventDefault(); |
| 175 | |
| 176 | var $that = $(this); |
| 177 | var frame; |
| 178 | // If the media frame already exists, reopen it. |
| 179 | if ( frame ) { |
| 180 | frame.open(); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Create a new media frame |
| 185 | frame = wp.media({ |
| 186 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 187 | button: { |
| 188 | text: 'Use this media' |
| 189 | }, |
| 190 | multiple: false // Set to true to allow multiple files to be selected |
| 191 | }); |
| 192 | |
| 193 | // When an image is selected in the media frame... |
| 194 | frame.on( 'select', function() { |
| 195 | // Get media attachment details from the frame state |
| 196 | var attachment = frame.state().get('selection').first().toJSON(); |
| 197 | $that.closest('.video_source_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 198 | $that.closest('.video_source_wrap_html5').find('input.input_source_video_id').val(attachment.id); |
| 199 | }); |
| 200 | // Finally, open the modal on click |
| 201 | frame.open(); |
| 202 | }); |
| 203 | |
| 204 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 205 | e.preventDefault(); |
| 206 | $(this).closest('.tutor-added-attachment').remove(); |
| 207 | }); |
| 208 | |
| 209 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 210 | e.preventDefault(); |
| 211 | |
| 212 | var $that = $(this); |
| 213 | var frame; |
| 214 | // If the media frame already exists, reopen it. |
| 215 | if ( frame ) { |
| 216 | frame.open(); |
| 217 | return; |
| 218 | } |
| 219 | // Create a new media frame |
| 220 | frame = wp.media({ |
| 221 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 222 | button: { |
| 223 | text: 'Use this media' |
| 224 | }, |
| 225 | multiple: true // Set to true to allow multiple files to be selected |
| 226 | }); |
| 227 | // When an image is selected in the media frame... |
| 228 | frame.on( 'select', function() { |
| 229 | // Get media attachment details from the frame state |
| 230 | var attachments = frame.state().get('selection').toJSON(); |
| 231 | if (attachments.length){ |
| 232 | for (var i=0; i < attachments.length; i++){ |
| 233 | var attachment = attachments[i]; |
| 234 | |
| 235 | 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>'; |
| 236 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 237 | } |
| 238 | } |
| 239 | }); |
| 240 | // Finally, open the modal on click |
| 241 | frame.open(); |
| 242 | }); |
| 243 | |
| 244 | /** |
| 245 | * Open Sidebar Menu |
| 246 | */ |
| 247 | if (tutor_data.open_tutor_admin_menu){ |
| 248 | var $adminMenu = $('#adminmenu'); |
| 249 | $adminMenu.find('[href="admin.php?page=tutor"]').closest('li.wp-has-submenu').addClass('wp-has-current-submenu'); |
| 250 | $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'); |
| 251 | } |
| 252 | |
| 253 | $(document).on('click', '.tutor-option-media-upload-btn', function(e){ |
| 254 | e.preventDefault(); |
| 255 | |
| 256 | var $that = $(this); |
| 257 | var frame; |
| 258 | if ( frame ) { |
| 259 | frame.open(); |
| 260 | return; |
| 261 | } |
| 262 | frame = wp.media({ |
| 263 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 264 | button: { |
| 265 | text: 'Use this media' |
| 266 | }, |
| 267 | multiple: false |
| 268 | }); |
| 269 | frame.on( 'select', function() { |
| 270 | var attachment = frame.state().get('selection').first().toJSON(); |
| 271 | $that.closest('.option-media-wrap').find('.option-media-preview').html('<img src="'+attachment.url+'" alt="" />'); |
| 272 | $that.closest('.option-media-wrap').find('input').val(attachment.id); |
| 273 | $that.closest('.option-media-wrap').find('.tutor-media-option-trash-btn').show(); |
| 274 | }); |
| 275 | frame.open(); |
| 276 | }); |
| 277 | |
| 278 | /** |
| 279 | * Remove option media |
| 280 | * @since v.1.4.3 |
| 281 | */ |
| 282 | $(document).on('click', '.tutor-media-option-trash-btn', function(e){ |
| 283 | e.preventDefault(); |
| 284 | |
| 285 | var $that = $(this); |
| 286 | $that.closest('.option-media-wrap').find('img').remove(); |
| 287 | $that.closest('.option-media-wrap').find('input').val(''); |
| 288 | $that.closest('.option-media-wrap').find('.tutor-media-option-trash-btn').hide(); |
| 289 | }); |
| 290 | |
| 291 | |
| 292 | $(document).on('change', '.tutor_addons_list_item', function(e) { |
| 293 | var $that = $(this); |
| 294 | |
| 295 | var isEnable = $that.prop('checked') ? 1 : 0; |
| 296 | var addonFieldName = $that.attr('name'); |
| 297 | |
| 298 | $.ajax({ |
| 299 | url : ajaxurl, |
| 300 | type : 'POST', |
| 301 | data : {isEnable:isEnable, addonFieldName:addonFieldName, action : 'addon_enable_disable'}, |
| 302 | success: function (data) { |
| 303 | if (data.success){ |
| 304 | //Success |
| 305 | } |
| 306 | } |
| 307 | }); |
| 308 | }); |
| 309 | |
| 310 | /** |
| 311 | * Add instructor |
| 312 | * @since v.1.0.3 |
| 313 | */ |
| 314 | $(document).on('submit', '#new-instructor-form', function(e){ |
| 315 | e.preventDefault(); |
| 316 | |
| 317 | var $that = $(this); |
| 318 | var formData = $that.serialize()+'&action=tutor_add_instructor'; |
| 319 | |
| 320 | $.ajax({ |
| 321 | url : ajaxurl, |
| 322 | type : 'POST', |
| 323 | data : formData, |
| 324 | success: function (data) { |
| 325 | if (data.success){ |
| 326 | $that.trigger("reset"); |
| 327 | $('#form-response').html('<p class="tutor-status-approved-context">'+data.data.msg+'</p>'); |
| 328 | }else{ |
| 329 | var errorMsg = ''; |
| 330 | |
| 331 | var errors = data.data.errors; |
| 332 | if (errors && Object.keys(errors).length){ |
| 333 | $.each(data.data.errors, function( index, value ) { |
| 334 | if (isObject(value)){ |
| 335 | $.each(value, function( key, value1 ) { |
| 336 | errorMsg += '<p class="tutor-required-fields">'+value1[0]+'</p>'; |
| 337 | }); |
| 338 | } else{ |
| 339 | errorMsg += '<p class="tutor-required-fields">'+value+'</p>'; |
| 340 | } |
| 341 | }); |
| 342 | $('#form-response').html(errorMsg); |
| 343 | } |
| 344 | |
| 345 | } |
| 346 | } |
| 347 | }); |
| 348 | }); |
| 349 | |
| 350 | |
| 351 | /** |
| 352 | * Instructor block unblock action |
| 353 | * @since v.1.5.3 |
| 354 | */ |
| 355 | |
| 356 | $(document).on('click', 'a.instructor-action', function(e){ |
| 357 | e.preventDefault(); |
| 358 | |
| 359 | var $that = $(this); |
| 360 | var action = $that.attr('data-action'); |
| 361 | var instructor_id = $that.attr('data-instructor-id'); |
| 362 | |
| 363 | var nonce_key = tutor_data.nonce_key; |
| 364 | var json_data = { instructor_id : instructor_id, action_name : action, action: 'instructor_approval_action'}; |
| 365 | json_data[nonce_key] = tutor_data[nonce_key]; |
| 366 | |
| 367 | $.ajax({ |
| 368 | url : ajaxurl, |
| 369 | type : 'POST', |
| 370 | data : json_data, |
| 371 | beforeSend: function () { |
| 372 | $that.addClass('tutor-updating-message'); |
| 373 | }, |
| 374 | success: function (data) { |
| 375 | location.reload(true); |
| 376 | }, |
| 377 | complete: function () { |
| 378 | $that.removeClass('tutor-updating-message'); |
| 379 | } |
| 380 | }); |
| 381 | }); |
| 382 | |
| 383 | function isObject (value) { |
| 384 | return value && typeof value === 'object' && value.constructor === Object; |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Tutor Assignments JS |
| 389 | * @since v.1.3.3 |
| 390 | */ |
| 391 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 392 | e.preventDefault(); |
| 393 | |
| 394 | var $that = $(this); |
| 395 | var topic_id = $(this).attr('data-topic-id'); |
| 396 | var course_id = $('#post_ID').val(); |
| 397 | |
| 398 | $.ajax({ |
| 399 | url : ajaxurl, |
| 400 | type : 'POST', |
| 401 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 402 | beforeSend: function () { |
| 403 | $that.addClass('tutor-updating-message'); |
| 404 | }, |
| 405 | success: function (data) { |
| 406 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 407 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 408 | |
| 409 | $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 410 | |
| 411 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 412 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 413 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 414 | }, |
| 415 | complete: function () { |
| 416 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 417 | $that.removeClass('tutor-updating-message'); |
| 418 | } |
| 419 | }); |
| 420 | }); |
| 421 | |
| 422 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 423 | e.preventDefault(); |
| 424 | |
| 425 | var $that = $(this); |
| 426 | var assignment_id = $that.attr('data-assignment-id'); |
| 427 | var topic_id = $that.attr('data-topic-id'); |
| 428 | var course_id = $('#post_ID').val(); |
| 429 | |
| 430 | $.ajax({ |
| 431 | url : ajaxurl, |
| 432 | type : 'POST', |
| 433 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 434 | beforeSend: function () { |
| 435 | $that.addClass('tutor-updating-message'); |
| 436 | }, |
| 437 | success: function (data) { |
| 438 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 439 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 440 | |
| 441 | $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id}); |
| 442 | |
| 443 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 444 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 445 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 446 | }, |
| 447 | complete: function () { |
| 448 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 449 | $that.removeClass('tutor-updating-message'); |
| 450 | } |
| 451 | }); |
| 452 | }); |
| 453 | |
| 454 | /** |
| 455 | * Update Assignment Data |
| 456 | */ |
| 457 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 458 | event.preventDefault(); |
| 459 | |
| 460 | var $that = $(this); |
| 461 | var content; |
| 462 | var inputid = 'tutor_assignments_modal_editor'; |
| 463 | var editor = tinyMCE.get(inputid); |
| 464 | if (editor) { |
| 465 | content = editor.getContent(); |
| 466 | } else { |
| 467 | content = $('#'+inputid).val(); |
| 468 | } |
| 469 | |
| 470 | var form_data = $(this).closest('form').serialize(); |
| 471 | form_data += '&assignment_content='+content; |
| 472 | |
| 473 | $.ajax({ |
| 474 | url : ajaxurl, |
| 475 | type : 'POST', |
| 476 | data : form_data, |
| 477 | beforeSend: function () { |
| 478 | $that.addClass('tutor-updating-message'); |
| 479 | }, |
| 480 | success: function (data) { |
| 481 | if (data.success){ |
| 482 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 483 | enable_sorting_topic_lesson(); |
| 484 | |
| 485 | //Close the modal |
| 486 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 487 | } |
| 488 | }, |
| 489 | complete: function () { |
| 490 | $that.removeClass('tutor-updating-message'); |
| 491 | } |
| 492 | }); |
| 493 | }); |
| 494 | |
| 495 | /** |
| 496 | * Add Assignment |
| 497 | */ |
| 498 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 499 | event.preventDefault(); |
| 500 | |
| 501 | var $that = $(this); |
| 502 | var frame; |
| 503 | // If the media frame already exists, reopen it. |
| 504 | if ( frame ) { |
| 505 | frame.open(); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | // Create a new media frame |
| 510 | frame = wp.media({ |
| 511 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 512 | button: { |
| 513 | text: 'Use this media' |
| 514 | }, |
| 515 | multiple: false // Set to true to allow multiple files to be selected |
| 516 | }); |
| 517 | |
| 518 | // When an image is selected in the media frame... |
| 519 | frame.on( 'select', function() { |
| 520 | // Get media attachment details from the frame state |
| 521 | var attachment = frame.state().get('selection').first().toJSON(); |
| 522 | |
| 523 | 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>'; |
| 524 | |
| 525 | $('#assignment-attached-file').append(field_markup); |
| 526 | $that.closest('.video_source_wrap_html5').find('input').val(attachment.id); |
| 527 | }); |
| 528 | // Finally, open the modal on click |
| 529 | frame.open(); |
| 530 | }); |
| 531 | |
| 532 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 533 | event.preventDefault(); |
| 534 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 535 | }); |
| 536 | |
| 537 | /** |
| 538 | * Used for backend profile photo upload. |
| 539 | */ |
| 540 | |
| 541 | //tutor_video_poster_upload_btn |
| 542 | $(document).on( 'click', '.tutor_video_poster_upload_btn', function( event ){ |
| 543 | event.preventDefault(); |
| 544 | |
| 545 | var $that = $(this); |
| 546 | var frame; |
| 547 | // If the media frame already exists, reopen it. |
| 548 | if ( frame ) { |
| 549 | frame.open(); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | // Create a new media frame |
| 554 | frame = wp.media({ |
| 555 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 556 | button: { |
| 557 | text: 'Use this media' |
| 558 | }, |
| 559 | multiple: false // Set to true to allow multiple files to be selected |
| 560 | }); |
| 561 | |
| 562 | // When an image is selected in the media frame... |
| 563 | frame.on( 'select', function() { |
| 564 | // Get media attachment details from the frame state |
| 565 | var attachment = frame.state().get('selection').first().toJSON(); |
| 566 | $that.closest('.tutor-video-poster-wrap').find('.video-poster-img').html('<img src="'+attachment.url+'" alt="" />'); |
| 567 | $that.closest('.tutor-video-poster-wrap').find('input').val(attachment.id); |
| 568 | }); |
| 569 | // Finally, open the modal on click |
| 570 | frame.open(); |
| 571 | }); |
| 572 | |
| 573 | |
| 574 | /** |
| 575 | * Tutor Memberships toggle in Paid Membership Pro panel |
| 576 | * @since v.1.3.6 |
| 577 | */ |
| 578 | |
| 579 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 580 | e.preventDefault(); |
| 581 | |
| 582 | var $that = $(this); |
| 583 | |
| 584 | if ($that.val() === 'category_wise_membership'){ |
| 585 | $('.membership_course_categories').show(); |
| 586 | } else{ |
| 587 | $('.membership_course_categories').hide(); |
| 588 | } |
| 589 | }); |
| 590 | |
| 591 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 592 | e.preventDefault(); |
| 593 | |
| 594 | var $that = $(this); |
| 595 | |
| 596 | if ($that.val() === 'category_wise_membership'){ |
| 597 | $('.membership_course_categories').show(); |
| 598 | } else{ |
| 599 | $('.membership_course_categories').hide(); |
| 600 | } |
| 601 | }); |
| 602 | |
| 603 | /** |
| 604 | * Find user/student from select2 |
| 605 | * @since v.1.4.0 |
| 606 | */ |
| 607 | |
| 608 | $('#select2_search_user_ajax').select2({ |
| 609 | allowClear: true, |
| 610 | placeholder: "Search students", |
| 611 | minimumInputLength: '1', |
| 612 | escapeMarkup: function( m ) { |
| 613 | return m; |
| 614 | }, |
| 615 | ajax: { |
| 616 | url : ajaxurl, |
| 617 | type : 'POST', |
| 618 | dataType: 'json', |
| 619 | delay: 1000, |
| 620 | data: function( params ) { |
| 621 | return { |
| 622 | term: params.term, |
| 623 | action: 'tutor_json_search_students' |
| 624 | }; |
| 625 | }, |
| 626 | processResults: function( data ) { |
| 627 | var terms = []; |
| 628 | if ( data ) { |
| 629 | $.each( data, function( id, text ) { |
| 630 | terms.push({ |
| 631 | id: id, |
| 632 | text: text |
| 633 | }); |
| 634 | }); |
| 635 | } |
| 636 | return { |
| 637 | results: terms |
| 638 | }; |
| 639 | |
| 640 | }, |
| 641 | cache: true |
| 642 | } |
| 643 | }); |
| 644 | |
| 645 | /** |
| 646 | * Confirm Alert for deleting enrollments data |
| 647 | * |
| 648 | * @since v.1.4.0 |
| 649 | */ |
| 650 | $(document).on( 'click', 'table.enrolments .delete a', function( e ){ |
| 651 | if (! confirm(tutor_data.delete_confirm_text)) { |
| 652 | e.preventDefault(); |
| 653 | } |
| 654 | }); |
| 655 | |
| 656 | }); |
| 657 |