зеркало из
1
0
Форкнуть 0
This commit is contained in:
Leo McArdle 2017-02-23 16:39:07 +00:00
Родитель fca6fda847
Коммит 0a60fcc6ed
7 изменённых файлов: 113 добавлений и 14 удалений

Просмотреть файл

@ -1,20 +1,50 @@
import Composer from 'discourse/models/composer';
import { getOwner } from 'discourse-common/lib/get-owner';
import showModal from 'discourse/lib/show-modal';
import PermissionType from 'discourse/models/permission-type';
export default {
shouldRender(args, component) {
return args.category.email_in
setupComponent(args, component) {
$('#create-topic').css('display', 'none')
var logged_in = !!Discourse.User.current()
logged_in ? component.set('logged_in', true) : component.set('logged_in', false)
var email_in = args.category.email_in
component.set('mailto', `mailto:${email_in}`)
var email_in_allow_strangers = args.category.email_in_allow_strangers
if (!email_in_allow_strangers && !logged_in) {
component.set('stranger_danger', true)
}
var canCreateTopicOnCategory = args.category.permission === PermissionType.FULL;
var disable_new_topic_buttons = logged_in && !canCreateTopicOnCategory
component.set('disable_new_topic_buttons', disable_new_topic_buttons)
if (disable_new_topic_buttons) component.set('mailto', '#')
},
setupComponent(args, component) {
var email_in = args.category.email_in
var email_in_allow_strangers = args.category.email_in_allow_strangers
var stranger_message = "This category doesn't support posting via email from strangers, so please ensure you've signed up for an account and use the email address registered with it, thanks!"
if (email_in_allow_strangers) {
component.set('mailto', `mailto:${email_in}`)
} else {
actions: {
createTopic () {
if (Discourse.User.current()) {
component.set('mailto', `mailto:${email_in}`)
getOwner(this).lookup('controller:composer').open({
categoryId: this.category.id,
action: Composer.CREATE_TOPIC,
draftKey: Composer.CREATE_TOPIC
});
} else {
component.set('mailto', `mailto:${email_in}?body=${encodeURIComponent(stranger_message)}`)
var model = this
showModal('login-prompt', { model })
}
},
handleEmail () {
if (this.stranger_danger) {
var model = this
showModal('login-prompt', { model })
} else {
window.location.href = this.mailto
}
}
}

Просмотреть файл

@ -0,0 +1,4 @@
import ModalFunctionality from "discourse/mixins/modal-functionality"
export default Ember.Controller.extend(ModalFunctionality, {
})

Просмотреть файл

@ -1 +1,18 @@
<a href="{{mailto}}" class="btn btn-default">{{fa-icon "envelope"}}{{i18n "user.email.title"}}</a>
{{#if category.email_in}}
<a href="{{mailto}}"
{{action "handleEmail"}}
id="create-topic-email"
class="btn btn-default no-text"
title="{{i18n "topic.create"}}"
disabled={{disable_new_topic_buttons}}>
{{fa-icon "envelope"}}
</a>
{{/if}}
<button id="create-topic-composer"
class="btn btn-default no-text {{unless logged_in 'disabled'}}"
{{action "createTopic"}}
title="{{i18n "topic.create"}}"
disabled={{disable_new_topic_buttons}}>
{{fa-icon "plus"}}
</button>

Просмотреть файл

@ -0,0 +1,31 @@
{{#d-modal-body title="expose_emails_in.login_prompt.title" class="login-prompt"}}
<div>
<h3>
{{#if model.stranger_danger}}
{{i18n "expose_emails_in.login_prompt.body_stranger"}}
{{else}}
{{i18n "expose_emails_in.login_prompt.body"}}
{{/if}}
{{d-button class="btn-primary login-button"
action="showLogin"
icon="user"
label="expose_emails_in.log_in_sign_up"}}
</h3>
{{#if model.category.email_in}}
<div class="email-in">
{{#if model.stranger_danger}}
{{i18n "expose_emails_in.login_prompt.email_stranger"}}
{{else}}
{{i18n "expose_emails_in.login_prompt.email"}}
{{/if}}
<a href="{{model.mailto}}"
{{action "handleEmail"}}
id="create-topic-email"
class="btn btn-default"
title="{{i18n "topic.create"}}">
{{fa-icon "envelope"}} {{model.category.email_in}}
</a>
</div>
{{/if}}
</div>
{{/d-modal-body}}

Просмотреть файл

@ -0,0 +1,5 @@
.login-prompt {
.email-in {
margin-top: 15px;
}
}

Просмотреть файл

@ -0,0 +1,10 @@
en:
js:
expose_emails_in:
log_in_sign_up: "Sign up / Log in"
login_prompt:
title: "Sign up / Log in to post"
body: "You must be logged in to compose a new topic:"
body_stranger: "You must be logged in to post a new topic:"
email: "Alternatively, start a new topic by email:"
email_stranger: "Already a member? Start a new topic by email:"

Просмотреть файл

@ -1,9 +1,11 @@
# name: expose-emails-in
# about: Discourse plugin which exposes category emails-in in useful ways
# version: 0.0.1
# version: 0.0.2
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-expose-emails-in
register_asset 'stylesheets/expose-emails-in.scss'
after_initialize do
add_to_serializer(:basic_category, :email_in, false) { object.email_in }
add_to_serializer(:basic_category, :email_in_allow_strangers, false) { object.email_in_allow_strangers }