FIX: Repeatedly editing a post was popping up abandon dialog

This commit is contained in:
Robin Ward 2013-07-03 14:44:02 -04:00
parent 115491a057
commit 44cd5505d3
5 changed files with 143 additions and 162 deletions

View file

@ -10,21 +10,21 @@ Discourse.ComposerController = Discourse.Controller.extend({
needs: ['modal', 'topic'], needs: ['modal', 'topic'],
togglePreview: function() { togglePreview: function() {
this.get('content').togglePreview(); this.get('model').togglePreview();
}, },
// Import a quote from the post // Import a quote from the post
importQuote: function() { importQuote: function() {
this.get('content').importQuote(); this.get('model').importQuote();
}, },
updateDraftStatus: function() { updateDraftStatus: function() {
this.get('content').updateDraftStatus(); this.get('model').updateDraftStatus();
}, },
appendText: function(text) { appendText: function(text) {
var c = this.get('content'); var c = this.get('model');
if (c) return c.appendText(text); if (c) { c.appendText(text); }
}, },
categories: function() { categories: function() {
@ -38,7 +38,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
message, message,
buttons; buttons;
composer = this.get('content'); composer = this.get('model');
if( composer.get('cantSubmitPost') ) { if( composer.get('cantSubmitPost') ) {
this.set('view.showTitleTip', Date.now()); this.set('view.showTitleTip', Date.now());
@ -51,12 +51,11 @@ Discourse.ComposerController = Discourse.Controller.extend({
// for now handle a very narrow use case // for now handle a very narrow use case
// if we are replying to a topic AND not on the topic pop the window up // if we are replying to a topic AND not on the topic pop the window up
if(!force && composer.get('replyingToTopic')) { if(!force && composer.get('replyingToTopic')) {
topic = this.get('topic'); topic = this.get('topic');
if (!topic || topic.get('id') !== composer.get('topic.id')) if (!topic || topic.get('id') !== composer.get('topic.id'))
{ {
message = Em.String.i18n("composer.posting_not_on_topic", {title: this.get('content.topic.title')}); message = Em.String.i18n("composer.posting_not_on_topic", {title: this.get('model.topic.title')});
buttons = [{ buttons = [{
"label": Em.String.i18n("composer.cancel"), "label": Em.String.i18n("composer.cancel"),
@ -77,7 +76,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
} }
buttons.push({ buttons.push({
"label": Em.String.i18n("composer.reply_original") + "<br/><div class='topic-title'>" + this.get('content.topic.title') + "</div>", "label": Em.String.i18n("composer.reply_original") + "<br/><div class='topic-title'>" + this.get('model.topic.title') + "</div>",
"class": "btn-primary btn-reply-on-original", "class": "btn-primary btn-reply-on-original",
"callback": function(){ "callback": function(){
_this.save(true); _this.save(true);
@ -118,25 +117,25 @@ Discourse.ComposerController = Discourse.Controller.extend({
similarVisible: function() { similarVisible: function() {
if (this.get('similarClosed')) return false; if (this.get('similarClosed')) return false;
if (this.get('content.composeState') !== Discourse.Composer.OPEN) return false; if (this.get('model.composeState') !== Discourse.Composer.OPEN) return false;
return (this.get('similarTopics.length') || 0) > 0; return (this.get('similarTopics.length') || 0) > 0;
}.property('similarTopics.length', 'similarClosed', 'content.composeState'), }.property('similarTopics.length', 'similarClosed', 'model.composeState'),
newUserEducationVisible: function() { newUserEducationVisible: function() {
if (!this.get('educationContents')) return false; if (!this.get('educationContents')) return false;
if (this.get('content.composeState') !== Discourse.Composer.OPEN) return false; if (this.get('model.composeState') !== Discourse.Composer.OPEN) return false;
if (!this.present('content.reply')) return false; if (!this.present('model.reply')) return false;
if (this.get('educationClosed')) return false; if (this.get('educationClosed')) return false;
return true; return true;
}.property('content.composeState', 'content.reply', 'educationClosed', 'educationContents'), }.property('model.composeState', 'model.reply', 'educationClosed', 'educationContents'),
fetchNewUserEducation: function() { fetchNewUserEducation: function() {
// We don't show education when editing a post. // We don't show education when editing a post.
if (this.get('content.editingPost')) return; if (this.get('model.editingPost')) return;
// If creating a topic, use topic_count, otherwise post_count // If creating a topic, use topic_count, otherwise post_count
var count = this.get('content.creatingTopic') ? Discourse.User.current('topic_count') : Discourse.User.current('reply_count'); var count = this.get('model.creatingTopic') ? Discourse.User.current('topic_count') : Discourse.User.current('reply_count');
if (count >= Discourse.SiteSettings.educate_until_posts) { if (count >= Discourse.SiteSettings.educate_until_posts) {
this.set('educationClosed', true); this.set('educationClosed', true);
this.set('educationContents', ''); this.set('educationContents', '');
@ -149,16 +148,16 @@ Discourse.ComposerController = Discourse.Controller.extend({
this.set('educationClosed', false); this.set('educationClosed', false);
// If visible update the text // If visible update the text
var educationKey = this.get('content.creatingTopic') ? 'new-topic' : 'new-reply'; var educationKey = this.get('model.creatingTopic') ? 'new-topic' : 'new-reply';
var composerController = this; var composerController = this;
Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) { Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) {
composerController.set('educationContents', result); composerController.set('educationContents', result);
}); });
}.observes('typedReply', 'content.creatingTopic', 'currentUser.reply_count'), }.observes('typedReply', 'model.creatingTopic', 'currentUser.reply_count'),
checkReplyLength: function() { checkReplyLength: function() {
this.set('typedReply', this.present('content.reply')); this.set('typedReply', this.present('model.reply'));
}, },
/** /**
@ -170,10 +169,10 @@ Discourse.ComposerController = Discourse.Controller.extend({
findSimilarTopics: function() { findSimilarTopics: function() {
// We don't care about similar topics unless creating a topic // We don't care about similar topics unless creating a topic
if (!this.get('content.creatingTopic')) return; if (!this.get('model.creatingTopic')) return;
var body = this.get('content.reply'); var body = this.get('model.reply');
var title = this.get('content.title'); var title = this.get('model.title');
// Ensure the fields are of the minimum length // Ensure the fields are of the minimum length
if (body.length < Discourse.SiteSettings.min_body_similar_length) return; if (body.length < Discourse.SiteSettings.min_body_similar_length) return;
@ -187,8 +186,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
}, },
saveDraft: function() { saveDraft: function() {
var model = this.get('content'); var model = this.get('model');
if (model) model.saveDraft(); if (model) { model.saveDraft(); }
}, },
/** /**
@ -236,13 +235,13 @@ Discourse.ComposerController = Discourse.Controller.extend({
return promise; return promise;
} }
var composer = this.get('content'); var composer = this.get('model');
if (composer && opts.draftKey !== composer.draftKey && composer.composeState === Discourse.Composer.DRAFT) { if (composer && opts.draftKey !== composer.draftKey && composer.composeState === Discourse.Composer.DRAFT) {
this.close(); this.close();
composer = null; composer = null;
} }
if (composer && !opts.tested && composer.wouldLoseChanges()) { if (composer && !opts.tested && composer.get('wouldLoseChanges')) {
if (composer.composeState === Discourse.Composer.DRAFT && composer.draftKey === opts.draftKey && composer.action === opts.action) { if (composer.composeState === Discourse.Composer.DRAFT && composer.draftKey === opts.draftKey && composer.action === opts.action) {
composer.set('composeState', Discourse.Composer.OPEN); composer.set('composeState', Discourse.Composer.OPEN);
promise.resolve(); promise.resolve();
@ -275,17 +274,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
} }
composer = composer || Discourse.Composer.open(opts); composer = composer || Discourse.Composer.open(opts);
this.set('content', composer); this.set('model', composer);
this.set('view.content', composer); composer.set('composeState', Discourse.Composer.OPEN);
promise.resolve(); promise.resolve();
return promise; return promise;
}, },
wouldLoseChanges: function() {
var composer = this.get('content');
return composer && composer.wouldLoseChanges();
},
// View a new reply we've made // View a new reply we've made
viewNewReply: function() { viewNewReply: function() {
Discourse.URL.routeTo(this.get('createdPost.url')); Discourse.URL.routeTo(this.get('createdPost.url'));
@ -294,17 +288,17 @@ Discourse.ComposerController = Discourse.Controller.extend({
}, },
destroyDraft: function() { destroyDraft: function() {
var key = this.get('content.draftKey'); var key = this.get('model.draftKey');
if (key) { if (key) {
Discourse.Draft.clear(key, this.get('content.draftSequence')); Discourse.Draft.clear(key, this.get('model.draftSequence'));
} }
}, },
cancel: function() { cancel: function() {
var composerController = this; var composerController = this;
return Ember.Deferred.promise(function (promise) { return Ember.Deferred.promise(function (promise) {
if (composerController.get('content.hasMetaData') || if (composerController.get('model.hasMetaData') || composerController.get('model.wouldLoseChanges')) {
((composerController.get('content.reply') || "") !== (composerController.get('content.originalText') || ""))) {
bootbox.confirm(Em.String.i18n("post.abandon"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) { bootbox.confirm(Em.String.i18n("post.abandon"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
if (result) { if (result) {
composerController.destroyDraft(); composerController.destroyDraft();
@ -324,38 +318,31 @@ Discourse.ComposerController = Discourse.Controller.extend({
}, },
openIfDraft: function() { openIfDraft: function() {
if (this.get('content.composeState') === Discourse.Composer.DRAFT) { if (this.get('model.viewDraft')) {
this.set('content.composeState', Discourse.Composer.OPEN); this.set('model.composeState', Discourse.Composer.OPEN);
} }
}, },
shrink: function() { shrink: function() {
if (this.get('content.reply') === this.get('content.originalText')) { if (this.get('model.wouldLoseChanges')) {
this.close();
} else {
this.collapse(); this.collapse();
} else {
this.close();
} }
}, },
collapse: function() { collapse: function() {
this.saveDraft(); this.saveDraft();
this.set('content.composeState', Discourse.Composer.DRAFT); this.set('model.composeState', Discourse.Composer.DRAFT);
}, },
close: function() { close: function() {
this.set('content', null); this.set('model', null);
this.set('view.content', null);
this.set('view.showTitleTip', false); this.set('view.showTitleTip', false);
this.set('view.showCategoryTip', false); this.set('view.showCategoryTip', false);
this.set('view.showReplyTip', false); this.set('view.showReplyTip', false);
}, },
closeIfCollapsed: function() {
if (this.get('content.composeState') === Discourse.Composer.DRAFT) {
this.close();
}
},
closeAutocomplete: function() { closeAutocomplete: function() {
$('#wmd-input').autocomplete({ cancel: true }); $('#wmd-input').autocomplete({ cancel: true });
}, },
@ -363,16 +350,16 @@ Discourse.ComposerController = Discourse.Controller.extend({
// Toggle the reply view // Toggle the reply view
toggle: function() { toggle: function() {
this.closeAutocomplete(); this.closeAutocomplete();
switch (this.get('content.composeState')) { switch (this.get('model.composeState')) {
case Discourse.Composer.OPEN: case Discourse.Composer.OPEN:
if (this.blank('content.reply') && this.blank('content.title')) { if (this.blank('model.reply') && this.blank('model.title')) {
this.close(); this.close();
} else { } else {
this.shrink(); this.shrink();
} }
break; break;
case Discourse.Composer.DRAFT: case Discourse.Composer.DRAFT:
this.set('content.composeState', Discourse.Composer.OPEN); this.set('model.composeState', Discourse.Composer.OPEN);
break; break;
case Discourse.Composer.SAVING: case Discourse.Composer.SAVING:
this.close(); this.close();
@ -382,7 +369,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
// ESC key hit // ESC key hit
hitEsc: function() { hitEsc: function() {
if (this.get('content.composeState') === Discourse.Composer.OPEN) { if (this.get('model.viewOpen')) {
this.shrink(); this.shrink();
} }
}, },
@ -390,8 +377,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
showOptions: function() { showOptions: function() {
var _ref; var _ref;
return (_ref = this.get('controllers.modal')) ? _ref.show(Discourse.ArchetypeOptionsModalView.create({ return (_ref = this.get('controllers.modal')) ? _ref.show(Discourse.ArchetypeOptionsModalView.create({
archetype: this.get('content.archetype'), archetype: this.get('model.archetype'),
metaData: this.get('content.metaData') metaData: this.get('model.metaData')
})) : void 0; })) : void 0;
} }
}); });

View file

@ -113,11 +113,11 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
var buffer = this.get('buffer'); var buffer = this.get('buffer');
var quotedText = Discourse.BBCode.buildQuoteBBCode(post, buffer); var quotedText = Discourse.BBCode.buildQuoteBBCode(post, buffer);
if (composerController.wouldLoseChanges()) { if (composerController.get('content.wouldLoseChanges')) {
composerController.appendText(quotedText); composerController.appendText(quotedText);
} else { } else {
composerController.open(composerOpts).then(function() { composerController.open(composerOpts).then(function() {
return composerController.appendText(quotedText); composerController.appendText(quotedText);
}); });
} }
this.set('buffer', ''); this.set('buffer', '');

View file

@ -34,25 +34,13 @@ Discourse.Composer = Discourse.Model.extend({
return Discourse.Site.instance().get('archetypes'); return Discourse.Site.instance().get('archetypes');
}.property(), }.property(),
creatingTopic: function() { creatingTopic: Em.computed.equal('action', CREATE_TOPIC),
return this.get('action') === CREATE_TOPIC; creatingPrivateMessage: Em.computed.equal('action', PRIVATE_MESSAGE),
}.property('action'), editingPost: Em.computed.equal('action', EDIT),
replyingToTopic: Em.computed.equal('action', REPLY),
creatingPrivateMessage: function() { viewOpen: Em.computed.equal('composeState', OPEN),
return this.get('action') === PRIVATE_MESSAGE; viewDraft: Em.computed.equal('composeState', DRAFT),
}.property('action'),
editingPost: function() {
return this.get('action') === EDIT;
}.property('action'),
replyingToTopic: function() {
return this.get('action') === REPLY;
}.property('action'),
viewOpen: function() {
return this.get('composeState') === OPEN;
}.property('composeState'),
archetype: function() { archetype: function() {
return this.get('archetypes').findProperty('id', this.get('archetypeId')); return this.get('archetypes').findProperty('id', this.get('archetypeId'));
@ -154,9 +142,7 @@ Discourse.Composer = Discourse.Model.extend({
return this.get('showPreview') ? Em.String.i18n('composer.hide_preview') : Em.String.i18n('composer.show_preview'); return this.get('showPreview') ? Em.String.i18n('composer.hide_preview') : Em.String.i18n('composer.show_preview');
}.property('showPreview'), }.property('showPreview'),
hidePreview: function() { hidePreview: Em.computed.not('showPreview'),
return !this.get('showPreview');
}.property('showPreview'),
// Whether to disable the post button // Whether to disable the post button
cantSubmitPost: function() { cantSubmitPost: function() {
@ -212,7 +198,7 @@ Discourse.Composer = Discourse.Model.extend({
wouldLoseChanges: function() { wouldLoseChanges: function() {
return this.get('reply') !== this.get('originalText'); return this.get('reply') !== this.get('originalText');
}, }.property('reply', 'save'),
/* /*
Open a composer Open a composer
@ -224,35 +210,33 @@ Discourse.Composer = Discourse.Model.extend({
quote - If we're opening a reply from a quote, the quote we're making quote - If we're opening a reply from a quote, the quote we're making
*/ */
open: function(opts) { open: function(opts) {
var topicId;
if (!opts) opts = {}; if (!opts) opts = {};
this.set('loading', false); this.set('loading', false);
if (opts.topic) {
topicId = opts.topic.get('id');
}
var replyBlank = (this.get("reply") || "") === ""; var replyBlank = Em.isEmpty(this.get("reply"));
var composer = this; var composer = this;
if (!replyBlank && if (!replyBlank &&
(opts.action !== this.get('action') || ((opts.reply || opts.action === this.EDIT) && this.get('reply') !== this.get('originalText'))) && (opts.action !== this.get('action') || ((opts.reply || opts.action === this.EDIT) && this.get('reply') !== this.get('originalText'))) &&
!opts.tested) { !opts.tested) {
opts.tested = true; opts.tested = true;
this.cancel(function() { this.cancel(function() { composer.open(opts); });
return composer.open(opts);
});
return; return;
} }
this.set('draftKey', opts.draftKey);
this.set('draftSequence', opts.draftSequence);
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';
this.set('composeState', opts.composerState || OPEN); this.setProperties({
this.set('action', opts.action); draftKey: opts.draftKey,
this.set('topic', opts.topic); draftSequence: opts.draftSequence,
this.set('targetUsernames', opts.usernames); composeState: opts.composerState || OPEN,
action: opts.action,
topic: opts.topic,
targetUsernames: opts.usernames
});
if (opts.post) { if (opts.post) {
this.set('post', opts.post); this.set('post', opts.post);
if (!this.get('topic')) { if (!this.get('topic')) {
@ -260,10 +244,13 @@ Discourse.Composer = Discourse.Model.extend({
} }
} }
this.set('categoryName', opts.categoryName || this.get('topic.category.name')); this.setProperties({
this.set('archetypeId', opts.archetypeId || Discourse.Site.instance().get('default_archetype')); categoryName: opts.categoryName || this.get('topic.category.name'),
this.set('metaData', opts.metaData ? Em.Object.create(opts.metaData) : null); archetypeId: opts.archetypeId || Discourse.Site.instance().get('default_archetype'),
this.set('reply', opts.reply || this.get("reply") || ""); metaData: opts.metaData ? Em.Object.create(opts.metaData) : null,
reply: opts.reply || this.get("reply") || ""
});
if (opts.postId) { if (opts.postId) {
this.set('loading', true); this.set('loading', true);
Discourse.Post.load(opts.postId).then(function(result) { Discourse.Post.load(opts.postId).then(function(result) {
@ -274,24 +261,22 @@ Discourse.Composer = Discourse.Model.extend({
// If we are editing a post, load it. // If we are editing a post, load it.
if (opts.action === EDIT && opts.post) { if (opts.action === EDIT && opts.post) {
this.set('title', this.get('topic.title')); this.setProperties({
this.set('loading', true); title: this.get('topic.title'),
loading: true
});
Discourse.Post.load(opts.post.get('id')).then(function(result) { Discourse.Post.load(opts.post.get('id')).then(function(result) {
composer.set('reply', result.get('raw')); composer.setProperties({
composer.set('originalText', composer.get('reply')); reply: result.get('raw'),
composer.set('loading', false); originalText: composer.get('reply'),
loading: false
});
}); });
} }
if (opts.title) { this.set('title', opts.title); }
this.set('originalText', opts.draft ? '' : this.get('reply'));
if (opts.title) {
this.set('title', opts.title);
}
if (opts.draft) {
this.set('originalText', '');
} else if (opts.reply) {
this.set('originalText', this.get('reply'));
}
return false; return false;
}, },
@ -316,15 +301,19 @@ Discourse.Composer = Discourse.Model.extend({
topic.save(); topic.save();
} }
post.set('raw', this.get('reply')); post.setProperties({
post.set('imageSizes', opts.imageSizes); raw: this.get('reply'),
post.set('cooked', $('#wmd-preview').html()); imageSizes: opts.imageSizes,
cooked: $('#wmd-preview').html()
});
this.set('composeState', CLOSED); this.set('composeState', CLOSED);
return Ember.Deferred.promise(function(promise) { return Ember.Deferred.promise(function(promise) {
post.save(function(savedPost) { post.save(function(savedPost) {
var posts = composer.get('topic.posts'); var posts = composer.get('topic.posts');
composer.set('originalText', composer.get('reply'));
// perhaps our post came from elsewhere eg. draft // perhaps our post came from elsewhere eg. draft
var idx = -1; var idx = -1;
var postNumber = post.get('post_number'); var postNumber = post.get('post_number');

View file

@ -23,57 +23,57 @@
<div class='control'> <div class='control'>
<a href='#' class='toggler' {{action toggle bubbles=false}} title='{{i18n composer.toggler}}'></a> <a href='#' class='toggler' {{action toggle bubbles=false}} title='{{i18n composer.toggler}}'></a>
{{#if content.viewOpen}} {{#if model.viewOpen}}
<div class='control-row reply-area'> <div class='control-row reply-area'>
<div class='reply-to'>{{{content.actionTitle}}}:</div> <div class='reply-to'>{{{model.actionTitle}}}:</div>
{{#if content.editTitle}} {{#if model.editTitle}}
<div class='form-element clearfix'> <div class='form-element clearfix'>
{{#if content.creatingPrivateMessage}} {{#if model.creatingPrivateMessage}}
{{userSelector topicId=controller.controllers.topic.content.id {{userSelector topicId=controller.controllers.topic.model.id
excludeCurrentUser="true" excludeCurrentUser="true"
id="private-message-users" id="private-message-users"
class="span8" class="span8"
placeholderKey="composer.users_placeholder" placeholderKey="composer.users_placeholder"
tabindex="1" tabindex="1"
usernames=content.targetUsernames}} usernames=model.targetUsernames}}
{{/if}} {{/if}}
<div class="title-input"> <div class="title-input">
{{textField value=content.title tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}} {{textField value=model.title tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}}
{{popupInputTip validation=view.titleValidation shownAt=view.showTitleTip}} {{popupInputTip validation=view.titleValidation shownAt=view.showTitleTip}}
</div> </div>
{{#unless content.creatingPrivateMessage}} {{#unless model.creatingPrivateMessage}}
<div class="category-input"> <div class="category-input">
{{categoryChooser valueAttribute="name" value=content.categoryName showUncategorized="true"}} {{categoryChooser valueAttribute="name" value=model.categoryName showUncategorized="true"}}
{{popupInputTip validation=view.categoryValidation shownAt=view.showCategoryTip}} {{popupInputTip validation=view.categoryValidation shownAt=view.showCategoryTip}}
</div> </div>
{{#if content.archetype.hasOptions}} {{#if model.archetype.hasOptions}}
<button class='btn' {{action showOptions}}>{{i18n topic.options}}</button> <button class='btn' {{action showOptions}}>{{i18n topic.options}}</button>
{{/if}} {{/if}}
{{#if content.showAdminOptions}} {{#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> <button {{action toggleAdminOptions target="view"}} class="btn no-text" title='{{i18n composer.admin_options_title}}'><i class="icon icon-wrench"></i></button>
{{/if}} {{/if}}
{{/unless}} {{/unless}}
</div> </div>
<div class="admin-options-form"> <div class="admin-options-form">
{{autoCloseForm autoCloseDays=content.auto_close_days}} {{autoCloseForm autoCloseDays=model.auto_close_days}}
</div> </div>
{{/if}} {{/if}}
<div class='wmd-controls'> <div class='wmd-controls'>
<div class='textarea-wrapper'> <div class='textarea-wrapper'>
<div class='wmd-button-bar' id='wmd-button-bar'></div> <div class='wmd-button-bar' id='wmd-button-bar'></div>
{{view Discourse.NotifyingTextArea parentBinding="view" tabindex="3" valueBinding="content.reply" id="wmd-input" placeholderKey="composer.reply_placeholder"}} {{view Discourse.NotifyingTextArea parentBinding="view" tabindex="3" valueBinding="model.reply" id="wmd-input" placeholderKey="composer.reply_placeholder"}}
{{popupInputTip validation=view.replyValidation shownAt=view.showReplyTip}} {{popupInputTip validation=view.replyValidation shownAt=view.showReplyTip}}
</div> </div>
<div class='preview-wrapper'> <div class='preview-wrapper'>
<div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div> <div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div>
</div> </div>
{{#if currentUser}} {{#if currentUser}}
<a href="#" {{action togglePreview}} class='toggle-preview'>{{{content.toggleText}}}</a> <a href="#" {{action togglePreview}} class='toggle-preview'>{{{model.toggleText}}}</a>
<div id='draft-status'></div> <div id='draft-status'></div>
{{#if view.isUploading}} {{#if view.isUploading}}
<div id="file-uploading"> <div id="file-uploading">
@ -85,7 +85,7 @@
{{#if currentUser}} {{#if currentUser}}
<div class='submit-panel'> <div class='submit-panel'>
<button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create content.cantSubmitPost:disabled"}}>{{view.content.saveText}}</button> <button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create model.cantSubmitPost:disabled"}}>{{model.saveText}}</button>
<a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a> <a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a>
</div> </div>
{{/if}} {{/if}}
@ -95,7 +95,7 @@
<div class='row'> <div class='row'>
<div class='span24'> <div class='span24'>
<div class='saving-text'> <div class='saving-text'>
{{#if content.createdPost}} {{#if model.createdPost}}
{{i18n composer.saved}} <a class='permalink' href="{{unbound createdPost.url}}" {{action viewNewReply}}>{{i18n composer.view_new_post}}</a> {{i18n composer.saved}} <a class='permalink' href="{{unbound createdPost.url}}" {{action viewNewReply}}>{{i18n composer.view_new_post}}</a>
{{else}} {{else}}
{{i18n composer.saving}} {{i18n composer.saving}}

View file

@ -11,24 +11,29 @@
Discourse.ComposerView = Discourse.View.extend({ Discourse.ComposerView = Discourse.View.extend({
templateName: 'composer', templateName: 'composer',
elementId: 'reply-control', elementId: 'reply-control',
classNameBindings: ['content.creatingPrivateMessage:private-message', classNameBindings: ['model.creatingPrivateMessage:private-message',
'composeState', 'composeState',
'content.loading', 'model.loading',
'content.editTitle', 'model.editTitle',
'postMade', 'postMade',
'content.creatingTopic:topic', 'model.creatingTopic:topic',
'content.showPreview', 'model.showPreview',
'content.hidePreview'], 'model.hidePreview'],
model: Em.computed.alias('controller.model'),
// This is just in case something still references content. Can probably be removed
content: Em.computed.alias('model'),
composeState: function() { composeState: function() {
var state = this.get('content.composeState'); var state = this.get('model.composeState');
if (state) return state; if (state) return state;
return Discourse.Composer.CLOSED; return Discourse.Composer.CLOSED;
}.property('content.composeState'), }.property('model.composeState'),
draftStatus: function() { draftStatus: function() {
$('#draft-status').text(this.get('content.draftStatus') || ""); $('#draft-status').text(this.get('model.draftStatus') || "");
}.observes('content.draftStatus'), }.observes('model.draftStatus'),
// Disable fields when we're loading // Disable fields when we're loading
loadingChanged: function() { loadingChanged: function() {
@ -41,11 +46,11 @@ Discourse.ComposerView = Discourse.View.extend({
postMade: function() { postMade: function() {
return this.present('controller.createdPost') ? 'created-post' : null; return this.present('controller.createdPost') ? 'created-post' : null;
}.property('content.createdPost'), }.property('model.createdPost'),
observeReplyChanges: function() { observeReplyChanges: function() {
var composerView = this; var composerView = this;
if (this.get('content.hidePreview')) return; if (this.get('model.hidePreview')) return;
Ember.run.next(null, function() { Ember.run.next(null, function() {
var $wmdPreview, caretPosition; var $wmdPreview, caretPosition;
if (composerView.editor) { if (composerView.editor) {
@ -60,7 +65,7 @@ Discourse.ComposerView = Discourse.View.extend({
} }
} }
}); });
}.observes('content.reply', 'content.hidePreview'), }.observes('model.reply', 'model.hidePreview'),
newUserEducationVisibilityChanged: function() { newUserEducationVisibilityChanged: function() {
var $panel = $('#new-user-education'); var $panel = $('#new-user-education');
@ -98,7 +103,7 @@ Discourse.ComposerView = Discourse.View.extend({
$('.topic-area').css('padding-bottom', sizePx); $('.topic-area').css('padding-bottom', sizePx);
$('.composer-popup').css('bottom', sizePx); $('.composer-popup').css('bottom', sizePx);
}); });
}.observes('content.composeState'), }.observes('model.composeState'),
keyUp: function(e) { keyUp: function(e) {
var controller = this.get('controller'); var controller = this.get('controller');
@ -142,7 +147,7 @@ Discourse.ComposerView = Discourse.View.extend({
Discourse.SyntaxHighlighting.apply($wmdPreview); Discourse.SyntaxHighlighting.apply($wmdPreview);
var post = this.get('controller.content.post'); var post = this.get('model.post');
var refresh = false; var refresh = false;
// If we are editing a post, we'll refresh its contents once. This is a feature that // If we are editing a post, we'll refresh its contents once. This is a feature that
@ -178,7 +183,7 @@ Discourse.ComposerView = Discourse.View.extend({
dataSource: function(term) { dataSource: function(term) {
return Discourse.UserSearch.search({ return Discourse.UserSearch.search({
term: term, term: term,
topicId: composerView.get('controller.controllers.topic.content.id') topicId: composerView.get('controller.controllers.topic.model.id')
}); });
}, },
key: "@", key: "@",
@ -220,7 +225,7 @@ Discourse.ComposerView = Discourse.View.extend({
$replyTitle.keyup(function() { $replyTitle.keyup(function() {
saveDraft(); saveDraft();
// removes the red background once the requirements are met // removes the red background once the requirements are met
if (composerView.get('controller.content.missingTitleCharacters') <= 0) { if (composerView.get('model.missingTitleCharacters') <= 0) {
$replyTitle.removeClass("requirements-not-met"); $replyTitle.removeClass("requirements-not-met");
} }
return true; return true;
@ -229,7 +234,7 @@ Discourse.ComposerView = Discourse.View.extend({
// when the title field loses the focus... // when the title field loses the focus...
$replyTitle.blur(function(){ $replyTitle.blur(function(){
// ...and the requirements are not met (ie. the minimum number of characters) // ...and the requirements are not met (ie. the minimum number of characters)
if (composerView.get('controller.content.missingTitleCharacters') > 0) { if (composerView.get('model.missingTitleCharacters') > 0) {
// then, "redify" the background // then, "redify" the background
$replyTitle.toggleClass("requirements-not-met", true); $replyTitle.toggleClass("requirements-not-met", true);
} }
@ -330,8 +335,8 @@ Discourse.ComposerView = Discourse.View.extend({
addMarkdown: function(text) { addMarkdown: function(text) {
var ctrl = $('#wmd-input').get(0), var ctrl = $('#wmd-input').get(0),
caretPosition = Discourse.Utilities.caretPosition(ctrl), caretPosition = Discourse.Utilities.caretPosition(ctrl),
current = this.get('content.reply'); current = this.get('model.reply');
this.set('content.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length)); this.set('model.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length));
Em.run.schedule('afterRender', function() { Em.run.schedule('afterRender', function() {
Discourse.Utilities.setCaretPosition(ctrl, caretPosition + text.length); Discourse.Utilities.setCaretPosition(ctrl, caretPosition + text.length);
@ -369,13 +374,13 @@ Discourse.ComposerView = Discourse.View.extend({
}, },
titleValidation: function() { titleValidation: function() {
var titleLength = this.get('content.titleLength'), var titleLength = this.get('model.titleLength'),
missingChars = this.get('content.missingTitleCharacters'), missingChars = this.get('model.missingTitleCharacters'),
reason; reason;
if( titleLength < 1 ){ if( titleLength < 1 ){
reason = Em.String.i18n('composer.error.title_missing'); reason = Em.String.i18n('composer.error.title_missing');
} else if( missingChars > 0 ) { } else if( missingChars > 0 ) {
reason = Em.String.i18n('composer.error.title_too_short', {min: this.get('content.minimumTitleLength')}); reason = Em.String.i18n('composer.error.title_too_short', {min: this.get('model.minimumTitleLength')});
} else if( titleLength > Discourse.SiteSettings.max_topic_title_length ) { } else if( titleLength > Discourse.SiteSettings.max_topic_title_length ) {
reason = Em.String.i18n('composer.error.title_too_long', {max: Discourse.SiteSettings.max_topic_title_length}); reason = Em.String.i18n('composer.error.title_too_long', {max: Discourse.SiteSettings.max_topic_title_length});
} }
@ -383,28 +388,28 @@ Discourse.ComposerView = Discourse.View.extend({
if( reason ) { if( reason ) {
return Discourse.InputValidation.create({ failed: true, reason: reason }); return Discourse.InputValidation.create({ failed: true, reason: reason });
} }
}.property('content.titleLength', 'content.missingTitleCharacters', 'content.minimumTitleLength'), }.property('model.titleLength', 'model.missingTitleCharacters', 'model.minimumTitleLength'),
categoryValidation: function() { categoryValidation: function() {
if( !Discourse.SiteSettings.allow_uncategorized_topics && !this.get('content.categoryName')) { if( !Discourse.SiteSettings.allow_uncategorized_topics && !this.get('model.categoryName')) {
return Discourse.InputValidation.create({ failed: true, reason: Em.String.i18n('composer.error.category_missing') }); return Discourse.InputValidation.create({ failed: true, reason: Em.String.i18n('composer.error.category_missing') });
} }
}.property('content.categoryName'), }.property('model.categoryName'),
replyValidation: function() { replyValidation: function() {
var replyLength = this.get('content.replyLength'), var replyLength = this.get('model.replyLength'),
missingChars = this.get('content.missingReplyCharacters'), missingChars = this.get('model.missingReplyCharacters'),
reason; reason;
if( replyLength < 1 ){ if( replyLength < 1 ){
reason = Em.String.i18n('composer.error.post_missing'); reason = Em.String.i18n('composer.error.post_missing');
} else if( missingChars > 0 ) { } else if( missingChars > 0 ) {
reason = Em.String.i18n('composer.error.post_length', {min: this.get('content.minimumPostLength')}); reason = Em.String.i18n('composer.error.post_length', {min: this.get('model.minimumPostLength')});
} }
if( reason ) { if( reason ) {
return Discourse.InputValidation.create({ failed: true, reason: reason }); return Discourse.InputValidation.create({ failed: true, reason: reason });
} }
}.property('content.reply', 'content.replyLength', 'content.missingReplyCharacters', 'content.minimumPostLength') }.property('model.reply', 'model.replyLength', 'model.missingReplyCharacters', 'model.minimumPostLength')
}); });
// not sure if this is the right way, keeping here for now, we could use a mixin perhaps // not sure if this is the right way, keeping here for now, we could use a mixin perhaps