Merge pull request #489 from ZogStriP/fix-editing-a-category-and-cancelling

fix some issues when editing a topic title and then cancelling it
This commit is contained in:
Robin Ward 2013-03-18 07:41:49 -07:00
commit c4a5f9d47b
3 changed files with 14 additions and 14 deletions

View file

@ -10,7 +10,7 @@
{{/if}} {{/if}}
{{#if view.editingTopic}} {{#if view.editingTopic}}
<input id='edit-title' type='text' {{bindAttr value="view.topic.title"}}> <input id='edit-title' type='text' {{bindAttr value="view.topic.title"}}>
{{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" valueBinding="view.topic.categoryName"}} {{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" sourceBinding="view.topic.categoryName"}}
<button class='btn btn-primary btn-small' {{action finishedEdit target="view"}}><i class='icon-ok'></i></button> <button class='btn btn-primary btn-small' {{action finishedEdit target="view"}}><i class='icon-ok'></i></button>
<button class='btn btn-small' {{action cancelEdit target="view"}}><i class='icon-remove'></i></button> <button class='btn btn-small' {{action cancelEdit target="view"}}><i class='icon-remove'></i></button>
{{else}} {{else}}

View file

@ -9,6 +9,7 @@
Discourse.ComboboxViewCategory = Discourse.ComboboxView.extend({ Discourse.ComboboxViewCategory = Discourse.ComboboxView.extend({
none: 'category.none', none: 'category.none',
dataAttributes: ['color', 'text_color', 'description'], dataAttributes: ['color', 'text_color', 'description'],
valueBinding: Ember.Binding.oneWay('source'),
template: function(text, templateData) { template: function(text, templateData) {
if (!templateData.color) return text; if (!templateData.color) return text;

View file

@ -345,24 +345,25 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
}, },
cancelEdit: function() { cancelEdit: function() {
// set the previous category back
this.set('controller.content.category', this.get('previousCategory'));
// clear the previous category
this.set('previousCategory', null);
// close editing mode // close editing mode
this.set('editingTopic', false); this.set('editingTopic', false);
}, },
finishedEdit: function() { finishedEdit: function() {
var new_val, topic;
if (this.get('editingTopic')) { if (this.get('editingTopic')) {
topic = this.get('topic'); var topic = this.get('topic');
new_val = $('#edit-title').val(); // retrieve the title from the text field
topic.set('title', new_val); var newTitle = $('#edit-title').val();
topic.set('fancy_title', new_val); // retrieve the category from the combox box
var newCategoryName = $('#topic-title select option:selected').val();
// manually update the titles & category
topic.setProperties({
title: newTitle,
fancy_title: newTitle,
categoryName: newCategoryName
});
// save the modifications
topic.save(); topic.save();
// clear the previous category
this.set('previousCategory', null);
// close editing mode // close editing mode
this.set('editingTopic', false); this.set('editingTopic', false);
} }
@ -370,8 +371,6 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
editTopic: function() { editTopic: function() {
if (!this.get('topic.can_edit')) return false; if (!this.get('topic.can_edit')) return false;
// save the category so we can get it back when cancelling the edit
this.set('previousCategory', this.get('controller.content.category'));
// enable editing mode // enable editing mode
this.set('editingTopic', true); this.set('editingTopic', true);
return false; return false;