fix edit reason when editing a reply

This commit is contained in:
Régis Hanol 2013-11-18 19:50:43 +01:00
parent a2466d182f
commit 6e3de67977
5 changed files with 76 additions and 38 deletions

View File

@ -12,6 +12,9 @@ Discourse.ComposerController = Discourse.Controller.extend({
replyAsNewTopicDraft: Em.computed.equal('model.draftKey', Discourse.Composer.REPLY_AS_NEW_TOPIC_KEY),
checkedMessages: false,
showEditReason: false,
editReason: null,
init: function() {
this._super();
this.set('similarTopics', Em.A());
@ -38,6 +41,10 @@ Discourse.ComposerController = Discourse.Controller.extend({
save: function() {
this.save();
},
displayEditReason: function() {
this.set("showEditReason", true);
}
},
@ -76,12 +83,15 @@ Discourse.ComposerController = Discourse.Controller.extend({
save: function(force) {
var composer = this.get('model'),
composerController = this;
self = this;
if( composer.get('cantSubmitPost') ) {
this.set('view.showTitleTip', Date.now());
this.set('view.showCategoryTip', Date.now());
this.set('view.showReplyTip', Date.now());
if(composer.get('cantSubmitPost')) {
var now = Date.now();
this.setProperties({
"view.showTitleTip": now,
"view.showCategoryTip": now,
"view.showReplyTip": now
});
return;
}
@ -108,7 +118,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
"callback": function(){
composer.set('topic', topic);
composer.set('post', null);
composerController.save(true);
self.save(true);
}
});
}
@ -117,7 +127,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
"label": I18n.t("composer.reply_original") + "<br/><div class='topic-title overflow-ellipsis'>" + this.get('model.topic.title') + "</div>",
"class": "btn-primary btn-reply-on-original",
"callback": function(){
composerController.save(true);
self.save(true);
}
});
@ -127,16 +137,17 @@ Discourse.ComposerController = Discourse.Controller.extend({
}
return composer.save({
imageSizes: this.get('view').imageSizes()
imageSizes: this.get('view').imageSizes(),
editReason: this.get("editReason")
}).then(function(opts) {
// If we replied as a new topic successfully, remove the draft.
if (composerController.get('replyAsNewTopicDraft')) {
composerController.destroyDraft();
if (self.get('replyAsNewTopicDraft')) {
self.destroyDraft();
}
opts = opts || {};
composerController.close();
self.close();
var currentUser = Discourse.User.current();
if (composer.get('creatingTopic')) {
@ -220,6 +231,11 @@ Discourse.ComposerController = Discourse.Controller.extend({
open: function(opts) {
if (!opts) opts = {};
this.setProperties({
showEditReason: false,
editReason: null
});
var composerMessages = this.get('controllers.composerMessages');
composerMessages.reset();
@ -233,7 +249,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
// ensure we have a view now, without it transitions are going to be messed
var view = this.get('view');
var composerController = this;
var self = this;
if (!view) {
// TODO: We should refactor how composer is inserted. It should probably use a
@ -247,7 +263,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
// we need to change stuff, otherwise css animations don't kick in
Em.run.next(function() {
Em.run.next(function() {
composerController.open(opts);
self.open(opts);
});
});
return promise;
@ -267,7 +283,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
} else {
opts.tested = true;
if (!opts.ignoreIfChanged) {
this.cancelComposer().then(function() { composerController.open(opts); },
this.cancelComposer().then(function() { self.open(opts); },
function() { return promise.reject(); });
}
return promise;
@ -279,7 +295,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
Discourse.Draft.get(opts.draftKey).then(function(data) {
opts.draftSequence = data.draft_sequence;
opts.draft = data.draft;
return composerController.open(opts);
return self.open(opts);
});
return promise;
}
@ -316,15 +332,15 @@ Discourse.ComposerController = Discourse.Controller.extend({
},
cancelComposer: function() {
var composerController = this;
var self = this;
return Ember.Deferred.promise(function (promise) {
if (composerController.get('model.hasMetaData') || composerController.get('model.replyDirty')) {
if (self.get('model.hasMetaData') || self.get('model.replyDirty')) {
bootbox.confirm(I18n.t("post.abandon"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if (result) {
composerController.destroyDraft();
composerController.get('model').clearState();
composerController.close();
self.destroyDraft();
self.get('model').clearState();
self.close();
promise.resolve();
} else {
promise.reject();
@ -332,8 +348,9 @@ Discourse.ComposerController = Discourse.Controller.extend({
});
} else {
// it is possible there is some sort of crazy draft with no body ... just give up on it
composerController.destroyDraft();
composerController.close();
self.destroyDraft();
self.get('model').clearState();
self.close();
promise.resolve();
}
});
@ -359,10 +376,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
},
close: function() {
this.set('model', null);
this.set('view.showTitleTip', false);
this.set('view.showCategoryTip', false);
this.set('view.showReplyTip', false);
this.setProperties({
model: null,
'view.showTitleTip': false,
'view.showCategoryTip': false,
'view.showReplyTip': false
});
},
closeAutocomplete: function() {

View File

@ -389,7 +389,8 @@ Discourse.Composer = Discourse.Model.extend({
originalText: null,
reply: null,
post: null,
title: null
title: null,
editReason: null
});
},
@ -412,7 +413,7 @@ Discourse.Composer = Discourse.Model.extend({
post.setProperties({
raw: this.get('reply'),
editReason: this.get('editReason'),
editReason: opts.editReason,
imageSizes: opts.imageSizes,
cooked: $('#wmd-preview').html()
});

View File

@ -9,7 +9,18 @@
{{#if model.viewOpen}}
<div class='control-row reply-area'>
<div class='reply-to'>{{{model.actionTitle}}}:</div>
<div class='reply-to'>
{{{model.actionTitle}}}:
{{#if canEdit}}
{{#if showEditReason}}
<div class="edit-reason-input">
{{textField value=editReason tabindex="5" id="edit-reason" maxlength="255" placeholderKey="composer.edit_reason_placeholder"}}
</div>
{{else}}
<a {{action displayEditReason}}>{{i18n composer.show_edit_reason}}</a>
{{/if}}
{{/if}}
</div>
{{#if model.canEditTitle}}
<div class='form-element clearfix'>
@ -39,11 +50,6 @@
{{#if model.showAdminOptions}}
<button {{action toggleAdminOptions target="view"}} class="btn no-text" title='{{i18n composer.admin_options_title}}'><i class="icon icon-wrench"></i></button>
{{/if}}
{{#if canEdit}}
<div class="edit-reason-input">
{{textField value=model.editReason tabindex="5" id="edit-reason" maxlength="255" placeholderKey="composer.edit_reason_placeholder"}}
</div>
{{/if}}
{{/unless}}
</div>

View File

@ -238,12 +238,11 @@
height: 400px;
}
.contents {
input#reply-title, input#edit-reason {
input#reply-title {
padding: 7px 10px;
margin: 6px 10px 3px 0;
}
input#reply-title { width: 400px; }
input#edit-reason { width: 200px; }
.wmd-controls {
@include transition(top 0.3s ease);
top: 100px;
@ -254,6 +253,7 @@
padding: 10px;
min-width: 1280px;
.form-element {
display: inline-block;
.chzn-container {
width: 400px;
margin-top: 6px;
@ -283,7 +283,18 @@
}
}
}
#reply-title, #edit-reason {
.edit-reason-input {
display: inline-block;
position: absolute;
margin-left: 10px;
top: 18px;
#edit-reason {
margin: 0;
padding: 5px;
float: left;
}
}
#reply-title {
margin-right: 10px;
float: left;
&:disabled {
@ -324,7 +335,7 @@
bottom: 8px;
}
}
.title-input, .category-input, .edit-reason-input {
.title-input, .category-input {
position: relative;
display: inline;
}

View File

@ -479,6 +479,7 @@ en:
users_placeholder: "Add a user"
title_placeholder: "Type your title here. What is this discussion about in one brief sentence?"
edit_reason_placeholder: "Short reason of your edit"
show_edit_reason: "(Add a reason)"
reply_placeholder: "Type here. Use Markdown or BBCode to format. Drag or paste an image to upload it."
view_new_post: "View your new post."
saving: "Saving..."