| 1 |
const ModalCourseItems = { |
| 2 |
|
| 3 |
toggle: function( context ) { |
| 4 |
context.commit( 'TOGGLE' ); |
| 5 |
}, |
| 6 |
|
| 7 |
open: function( context, sectionId ) { |
| 8 |
context.commit( 'SET_SECTION', sectionId ); |
| 9 |
context.commit( 'RESET' ); |
| 10 |
context.commit( 'TOGGLE' ); |
| 11 |
}, |
| 12 |
|
| 13 |
searchItems: function( context, payload ) { |
| 14 |
context.commit( 'SEARCH_ITEMS_REQUEST' ); |
| 15 |
|
| 16 |
LP.Request( { |
| 17 |
type: 'search-items', |
| 18 |
query: payload.query, |
| 19 |
item_type: payload.type, |
| 20 |
page: payload.page, |
| 21 |
exclude: JSON.stringify( [] ), |
| 22 |
} ).then( |
| 23 |
function( response ) { |
| 24 |
var result = response.body; |
| 25 |
|
| 26 |
if ( ! result.success ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
var data = result.data; |
| 31 |
|
| 32 |
context.commit( 'SET_LIST_ITEMS', data.items ); |
| 33 |
context.commit( 'UPDATE_PAGINATION', data.pagination ); |
| 34 |
context.commit( 'SEARCH_ITEMS_SUCCESS' ); |
| 35 |
}, |
| 36 |
function( error ) { |
| 37 |
context.commit( 'SEARCH_ITEMS_FAILURE' ); |
| 38 |
|
| 39 |
console.error( error ); |
| 40 |
} |
| 41 |
); |
| 42 |
}, |
| 43 |
|
| 44 |
addItem: function( context, item ) { |
| 45 |
context.commit( 'ADD_ITEM', item ); |
| 46 |
}, |
| 47 |
|
| 48 |
removeItem: function( context, index ) { |
| 49 |
context.commit( 'REMOVE_ADDED_ITEM', index ); |
| 50 |
}, |
| 51 |
|
| 52 |
addItemsToSection: function( context ) { |
| 53 |
var items = context.getters.addedItems; |
| 54 |
|
| 55 |
if ( items.length > 0 ) { |
| 56 |
LP.Request( { |
| 57 |
type: 'add-items-to-section', |
| 58 |
section_id: context.getters.section, |
| 59 |
items: JSON.stringify( items ), |
| 60 |
} ).then( |
| 61 |
function( response ) { |
| 62 |
var result = response.body; |
| 63 |
|
| 64 |
if ( result.success ) { |
| 65 |
context.commit( 'TOGGLE' ); |
| 66 |
|
| 67 |
var items = result.data; |
| 68 |
context.commit( 'ss/UPDATE_SECTION_ITEMS', { |
| 69 |
section_id: context.getters.section, |
| 70 |
items: items, |
| 71 |
}, { root: true } ); |
| 72 |
} |
| 73 |
}, |
| 74 |
function( error ) { |
| 75 |
console.error( error ); |
| 76 |
} |
| 77 |
); |
| 78 |
} |
| 79 |
}, |
| 80 |
}; |
| 81 |
|
| 82 |
export default ModalCourseItems; |
| 83 |
|