From b04dfd52c140613166f8e43a1e2dc7d8968974ce Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Tue, 17 Jun 2014 14:20:54 -0600 Subject: [PATCH] Cleanup Misc Ember Code No issue Misc Places - Removed expired, irrelevant, and fixed todos FloatingHeaderPartial - Fixed "Written" vs "Published" text logic SettingsGeneralController - Removed single quotes from property names EditorBaseController, MarkerManagerMixin - Aligned var declarations PostItemView - Commented out unfunctional code for feature request #2398 - Switched `isPage`, `isFeatured` to be computed properties in `Po - use `toggleProperty` in `PostController.action.toggleFeatured` --- core/client/controllers/posts/post.js | 8 +++----- core/client/controllers/settings/general.js | 7 +++---- core/client/mixins/editor-base-controller.js | 2 +- core/client/mixins/marker-manager.js | 15 +++++++-------- core/client/routes/signout.js | 1 - core/client/templates/-floating-header.hbs | 4 +--- core/client/views/post-item-view.js | 17 ++++++----------- 7 files changed, 21 insertions(+), 33 deletions(-) diff --git a/core/client/controllers/posts/post.js b/core/client/controllers/posts/post.js index 84d0c6bf85..d7a4f0e55b 100644 --- a/core/client/controllers/posts/post.js +++ b/core/client/controllers/posts/post.js @@ -4,18 +4,16 @@ var PostController = Ember.ObjectController.extend({ actions: { toggleFeatured: function () { - var featured = !this.get('featured'), + var featured = this.toggleProperty('featured'), self = this; - this.set('featured', featured); - this.get('model').save().then(function () { self.notifications.showSuccess('Post successfully marked as ' + (featured ? 'featured' : 'not featured') + '.'); - }, function () { + }).catch(function () { self.notifications.showError('An error occured while saving the post.'); }); } } }); -export default PostController; +export default PostController; \ No newline at end of file diff --git a/core/client/controllers/settings/general.js b/core/client/controllers/settings/general.js index 0e44cce9c6..95aeea9396 100644 --- a/core/client/controllers/settings/general.js +++ b/core/client/controllers/settings/general.js @@ -1,4 +1,3 @@ - var elementLookup = { title: '#blog-title', description: '#blog-description', @@ -20,7 +19,7 @@ var SettingsGeneralController = Ember.ObjectController.extend({ }.property('permalinks'), actions: { - 'save': function () { + save: function () { // Validate and save settings var model = this.get('model'), // @TODO: Don't know how to scope this to this controllers view because this.view is null @@ -46,11 +45,11 @@ var SettingsGeneralController = Ember.ObjectController.extend({ } }, - 'uploadLogo': function () { + uploadLogo: function () { // @TODO: Integrate with Modal component }, - 'uploadCover': function () { + uploadCover: function () { // @TODO: Integrate with Modal component } } diff --git a/core/client/mixins/editor-base-controller.js b/core/client/mixins/editor-base-controller.js index 11cd5bab71..ef2ecf0322 100644 --- a/core/client/mixins/editor-base-controller.js +++ b/core/client/mixins/editor-base-controller.js @@ -111,7 +111,7 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, { // when returned from the server with ids. updateTags: function () { var tags = this.get('model.tags'), - oldTags = tags.filterBy('id', null); + oldTags = tags.filterBy('id', null); tags.removeObjects(oldTags); oldTags.invoke('deleteRecord'); diff --git a/core/client/mixins/marker-manager.js b/core/client/mixins/marker-manager.js index b41b9f0e6a..8f0c787129 100644 --- a/core/client/mixins/marker-manager.js +++ b/core/client/mixins/marker-manager.js @@ -11,10 +11,10 @@ var MarkerManager = Ember.Mixin.create({ // Add markers to the line if it needs one initMarkers: function (line) { var imageMarkdownRegex = this.get('imageMarkdownRegex'), - markerRegex = this.get('markerRegex'), - editor = this.get('codemirror'), - isImage = line.text.match(imageMarkdownRegex), - hasMarker = line.text.match(markerRegex); + markerRegex = this.get('markerRegex'), + editor = this.get('codemirror'), + isImage = line.text.match(imageMarkdownRegex), + hasMarker = line.text.match(markerRegex); if (isImage && !hasMarker) { this.addMarker(line, editor.getLineNumber(line)); @@ -159,12 +159,11 @@ var MarkerManager = Ember.Mixin.create({ // Removes the marker on the given line if there is one stripMarkerFromLine: function (line) { - var ln, - editor = this.get('codemirror'), + var editor = this.get('codemirror'), + ln = editor.getLineNumber(line), markerRegex = /\{<([\w\W]*?)>\}/, markerText = line.text.match(markerRegex); - ln = editor.getLineNumber(line); if (markerText) { editor.replaceRange( @@ -189,7 +188,7 @@ var MarkerManager = Ember.Mixin.create({ editor.eachLine(function (line) { var markerText = self.markerRegexForId(id).exec(line.text), - ln; + ln; if (markerText) { ln = editor.getLineNumber(line); diff --git a/core/client/routes/signout.js b/core/client/routes/signout.js index 21c98b6c4a..57f1a589b7 100644 --- a/core/client/routes/signout.js +++ b/core/client/routes/signout.js @@ -16,7 +16,6 @@ var SignoutRoute = AuthenticatedRoute.extend(styleBody, { } }).then(function () { self.notifications.showSuccess('You were successfully signed out.'); - // @TODO: new CSRF token to enable logging back in w/o refreshing - see issue #2861 for details self.transitionTo('signin'); }, function (resp) { self.notifications.showAPIError(resp, 'There was a problem logging out, please try again.'); diff --git a/core/client/templates/-floating-header.hbs b/core/client/templates/-floating-header.hbs index 9b558be23d..358d5841bf 100644 --- a/core/client/templates/-floating-header.hbs +++ b/core/client/templates/-floating-header.hbs @@ -1,12 +1,10 @@
- {{!-- @TODO: add back title updates depending on featured state --}} - {{!-- @TODO: the if published doesn't seem to work, needs to be fixed --}} - {{#if published}}Published{{else}}Written{{/if}} + {{#if isPublished}}Published{{else}}Written{{/if}} by {{#if author.name}}{{author.name}}{{else}}{{author.email}}{{/if}} diff --git a/core/client/views/post-item-view.js b/core/client/views/post-item-view.js index 99ac893d43..7b1add7cf4 100644 --- a/core/client/views/post-item-view.js +++ b/core/client/views/post-item-view.js @@ -1,23 +1,18 @@ import itemView from 'ghost/views/item-view'; var PostItemView = itemView.extend({ - classNameBindings: ['isFeatured', 'isPage'], + classNameBindings: ['isFeatured:featured', 'isPage:page'], - isFeatured: function () { - if (this.get('controller.model.featured')) { - return 'featured'; - } - }.property('controller.model.featured'), + isFeatured: Ember.computed.alias('controller.model.featured'), - isPage: function () { - if (this.get('controller.model.page')) { - return 'page'; - } - }.property('controller.model.page'), + isPage: Ember.computed.alias('controller.model.page'), + // WIP for #2308 + /* openEditor: function () { this.get('controller').send('openEditor', this.get('controller.model')); // send action to handle transition to editor route }.on('doubleClick') + */ }); export default PostItemView;