Skip to content

Commit

Permalink
Save tags on focus-out
Browse files Browse the repository at this point in the history
Ref TryGhost#4248
Current bugs
- Saves even if you didn't make changes
  • Loading branch information
novaugust committed Nov 22, 2014
1 parent 09658f8 commit d1a4d6a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
33 changes: 25 additions & 8 deletions core/client/controllers/settings/tags.js
@@ -1,27 +1,31 @@
import PaginationMixin from 'ghost/mixins/pagination-controller';
import boundOneWay from 'ghost/utils/bound-one-way';

var TagsController = Ember.ArrayController.extend(PaginationMixin, {
tags: Ember.computed.alias('model'),

activeTag: null,
activeTagSlug: boundOneWay('activeTag.slug'),
activeTagName: boundOneWay('activeTag.name'),
activeTagDescription: boundOneWay('activeTag.description'),

init: function (options) {
options = options || {};
options.modelType = 'tag';
this._super(options);
},

actions: {
// Clear any unsaved changes until autosave is implemented
closeTagEditor: function () {
this.get('activeTag').rollback();
this.send('closeSettingsMenu');
},
newTag: function () {
this.set('activeTag', this.store.createRecord('tag'));
this.send('openSettingsMenu');
},

editTag: function (tag) {
this.set('activeTag', tag);
this.send('openSettingsMenu');
},

deleteTag: function (tag) {
var name = tag.get('name'),
self = this;
Expand All @@ -34,11 +38,24 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, {
self.notifications.showAPIError(error);
});
},
saveTag: function (tag) {
var name = tag.get('name'),

saveActiveTag: function () {
debugger;
var activeTag = this.get('activeTag'),
self = this;

tag.save().then(function () {
activeTag.setProperties({
slug: this.get('activeTagSlug'),
name: this.get('activeTagName'),
description: this.get('activeTagDescription')
});

// Don't save unless the tag has a name
if (!(activeTag.get('name'))) {
return;
}

activeTag.save().then(function () {
self.notifications.showSuccess('Saved ' + name);
}).catch(function (error) {
self.notifications.showAPIError(error);
Expand Down
1 change: 0 additions & 1 deletion core/client/routes/settings/tags.js
Expand Up @@ -3,7 +3,6 @@ import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import PaginationRouteMixin from 'ghost/mixins/pagination-route';

var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {

beforeModel: function () {
if (!this.get('config.tagsUI')) {
return this.transitionTo('settings.general');
Expand Down
11 changes: 5 additions & 6 deletions core/client/templates/settings/tags/settings-menu.hbs
@@ -1,33 +1,32 @@
<div class="content-cover" {{action "closeTagEditor"}}></div>
<div class="content-cover" {{action "closeSettingsMenu"}}></div>
<div class="settings-menu-container">
<div class="settings-menu settings-menu-pane settings-menu-pane-in">
<div class="settings-menu-header">
<h4>Tag Settings</h4>
<button class="close icon-x settings-menu-header-action" {{action "closeTagEditor"}}>
<button class="close icon-x settings-menu-header-action" {{action "closeSettingsMenu"}}>
<span class="hidden">Close</span>
</button>
</div>
<div class="settings-menu-content">
<form>
<div class="form-group">
<label>Tag Name</label>
{{input type="text" value=activeTag.name}}
{{gh-input type="text" value=activeTagName focus-out="saveActiveTag"}}
</div>

<div class="form-group">
<label>Slug</label>{{!--@TODO show full url preview, not just slug--}}
{{input type="text" value=activeTag.slug}}
{{gh-input type="text" value=activeTagSlug focus-out="saveActiveTag"}}
</div>

<div class="form-group">
<label>Description</label>
{{textarea value=activeTag.description}}
{{gh-textarea value=activeTagDescription focus-out="saveActiveTag"}}
</div>

{{#unless activeTag.isNew}}
<button class="btn btn-red icon-trash" {{action "deleteTag" activeTag}}>Delete Tag</button>
{{/unless}}
<button class="btn btn-green tag-save-button" {{action "saveTag" activeTag}}>{{view.saveText}}</button>
</form>
</div>
</div>
Expand Down

0 comments on commit d1a4d6a

Please sign in to comment.