2015-10-15 14:03:26 +02:00
|
|
|
/* global key */
|
|
|
|
import Ember from 'ember';
|
2016-05-24 14:06:59 +02:00
|
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
2016-04-26 23:32:17 +02:00
|
|
|
import {invokeAction} from 'ember-invoke-action';
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2016-01-19 14:03:27 +01:00
|
|
|
const {
|
|
|
|
Component,
|
|
|
|
Handlebars,
|
|
|
|
computed,
|
|
|
|
get,
|
2016-06-11 18:52:36 +02:00
|
|
|
inject: {service},
|
|
|
|
String: {htmlSafe}
|
2016-01-19 14:03:27 +01:00
|
|
|
} = Ember;
|
|
|
|
const {reads} = computed;
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
export default Component.extend({
|
2015-10-15 14:03:26 +02:00
|
|
|
|
|
|
|
tag: null,
|
|
|
|
|
|
|
|
scratchName: boundOneWay('tag.name'),
|
|
|
|
scratchSlug: boundOneWay('tag.slug'),
|
|
|
|
scratchDescription: boundOneWay('tag.description'),
|
2016-01-23 19:12:22 +01:00
|
|
|
scratchMetaTitle: boundOneWay('tag.metaTitle'),
|
|
|
|
scratchMetaDescription: boundOneWay('tag.metaDescription'),
|
2015-10-15 14:03:26 +02:00
|
|
|
|
|
|
|
isViewingSubview: false,
|
|
|
|
|
2016-06-13 16:21:41 +02:00
|
|
|
feature: service(),
|
2016-01-19 14:03:27 +01:00
|
|
|
config: service(),
|
|
|
|
mediaQueries: service(),
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2016-01-19 14:03:27 +01:00
|
|
|
isMobile: reads('mediaQueries.maxWidth600'),
|
2015-11-20 18:26:34 +01:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
title: computed('tag.isNew', function () {
|
2015-10-15 14:03:26 +02:00
|
|
|
if (this.get('tag.isNew')) {
|
|
|
|
return 'New Tag';
|
|
|
|
} else {
|
|
|
|
return 'Tag Settings';
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
seoTitle: computed('scratchName', 'scratchMetaTitle', function () {
|
2015-10-15 14:03:26 +02:00
|
|
|
let metaTitle = this.get('scratchMetaTitle') || '';
|
|
|
|
|
|
|
|
metaTitle = metaTitle.length > 0 ? metaTitle : this.get('scratchName');
|
|
|
|
|
|
|
|
if (metaTitle && metaTitle.length > 70) {
|
|
|
|
metaTitle = metaTitle.substring(0, 70).trim();
|
2015-10-28 12:36:45 +01:00
|
|
|
metaTitle = Handlebars.Utils.escapeExpression(metaTitle);
|
2016-06-11 18:52:36 +02:00
|
|
|
metaTitle = htmlSafe(`${metaTitle}…`);
|
2015-10-15 14:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return metaTitle;
|
|
|
|
}),
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
seoURL: computed('scratchSlug', function () {
|
|
|
|
let blogUrl = this.get('config.blogUrl');
|
|
|
|
let seoSlug = this.get('scratchSlug') || '';
|
2015-10-15 14:03:26 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
let seoURL = `${blogUrl}/tag/${seoSlug}`;
|
2015-10-15 14:03:26 +02:00
|
|
|
|
|
|
|
// only append a slash to the URL if the slug exists
|
|
|
|
if (seoSlug) {
|
|
|
|
seoURL += '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seoURL.length > 70) {
|
|
|
|
seoURL = seoURL.substring(0, 70).trim();
|
2016-06-11 18:52:36 +02:00
|
|
|
seoURL = htmlSafe(`${seoURL}…`);
|
2015-10-15 14:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return seoURL;
|
|
|
|
}),
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
seoDescription: computed('scratchDescription', 'scratchMetaDescription', function () {
|
2015-10-15 14:03:26 +02:00
|
|
|
let metaDescription = this.get('scratchMetaDescription') || '';
|
|
|
|
|
|
|
|
metaDescription = metaDescription.length > 0 ? metaDescription : this.get('scratchDescription');
|
|
|
|
|
|
|
|
if (metaDescription && metaDescription.length > 156) {
|
|
|
|
metaDescription = metaDescription.substring(0, 156).trim();
|
2015-10-28 12:36:45 +01:00
|
|
|
metaDescription = Handlebars.Utils.escapeExpression(metaDescription);
|
2016-06-11 18:52:36 +02:00
|
|
|
metaDescription = htmlSafe(`${metaDescription}…`);
|
2015-10-15 14:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return metaDescription;
|
|
|
|
}),
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
didReceiveAttrs(attrs) {
|
2015-11-15 12:06:49 +01:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2015-10-15 14:03:26 +02:00
|
|
|
if (get(attrs, 'newAttrs.tag.value.id') !== get(attrs, 'oldAttrs.tag.value.id')) {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
reset() {
|
2015-10-15 14:03:26 +02:00
|
|
|
this.set('isViewingSubview', false);
|
|
|
|
if (this.$()) {
|
|
|
|
this.$('.settings-menu-pane').scrollTop(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
focusIn() {
|
2015-10-15 14:03:26 +02:00
|
|
|
key.setScope('tag-settings-form');
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
focusOut() {
|
2015-10-15 14:03:26 +02:00
|
|
|
key.setScope('default');
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-10-28 12:36:45 +01:00
|
|
|
setProperty(property, value) {
|
2016-04-28 17:34:36 +02:00
|
|
|
invokeAction(this, 'setProperty', property, value);
|
2015-10-15 14:03:26 +02:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
setCoverImage(image) {
|
2016-06-13 16:21:41 +02:00
|
|
|
this.send('setProperty', 'image', image);
|
2015-10-15 14:03:26 +02:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
clearCoverImage() {
|
2016-06-13 16:21:41 +02:00
|
|
|
this.send('setProperty', 'image', '');
|
2015-10-15 14:03:26 +02:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
openMeta() {
|
2015-10-15 14:03:26 +02:00
|
|
|
this.set('isViewingSubview', true);
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
closeMeta() {
|
2015-10-15 14:03:26 +02:00
|
|
|
this.set('isViewingSubview', false);
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
deleteTag() {
|
2016-04-26 23:32:17 +02:00
|
|
|
invokeAction(this, 'showDeleteTagModal');
|
2015-10-15 14:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|