@@ -4,29 +4,105 @@ import boundOneWay from 'ghost/utils/bound-one-way';
44var TagsController = Ember . ArrayController . extend ( PaginationMixin , {
55 tags : Ember . computed . alias ( 'model' ) ,
66
7+ needs : 'application' ,
8+
79 activeTag : null ,
810 activeTagNameScratch : boundOneWay ( 'activeTag.name' ) ,
911 activeTagSlugScratch : boundOneWay ( 'activeTag.slug' ) ,
1012 activeTagDescriptionScratch : boundOneWay ( 'activeTag.description' ) ,
13+ activeTagMetaTitleScratch : boundOneWay ( 'activeTag.meta_title' ) ,
14+ activeTagMetaDescriptionScratch : boundOneWay ( 'activeTag.meta_description' ) ,
1115
1216 init : function ( options ) {
1317 options = options || { } ;
1418 options . modelType = 'tag' ;
1519 this . _super ( options ) ;
1620 } ,
1721
18- saveActiveTag : function ( ) {
22+ isViewingSubview : Ember . computed ( 'controllers.application.showSettingsMenu' , function ( key , value ) {
23+ // Not viewing a subview if we can't even see the PSM
24+ if ( ! this . get ( 'controllers.application.showSettingsMenu' ) ) {
25+ return false ;
26+ }
27+ if ( arguments . length > 1 ) {
28+ return value ;
29+ }
30+
31+ return false ;
32+ } ) ,
33+
34+ showErrors : function ( errors ) {
35+ errors = Ember . isArray ( errors ) ? errors : [ errors ] ;
36+ this . notifications . showErrors ( errors ) ;
37+ } ,
38+
39+ saveActiveTagProperty : function ( propKey , newValue ) {
1940 var activeTag = this . get ( 'activeTag' ) ,
20- name = activeTag . get ( 'name' ) ,
41+ currentValue = activeTag . get ( propKey ) ,
2142 self = this ;
2243
23- activeTag . save ( ) . then ( function ( ) {
24- self . notifications . showSuccess ( 'Saved ' + name ) ;
25- } ) . catch ( function ( error ) {
26- self . notifications . showAPIError ( error ) ;
44+ newValue = newValue . trim ( ) ;
45+
46+ // Quit if there was no change
47+ if ( newValue === currentValue ) {
48+ return ;
49+ }
50+
51+ activeTag . set ( propKey , newValue ) ;
52+
53+ this . notifications . closePassive ( ) ;
54+
55+ activeTag . save ( ) . catch ( function ( errors ) {
56+ self . showErrors ( errors ) ;
2757 } ) ;
2858 } ,
2959
60+ seoTitle : Ember . computed ( 'scratch' , 'activeTagNameScratch' , 'activeTagMetaTitleScratch' , function ( ) {
61+ var metaTitle = this . get ( 'activeTagMetaTitleScratch' ) || '' ;
62+
63+ metaTitle = metaTitle . length > 0 ? metaTitle : this . get ( 'activeTagNameScratch' ) ;
64+
65+ if ( metaTitle && metaTitle . length > 70 ) {
66+ metaTitle = metaTitle . substring ( 0 , 70 ) . trim ( ) ;
67+ metaTitle = Ember . Handlebars . Utils . escapeExpression ( metaTitle ) ;
68+ metaTitle = new Ember . Handlebars . SafeString ( metaTitle + '…' ) ;
69+ }
70+
71+ return metaTitle ;
72+ } ) ,
73+
74+ seoURL : Ember . computed ( 'activeTagSlugScratch' , function ( ) {
75+ var blogUrl = this . get ( 'config' ) . blogUrl ,
76+ seoSlug = this . get ( 'activeTagSlugScratch' ) ? this . get ( 'activeTagSlugScratch' ) : '' ,
77+ seoURL = blogUrl + '/tag/' + seoSlug ;
78+
79+ // only append a slash to the URL if the slug exists
80+ if ( seoSlug ) {
81+ seoURL += '/' ;
82+ }
83+
84+ if ( seoURL . length > 70 ) {
85+ seoURL = seoURL . substring ( 0 , 70 ) . trim ( ) ;
86+ seoURL = new Ember . Handlebars . SafeString ( seoURL + '…' ) ;
87+ }
88+
89+ return seoURL ;
90+ } ) ,
91+
92+ seoDescription : Ember . computed ( 'scratch' , 'activeTagDescriptionScratch' , 'activeTagMetaDescriptionScratch' , function ( ) {
93+ var metaDescription = this . get ( 'activeTagMetaDescriptionScratch' ) || '' ;
94+
95+ metaDescription = metaDescription . length > 0 ? metaDescription : this . get ( 'activeTagDescriptionScratch' ) ;
96+
97+ if ( metaDescription && metaDescription . length > 156 ) {
98+ metaDescription = metaDescription . substring ( 0 , 156 ) . trim ( ) ;
99+ metaDescription = Ember . Handlebars . Utils . escapeExpression ( metaDescription ) ;
100+ metaDescription = new Ember . Handlebars . SafeString ( metaDescription + '…' ) ;
101+ }
102+
103+ return metaDescription ;
104+ } ) ,
105+
30106 actions : {
31107 newTag : function ( ) {
32108 this . set ( 'activeTag' , this . store . createRecord ( 'tag' ) ) ;
@@ -52,47 +128,39 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, {
52128 } ,
53129
54130 saveActiveTagName : function ( name ) {
55- var activeTag = this . get ( 'activeTag' ) ,
56- currentName = activeTag . get ( 'name' ) ;
57-
58- name = name . trim ( ) ;
59- if ( ! name || name === currentName ) {
60- return ;
61- }
62-
63- // setting all of the properties as they are not saved until name is present
64- activeTag . setProperties ( {
65- name : name ,
66- slug : this . get ( 'activeTagSlugScratch' ) . trim ( ) ,
67- description : this . get ( 'activeTagDescriptionScratch' ) . trim ( )
68- } ) ;
69- this . saveActiveTag ( ) ;
131+ this . saveActiveTagProperty ( 'name' , name ) ;
70132 } ,
71133
72134 saveActiveTagSlug : function ( slug ) {
73- var name = this . get ( 'activeTag.name' ) ,
74- currentSlug = this . get ( 'activeTag.slug' ) || '' ;
135+ this . saveActiveTagProperty ( 'slug' , slug ) ;
136+ } ,
75137
76- slug = slug . trim ( ) ;
77- if ( ! name || ! slug || slug === currentSlug ) {
78- return ;
79- }
138+ saveActiveTagDescription : function ( description ) {
139+ this . saveActiveTagProperty ( 'description' , description ) ;
140+ } ,
80141
81- this . set ( 'activeTag.slug' , slug ) ;
82- this . saveActiveTag ( ) ;
142+ saveActiveTagMetaTitle : function ( metaTitle ) {
143+ this . saveActiveTagProperty ( 'meta_title' , metaTitle ) ;
83144 } ,
84145
85- saveActiveTagDescription : function ( description ) {
86- var name = this . get ( 'activeTag.name' ) ,
87- currentDescription = this . get ( 'activeTag.description' ) || '' ;
146+ saveActiveTagMetaDescription : function ( metaDescription ) {
147+ this . saveActiveTagProperty ( 'meta_description' , metaDescription ) ;
148+ } ,
88149
89- description = description . trim ( ) ;
90- if ( ! name || description === currentDescription ) {
91- return ;
92- }
150+ showSubview : function ( ) {
151+ this . set ( 'isViewingSubview' , true ) ;
152+ } ,
153+
154+ closeSubview : function ( ) {
155+ this . set ( 'isViewingSubview' , false ) ;
156+ } ,
157+
158+ setCoverImage : function ( image ) {
159+ this . saveActiveTagProperty ( 'image' , image ) ;
160+ } ,
93161
94- this . set ( 'activeTag.description' , description ) ;
95- this . saveActiveTag ( ) ;
162+ clearCoverImage : function ( ) {
163+ this . saveActiveTagProperty ( 'image' , '' ) ;
96164 }
97165 }
98166} ) ;
0 commit comments