PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.5
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.5
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / apps / js / admin / editor / actions / modal-quiz-items.js

modal-quiz-items.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.5, at assets/src/apps/js/admin/editor/actions/modal-quiz-items.js

83 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const ModalQuizItems = {
2
3 toggle: function( context ) {
4 context.commit( 'TOGGLE' );
5 },
6
7 // open modal
8 open: function( context, quizId ) {
9 context.commit( 'SET_QUIZ', quizId );
10 context.commit( 'RESET' );
11 context.commit( 'TOGGLE' );
12 },
13
14 // query available question
15 searchItems: function( context, payload ) {
16 context.commit( 'SEARCH_ITEM_REQUEST' );
17
18 LP.Request( {
19 type: 'search-items',
20 query: payload.query,
21 page: payload.page,
22 exclude: JSON.stringify( [] ),
23 } ).then(
24 function( response ) {
25 var result = response.body;
26
27 if ( ! result.success ) {
28 return;
29 }
30
31 var data = result.data;
32
33 context.commit( 'SET_LIST_ITEMS', data.items );
34 context.commit( 'UPDATE_PAGINATION', data.pagination );
35 context.commit( 'SEARCH_ITEM_SUCCESS' );
36 },
37 function( error ) {
38 context.commit( 'SEARCH_ITEMS_FAIL' );
39
40 console.log( error );
41 }
42 );
43 },
44
45 // add question
46 addItem: function( context, item ) {
47 context.commit( 'ADD_ITEM', item );
48 },
49
50 // remove question
51 removeItem: function( context, index ) {
52 context.commit( 'REMOVE_ADDED_ITEM', index );
53 },
54
55 addQuestionsToQuiz: function( context, quiz ) {
56 var items = context.getters.addedItems;
57 if ( items.length > 0 ) {
58 LP.Request( {
59 type: 'add-questions-to-quiz',
60 items: JSON.stringify( items ),
61 draft_quiz: JSON.stringify( quiz ),
62 } ).then(
63 function( response ) {
64 var result = response.body;
65
66 if ( result.success ) {
67 var questions = result.data;
68
69 // update quiz list questions
70 context.commit( 'lqs/SET_QUESTIONS', questions, { root: true } );
71 context.commit( 'TOGGLE' );
72 }
73 },
74 function( error ) {
75 console.log( error );
76 }
77 );
78 }
79 },
80 };
81
82 export default ModalQuizItems;
83