diff --git a/web/src/components/CourseRedactor.vue b/web/src/components/CourseRedactor.vue index f73144fb..5dd557c8 100644 --- a/web/src/components/CourseRedactor.vue +++ b/web/src/components/CourseRedactor.vue @@ -537,8 +537,7 @@ api.saveCourse(this.course, this.accessToken) .then((response) => { this.courseSaving = false; - this.course = api.convertCourseJson(response.data); - this.course.live = this.live; + this.processCourseJson(response.data); }) .catch((err) => { this.courseSaving = false; @@ -812,10 +811,7 @@ .catch((err) => { this.courseSyncHook = false; this.courseSaving = false; - //console.error(err); this.changeSavingStatus(true, true); - // alert('Произошло что-то страшное: '+err.toString()); - //console.log(err.response.data); if(err.response) { for(let i in err.response.data) { if(typeof err.response.data[i] === "array") { @@ -967,19 +963,7 @@ } }); - // if (this.courseId) { - // this.loadCourse().then(()=>{this.updateViewSection(window.location, 'load')}).catch(()=>{ - // this.updateViewSection(window.location, 'load err') - // }) - // } else { - // this.loadCourseDraft().then(()=>{this.updateViewSection(window.location, 'load draft')}).catch(()=>{ - // this.updateViewSection(window.location, 'load draft err') - // }); - // } - - //console.log('wait promises'); Promise.all(promises.map(p => p.catch(e => e))).then(()=>{ - //console.log('promises end'); this.mounting = false; let load; if (this.courseId) { @@ -995,9 +979,6 @@ this.updateViewSection(window.location, 'load err '+this.courseId) }) }); - - //console.log('mounted end'); - // this.updateViewSection(window.location); }, computed: { displayPrice: { @@ -1027,17 +1008,12 @@ watch: { 'course': { handler: function (newValue, oldValue) { - // //console.log('watch', JSON.stringify(newValue), JSON.stringify(oldValue)); // Если курс загрузился и есть ID - делаем кнопки превью и публикации активными - //console.log('newValue.id', newValue.id); if (newValue.id) { - // //console.log('newValue.id disabled remove', newValue.id); $('#course-redactor__preview-button').removeAttr('disabled'); $('#course-redactor__publish-button').removeAttr('disabled'); } - // //console.log('courseSyncHook', this.courseSyncHook); if (this.courseSyncHook || this.courseLoading) { - //console.log('abort save draft', this.courseSyncHook, this.courseLoading); return; } this.saveCourseDraft(newValue, oldValue); diff --git a/web/src/js/modules/api.js b/web/src/js/modules/api.js index 086b932b..8acb7de1 100644 --- a/web/src/js/modules/api.js +++ b/web/src/js/modules/api.js @@ -90,7 +90,7 @@ export const api = { }); }, saveCourse: (courseObject, accessToken) => { - const isAdding = (!courseObject.hasOwnProperty('id') || !courseObject.hasOwnProperty('id')); + const isAdding = !courseObject.id; let deferredStart = null; if (courseObject.is_deferred) { @@ -114,7 +114,7 @@ export const api = { access_duration: courseObject.is_paid && courseObject.access_duration || 0, is_featured: courseObject.is_featured, slug: (courseObject.slug || '').toLowerCase(), - date: (courseObject.date) ? courseObject.date.value:null, + date: (courseObject.date) ? courseObject.date.value : null, stream: courseObject.stream, cover: courseObject.coverImageId ? courseObject.coverImageId : null, gallery: { @@ -212,14 +212,14 @@ export const api = { }, convertContentJson: (contentJson, forSaving) => { if(forSaving){ - return contentJson.map((block, index) => { + let content = contentJson.map((block, index) => { if (block.type === 'text') { return { 'type': 'text', 'data': { 'id': block.data.id ? block.data.id : null, 'uuid': block.uuid, - 'position': ++index, + 'position': index + 1, 'title': block.data.title, 'txt': block.data.text, } @@ -230,7 +230,7 @@ export const api = { 'data': { 'id': block.data.id ? block.data.id : null, 'uuid': block.uuid, - 'position': ++index, + 'position': index + 1, 'title': block.data.title, 'img': block.data.image_id, } @@ -241,7 +241,7 @@ export const api = { 'data': { 'id': block.data.id ? block.data.id : null, 'uuid': block.uuid, - 'position': ++index, + 'position': index + 1, 'title': block.data.title, 'img': block.data.image_id, 'txt': block.data.text, @@ -253,7 +253,7 @@ export const api = { 'data': { 'id': block.data.id ? block.data.id : null, 'uuid': block.uuid, - 'position': ++index, + 'position': index + 1, 'title': block.data.title, 'images': api.convertGalleryImagesJson(block.data.images), } @@ -271,6 +271,7 @@ export const api = { } } }); + return content; } return contentJson.sort((a, b) => { if (a.position < b.position) {