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