From 2baf917f889a936f28134b82f58a29626a6c6945 Mon Sep 17 00:00:00 2001 From: Vitaly Baev Date: Thu, 15 Feb 2018 19:08:40 +0300 Subject: [PATCH] =?UTF-8?q?slug=20+=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D1=83=D1=80=D1=81=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/CourseRedactor.vue | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/web/src/components/CourseRedactor.vue b/web/src/components/CourseRedactor.vue index d26b1aa1..b19c3a91 100644 --- a/web/src/components/CourseRedactor.vue +++ b/web/src/components/CourseRedactor.vue @@ -31,7 +31,7 @@ rows="1" title="Название курса" v-autosize="course.title" - @input="$v.course.title.$touch()" + @change="onCourseNameInput" v-model="course.title"> @@ -67,7 +67,7 @@
ССЫЛКА
- +
{{ courseFullUrl }}
@@ -253,9 +253,9 @@ import LessonRedactor from "./LessonRedactor"; import {api} from "../js/modules/api"; import BlockAdd from "./blocks/BlockAdd"; - import debounce from 'lodash.debounce'; import $ from 'jquery'; import {required, minValue, numeric } from 'vuelidate/lib/validators' + import slugify from 'slugify'; export default { name: "course-redactor", @@ -266,6 +266,7 @@ me: null, users: null, ROLE_ADMIN: ROLE_ADMIN, + slugChanged: false, course: { title: '', status: null, @@ -381,7 +382,12 @@ onCoursePriceChange(event) { this.course.price = event.target.value; }, - + onCourseNameInput() { + this.$v.course.title.$touch(); + if (!this.slugChanged) { + this.course.url = slugify(this.course.title); + } + }, updateCategory() { if (this.categoryOptions && Array.isArray(this.categoryOptions) && this.course.category) { this.categoryOptions.forEach((category) => { @@ -511,7 +517,7 @@ publishButton.attr('disabled', 'disabled'); api.publishCourse(this.course.id, this.accessToken) .then((response) => { - document.getElementById('course-redactor__saving-status').innerText = 'НА МОДЕРАЦИИ'; + window.location = '/course/on-moderation'; }) .catch(() => { publishButton.removeAttr('disabled'); @@ -528,11 +534,14 @@ if (this.savingDebounceTimeout) { clearTimeout(this.savingDebounceTimeout); } + this.courseSyncHook = false; this.savingDebounceTimeout = setTimeout(() => { this.courseSaving = true; clearTimeout(this.savingTimeout); document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНИЕ'; - api.saveCourse(this.course, this.accessToken) + const courseObject = this.course; + courseObject.url = slugify(courseObject.url); + api.saveCourse(courseObject, this.accessToken) .then((response) => { this.courseSaving = false; document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНО'; @@ -545,11 +554,15 @@ courseData.coverImage = this.course.coverImage; } this.course = courseData; + if (courseData.url) { + this.slugChanged = true; + } this.$nextTick(() => { this.courseSyncHook = false; - }) + }); }) .catch((err) => { + this.courseSyncHook = false; this.courseSaving = false; }); }, 2000); @@ -643,8 +656,11 @@ } }, courseFullUrl() { - let suffix = this.course.url ? this.course.url : 'ваша_ссылка'; - return `https://lil.city/course/${suffix}`; + if (!this.course.url) { + return `https://lil.city/course/${this.course.id}`; + } + let suffix = this.course.url ? this.course.url : 'ваша_ссылка'; + return `https://lil.city/course/${suffix}`; }, }, watch: {