|
28 | 28 |
|
29 | 29 | errors: [],
|
30 | 30 |
|
31 |
| - formWatcher: null, |
| 31 | + postBodyWatcher: null, |
32 | 32 |
|
33 | 33 | form: {
|
34 | 34 | id: '',
|
|
66 | 66 | },
|
67 | 67 |
|
68 | 68 | 'form.published'(val) {
|
69 |
| - if (this.formWatcher) { |
70 |
| - this.formWatcher(); |
| 69 | + if (this.postBodyWatcher) { |
| 70 | + this.postBodyWatcher(); |
71 | 71 | }
|
72 | 72 |
|
73 | 73 | if (!val) {
|
74 |
| - this.watchChangesAndSave(); |
| 74 | + this.watchBodyChangesAndSave(); |
75 | 75 | }
|
76 | 76 | },
|
77 | 77 |
|
|
130 | 130 | fillForm(data) {
|
131 | 131 | this.form.id = data.id;
|
132 | 132 | this.form.publish_date = data.publish_date;
|
| 133 | + this.form.slug = 'draft-' + this.form.id; |
133 | 134 |
|
134 | 135 | if (this.id != 'new') {
|
135 | 136 | this.form.title = data.title;
|
|
155 | 156 | }
|
156 | 157 |
|
157 | 158 | if (!this.form.published) {
|
158 |
| - this.watchChangesAndSave(); |
| 159 | + this.watchBodyChangesAndSave(); |
159 | 160 | }
|
160 | 161 | },
|
161 | 162 |
|
162 | 163 |
|
163 | 164 | /**
|
164 | 165 | * Watch changes and save the post.
|
165 | 166 | */
|
166 |
| - watchChangesAndSave() { |
| 167 | + watchBodyChangesAndSave() { |
167 | 168 | setTimeout(() => {
|
168 |
| - this.formWatcher = this.$watch('form', _.debounce(() => this.save(), 1000), {deep: true}); |
| 169 | + this.postBodyWatcher = this.$watch('form.body', _.debounce(() => this.save(), 1000), {deep: true}); |
169 | 170 | }, 1000);
|
170 | 171 | },
|
171 | 172 |
|
|
182 | 183 | this.authors = response.data.data;
|
183 | 184 |
|
184 | 185 | if (!this.form.author_id && this.authors) {
|
185 |
| - this.form.author_id = _.first(this.authors).id; |
| 186 | + this.form.author_id = this.Wink.author.id; |
186 | 187 | }
|
187 | 188 | });
|
188 | 189 | },
|
|
300 | 301 | * Save the post.
|
301 | 302 | */
|
302 | 303 | save() {
|
| 304 | + if (this.status) return; |
| 305 | +
|
303 | 306 | this.errors = [];
|
304 | 307 | this.status = 'Saving...';
|
305 | 308 |
|
306 |
| - this.form.slug = this.form.slug || 'draft-' + this.form.id; |
307 |
| - this.form.title = this.form.title || 'Draft'; |
| 309 | + if (this.form.title != 'Draft' && (!this.form.slug || this.form.slug.startsWith('draft-'))) { |
| 310 | + this.form.slug = this.slugify(this.form.title); |
| 311 | + } |
308 | 312 |
|
309 | 313 | this.http().post('/api/posts/' + this.id, this.form).then(response => {
|
310 | 314 | this.status = '';
|
|
313 | 317 | this.$router.push({name: 'post-edit', params: {id: this.form.id}})
|
314 | 318 | }
|
315 | 319 | }).catch(error => {
|
| 320 | + this.status = ''; |
| 321 | + |
316 | 322 | this.errors = error.response.data.errors;
|
317 | 323 |
|
318 | 324 | this.settingsModalShown = true;
|
|
0 commit comments