Chart.bundle.min.js
4 years ago
gutenberg_blocks.js
5 years ago
mce-button.js
4 years ago
tutor-admin.js
4 years ago
tutor-front.js
4 years ago
tutor-setup.js
5 years ago
tutor.js
4 years ago
tutor-admin.js
774 lines
| 1 | jQuery(document).ready(function($){ |
| 2 | 'use strict'; |
| 3 | |
| 4 | const { __, _x, _n, _nx } = wp.i18n; |
| 5 | const search_student_placeholder = __( 'Search students', 'tutor' ); |
| 6 | /** |
| 7 | * Color Picker |
| 8 | * @since v.1.2.21 |
| 9 | */ |
| 10 | if (jQuery().wpColorPicker) { |
| 11 | $('.tutor_colorpicker').wpColorPicker(); |
| 12 | } |
| 13 | |
| 14 | if (jQuery().select2){ |
| 15 | $('.tutor_select2').select2(); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Option Settings Nav Tab |
| 20 | */ |
| 21 | $('.tutor-option-nav-tabs li a').click(function(e){ |
| 22 | e.preventDefault(); |
| 23 | var tab_page_id = $(this).attr('data-tab'); |
| 24 | $('.option-nav-item').removeClass('current'); |
| 25 | $(this).closest('li').addClass('current'); |
| 26 | $('.tutor-option-nav-page').hide(); |
| 27 | $(tab_page_id).addClass('current-page').show(); |
| 28 | window.history.pushState('obj', '', $(this).attr('href')); |
| 29 | }); |
| 30 | |
| 31 | $('#save_tutor_option').click(function (e) { |
| 32 | e.preventDefault(); |
| 33 | $(this).closest('form').submit(); |
| 34 | }); |
| 35 | $('#tutor-option-form').submit(function(e){ |
| 36 | e.preventDefault(); |
| 37 | |
| 38 | var $form = $(this); |
| 39 | var data = $form.serializeObject(); |
| 40 | |
| 41 | $.ajax({ |
| 42 | url : window._tutorobject.ajaxurl, |
| 43 | type : 'POST', |
| 44 | data : data, |
| 45 | beforeSend: function () { |
| 46 | $form.find('.button').addClass('tutor-updating-message'); |
| 47 | }, |
| 48 | success: function (data) { |
| 49 | data.success ? |
| 50 | tutor_toast(__('Saved', 'tutor'), $form.data('toast_success_message'), 'success') : |
| 51 | tutor_toast(__('Request Error', 'tutor'), __('Could not save', 'tutor'), 'error'); |
| 52 | }, |
| 53 | complete: function () { |
| 54 | $form.find('.button').removeClass('tutor-updating-message'); |
| 55 | } |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | /** |
| 60 | * Withdraw nav tabs |
| 61 | * @since v.1.1.2 |
| 62 | */ |
| 63 | $(document).on('click', '.withdraw-method-nav li a', function(e){ |
| 64 | e.preventDefault(); |
| 65 | var tab_page_id = $(this).attr('data-target-id'); |
| 66 | $('.withdraw-method-form-wrap').hide(); |
| 67 | $('#'+tab_page_id).show(); |
| 68 | }); |
| 69 | |
| 70 | /** |
| 71 | * End Withdraw nav tabs |
| 72 | */ |
| 73 | |
| 74 | /** |
| 75 | * Don't move it to anywhere? |
| 76 | */ |
| 77 | function enable_sorting_topic_lesson(){ |
| 78 | if (jQuery().sortable) { |
| 79 | $(".course-contents").sortable({ |
| 80 | handle: ".course-move-handle", |
| 81 | start: function (e, ui) { |
| 82 | ui.placeholder.css('visibility', 'visible'); |
| 83 | }, |
| 84 | stop: function (e, ui) { |
| 85 | tutor_sorting_topics_and_lesson(); |
| 86 | }, |
| 87 | }); |
| 88 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 89 | connectWith: ".tutor-lessons", |
| 90 | items: "div.course-content-item", |
| 91 | start: function (e, ui) { |
| 92 | ui.placeholder.css('visibility', 'visible'); |
| 93 | }, |
| 94 | stop: function (e, ui) { |
| 95 | tutor_sorting_topics_and_lesson(); |
| 96 | }, |
| 97 | }); |
| 98 | } |
| 99 | } |
| 100 | enable_sorting_topic_lesson(); |
| 101 | function tutor_sorting_topics_and_lesson(){ |
| 102 | var topics = {}; |
| 103 | $('.tutor-topics-wrap').each(function(index, item){ |
| 104 | var $topic = $(this); |
| 105 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 106 | var lessons = {}; |
| 107 | |
| 108 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 109 | var $lesson = $(this); |
| 110 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 111 | |
| 112 | lessons[lessonIndex] = lesson_id; |
| 113 | }); |
| 114 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 115 | }); |
| 116 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Lesson Update or Create Modal |
| 121 | */ |
| 122 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 123 | event.preventDefault(); |
| 124 | |
| 125 | var $that = $(this); |
| 126 | var content; |
| 127 | var inputid = 'tutor_lesson_modal_editor'; |
| 128 | var editor = tinyMCE.get(inputid); |
| 129 | if (editor) { |
| 130 | content = editor.getContent(); |
| 131 | } else { |
| 132 | content = $('#'+inputid).val(); |
| 133 | } |
| 134 | |
| 135 | var form_data = $(this).closest('form').serializeObject(); |
| 136 | form_data.lesson_content = content; |
| 137 | |
| 138 | $.ajax({ |
| 139 | url : window._tutorobject.ajaxurl, |
| 140 | type : 'POST', |
| 141 | data : form_data, |
| 142 | beforeSend: function () { |
| 143 | $that.addClass('tutor-updating-message'); |
| 144 | }, |
| 145 | success: function (data) { |
| 146 | if (data.success){ |
| 147 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 148 | enable_sorting_topic_lesson(); |
| 149 | |
| 150 | //Close the modal |
| 151 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 152 | |
| 153 | tutor_toast(__('Lesson Updated', 'tutor'), $that.data('toast_success_message'), 'success'); |
| 154 | } |
| 155 | }, |
| 156 | complete: function () { |
| 157 | $that.removeClass('tutor-updating-message'); |
| 158 | } |
| 159 | }); |
| 160 | }); |
| 161 | |
| 162 | /** |
| 163 | * Lesson Video |
| 164 | */ |
| 165 | $(document).on('change', '.tutor_lesson_video_source', function(e){ |
| 166 | var selector = $(this).val(); |
| 167 | $('[class^="video_source_wrap"]').hide(); |
| 168 | $('.video_source_wrap_'+selector).show(); |
| 169 | |
| 170 | if (selector === 'html5'){ |
| 171 | $('.tutor-video-poster-field').show(); |
| 172 | } else{ |
| 173 | $('.tutor-video-poster-field').hide(); |
| 174 | } |
| 175 | }); |
| 176 | |
| 177 | $(document).on( 'click', '.video_source_wrap_html5 .video_upload_btn', function( event ){ |
| 178 | event.preventDefault(); |
| 179 | |
| 180 | var $that = $(this); |
| 181 | var frame; |
| 182 | // If the media frame already exists, reopen it. |
| 183 | if ( frame ) { |
| 184 | frame.open(); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | // Create a new media frame |
| 189 | frame = wp.media({ |
| 190 | title: __( 'Select or Upload Media Of Your Choice', 'tutor' ), |
| 191 | button: { |
| 192 | text: __( 'Upload media', 'tutor' ) |
| 193 | }, |
| 194 | library: { type: 'video' }, |
| 195 | multiple: false // Set to true to allow multiple files to be selected |
| 196 | }); |
| 197 | |
| 198 | // When an image is selected in the media frame... |
| 199 | frame.on( 'select', function() { |
| 200 | // Get media attachment details from the frame state |
| 201 | var attachment = frame.state().get('selection').first().toJSON(); |
| 202 | $that.closest('.video_source_wrap_html5').find('span.video_media_id').data('video_url', attachment.url).text(attachment.id).trigger('paste').closest('p').show(); |
| 203 | $that.closest('.video_source_wrap_html5').find('input.input_source_video_id').val(attachment.id); |
| 204 | }); |
| 205 | // Finally, open the modal on click |
| 206 | frame.open(); |
| 207 | }); |
| 208 | |
| 209 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 210 | e.preventDefault(); |
| 211 | $(this).closest('.tutor-added-attachment').remove(); |
| 212 | }); |
| 213 | |
| 214 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 215 | e.preventDefault(); |
| 216 | |
| 217 | var $that = $(this); |
| 218 | var frame; |
| 219 | // If the media frame already exists, reopen it. |
| 220 | if ( frame ) { |
| 221 | frame.open(); |
| 222 | return; |
| 223 | } |
| 224 | // Create a new media frame |
| 225 | frame = wp.media({ |
| 226 | title: __( 'Select or Upload Media Of Your Choice', 'tutor' ), |
| 227 | button: { |
| 228 | text: __( 'Upload media', 'tutor' ) |
| 229 | }, |
| 230 | multiple: true // Set to true to allow multiple files to be selected |
| 231 | }); |
| 232 | // When an image is selected in the media frame... |
| 233 | frame.on( 'select', function() { |
| 234 | // Get media attachment details from the frame state |
| 235 | var attachments = frame.state().get('selection').toJSON(); |
| 236 | if (attachments.length){ |
| 237 | for (var i=0; i < attachments.length; i++){ |
| 238 | var attachment = attachments[i]; |
| 239 | |
| 240 | 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>'; |
| 241 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 242 | } |
| 243 | } |
| 244 | }); |
| 245 | // Finally, open the modal on click |
| 246 | frame.open(); |
| 247 | }); |
| 248 | |
| 249 | /** |
| 250 | * Open Sidebar Menu |
| 251 | */ |
| 252 | if (_tutorobject.open_tutor_admin_menu){ |
| 253 | var $adminMenu = $('#adminmenu'); |
| 254 | $adminMenu.find('[href="admin.php?page=tutor"]').closest('li.wp-has-submenu').addClass('wp-has-current-submenu'); |
| 255 | $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'); |
| 256 | } |
| 257 | |
| 258 | $(document).on('click', '.tutor-option-media-upload-btn', function(e){ |
| 259 | e.preventDefault(); |
| 260 | |
| 261 | var $that = $(this); |
| 262 | var frame; |
| 263 | if ( frame ) { |
| 264 | frame.open(); |
| 265 | return; |
| 266 | } |
| 267 | frame = wp.media({ |
| 268 | title: __( 'Select or Upload Media Of Your Choice', 'tutor' ), |
| 269 | button: { |
| 270 | text: __( 'Upload media', 'tutor' ) |
| 271 | }, |
| 272 | multiple: false |
| 273 | }); |
| 274 | frame.on( 'select', function() { |
| 275 | var attachment = frame.state().get('selection').first().toJSON(); |
| 276 | $that.closest('.option-media-wrap').find('.option-media-preview').html('<img src="'+attachment.url+'" alt="" />'); |
| 277 | $that.closest('.option-media-wrap').find('input').val(attachment.id); |
| 278 | $that.closest('.option-media-wrap').find('.tutor-media-option-trash-btn').show(); |
| 279 | }); |
| 280 | frame.open(); |
| 281 | }); |
| 282 | |
| 283 | /** |
| 284 | * Remove option media |
| 285 | * @since v.1.4.3 |
| 286 | */ |
| 287 | $(document).on('click', '.tutor-media-option-trash-btn', function(e){ |
| 288 | e.preventDefault(); |
| 289 | |
| 290 | var $that = $(this); |
| 291 | $that.closest('.option-media-wrap').find('img').remove(); |
| 292 | $that.closest('.option-media-wrap').find('input').val(''); |
| 293 | $that.closest('.option-media-wrap').find('.tutor-media-option-trash-btn').hide(); |
| 294 | }); |
| 295 | |
| 296 | |
| 297 | $(document).on('change', '.tutor_addons_list_item', function(e) { |
| 298 | var $that = $(this); |
| 299 | |
| 300 | var isEnable = $that.prop('checked') ? 1 : 0; |
| 301 | var addonFieldName = $that.attr('name'); |
| 302 | |
| 303 | $.ajax({ |
| 304 | url : window._tutorobject.ajaxurl, |
| 305 | type : 'POST', |
| 306 | data : {isEnable:isEnable, addonFieldName:addonFieldName, action : 'addon_enable_disable'}, |
| 307 | success: function (data) { |
| 308 | if (data.success){ |
| 309 | //Success |
| 310 | } |
| 311 | } |
| 312 | }); |
| 313 | }); |
| 314 | |
| 315 | /** |
| 316 | * Add instructor |
| 317 | * @since v.1.0.3 |
| 318 | */ |
| 319 | $(document).on('submit', '#new-instructor-form', function(e){ |
| 320 | e.preventDefault(); |
| 321 | |
| 322 | var $that = $(this); |
| 323 | var formData = $that.serializeObject(); |
| 324 | formData.action = 'tutor_add_instructor'; |
| 325 | |
| 326 | $.ajax({ |
| 327 | url : window._tutorobject.ajaxurl, |
| 328 | type : 'POST', |
| 329 | data : formData, |
| 330 | success: function (data) { |
| 331 | if (data.success){ |
| 332 | $that.trigger("reset"); |
| 333 | $('#form-response').html('<p class="tutor-status-approved-context">'+data.data.msg+'</p>'); |
| 334 | }else{ |
| 335 | var errorMsg = ''; |
| 336 | |
| 337 | var errors = data.data.errors; |
| 338 | if (errors && Object.keys(errors).length){ |
| 339 | $.each(data.data.errors, function( index, value ) { |
| 340 | if (isObject(value)){ |
| 341 | $.each(value, function( key, value1 ) { |
| 342 | errorMsg += '<p class="tutor-required-fields">'+value1[0]+'</p>'; |
| 343 | }); |
| 344 | } else{ |
| 345 | errorMsg += '<p class="tutor-required-fields">'+value+'</p>'; |
| 346 | } |
| 347 | }); |
| 348 | $('#form-response').html(errorMsg); |
| 349 | } |
| 350 | |
| 351 | } |
| 352 | } |
| 353 | }); |
| 354 | }); |
| 355 | |
| 356 | |
| 357 | /** |
| 358 | * Instructor block unblock action |
| 359 | * @since v.1.5.3 |
| 360 | */ |
| 361 | |
| 362 | $(document).on('click', 'a.instructor-action', function(e){ |
| 363 | e.preventDefault(); |
| 364 | |
| 365 | var $that = $(this); |
| 366 | var action = $that.attr('data-action'); |
| 367 | var instructor_id = $that.attr('data-instructor-id'); |
| 368 | |
| 369 | var prompt_message = $that.attr('data-prompt-message'); |
| 370 | if(prompt_message && !confirm(prompt_message)){ |
| 371 | // Avoid Accidental CLick |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | var nonce_key = _tutorobject.nonce_key; |
| 376 | var json_data = { instructor_id : instructor_id, action_name : action, action: 'instructor_approval_action'}; |
| 377 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 378 | |
| 379 | $.ajax({ |
| 380 | url : window._tutorobject.ajaxurl, |
| 381 | type : 'POST', |
| 382 | data : json_data, |
| 383 | beforeSend: function () { |
| 384 | $that.addClass('tutor-updating-message'); |
| 385 | }, |
| 386 | success: function (data) { |
| 387 | location.reload(true); |
| 388 | }, |
| 389 | complete: function () { |
| 390 | $that.removeClass('tutor-updating-message'); |
| 391 | } |
| 392 | }); |
| 393 | }); |
| 394 | |
| 395 | function isObject (value) { |
| 396 | return value && typeof value === 'object' && value.constructor === Object; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Tutor Assignments JS |
| 401 | * @since v.1.3.3 |
| 402 | */ |
| 403 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 404 | e.preventDefault(); |
| 405 | |
| 406 | var $that = $(this); |
| 407 | var topic_id = $(this).attr('data-topic-id'); |
| 408 | var course_id = $('#post_ID').val(); |
| 409 | |
| 410 | $.ajax({ |
| 411 | url : window._tutorobject.ajaxurl, |
| 412 | type : 'POST', |
| 413 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 414 | beforeSend: function () { |
| 415 | $that.addClass('tutor-updating-message'); |
| 416 | }, |
| 417 | success: function (data) { |
| 418 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 419 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 420 | |
| 421 | $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 422 | |
| 423 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 424 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 425 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 426 | }, |
| 427 | complete: function () { |
| 428 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 429 | $that.removeClass('tutor-updating-message'); |
| 430 | } |
| 431 | }); |
| 432 | }); |
| 433 | |
| 434 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 435 | e.preventDefault(); |
| 436 | |
| 437 | var $that = $(this); |
| 438 | var assignment_id = $that.attr('data-assignment-id'); |
| 439 | var topic_id = $that.attr('data-topic-id'); |
| 440 | var course_id = $('#post_ID').val(); |
| 441 | |
| 442 | $.ajax({ |
| 443 | url : window._tutorobject.ajaxurl, |
| 444 | type : 'POST', |
| 445 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 446 | beforeSend: function () { |
| 447 | $that.addClass('tutor-updating-message'); |
| 448 | }, |
| 449 | success: function (data) { |
| 450 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 451 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 452 | |
| 453 | $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id}); |
| 454 | |
| 455 | tinymce.init(tinyMCEPreInit.mceInit.tutor_editor_config); |
| 456 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 457 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 458 | }, |
| 459 | complete: function () { |
| 460 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 461 | $that.removeClass('tutor-updating-message'); |
| 462 | } |
| 463 | }); |
| 464 | }); |
| 465 | |
| 466 | /** |
| 467 | * Update Assignment Data |
| 468 | */ |
| 469 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 470 | event.preventDefault(); |
| 471 | |
| 472 | var $that = $(this); |
| 473 | var content; |
| 474 | var inputid = 'tutor_assignments_modal_editor'; |
| 475 | var editor = tinyMCE.get(inputid); |
| 476 | if (editor) { |
| 477 | content = editor.getContent(); |
| 478 | } else { |
| 479 | content = $('#'+inputid).val(); |
| 480 | } |
| 481 | |
| 482 | var form_data = $(this).closest('form').serializeObject(); |
| 483 | form_data.assignment_content = content; |
| 484 | |
| 485 | $.ajax({ |
| 486 | url : window._tutorobject.ajaxurl, |
| 487 | type : 'POST', |
| 488 | data : form_data, |
| 489 | beforeSend: function () { |
| 490 | $that.addClass('tutor-updating-message'); |
| 491 | }, |
| 492 | success: function (data) { |
| 493 | if (data.success){ |
| 494 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 495 | enable_sorting_topic_lesson(); |
| 496 | |
| 497 | //Close the modal |
| 498 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 499 | |
| 500 | tutor_toast(__('Assignment Updated', 'tutor'), $that.data('toast_success_message'), 'success'); |
| 501 | } |
| 502 | }, |
| 503 | complete: function () { |
| 504 | $that.removeClass('tutor-updating-message'); |
| 505 | } |
| 506 | }); |
| 507 | }); |
| 508 | |
| 509 | /** |
| 510 | * Add Assignment |
| 511 | */ |
| 512 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 513 | event.preventDefault(); |
| 514 | |
| 515 | var $that = $(this); |
| 516 | var frame; |
| 517 | // If the media frame already exists, reopen it. |
| 518 | if ( frame ) { |
| 519 | frame.open(); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | // Create a new media frame |
| 524 | frame = wp.media({ |
| 525 | title: __( 'Select or Upload Media Of Your Choice', 'tutor' ), |
| 526 | button: { |
| 527 | text: __( 'Upload media', 'tutor' ) |
| 528 | }, |
| 529 | multiple: false // Set to true to allow multiple files to be selected |
| 530 | }); |
| 531 | |
| 532 | // When an image is selected in the media frame... |
| 533 | frame.on( 'select', function() { |
| 534 | // Get media attachment details from the frame state |
| 535 | var attachment = frame.state().get('selection').first().toJSON(); |
| 536 | |
| 537 | 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>'; |
| 538 | |
| 539 | $('#assignment-attached-file').append(field_markup); |
| 540 | $that.closest('.video_source_wrap_html5').find('input').val(attachment.id); |
| 541 | }); |
| 542 | // Finally, open the modal on click |
| 543 | frame.open(); |
| 544 | }); |
| 545 | |
| 546 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 547 | event.preventDefault(); |
| 548 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 549 | }); |
| 550 | |
| 551 | /** |
| 552 | * Used for backend profile photo upload. |
| 553 | */ |
| 554 | |
| 555 | //tutor_video_poster_upload_btn |
| 556 | $(document).on( 'click', '.tutor_video_poster_upload_btn', function( event ){ |
| 557 | event.preventDefault(); |
| 558 | |
| 559 | var $that = $(this); |
| 560 | var frame; |
| 561 | // If the media frame already exists, reopen it. |
| 562 | if ( frame ) { |
| 563 | frame.open(); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | // Create a new media frame |
| 568 | frame = wp.media({ |
| 569 | title: __( 'Select or Upload Media Of Your Choice', 'tutor' ), |
| 570 | button: { |
| 571 | text: __( 'Upload media', 'tutor') |
| 572 | }, |
| 573 | multiple: false // Set to true to allow multiple files to be selected |
| 574 | }); |
| 575 | |
| 576 | // When an image is selected in the media frame... |
| 577 | frame.on( 'select', function() { |
| 578 | // Get media attachment details from the frame state |
| 579 | var attachment = frame.state().get('selection').first().toJSON(); |
| 580 | $that.closest('.tutor-video-poster-wrap').find('.video-poster-img').html('<img src="'+attachment.sizes.thumbnail.url+'" alt="" />'); |
| 581 | $that.closest('.tutor-video-poster-wrap').find('input').val(attachment.id); |
| 582 | }); |
| 583 | // Finally, open the modal on click |
| 584 | frame.open(); |
| 585 | }); |
| 586 | |
| 587 | |
| 588 | /** |
| 589 | * Tutor Memberships toggle in Paid Membership Pro panel |
| 590 | * @since v.1.3.6 |
| 591 | */ |
| 592 | |
| 593 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 594 | e.preventDefault(); |
| 595 | |
| 596 | var $that = $(this); |
| 597 | |
| 598 | if ($that.val() === 'category_wise_membership'){ |
| 599 | $('.membership_course_categories').show(); |
| 600 | } else{ |
| 601 | $('.membership_course_categories').hide(); |
| 602 | } |
| 603 | }); |
| 604 | |
| 605 | $(document).on( 'change', '#tutor_pmpro_membership_model_select', function( e ){ |
| 606 | e.preventDefault(); |
| 607 | |
| 608 | var $that = $(this); |
| 609 | |
| 610 | if ($that.val() === 'category_wise_membership'){ |
| 611 | $('.membership_course_categories').show(); |
| 612 | } else{ |
| 613 | $('.membership_course_categories').hide(); |
| 614 | } |
| 615 | }); |
| 616 | |
| 617 | // Require category selection |
| 618 | $(document).on('submit', '.pmpro_admin form', function(e) { |
| 619 | var form = $(this); |
| 620 | |
| 621 | if(!form.find('input[name="tutor_action"]').length) { |
| 622 | // Level editor or tutor action not necessary |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | if( |
| 627 | form.find('[name="tutor_pmpro_membership_model"]').val()=='category_wise_membership' && |
| 628 | !form.find('.membership_course_categories input:checked').length) { |
| 629 | |
| 630 | if(!confirm(__('Do you want to save without any category?', 'tutor'))) { |
| 631 | e.preventDefault(); |
| 632 | } |
| 633 | } |
| 634 | }); |
| 635 | |
| 636 | /** |
| 637 | * Find user/student from select2 |
| 638 | * @since v.1.4.0 |
| 639 | */ |
| 640 | $('#select2_search_user_ajax').select2({ |
| 641 | allowClear: true, |
| 642 | |
| 643 | minimumInputLength: 1, |
| 644 | placeholder: search_student_placeholder, |
| 645 | language: { |
| 646 | inputTooShort: function() { |
| 647 | return __( 'Please add 1 or more character', 'tutor' ); |
| 648 | }, |
| 649 | }, |
| 650 | escapeMarkup: function( m ) { |
| 651 | return m; |
| 652 | }, |
| 653 | ajax: { |
| 654 | url : window._tutorobject.ajaxurl, |
| 655 | type : 'POST', |
| 656 | dataType: 'json', |
| 657 | delay: 1000, |
| 658 | data: function( params ) { |
| 659 | return { |
| 660 | term: params.term, |
| 661 | action: 'tutor_json_search_students' |
| 662 | }; |
| 663 | }, |
| 664 | processResults: function( data ) { |
| 665 | var terms = []; |
| 666 | if ( data ) { |
| 667 | $.each( data, function( id, text ) { |
| 668 | terms.push({ |
| 669 | id: id, |
| 670 | text: text |
| 671 | }); |
| 672 | }); |
| 673 | } |
| 674 | return { |
| 675 | results: terms |
| 676 | }; |
| 677 | |
| 678 | }, |
| 679 | cache: true |
| 680 | } |
| 681 | }); |
| 682 | |
| 683 | /** |
| 684 | * Confirm Alert for deleting enrollments data |
| 685 | * |
| 686 | * @since v.1.4.0 |
| 687 | */ |
| 688 | $(document).on( 'click', 'table.enrolments .delete a', function( e ){ |
| 689 | e.preventDefault(); |
| 690 | |
| 691 | var url = $(this).attr('href'); |
| 692 | var popup; |
| 693 | |
| 694 | var data = { |
| 695 | title: __('Delete this enrolment', 'tutor'), |
| 696 | description : __('All of the course data like quiz attempts, assignment, lesson <br/>progress will be deleted if you delete this student\'s enrollment.', 'tutor'), |
| 697 | buttons : { |
| 698 | reset: { |
| 699 | title: __('Cancel', 'tutor'), |
| 700 | class: 'secondary', |
| 701 | |
| 702 | callback: function() { |
| 703 | popup.remove(); |
| 704 | } |
| 705 | }, |
| 706 | keep: { |
| 707 | title: __('Yes, Delete This', 'tutor'), |
| 708 | class: 'primary', |
| 709 | callback: function() { |
| 710 | window.location.replace(url); |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | }; |
| 715 | |
| 716 | popup = new window.tutor_popup($, 'icon-trash', 40).popup(data); |
| 717 | }); |
| 718 | |
| 719 | |
| 720 | /** |
| 721 | * Show hide is course public checkbox (backend dashboard editor) |
| 722 | * |
| 723 | * @since v.1.7.2 |
| 724 | */ |
| 725 | var price_type = $('#tutor-attach-product [name="tutor_course_price_type"]'); |
| 726 | if(price_type.length==0){ |
| 727 | $('#_tutor_is_course_public_meta_checkbox').show(); |
| 728 | } |
| 729 | else{ |
| 730 | price_type.change(function(){ |
| 731 | if($(this).prop('checked')){ |
| 732 | var method = $(this).val()=='paid' ? 'hide' : 'show'; |
| 733 | $('#_tutor_is_course_public_meta_checkbox')[method](); |
| 734 | } |
| 735 | }).trigger('change'); |
| 736 | } |
| 737 | |
| 738 | |
| 739 | /** |
| 740 | * Focus selected instructor layout in setting page |
| 741 | * |
| 742 | * @since v.1.7.5 |
| 743 | */ |
| 744 | $(document).on('click', '.instructor-layout-template', function(){ |
| 745 | $('.instructor-layout-template').removeClass('selected-template'); |
| 746 | $(this).addClass('selected-template'); |
| 747 | }); |
| 748 | |
| 749 | |
| 750 | |
| 751 | /** |
| 752 | * Programmatically open preview link. For some reason it's not working normally. |
| 753 | * |
| 754 | * @since v.1.7.9 |
| 755 | */ |
| 756 | $('#preview-action a.preview').click(function(e) { |
| 757 | var href = $(this).attr('href'); |
| 758 | |
| 759 | if(href) { |
| 760 | e.preventDefault(); |
| 761 | window.open(href, '_blank'); |
| 762 | } |
| 763 | }); |
| 764 | |
| 765 | /** Disable typing on datePicker field */ |
| 766 | $('.hasDatepicker, .tutor_date_picker').keydown( function( e ) { |
| 767 | if ( e.keyCode !== 8 ) { |
| 768 | e.preventDefault(); |
| 769 | } |
| 770 | }); |
| 771 | |
| 772 | }); |
| 773 | |
| 774 |