Used possible channels from backend.

This commit is contained in:
Martin Edenhofer 2015-09-01 01:12:51 +02:00
parent bcc72a9793
commit e530383cf2
7 changed files with 101 additions and 68 deletions

View file

@ -243,6 +243,8 @@ class App.ChannelEmailAccountOverview extends App.Controller
render: (data = {}) => render: (data = {}) =>
@channelDriver = data.channel_driver
# get channels # get channels
account_channels = [] account_channels = []
for channel_id in data.account_channel_ids for channel_id in data.account_channel_ids
@ -272,8 +274,9 @@ class App.ChannelEmailAccountOverview extends App.Controller
wizard: (e) => wizard: (e) =>
e.preventDefault() e.preventDefault()
new App.ChannelEmailAccountWizard( new App.ChannelEmailAccountWizard(
container: @el.closest('.content') container: @el.closest('.content')
callback: @load callback: @load
channelDriver: @channelDriver
) )
edit_inbound: (e) => edit_inbound: (e) =>
@ -282,10 +285,11 @@ class App.ChannelEmailAccountOverview extends App.Controller
channel = App.Channel.find(id) channel = App.Channel.find(id)
slide = 'js-inbound' slide = 'js-inbound'
new App.ChannelEmailAccountWizard( new App.ChannelEmailAccountWizard(
container: @el.closest('.content') container: @el.closest('.content')
slide: slide slide: slide
channel: channel channel: channel
callback: @load callback: @load
channelDriver: @channelDriver
) )
edit_outbound: (e) => edit_outbound: (e) =>
@ -294,10 +298,11 @@ class App.ChannelEmailAccountOverview extends App.Controller
channel = App.Channel.find(id) channel = App.Channel.find(id)
slide = 'js-outbound' slide = 'js-outbound'
new App.ChannelEmailAccountWizard( new App.ChannelEmailAccountWizard(
container: @el.closest('.content') container: @el.closest('.content')
slide: slide slide: slide
channel: channel channel: channel
callback: @load callback: @load
channelDriver: @channelDriver
) )
delete: (e) => delete: (e) =>
@ -341,9 +346,10 @@ class App.ChannelEmailAccountOverview extends App.Controller
channel = App.Channel.find(id) channel = App.Channel.find(id)
slide = 'js-outbound' slide = 'js-outbound'
new App.ChannelEmailNotificationWizard( new App.ChannelEmailNotificationWizard(
container: @el.closest('.content') container: @el.closest('.content')
channel: channel channel: channel
callback: @load callback: @load
channelDriver: @channelDriver
) )
class App.ChannelEmailAccountWizard extends App.Wizard class App.ChannelEmailAccountWizard extends App.Wizard
@ -403,11 +409,8 @@ class App.ChannelEmailAccountWizard extends App.Wizard
@showSlide('js-intro') @showSlide('js-intro')
# outbound # outbound
adapters =
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup'
smtp: 'SMTP - configure your own outgoing SMTP settings'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters }, { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound },
] ]
new App.ControllerForm( new App.ControllerForm(
el: @$('.base-outbound-type') el: @$('.base-outbound-type')
@ -421,7 +424,7 @@ class App.ChannelEmailAccountWizard extends App.Wizard
# inbound # inbound
configureAttributesInbound = [ configureAttributesInbound = [
{ name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'imap', pop3: 'pop3' } }, { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: @channelDriver.email.inbound },
{ name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false },
{ name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', }, { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', },
{ name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true },
@ -700,11 +703,8 @@ class App.ChannelEmailNotificationWizard extends App.Wizard
@showSlide('js-outbound') @showSlide('js-outbound')
# outbound # outbound
adapters =
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup'
smtp: 'SMTP - configure your own outgoing SMTP settings'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters }, { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound },
] ]
new App.ControllerForm( new App.ControllerForm(
el: @$('.base-outbound-type') el: @$('.base-outbound-type')

View file

@ -404,13 +404,10 @@ class EmailNotification extends App.Wizard
# set title # set title
@title 'Email Notifications' @title 'Email Notifications'
@adapters = [ @channelDriver =
{ email:
name: 'Email' inbound: {}
class: 'email' outbound: {}
link: '#getting_started/channel/email'
},
]
@fetch() @fetch()
@ -432,43 +429,45 @@ class EmailNotification extends App.Wizard
@navigate '#import/' + data.import_backend @navigate '#import/' + data.import_backend
return return
@channelDriver = data.channel_driver
# render page # render page
@render() @render()
) )
render: -> render: ->
@html App.view('getting_started/email_notification')() @html App.view('getting_started/email_notification')()
adapters =
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup'
smtp: 'SMTP - configure your own outgoing SMTP settings'
adapter_used = 'sendmail'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used }, { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound },
] ]
new App.ControllerForm( new App.ControllerForm(
el: @$('.base-outbound-type'), el: @$('.base-outbound-type')
model: { configure_attributes: configureAttributesOutbound, className: '' }, model:
configure_attributes: configureAttributesOutbound
className: ''
params:
adapter: @account.outbound.adapter || 'sendmail'
) )
@toggleOutboundAdapter() @toggleOutboundAdapter()
toggleOutboundAdapter: => toggleOutboundAdapter: =>
# show used backend # show used backend
channel_used = { options: {} } @el.find('.base-outbound-settings').html('')
adapter = @$('.js-outbound [name=adapter]').val() adapter = @$('.js-outbound [name=adapter]').val()
if adapter is 'smtp' if adapter is 'smtp'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autofocus: true, default: (channel_used['options']&&channel_used['options']['host']) }, { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autofocus: true },
{ name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, autocomplete: 'off', default: (channel_used['options']&&channel_used['options']['user']) }, { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, autocomplete: 'off' },
{ name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true, default: (channel_used['options']&&channel_used['options']['password']) }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true },
] ]
@form = new App.ControllerForm( @form = new App.ControllerForm(
el: @$('.base-outbound-settings') el: @$('.base-outbound-settings')
model: { configure_attributes: configureAttributesOutbound, className: '' } model:
configure_attributes: configureAttributesOutbound
className: ''
params: @account.outbound
) )
else
@el.find('.base-outbound-settings').html('')
submit: (e) => submit: (e) =>
e.preventDefault() e.preventDefault()
@ -634,6 +633,11 @@ class ChannelEmail extends App.Wizard
outbound: {} outbound: {}
meta: {} meta: {}
@channelDriver =
email:
inbound: {}
outbound: {}
@fetch() @fetch()
release: => release: =>
@ -654,6 +658,8 @@ class ChannelEmail extends App.Wizard
@navigate '#import/' + data.import_backend @navigate '#import/' + data.import_backend
return return
@channelDriver = data.channel_driver
# render page # render page
@render() @render()
) )
@ -664,29 +670,32 @@ class ChannelEmail extends App.Wizard
@showSlide('js-intro') @showSlide('js-intro')
# outbound # outbound
adapters =
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup'
smtp: 'SMTP - configure your own outgoing SMTP settings'
adapter_used = 'smtp'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used }, { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound },
] ]
new App.ControllerForm( new App.ControllerForm(
el: @$('.base-outbound-type'), el: @$('.base-outbound-type')
model: { configure_attributes: configureAttributesOutbound, className: '' }, model:
configure_attributes: configureAttributesOutbound
className: ''
params:
adapter: @account.outbound.adapter || 'smtp'
) )
@toggleOutboundAdapter() @toggleOutboundAdapter()
# inbound # inbound
configureAttributesInbound = [ configureAttributesInbound = [
{ name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } }, { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: @channelDriver.email.inbound },
{ name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false },
{ name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', }, { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', },
{ name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true },
] ]
new App.ControllerForm( new App.ControllerForm(
el: @$('.base-inbound-settings'), el: @$('.base-inbound-settings'),
model: { configure_attributes: configureAttributesInbound, className: '' }, model:
configure_attributes: configureAttributesInbound
className: ''
params: @account.inbound
) )
toggleOutboundAdapter: => toggleOutboundAdapter: =>
@ -702,16 +711,17 @@ class ChannelEmail extends App.Wizard
adapter = @$('.js-outbound [name=adapter]').val() adapter = @$('.js-outbound [name=adapter]').val()
if adapter is 'smtp' if adapter is 'smtp'
configureAttributesOutbound = [ configureAttributesOutbound = [
{ name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autofocus: true, default: (channel_used['options']&&channel_used['options']['host']) }, { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autofocus: true },
{ name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, autocomplete: 'off', default: (channel_used['options']&&channel_used['options']['user']) }, { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, autocomplete: 'off', },
{ name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true, default: (channel_used['options']&&channel_used['options']['password']) }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true },
] ]
@form = new App.ControllerForm( @form = new App.ControllerForm(
el: @$('.base-outbound-settings') el: @$('.base-outbound-settings')
model: { configure_attributes: configureAttributesOutbound, className: '' } model:
configure_attributes: configureAttributesOutbound
className: ''
params: @account.outbound
) )
else
@el.find('.base-outbound-settings').html('')
probeBasedOnIntro: (e) => probeBasedOnIntro: (e) =>
e.preventDefault() e.preventDefault()

View file

@ -62,6 +62,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
notification_channel_ids: notification_channel_ids, notification_channel_ids: notification_channel_ids,
email_address_ids: email_address_ids, email_address_ids: email_address_ids,
not_used_email_address_ids: not_used_email_address_ids, not_used_email_address_ids: not_used_email_address_ids,
channel_driver: {
email: EmailHelper.available_driver,
}
} }
end end

View file

@ -226,6 +226,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
addresses: addresses, addresses: addresses,
groups: groups, groups: groups,
config: config_to_update, config: config_to_update,
channel_driver: {
email: EmailHelper.available_driver,
},
} }
true true
end end

View file

@ -9,8 +9,14 @@ get available driver
returns returns
{ {
:inbound => ['imap', 'pop3'], inbound: {
:outbound => ['smtp', 'sendmail'], imap: 'IMAP',
pop3: 'POP3',
},
outbound: {
smtp: 'SMTP - configure your own outgoing SMTP settings',
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup',
},
} }
=end =end
@ -18,13 +24,24 @@ returns
def self.available_driver def self.available_driver
if Setting.get('system_online_service') if Setting.get('system_online_service')
return { return {
inbound: %w(imap pop3), inbound: {
outbound: %w(smtp), imap: 'IMAP',
pop3: 'POP3',
},
outbound: {
smtp: 'SMTP - configure your own outgoing SMTP settings',
},
} }
end end
{ {
inbound: %w(imap pop3), inbound: {
outbound: %w(smtp sendmail), imap: 'IMAP',
pop3: 'POP3',
},
outbound: {
smtp: 'SMTP - configure your own outgoing SMTP settings',
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup',
},
} }
end end

View file

@ -189,7 +189,7 @@ returns on fail
adapter = params[:adapter].downcase adapter = params[:adapter].downcase
# validate adapter # validate adapter
if !EmailHelper.available_driver[:inbound].include?(adapter) if !EmailHelper.available_driver[:inbound][adapter.to_sym]
return { return {
result: 'failed', result: 'failed',
message: "Unknown adapter '#{adapter}'", message: "Unknown adapter '#{adapter}'",
@ -268,7 +268,7 @@ returns on fail
adapter = params[:adapter].downcase adapter = params[:adapter].downcase
# validate adapter # validate adapter
if !EmailHelper.available_driver[:outbound].include?(adapter) if !EmailHelper.available_driver[:outbound][adapter.to_sym]
return { return {
result: 'failed', result: 'failed',
message: "Unknown adapter '#{adapter}'", message: "Unknown adapter '#{adapter}'",

View file

@ -69,7 +69,7 @@ or
# validate adapter # validate adapter
adapter = params[:inbound][:adapter].downcase adapter = params[:inbound][:adapter].downcase
if !EmailHelper.available_driver[:inbound].include?(adapter) if !EmailHelper.available_driver[:inbound][adapter.to_sym]
return { return {
result: 'failed', result: 'failed',
message: "Unknown adapter '#{adapter}'", message: "Unknown adapter '#{adapter}'",