From 9605f88a098eada68730292336f6e5217c6b1d45 Mon Sep 17 00:00:00 2001 From: Vitaly Baev Date: Thu, 15 Feb 2018 12:18:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/CourseRedactor.vue | 46 +++++++++++++++------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/web/src/components/CourseRedactor.vue b/web/src/components/CourseRedactor.vue index dfdb2678..2f2fd7fb 100644 --- a/web/src/components/CourseRedactor.vue +++ b/web/src/components/CourseRedactor.vue @@ -334,6 +334,7 @@ ], showErrors: false, savingTimeout: null, + savingDebounceTimeout: null, categoryOptions: [], courseSyncHook: false, // Если true, то watch не будет отправлять курс на обновление } @@ -519,30 +520,35 @@ let newTab = window.open(`/course/${this.course.id}`, '_blank'); newTab.focus(); }, - saveCourseDraft: debounce(function (newValue, oldValue) { + saveCourseDraft: function (newValue, oldValue) { if (!oldValue.id) { return; } - this.courseSaving = true; - clearTimeout(this.savingTimeout); - document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНИЕ'; - api.saveCourse(this.course, this.accessToken) - .then((response) => { - this.courseSaving = false; - document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНО'; - this.savingTimeout = setTimeout(() => { - document.getElementById('course-redactor__saving-status').innerText = ''; - }, 2000); - this.courseSyncHook = true; - this.course = api.convertCourseJson(response.data); - this.$nextTick(() => { - this.courseSyncHook = false; + if (this.savingDebounceTimeout) { + clearTimeout(this.savingDebounceTimeout); + } + this.savingDebounceTimeout = setTimeout(() => { + this.courseSaving = true; + clearTimeout(this.savingTimeout); + document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНИЕ'; + api.saveCourse(this.course, this.accessToken) + .then((response) => { + this.courseSaving = false; + document.getElementById('course-redactor__saving-status').innerText = 'СОХРАНЕНО'; + this.savingTimeout = setTimeout(() => { + document.getElementById('course-redactor__saving-status').innerText = ''; + }, 2000); + this.courseSyncHook = true; + this.course = api.convertCourseJson(response.data); + this.$nextTick(() => { + this.courseSyncHook = false; + }) }) - }) - .catch((err) => { - this.courseSaving = false; - }); - }, 2000) + .catch((err) => { + this.courseSaving = false; + }); + }, 2000); + } }, mounted() { api.getCategories(this.accessToken)