Merge pull request #3649 from tgxworld/click_reply_should_clear_edit
Click reply should clear edit
This commit is contained in:
commit
5658119a36
|
@ -398,7 +398,8 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
// If we're already open, we don't have to do anything
|
// If we're already open, we don't have to do anything
|
||||||
if (composerModel.get('composeState') === Discourse.Composer.OPEN &&
|
if (composerModel.get('composeState') === Discourse.Composer.OPEN &&
|
||||||
composerModel.get('draftKey') === opts.draftKey) {
|
composerModel.get('draftKey') === opts.draftKey &&
|
||||||
|
composerModel.get('action') === opts.action ) {
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +407,7 @@ export default Ember.Controller.extend({
|
||||||
if (composerModel.get('composeState') === Discourse.Composer.DRAFT &&
|
if (composerModel.get('composeState') === Discourse.Composer.DRAFT &&
|
||||||
composerModel.get('draftKey') === opts.draftKey) {
|
composerModel.get('draftKey') === opts.draftKey) {
|
||||||
composerModel.set('composeState', Discourse.Composer.OPEN);
|
composerModel.set('composeState', Discourse.Composer.OPEN);
|
||||||
return resolve();
|
if (composerModel.get('action') === opts.action) return resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a different draft, cancel it and try opening again.
|
// If it's a different draft, cancel it and try opening again.
|
||||||
|
|
|
@ -371,12 +371,11 @@ const Composer = RestModel.extend({
|
||||||
|
|
||||||
const composer = this;
|
const composer = this;
|
||||||
if (!replyBlank &&
|
if (!replyBlank &&
|
||||||
(opts.action !== this.get('action') || ((opts.reply || opts.action === this.EDIT) && this.get('reply') !== this.get('originalText'))) &&
|
((opts.reply || opts.action === this.EDIT) && this.get('replyDirty'))) {
|
||||||
!opts.tested) {
|
|
||||||
opts.tested = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.action === REPLY && this.get('action') === EDIT) this.set('reply', '');
|
||||||
if (!opts.draftKey) throw 'draft key is required';
|
if (!opts.draftKey) throw 'draft key is required';
|
||||||
if (opts.draftSequence === null) throw 'draft sequence is required';
|
if (opts.draftSequence === null) throw 'draft sequence is required';
|
||||||
|
|
||||||
|
|
|
@ -187,3 +187,63 @@ test("Edit the first post", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Composer can switch between edits", () => {
|
||||||
|
visit("/t/this-is-a-test-topic/9");
|
||||||
|
|
||||||
|
click('.topic-post:eq(0) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
click('.topic-post:eq(1) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Composer can toggle between edit and reply", () => {
|
||||||
|
visit("/t/this-is-a-test-topic/9");
|
||||||
|
|
||||||
|
click('.topic-post:eq(0) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
click('.topic-post:eq(0) button[data-action=reply]');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val(), "", 'it clears the input');
|
||||||
|
});
|
||||||
|
click('.topic-post:eq(0) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Composer with dirty reply can toggle to edit", () => {
|
||||||
|
visit("/t/this-is-a-test-topic/9");
|
||||||
|
|
||||||
|
click('.topic-post:eq(0) button[data-action=reply]');
|
||||||
|
fillIn('.wmd-input', 'This is a dirty reply');
|
||||||
|
click('.topic-post:eq(0) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||||
|
});
|
||||||
|
click('.modal-footer a:eq(0)');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Composer draft with dirty reply can toggle to edit", () => {
|
||||||
|
visit("/t/this-is-a-test-topic/9");
|
||||||
|
|
||||||
|
click('.topic-post:eq(0) button[data-action=reply]');
|
||||||
|
fillIn('.wmd-input', 'This is a dirty reply');
|
||||||
|
click('.toggler');
|
||||||
|
click('.topic-post:eq(0) button[data-action=edit]');
|
||||||
|
andThen(() => {
|
||||||
|
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||||
|
});
|
||||||
|
click('.modal-footer a:eq(0)');
|
||||||
|
andThen(() => {
|
||||||
|
equal(find('.wmd-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
"/posts/398": {"id":398,"name":"Uwe Keim","username":"uwe_keim","avatar_template":"/user_avatar/meta.discourse.org/uwe_keim/{size}/5697.png","uploaded_avatar_id":5697,"created_at":"2013-02-05T21:29:00.280Z","cooked":"<p>Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?</p>","post_number":1,"post_type":1,"updated_at":"2013-02-05T21:29:00.280Z","like_count":0,"reply_count":1,"reply_to_post_number":null,"quote_count":0,"avg_time":25,"incoming_link_count":314,"reads":475,"score":1702.25,"yours":false,"topic_id":280,"topic_slug":"internationalization-localization","display_username":"Uwe Keim","primary_group_name":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"user_title":null,"raw":"Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?","actions_summary":[{"id":2,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":3,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":4,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":5,"count":0,"hidden":true,"can_act":true,"can_defer_flags":false},{"id":6,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":7,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":8,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false}],"moderator":false,"admin":false,"staff":false,"user_id":255,"hidden":false,"hidden_reason_id":null,"trust_level":2,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false}
|
"/posts/398": {"id":398,"name":"Uwe Keim","username":"uwe_keim","avatar_template":"/user_avatar/meta.discourse.org/uwe_keim/{size}/5697.png","uploaded_avatar_id":5697,"created_at":"2013-02-05T21:29:00.280Z","cooked":"<p>Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?</p>","post_number":1,"post_type":1,"updated_at":"2013-02-05T21:29:00.280Z","like_count":0,"reply_count":1,"reply_to_post_number":null,"quote_count":0,"avg_time":25,"incoming_link_count":314,"reads":475,"score":1702.25,"yours":false,"topic_id":280,"topic_slug":"internationalization-localization","display_username":"Uwe Keim","primary_group_name":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"user_title":null,"raw":"Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?","actions_summary":[{"id":2,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":3,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":4,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":5,"count":0,"hidden":true,"can_act":true,"can_defer_flags":false},{"id":6,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":7,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false},{"id":8,"count":0,"hidden":false,"can_act":true,"can_defer_flags":false}],"moderator":false,"admin":false,"staff":false,"user_id":255,"hidden":false,"hidden_reason_id":null,"trust_level":2,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false},
|
||||||
|
"/posts/18": {"id":18,"username":"eviltrout","avatar_template":"//www.gravatar.com/avatar/c6e17f2ae2a215e87ff9e878a4e63cd9.png?s={size}&r=pg&d=identicon","name":"Evil Trout","uploaded_avatar_id":9,"created_at":"2015-08-13T14:49:11.840Z","cooked":"<p>This is the first post.</p>","post_number":1,"post_type":1,"updated_at":"2015-08-13T14:49:11.840Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":9,"topic_slug":"this-is-a-test-topic","display_username":"","primary_group_name":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"user_title":null,"raw":"This is the first post.","actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false},
|
||||||
|
"/posts/19": {"id":19,"username":"eviltrout","avatar_template":"//www.gravatar.com/avatar/c6e17f2ae2a215e87ff9e878a4e63cd9.png?s={size}&r=pg&d=identicon","name":"Evil Trout","uploaded_avatar_id":9,"created_at":"2015-08-13T14:49:18.231Z","cooked":"<p>This is the second post.</p>","post_number":2,"post_type":1,"updated_at":"2015-08-13T14:49:18.231Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":9,"topic_slug":"this-is-a-test-topic","display_username":"","primary_group_name":null,"version":1,"can_edit":true,"can_delete":true,"can_recover":true,"read":true,"user_title":null,"raw":"This is the second post.","actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -111,6 +111,10 @@ export default function() {
|
||||||
return response(fixturesByUrl['/t/28830/1.json']);
|
return response(fixturesByUrl['/t/28830/1.json']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.get("/t/9.json", function() {
|
||||||
|
return response(fixturesByUrl['/t/9/1.json']);
|
||||||
|
});
|
||||||
|
|
||||||
this.get("/t/id_for/:slug", function() {
|
this.get("/t/id_for/:slug", function() {
|
||||||
return response({id: 280, slug: "internationalization-localization", url: "/t/internationalization-localization/280"});
|
return response({id: 280, slug: "internationalization-localization", url: "/t/internationalization-localization/280"});
|
||||||
});
|
});
|
||||||
|
@ -120,6 +124,7 @@ export default function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.delete('/draft.json', success);
|
this.delete('/draft.json', success);
|
||||||
|
this.post('/draft.json', success);
|
||||||
|
|
||||||
this.get('/users/:username/staff-info.json', () => response({}));
|
this.get('/users/:username/staff-info.json', () => response({}));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue