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