FIX: Repeatedly editing a post was popping up abandon dialog
This commit is contained in:
parent
115491a057
commit
44cd5505d3
|
@ -10,21 +10,21 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
needs: ['modal', 'topic'],
|
||||
|
||||
togglePreview: function() {
|
||||
this.get('content').togglePreview();
|
||||
this.get('model').togglePreview();
|
||||
},
|
||||
|
||||
// Import a quote from the post
|
||||
importQuote: function() {
|
||||
this.get('content').importQuote();
|
||||
this.get('model').importQuote();
|
||||
},
|
||||
|
||||
updateDraftStatus: function() {
|
||||
this.get('content').updateDraftStatus();
|
||||
this.get('model').updateDraftStatus();
|
||||
},
|
||||
|
||||
appendText: function(text) {
|
||||
var c = this.get('content');
|
||||
if (c) return c.appendText(text);
|
||||
var c = this.get('model');
|
||||
if (c) { c.appendText(text); }
|
||||
},
|
||||
|
||||
categories: function() {
|
||||
|
@ -38,7 +38,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
message,
|
||||
buttons;
|
||||
|
||||
composer = this.get('content');
|
||||
composer = this.get('model');
|
||||
|
||||
if( composer.get('cantSubmitPost') ) {
|
||||
this.set('view.showTitleTip', Date.now());
|
||||
|
@ -51,12 +51,11 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
|
||||
// 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(!force && composer.get('replyingToTopic')) {
|
||||
topic = this.get('topic');
|
||||
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 = [{
|
||||
"label": Em.String.i18n("composer.cancel"),
|
||||
|
@ -77,7 +76,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
}
|
||||
|
||||
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",
|
||||
"callback": function(){
|
||||
_this.save(true);
|
||||
|
@ -118,25 +117,25 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
|
||||
similarVisible: function() {
|
||||
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;
|
||||
}.property('similarTopics.length', 'similarClosed', 'content.composeState'),
|
||||
}.property('similarTopics.length', 'similarClosed', 'model.composeState'),
|
||||
|
||||
newUserEducationVisible: function() {
|
||||
if (!this.get('educationContents')) return false;
|
||||
if (this.get('content.composeState') !== Discourse.Composer.OPEN) return false;
|
||||
if (!this.present('content.reply')) return false;
|
||||
if (this.get('model.composeState') !== Discourse.Composer.OPEN) return false;
|
||||
if (!this.present('model.reply')) return false;
|
||||
if (this.get('educationClosed')) return false;
|
||||
return true;
|
||||
}.property('content.composeState', 'content.reply', 'educationClosed', 'educationContents'),
|
||||
}.property('model.composeState', 'model.reply', 'educationClosed', 'educationContents'),
|
||||
|
||||
fetchNewUserEducation: function() {
|
||||
|
||||
// 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
|
||||
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) {
|
||||
this.set('educationClosed', true);
|
||||
this.set('educationContents', '');
|
||||
|
@ -149,16 +148,16 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
this.set('educationClosed', false);
|
||||
|
||||
// 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;
|
||||
Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) {
|
||||
composerController.set('educationContents', result);
|
||||
});
|
||||
|
||||
}.observes('typedReply', 'content.creatingTopic', 'currentUser.reply_count'),
|
||||
}.observes('typedReply', 'model.creatingTopic', 'currentUser.reply_count'),
|
||||
|
||||
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() {
|
||||
|
||||
// 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 title = this.get('content.title');
|
||||
var body = this.get('model.reply');
|
||||
var title = this.get('model.title');
|
||||
|
||||
// Ensure the fields are of the minimum length
|
||||
if (body.length < Discourse.SiteSettings.min_body_similar_length) return;
|
||||
|
@ -187,8 +186,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
},
|
||||
|
||||
saveDraft: function() {
|
||||
var model = this.get('content');
|
||||
if (model) model.saveDraft();
|
||||
var model = this.get('model');
|
||||
if (model) { model.saveDraft(); }
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -236,13 +235,13 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
return promise;
|
||||
}
|
||||
|
||||
var composer = this.get('content');
|
||||
var composer = this.get('model');
|
||||
if (composer && opts.draftKey !== composer.draftKey && composer.composeState === Discourse.Composer.DRAFT) {
|
||||
this.close();
|
||||
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) {
|
||||
composer.set('composeState', Discourse.Composer.OPEN);
|
||||
promise.resolve();
|
||||
|
@ -275,17 +274,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
}
|
||||
|
||||
composer = composer || Discourse.Composer.open(opts);
|
||||
this.set('content', composer);
|
||||
this.set('view.content', composer);
|
||||
this.set('model', composer);
|
||||
composer.set('composeState', Discourse.Composer.OPEN);
|
||||
promise.resolve();
|
||||
return promise;
|
||||
},
|
||||
|
||||
wouldLoseChanges: function() {
|
||||
var composer = this.get('content');
|
||||
return composer && composer.wouldLoseChanges();
|
||||
},
|
||||
|
||||
// View a new reply we've made
|
||||
viewNewReply: function() {
|
||||
Discourse.URL.routeTo(this.get('createdPost.url'));
|
||||
|
@ -294,17 +288,17 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
},
|
||||
|
||||
destroyDraft: function() {
|
||||
var key = this.get('content.draftKey');
|
||||
var key = this.get('model.draftKey');
|
||||
if (key) {
|
||||
Discourse.Draft.clear(key, this.get('content.draftSequence'));
|
||||
Discourse.Draft.clear(key, this.get('model.draftSequence'));
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
var composerController = this;
|
||||
|
||||
return Ember.Deferred.promise(function (promise) {
|
||||
if (composerController.get('content.hasMetaData') ||
|
||||
((composerController.get('content.reply') || "") !== (composerController.get('content.originalText') || ""))) {
|
||||
if (composerController.get('model.hasMetaData') || composerController.get('model.wouldLoseChanges')) {
|
||||
bootbox.confirm(Em.String.i18n("post.abandon"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
|
||||
if (result) {
|
||||
composerController.destroyDraft();
|
||||
|
@ -324,38 +318,31 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
},
|
||||
|
||||
openIfDraft: function() {
|
||||
if (this.get('content.composeState') === Discourse.Composer.DRAFT) {
|
||||
this.set('content.composeState', Discourse.Composer.OPEN);
|
||||
if (this.get('model.viewDraft')) {
|
||||
this.set('model.composeState', Discourse.Composer.OPEN);
|
||||
}
|
||||
},
|
||||
|
||||
shrink: function() {
|
||||
if (this.get('content.reply') === this.get('content.originalText')) {
|
||||
this.close();
|
||||
} else {
|
||||
if (this.get('model.wouldLoseChanges')) {
|
||||
this.collapse();
|
||||
} else {
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
|
||||
collapse: function() {
|
||||
this.saveDraft();
|
||||
this.set('content.composeState', Discourse.Composer.DRAFT);
|
||||
this.set('model.composeState', Discourse.Composer.DRAFT);
|
||||
},
|
||||
|
||||
close: function() {
|
||||
this.set('content', null);
|
||||
this.set('view.content', null);
|
||||
this.set('model', null);
|
||||
this.set('view.showTitleTip', false);
|
||||
this.set('view.showCategoryTip', false);
|
||||
this.set('view.showReplyTip', false);
|
||||
},
|
||||
|
||||
closeIfCollapsed: function() {
|
||||
if (this.get('content.composeState') === Discourse.Composer.DRAFT) {
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
|
||||
closeAutocomplete: function() {
|
||||
$('#wmd-input').autocomplete({ cancel: true });
|
||||
},
|
||||
|
@ -363,16 +350,16 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
// Toggle the reply view
|
||||
toggle: function() {
|
||||
this.closeAutocomplete();
|
||||
switch (this.get('content.composeState')) {
|
||||
switch (this.get('model.composeState')) {
|
||||
case Discourse.Composer.OPEN:
|
||||
if (this.blank('content.reply') && this.blank('content.title')) {
|
||||
if (this.blank('model.reply') && this.blank('model.title')) {
|
||||
this.close();
|
||||
} else {
|
||||
this.shrink();
|
||||
}
|
||||
break;
|
||||
case Discourse.Composer.DRAFT:
|
||||
this.set('content.composeState', Discourse.Composer.OPEN);
|
||||
this.set('model.composeState', Discourse.Composer.OPEN);
|
||||
break;
|
||||
case Discourse.Composer.SAVING:
|
||||
this.close();
|
||||
|
@ -382,7 +369,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
|
||||
// ESC key hit
|
||||
hitEsc: function() {
|
||||
if (this.get('content.composeState') === Discourse.Composer.OPEN) {
|
||||
if (this.get('model.viewOpen')) {
|
||||
this.shrink();
|
||||
}
|
||||
},
|
||||
|
@ -390,8 +377,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
showOptions: function() {
|
||||
var _ref;
|
||||
return (_ref = this.get('controllers.modal')) ? _ref.show(Discourse.ArchetypeOptionsModalView.create({
|
||||
archetype: this.get('content.archetype'),
|
||||
metaData: this.get('content.metaData')
|
||||
archetype: this.get('model.archetype'),
|
||||
metaData: this.get('model.metaData')
|
||||
})) : void 0;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -113,11 +113,11 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
|||
|
||||
var buffer = this.get('buffer');
|
||||
var quotedText = Discourse.BBCode.buildQuoteBBCode(post, buffer);
|
||||
if (composerController.wouldLoseChanges()) {
|
||||
if (composerController.get('content.wouldLoseChanges')) {
|
||||
composerController.appendText(quotedText);
|
||||
} else {
|
||||
composerController.open(composerOpts).then(function() {
|
||||
return composerController.appendText(quotedText);
|
||||
composerController.appendText(quotedText);
|
||||
});
|
||||
}
|
||||
this.set('buffer', '');
|
||||
|
|
|
@ -34,25 +34,13 @@ Discourse.Composer = Discourse.Model.extend({
|
|||
return Discourse.Site.instance().get('archetypes');
|
||||
}.property(),
|
||||
|
||||
creatingTopic: function() {
|
||||
return this.get('action') === CREATE_TOPIC;
|
||||
}.property('action'),
|
||||
creatingTopic: Em.computed.equal('action', CREATE_TOPIC),
|
||||
creatingPrivateMessage: Em.computed.equal('action', PRIVATE_MESSAGE),
|
||||
editingPost: Em.computed.equal('action', EDIT),
|
||||
replyingToTopic: Em.computed.equal('action', REPLY),
|
||||
|
||||
creatingPrivateMessage: function() {
|
||||
return this.get('action') === PRIVATE_MESSAGE;
|
||||
}.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'),
|
||||
viewOpen: Em.computed.equal('composeState', OPEN),
|
||||
viewDraft: Em.computed.equal('composeState', DRAFT),
|
||||
|
||||
archetype: function() {
|
||||
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');
|
||||
}.property('showPreview'),
|
||||
|
||||
hidePreview: function() {
|
||||
return !this.get('showPreview');
|
||||
}.property('showPreview'),
|
||||
hidePreview: Em.computed.not('showPreview'),
|
||||
|
||||
// Whether to disable the post button
|
||||
cantSubmitPost: function() {
|
||||
|
@ -212,7 +198,7 @@ Discourse.Composer = Discourse.Model.extend({
|
|||
|
||||
wouldLoseChanges: function() {
|
||||
return this.get('reply') !== this.get('originalText');
|
||||
},
|
||||
}.property('reply', 'save'),
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
open: function(opts) {
|
||||
var topicId;
|
||||
if (!opts) opts = {};
|
||||
|
||||
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;
|
||||
if (!replyBlank &&
|
||||
(opts.action !== this.get('action') || ((opts.reply || opts.action === this.EDIT) && this.get('reply') !== this.get('originalText'))) &&
|
||||
!opts.tested) {
|
||||
opts.tested = true;
|
||||
this.cancel(function() {
|
||||
return composer.open(opts);
|
||||
});
|
||||
this.cancel(function() { composer.open(opts); });
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('draftKey', opts.draftKey);
|
||||
this.set('draftSequence', opts.draftSequence);
|
||||
if (!opts.draftKey) throw 'draft key is required';
|
||||
if (opts.draftSequence === null) throw 'draft sequence is required';
|
||||
|
||||
this.set('composeState', opts.composerState || OPEN);
|
||||
this.set('action', opts.action);
|
||||
this.set('topic', opts.topic);
|
||||
this.set('targetUsernames', opts.usernames);
|
||||
this.setProperties({
|
||||
draftKey: opts.draftKey,
|
||||
draftSequence: opts.draftSequence,
|
||||
composeState: opts.composerState || OPEN,
|
||||
action: opts.action,
|
||||
topic: opts.topic,
|
||||
targetUsernames: opts.usernames
|
||||
});
|
||||
|
||||
if (opts.post) {
|
||||
this.set('post', opts.post);
|
||||
if (!this.get('topic')) {
|
||||
|
@ -260,10 +244,13 @@ Discourse.Composer = Discourse.Model.extend({
|
|||
}
|
||||
}
|
||||
|
||||
this.set('categoryName', opts.categoryName || this.get('topic.category.name'));
|
||||
this.set('archetypeId', opts.archetypeId || Discourse.Site.instance().get('default_archetype'));
|
||||
this.set('metaData', opts.metaData ? Em.Object.create(opts.metaData) : null);
|
||||
this.set('reply', opts.reply || this.get("reply") || "");
|
||||
this.setProperties({
|
||||
categoryName: opts.categoryName || this.get('topic.category.name'),
|
||||
archetypeId: opts.archetypeId || Discourse.Site.instance().get('default_archetype'),
|
||||
metaData: opts.metaData ? Em.Object.create(opts.metaData) : null,
|
||||
reply: opts.reply || this.get("reply") || ""
|
||||
});
|
||||
|
||||
if (opts.postId) {
|
||||
this.set('loading', true);
|
||||
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 (opts.action === EDIT && opts.post) {
|
||||
this.set('title', this.get('topic.title'));
|
||||
this.set('loading', true);
|
||||
this.setProperties({
|
||||
title: this.get('topic.title'),
|
||||
loading: true
|
||||
});
|
||||
|
||||
Discourse.Post.load(opts.post.get('id')).then(function(result) {
|
||||
composer.set('reply', result.get('raw'));
|
||||
composer.set('originalText', composer.get('reply'));
|
||||
composer.set('loading', false);
|
||||
composer.setProperties({
|
||||
reply: result.get('raw'),
|
||||
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;
|
||||
},
|
||||
|
||||
|
@ -316,15 +301,19 @@ Discourse.Composer = Discourse.Model.extend({
|
|||
topic.save();
|
||||
}
|
||||
|
||||
post.set('raw', this.get('reply'));
|
||||
post.set('imageSizes', opts.imageSizes);
|
||||
post.set('cooked', $('#wmd-preview').html());
|
||||
post.setProperties({
|
||||
raw: this.get('reply'),
|
||||
imageSizes: opts.imageSizes,
|
||||
cooked: $('#wmd-preview').html()
|
||||
});
|
||||
this.set('composeState', CLOSED);
|
||||
|
||||
return Ember.Deferred.promise(function(promise) {
|
||||
post.save(function(savedPost) {
|
||||
var posts = composer.get('topic.posts');
|
||||
|
||||
composer.set('originalText', composer.get('reply'));
|
||||
|
||||
// perhaps our post came from elsewhere eg. draft
|
||||
var idx = -1;
|
||||
var postNumber = post.get('post_number');
|
||||
|
|
|
@ -23,57 +23,57 @@
|
|||
<div class='control'>
|
||||
<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='reply-to'>{{{content.actionTitle}}}:</div>
|
||||
<div class='reply-to'>{{{model.actionTitle}}}:</div>
|
||||
|
||||
{{#if content.editTitle}}
|
||||
{{#if model.editTitle}}
|
||||
<div class='form-element clearfix'>
|
||||
{{#if content.creatingPrivateMessage}}
|
||||
{{userSelector topicId=controller.controllers.topic.content.id
|
||||
{{#if model.creatingPrivateMessage}}
|
||||
{{userSelector topicId=controller.controllers.topic.model.id
|
||||
excludeCurrentUser="true"
|
||||
id="private-message-users"
|
||||
class="span8"
|
||||
placeholderKey="composer.users_placeholder"
|
||||
tabindex="1"
|
||||
usernames=content.targetUsernames}}
|
||||
usernames=model.targetUsernames}}
|
||||
{{/if}}
|
||||
|
||||
<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}}
|
||||
</div>
|
||||
|
||||
{{#unless content.creatingPrivateMessage}}
|
||||
{{#unless model.creatingPrivateMessage}}
|
||||
<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}}
|
||||
</div>
|
||||
{{#if content.archetype.hasOptions}}
|
||||
{{#if model.archetype.hasOptions}}
|
||||
<button class='btn' {{action showOptions}}>{{i18n topic.options}}</button>
|
||||
{{/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>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
</div>
|
||||
|
||||
<div class="admin-options-form">
|
||||
{{autoCloseForm autoCloseDays=content.auto_close_days}}
|
||||
{{autoCloseForm autoCloseDays=model.auto_close_days}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class='wmd-controls'>
|
||||
<div class='textarea-wrapper'>
|
||||
<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}}
|
||||
</div>
|
||||
<div class='preview-wrapper'>
|
||||
<div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div>
|
||||
</div>
|
||||
{{#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>
|
||||
{{#if view.isUploading}}
|
||||
<div id="file-uploading">
|
||||
|
@ -85,7 +85,7 @@
|
|||
|
||||
{{#if currentUser}}
|
||||
<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>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
@ -95,7 +95,7 @@
|
|||
<div class='row'>
|
||||
<div class='span24'>
|
||||
<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>
|
||||
{{else}}
|
||||
{{i18n composer.saving}}
|
||||
|
|
|
@ -11,24 +11,29 @@
|
|||
Discourse.ComposerView = Discourse.View.extend({
|
||||
templateName: 'composer',
|
||||
elementId: 'reply-control',
|
||||
classNameBindings: ['content.creatingPrivateMessage:private-message',
|
||||
classNameBindings: ['model.creatingPrivateMessage:private-message',
|
||||
'composeState',
|
||||
'content.loading',
|
||||
'content.editTitle',
|
||||
'model.loading',
|
||||
'model.editTitle',
|
||||
'postMade',
|
||||
'content.creatingTopic:topic',
|
||||
'content.showPreview',
|
||||
'content.hidePreview'],
|
||||
'model.creatingTopic:topic',
|
||||
'model.showPreview',
|
||||
'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() {
|
||||
var state = this.get('content.composeState');
|
||||
var state = this.get('model.composeState');
|
||||
if (state) return state;
|
||||
return Discourse.Composer.CLOSED;
|
||||
}.property('content.composeState'),
|
||||
}.property('model.composeState'),
|
||||
|
||||
draftStatus: function() {
|
||||
$('#draft-status').text(this.get('content.draftStatus') || "");
|
||||
}.observes('content.draftStatus'),
|
||||
$('#draft-status').text(this.get('model.draftStatus') || "");
|
||||
}.observes('model.draftStatus'),
|
||||
|
||||
// Disable fields when we're loading
|
||||
loadingChanged: function() {
|
||||
|
@ -41,11 +46,11 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
|
||||
postMade: function() {
|
||||
return this.present('controller.createdPost') ? 'created-post' : null;
|
||||
}.property('content.createdPost'),
|
||||
}.property('model.createdPost'),
|
||||
|
||||
observeReplyChanges: function() {
|
||||
var composerView = this;
|
||||
if (this.get('content.hidePreview')) return;
|
||||
if (this.get('model.hidePreview')) return;
|
||||
Ember.run.next(null, function() {
|
||||
var $wmdPreview, caretPosition;
|
||||
if (composerView.editor) {
|
||||
|
@ -60,7 +65,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
}
|
||||
}
|
||||
});
|
||||
}.observes('content.reply', 'content.hidePreview'),
|
||||
}.observes('model.reply', 'model.hidePreview'),
|
||||
|
||||
newUserEducationVisibilityChanged: function() {
|
||||
var $panel = $('#new-user-education');
|
||||
|
@ -98,7 +103,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
$('.topic-area').css('padding-bottom', sizePx);
|
||||
$('.composer-popup').css('bottom', sizePx);
|
||||
});
|
||||
}.observes('content.composeState'),
|
||||
}.observes('model.composeState'),
|
||||
|
||||
keyUp: function(e) {
|
||||
var controller = this.get('controller');
|
||||
|
@ -142,7 +147,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
|
||||
Discourse.SyntaxHighlighting.apply($wmdPreview);
|
||||
|
||||
var post = this.get('controller.content.post');
|
||||
var post = this.get('model.post');
|
||||
var refresh = false;
|
||||
|
||||
// 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) {
|
||||
return Discourse.UserSearch.search({
|
||||
term: term,
|
||||
topicId: composerView.get('controller.controllers.topic.content.id')
|
||||
topicId: composerView.get('controller.controllers.topic.model.id')
|
||||
});
|
||||
},
|
||||
key: "@",
|
||||
|
@ -220,7 +225,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
$replyTitle.keyup(function() {
|
||||
saveDraft();
|
||||
// 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");
|
||||
}
|
||||
return true;
|
||||
|
@ -229,7 +234,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
// when the title field loses the focus...
|
||||
$replyTitle.blur(function(){
|
||||
// ...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
|
||||
$replyTitle.toggleClass("requirements-not-met", true);
|
||||
}
|
||||
|
@ -330,8 +335,8 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
addMarkdown: function(text) {
|
||||
var ctrl = $('#wmd-input').get(0),
|
||||
caretPosition = Discourse.Utilities.caretPosition(ctrl),
|
||||
current = this.get('content.reply');
|
||||
this.set('content.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length));
|
||||
current = this.get('model.reply');
|
||||
this.set('model.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length));
|
||||
|
||||
Em.run.schedule('afterRender', function() {
|
||||
Discourse.Utilities.setCaretPosition(ctrl, caretPosition + text.length);
|
||||
|
@ -369,13 +374,13 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
},
|
||||
|
||||
titleValidation: function() {
|
||||
var titleLength = this.get('content.titleLength'),
|
||||
missingChars = this.get('content.missingTitleCharacters'),
|
||||
var titleLength = this.get('model.titleLength'),
|
||||
missingChars = this.get('model.missingTitleCharacters'),
|
||||
reason;
|
||||
if( titleLength < 1 ){
|
||||
reason = Em.String.i18n('composer.error.title_missing');
|
||||
} 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 ) {
|
||||
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 ) {
|
||||
return Discourse.InputValidation.create({ failed: true, reason: reason });
|
||||
}
|
||||
}.property('content.titleLength', 'content.missingTitleCharacters', 'content.minimumTitleLength'),
|
||||
}.property('model.titleLength', 'model.missingTitleCharacters', 'model.minimumTitleLength'),
|
||||
|
||||
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') });
|
||||
}
|
||||
}.property('content.categoryName'),
|
||||
}.property('model.categoryName'),
|
||||
|
||||
replyValidation: function() {
|
||||
var replyLength = this.get('content.replyLength'),
|
||||
missingChars = this.get('content.missingReplyCharacters'),
|
||||
var replyLength = this.get('model.replyLength'),
|
||||
missingChars = this.get('model.missingReplyCharacters'),
|
||||
reason;
|
||||
if( replyLength < 1 ){
|
||||
reason = Em.String.i18n('composer.error.post_missing');
|
||||
} 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 ) {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue