2017-08-22 10:53:26 +03:00
|
|
|
|
import Component from '@ember/component';
|
2016-05-24 15:06:59 +03:00
|
|
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
2022-02-01 12:34:03 +03:00
|
|
|
|
import classic from 'ember-classic-decorator';
|
2022-09-23 20:15:08 +03:00
|
|
|
|
import moment from 'moment-timezone';
|
2022-01-21 22:25:47 +03:00
|
|
|
|
import {action, computed} from '@ember/object';
|
2021-05-10 22:38:07 +03:00
|
|
|
|
import {alias, or} from '@ember/object/computed';
|
2022-11-03 14:14:36 +03:00
|
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2017-10-30 12:38:01 +03:00
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-01 12:34:03 +03:00
|
|
|
|
import {tagName} from '@ember-decorators/component';
|
2023-04-18 12:57:41 +03:00
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
2017-06-08 18:00:10 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@classic
|
|
|
|
|
@tagName('')
|
|
|
|
|
export default class GhPostSettingsMenu extends Component {
|
2022-02-01 20:03:45 +03:00
|
|
|
|
@service feature;
|
|
|
|
|
@service store;
|
|
|
|
|
@service ajax;
|
|
|
|
|
@service ghostPaths;
|
|
|
|
|
@service notifications;
|
|
|
|
|
@service slugGenerator;
|
|
|
|
|
@service session;
|
|
|
|
|
@service settings;
|
|
|
|
|
@service ui;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
2022-11-03 14:14:36 +03:00
|
|
|
|
@inject config;
|
|
|
|
|
|
2023-04-18 12:57:41 +03:00
|
|
|
|
@tracked showPostHistory = false;
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post = null;
|
|
|
|
|
isViewingSubview = false;
|
|
|
|
|
|
|
|
|
|
@alias('post.canonicalUrlScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
canonicalUrlScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.customExcerptScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
customExcerptScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.codeinjectionFootScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
codeinjectionFootScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.codeinjectionHeadScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
codeinjectionHeadScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.metaDescriptionScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
metaDescriptionScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.metaTitleScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
metaTitleScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.ogDescriptionScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
ogDescriptionScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.ogTitleScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
ogTitleScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.twitterDescriptionScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
twitterDescriptionScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@alias('post.twitterTitleScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
twitterTitleScratch;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@boundOneWay('post.slug')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
slugValue;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@boundOneWay('post.uuid')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
uuidValue;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
2023-02-13 23:30:02 +03:00
|
|
|
|
@or('metaDescriptionScratch', 'customExcerptScratch')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
seoDescription;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or(
|
|
|
|
|
'ogDescriptionScratch',
|
|
|
|
|
'customExcerptScratch',
|
|
|
|
|
'seoDescription',
|
|
|
|
|
'post.excerpt',
|
|
|
|
|
'settings.description',
|
|
|
|
|
''
|
|
|
|
|
)
|
2022-02-10 13:41:36 +03:00
|
|
|
|
facebookDescription;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or(
|
|
|
|
|
'post.ogImage',
|
|
|
|
|
'post.featureImage',
|
|
|
|
|
'settings.ogImage',
|
|
|
|
|
'settings.coverImage'
|
|
|
|
|
)
|
2022-02-10 13:41:36 +03:00
|
|
|
|
facebookImage;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or('ogTitleScratch', 'seoTitle')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
facebookTitle;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or(
|
|
|
|
|
'twitterDescriptionScratch',
|
|
|
|
|
'customExcerptScratch',
|
|
|
|
|
'seoDescription',
|
|
|
|
|
'post.excerpt',
|
|
|
|
|
'settings.description',
|
|
|
|
|
''
|
|
|
|
|
)
|
2022-02-10 13:41:36 +03:00
|
|
|
|
twitterDescription;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or(
|
|
|
|
|
'post.twitterImage',
|
|
|
|
|
'post.featureImage',
|
|
|
|
|
'settings.twitterImage',
|
|
|
|
|
'settings.coverImage'
|
|
|
|
|
)
|
2022-02-10 13:41:36 +03:00
|
|
|
|
twitterImage;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or('twitterTitleScratch', 'seoTitle')
|
2022-02-10 13:41:36 +03:00
|
|
|
|
twitterTitle;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@or(
|
|
|
|
|
'session.user.isOwnerOnly',
|
|
|
|
|
'session.user.isAdminOnly',
|
|
|
|
|
'session.user.isEditor'
|
|
|
|
|
)
|
2022-02-10 13:41:36 +03:00
|
|
|
|
showVisibilityInput;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
@computed('metaTitleScratch', 'post.titleScratch')
|
|
|
|
|
get seoTitle() {
|
2018-06-14 14:38:43 +03:00
|
|
|
|
return this.metaTitleScratch || this.post.titleScratch || '(Untitled)';
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|
2018-06-14 14:38:43 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@computed('post.{slug,canonicalUrl}', 'config.blogUrl')
|
|
|
|
|
get seoURL() {
|
2021-03-30 12:10:34 +03:00
|
|
|
|
const urlParts = [];
|
2014-10-22 01:20:51 +04:00
|
|
|
|
|
2021-03-30 12:10:34 +03:00
|
|
|
|
if (this.post.canonicalUrl) {
|
2021-07-14 17:53:55 +03:00
|
|
|
|
try {
|
|
|
|
|
const canonicalUrl = new URL(this.post.canonicalUrl);
|
|
|
|
|
urlParts.push(canonicalUrl.host);
|
|
|
|
|
urlParts.push(...canonicalUrl.pathname.split('/').reject(p => !p));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// no-op, invalid URL
|
|
|
|
|
}
|
2019-03-12 13:40:07 +03:00
|
|
|
|
} else {
|
2022-10-07 17:24:03 +03:00
|
|
|
|
const blogUrl = new URL(this.config.blogUrl);
|
2021-03-30 12:10:34 +03:00
|
|
|
|
urlParts.push(blogUrl.host);
|
|
|
|
|
urlParts.push(...blogUrl.pathname.split('/').reject(p => !p));
|
|
|
|
|
urlParts.push(this.post.slug);
|
2019-03-12 13:40:07 +03:00
|
|
|
|
}
|
2021-03-30 12:10:34 +03:00
|
|
|
|
|
2021-08-04 15:40:45 +03:00
|
|
|
|
return urlParts.join(' › ');
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|
2014-09-15 04:40:24 +04:00
|
|
|
|
|
2023-05-02 17:58:56 +03:00
|
|
|
|
get canViewPostHistory() {
|
2023-06-13 13:38:39 +03:00
|
|
|
|
// Can only view history for lexical posts
|
|
|
|
|
if (this.post.lexical === null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Can view history for all unpublished/unsent posts
|
|
|
|
|
if (!this.post.isPublished && !this.post.isSent) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-05-02 17:58:56 +03:00
|
|
|
|
|
2023-06-13 13:38:39 +03:00
|
|
|
|
// Cannot view history for published posts if there isn't a web version
|
|
|
|
|
if (this.post.emailOnly) {
|
|
|
|
|
return false;
|
2023-05-02 17:58:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 13:38:39 +03:00
|
|
|
|
return true;
|
2023-05-02 17:58:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 21:57:58 +03:00
|
|
|
|
willDestroyElement() {
|
2022-02-01 12:34:03 +03:00
|
|
|
|
super.willDestroyElement(...arguments);
|
2021-07-15 17:27:29 +03:00
|
|
|
|
|
2021-07-02 21:57:58 +03:00
|
|
|
|
let post = this.post;
|
|
|
|
|
let errors = post.get('errors');
|
2018-01-11 20:43:23 +03:00
|
|
|
|
|
2021-07-02 21:57:58 +03:00
|
|
|
|
// reset the publish date if it has an error
|
|
|
|
|
if (errors.has('publishedAtBlogDate') || errors.has('publishedAtBlogTime')) {
|
|
|
|
|
post.set('publishedAtBlogTZ', post.get('publishedAtUTC'));
|
|
|
|
|
post.validate({attribute: 'publishedAtBlog'});
|
2018-01-11 20:43:23 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 21:03:52 +03:00
|
|
|
|
this.setSidebarWidthVariable(0);
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|
2021-07-02 21:03:52 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
showSubview(subview) {
|
|
|
|
|
this.set('isViewingSubview', true);
|
|
|
|
|
this.set('subview', subview);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
closeSubview() {
|
|
|
|
|
this.set('isViewingSubview', false);
|
|
|
|
|
this.set('subview', null);
|
|
|
|
|
}
|
2017-06-08 18:00:10 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
discardEnter() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-06-08 18:00:10 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
toggleFeatured() {
|
|
|
|
|
this.toggleProperty('post.featured');
|
2015-09-24 20:49:36 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If this is a new post. Don't save the post. Defer the save
|
|
|
|
|
// to the user pressing the save button
|
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-23 12:47:35 +04:00
|
|
|
|
|
2023-04-18 12:57:41 +03:00
|
|
|
|
@action
|
|
|
|
|
openPostHistory() {
|
|
|
|
|
this.showPostHistory = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
closePostHistory() {
|
|
|
|
|
this.showPostHistory = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* triggered by user manually changing slug
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
updateSlug(newSlug) {
|
|
|
|
|
return this.updateSlugTask
|
|
|
|
|
.perform(newSlug)
|
|
|
|
|
.catch((error) => {
|
2016-07-19 02:23:43 +03:00
|
|
|
|
this.showError(error);
|
2019-03-06 16:53:54 +03:00
|
|
|
|
this.post.rollbackAttributes();
|
2014-07-01 16:18:47 +04:00
|
|
|
|
});
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|
2021-06-23 21:45:17 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setPublishedAtBlogDate(date) {
|
2022-10-07 13:20:06 +03:00
|
|
|
|
// date is a Date object that contains the correct date string in the blog timezone
|
2022-02-01 12:34:03 +03:00
|
|
|
|
let post = this.post;
|
2022-10-07 13:20:06 +03:00
|
|
|
|
let dateString = moment.tz(date, this.settings.get('timezone')).format('YYYY-MM-DD');
|
2021-06-23 21:45:17 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.get('errors').remove('publishedAtBlogDate');
|
2014-07-01 16:18:47 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (post.get('isNew') || date === post.get('publishedAtBlogDate')) {
|
|
|
|
|
post.validate({property: 'publishedAtBlog'});
|
|
|
|
|
} else {
|
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-08 10:02:21 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
async setVisibility(segment) {
|
|
|
|
|
this.post.set('tiers', segment);
|
|
|
|
|
try {
|
|
|
|
|
await this.post.validate({property: 'visibility'});
|
|
|
|
|
await this.post.validate({property: 'tiers'});
|
|
|
|
|
if (this.post.get('isDraft') && this.post.changedAttributes().tiers) {
|
|
|
|
|
await this.savePostTask.perform();
|
2017-03-17 20:16:21 +03:00
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
|
} catch (e) {
|
|
|
|
|
if (!e) {
|
|
|
|
|
// validation error
|
2017-08-01 11:24:46 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-01 11:24:46 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setPublishedAtBlogTime(time) {
|
|
|
|
|
let post = this.post;
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.get('errors').remove('publishedAtBlogDate');
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (post.get('isNew') || time === post.get('publishedAtBlogTime')) {
|
|
|
|
|
post.validate({property: 'publishedAtBlog'});
|
|
|
|
|
} else {
|
|
|
|
|
post.set('publishedAtBlogTime', time);
|
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setCustomExcerpt(excerpt) {
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentExcerpt = post.get('customExcerpt');
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (excerpt === currentExcerpt) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.set('customExcerpt', excerpt);
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return post.validate({property: 'customExcerpt'}).then(() => this.savePostTask.perform());
|
|
|
|
|
}
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setHeaderInjection(code) {
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentCode = post.get('codeinjectionHead');
|
2017-08-02 12:32:51 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (code === currentCode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-01 11:24:46 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.set('codeinjectionHead', code);
|
2014-09-23 13:37:08 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return post.validate({property: 'codeinjectionHead'}).then(() => this.savePostTask.perform());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
setFooterInjection(code) {
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentCode = post.get('codeinjectionFoot');
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (code === currentCode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.set('codeinjectionFoot', code);
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return post.validate({property: 'codeinjectionFoot'}).then(() => this.savePostTask.perform());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
setMetaTitle(metaTitle) {
|
|
|
|
|
// Grab the post and current stored meta title
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentTitle = post.get('metaTitle');
|
|
|
|
|
|
|
|
|
|
// If the title entered matches the stored meta title, do nothing
|
|
|
|
|
if (currentTitle === metaTitle) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered is different, set it as the new meta title
|
|
|
|
|
post.set('metaTitle', metaTitle);
|
2014-09-23 13:37:08 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the meta title is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'metaTitle'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2014-09-23 13:37:08 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setMetaDescription(metaDescription) {
|
|
|
|
|
// Grab the post and current stored meta description
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentDescription = post.get('metaDescription');
|
2014-09-19 03:42:07 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered matches the stored meta title, do nothing
|
|
|
|
|
if (currentDescription === metaDescription) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-16 02:46:40 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered is different, set it as the new meta title
|
|
|
|
|
post.set('metaDescription', metaDescription);
|
2019-03-12 13:40:07 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the meta title is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'metaDescription'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2019-03-12 13:40:07 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-03-12 13:40:07 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setCanonicalUrl(value) {
|
|
|
|
|
// Grab the post and current stored meta description
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentCanonicalUrl = post.canonicalUrl;
|
2019-03-12 13:40:07 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the value entered matches the stored value, do nothing
|
|
|
|
|
if (currentCanonicalUrl === value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-03-12 13:40:07 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the value supplied is different, set it as the new value
|
|
|
|
|
post.set('canonicalUrl', value);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the value is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'canonicalUrl'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2017-08-03 14:45:14 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setOgTitle(ogTitle) {
|
|
|
|
|
// Grab the post and current stored facebook title
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentTitle = post.get('ogTitle');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered matches the stored facebook title, do nothing
|
|
|
|
|
if (currentTitle === ogTitle) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered is different, set it as the new facebook title
|
|
|
|
|
post.set('ogTitle', ogTitle);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the facebook title is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'ogTitle'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2017-08-03 14:45:14 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setOgDescription(ogDescription) {
|
|
|
|
|
// Grab the post and current stored facebook description
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentDescription = post.get('ogDescription');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered matches the stored facebook description, do nothing
|
|
|
|
|
if (currentDescription === ogDescription) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the description entered is different, set it as the new facebook description
|
|
|
|
|
post.set('ogDescription', ogDescription);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the facebook description is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'ogDescription'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2017-08-03 14:45:14 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setTwitterTitle(twitterTitle) {
|
|
|
|
|
// Grab the post and current stored twitter title
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentTitle = post.get('twitterTitle');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered matches the stored twitter title, do nothing
|
|
|
|
|
if (currentTitle === twitterTitle) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the title entered is different, set it as the new twitter title
|
|
|
|
|
post.set('twitterTitle', twitterTitle);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the twitter title is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'twitterTitle'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2017-08-03 14:45:14 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setTwitterDescription(twitterDescription) {
|
|
|
|
|
// Grab the post and current stored twitter description
|
|
|
|
|
let post = this.post;
|
|
|
|
|
let currentDescription = post.get('twitterDescription');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the description entered matches the stored twitter description, do nothing
|
|
|
|
|
if (currentDescription === twitterDescription) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-11-05 14:00:07 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// If the description entered is different, set it as the new twitter description
|
|
|
|
|
post.set('twitterDescription', twitterDescription);
|
2014-09-16 02:46:40 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// Make sure the twitter description is valid and if so, save it into the post
|
|
|
|
|
return post.validate({property: 'twitterDescription'}).then(() => {
|
|
|
|
|
if (post.get('isNew')) {
|
2014-09-16 02:46:40 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
return this.savePostTask.perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-16 02:46:40 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setCoverImage(image) {
|
|
|
|
|
this.set('post.featureImage', image);
|
2014-09-16 02:46:40 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-16 02:46:40 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-15 04:40:24 +04:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
clearCoverImage() {
|
|
|
|
|
this.set('post.featureImage', '');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setOgImage(image) {
|
|
|
|
|
this.set('post.ogImage', image);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
clearOgImage() {
|
|
|
|
|
this.set('post.ogImage', '');
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
setTwitterImage(image) {
|
|
|
|
|
this.set('post.twitterImage', image);
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-03 14:45:14 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
clearTwitterImage() {
|
|
|
|
|
this.set('post.twitterImage', '');
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
if (this.get('post.isNew')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
this.post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
@action
|
|
|
|
|
changeAuthors(newAuthors) {
|
|
|
|
|
let post = this.post;
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
// return if nothing changed
|
|
|
|
|
if (newAuthors.mapBy('id').join() === post.get('authors').mapBy('id').join()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-08-19 12:16:32 +03:00
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
|
post.set('authors', newAuthors);
|
|
|
|
|
post.validate({property: 'authors'});
|
|
|
|
|
|
|
|
|
|
// if this is a new post (never been saved before), don't try to save it
|
|
|
|
|
if (post.get('isNew')) {
|
|
|
|
|
return;
|
2014-06-08 10:02:21 +04:00
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
|
|
this.savePostTask.perform().catch((error) => {
|
|
|
|
|
this.showError(error);
|
|
|
|
|
post.rollbackAttributes();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
deletePostInternal() {
|
|
|
|
|
if (this.deletePost) {
|
|
|
|
|
this.deletePost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
setSidebarWidthFromElement(element) {
|
|
|
|
|
const width = element.getBoundingClientRect().width;
|
|
|
|
|
this.setSidebarWidthVariable(width);
|
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
|
|
|
|
|
|
showError(error) {
|
|
|
|
|
// TODO: remove null check once ValidationEngine has been removed
|
|
|
|
|
if (error) {
|
2019-03-06 16:53:54 +03:00
|
|
|
|
this.notifications.showAPIError(error);
|
2018-01-11 20:43:23 +03:00
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|
2021-07-02 21:03:52 +03:00
|
|
|
|
|
|
|
|
|
setSidebarWidthVariable(width) {
|
|
|
|
|
document.documentElement.style.setProperty('--editor-sidebar-width', `${width}px`);
|
2014-06-08 10:02:21 +04:00
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
|
}
|