diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index 0dfa0912b..4d9568c00 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -204,8 +204,15 @@ class App.ControllerGenericDestroyConfirm extends App.ControllerModal onSubmit: (e) -> e.preventDefault() - @hide() - @item.destroy() + @item.destroy( + done: => + if @callback + @callback() + @hide() + fail: => + @log 'errors' + @hide() + ) class App.ControllerDrox extends App.Controller constructor: (params) -> diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index 4ff00d118..3ff4c697e 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -411,7 +411,7 @@ class App.ChannelEmailAccountWizard extends App.Controller configure_attributes: configureAttributesOutbound className: '' params: - adapter: @account.outbound.adapter || 'sendmail' + adapter: @account.outbound.adapter || 'smtp' ) @toggleOutboundAdapter() @@ -419,8 +419,8 @@ class App.ChannelEmailAccountWizard extends App.Controller configureAttributesInbound = [ { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'imap', pop3: 'pop3' } }, { 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 }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, single: true }, + { 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 }, ] new App.ControllerForm( el: @$('.base-inbound-settings'), @@ -439,13 +439,13 @@ class App.ChannelEmailAccountWizard extends App.Controller channel_used['options']['password'] = @account['meta']['password'] # show used backend - @el.find('.base-outbound-settings').html('') + @$('.base-outbound-settings').html('') adapter = @$('.js-outbound [name=adapter]').val() if adapter is 'smtp' configureAttributesOutbound = [ { 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 }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true }, + { 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 }, ] @form = new App.ControllerForm( el: @$('.base-outbound-settings') @@ -504,7 +504,8 @@ class App.ChannelEmailAccountWizard extends App.Controller params = @formParam(e.target) # let backend know about the channel - params.channel_id = @channel.id + if @channel + params.channel_id = @channel.id @disable(e) @@ -523,17 +524,26 @@ class App.ChannelEmailAccountWizard extends App.Controller @account.inbound = params @showSlide('js-outbound') + + # fill user / password based on inbound settings if !@channel - @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] ) - @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) + if @account['inbound']['options'] + @$('.js-outbound [name="options::host"]').val( @account['inbound']['options']['host'] ) + @$('.js-outbound [name="options::user"]').val( @account['inbound']['options']['user'] ) + @$('.js-outbound [name="options::password"]').val( @account['inbound']['options']['password'] ) + else + @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] ) + @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) else @showSlide('js-inbound') @showAlert('js-inbound', data.message_human || data.message ) + @showInvalidField('js-inbound', data.invalid_field) @enable(e) fail: => @showSlide('js-inbound') @showAlert('js-inbound', data.message_human || data.message ) + @showInvalidField('js-inbound', data.invalid_field) @enable(e) ) @@ -550,7 +560,8 @@ class App.ChannelEmailAccountWizard extends App.Controller params['email'] = email_addresses[0].email # let backend know about the channel - params.channel_id = @channel.id + if @channel + params.channel_id = @channel.id @disable(e) @@ -572,10 +583,12 @@ class App.ChannelEmailAccountWizard extends App.Controller else @showSlide('js-outbound') @showAlert('js-outbound', data.message_human || data.message ) + @showInvalidField('js-outbound', data.invalid_field) @enable(e) fail: => @showSlide('js-outbound') @showAlert('js-outbound', data.message_human || data.message ) + @showInvalidField('js-outbound', data.invalid_field) @enable(e) ) @@ -599,24 +612,29 @@ class App.ChannelEmailAccountWizard extends App.Controller processData: true success: (data, status, xhr) => if data.result is 'ok' - @el.remove() + @el.modal('hide') else - if count is 2 - @showAlert('js-verify', data.message_human || data.message ) - @delay( - => - @showSlide('js-intro') - @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) - - 2300 - ) + if data.source is 'inbound' || data.source is 'outbound' + @showSlide("js-#{data.source}") + @showAlert("js-#{data.source}", data.message_human || data.message ) + @showInvalidField("js-#{data.source}", data.invalid_field) else - if data.subject && @account - @account.subject = data.subject - @verify( @account, count + 1 ) + if count is 2 + @showAlert('js-verify', data.message_human || data.message ) + @delay( + => + @showSlide('js-intro') + @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.') + + 2300 + ) + else + if data.subject && @account + @account.subject = data.subject + @verify( @account, count + 1 ) fail: => @showSlide('js-intro') - @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) + @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.') ) goToSlide: (e) => @@ -644,6 +662,13 @@ class App.ChannelEmailAccountWizard extends App.Controller @formEnable(e) @$('.wizard-controls .btn').attr('disabled', false) + showInvalidField: (screen, fields) => + @$(".#{screen}").find('.form-group').removeClass('has-error') + return if !fields + for field, type of fields + if type + @$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error') + hide: (e) => e.preventDefault() @el.modal('hide') @@ -727,8 +752,8 @@ class App.ChannelEmailNotificationWizard extends App.Controller if adapter is 'smtp' configureAttributesOutbound = [ { 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 }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true }, + { 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 }, ] @form = new App.ControllerForm( el: @$('.base-outbound-settings') diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index becf4d996..5e628c469 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -466,8 +466,8 @@ class EmailNotification extends App.ControllerContent if adapter is 'smtp' 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::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true, default: (channel_used['options']&&channel_used['options']['password']) }, + { 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::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']) }, ] @form = new App.ControllerForm( el: @$('.base-outbound-settings') @@ -696,7 +696,7 @@ class ChannelEmail extends App.ControllerContent adapters = sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup' smtp: 'SMTP - configure your own outgoing SMTP settings' - adapter_used = 'sendmail' + adapter_used = 'smtp' configureAttributesOutbound = [ { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used }, ] @@ -710,8 +710,8 @@ class ChannelEmail extends App.ControllerContent configureAttributesInbound = [ { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } }, { 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 }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, single: true }, + { 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 }, ] new App.ControllerForm( el: @$('.base-inbound-settings'), @@ -727,12 +727,13 @@ class ChannelEmail extends App.ControllerContent channel_used['options']['password'] = @account['meta']['password'] # show used backend + @$('.base-outbound-settings').html('') adapter = @$('.js-outbound [name=adapter]').val() if adapter is 'smtp' 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::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true, default: (channel_used['options']&&channel_used['options']['password']) }, + { 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::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']) }, ] @form = new App.ControllerForm( el: @$('.base-outbound-settings') @@ -764,6 +765,9 @@ class ChannelEmail extends App.ControllerContent for key, value of data.setting @account[key] = value @verify(@account) + else if data.result is 'duplicate' + @showSlide('js-intro') + @showAlert('js-intro', 'Account already exists!' ) else @showSlide('js-inbound') @showAlert('js-inbound', 'Unable to detect your server settings. Manual configuration needed.' ) @@ -798,16 +802,26 @@ class ChannelEmail extends App.ControllerContent @account.inbound = params @showSlide('js-outbound') - @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] ) - @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) + + # fill user / password based on inbound settings + if !@channel + if @account['inbound']['options'] + @$('.js-outbound [name="options::host"]').val( @account['inbound']['options']['host'] ) + @$('.js-outbound [name="options::user"]').val( @account['inbound']['options']['user'] ) + @$('.js-outbound [name="options::password"]').val( @account['inbound']['options']['password'] ) + else + @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] ) + @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) else @showSlide('js-inbound') @showAlert('js-inbound', data.message_human || data.message ) + @showInvalidField('js-inbound', data.invalid_field) @enable(e) fail: => @showSlide('js-inbound') @showAlert('js-inbound', data.message_human || data.message ) + @showInvalidField('js-inbound', data.invalid_field) @enable(e) ) @@ -837,10 +851,12 @@ class ChannelEmail extends App.ControllerContent else @showSlide('js-outbound') @showAlert('js-outbound', data.message_human || data.message ) + @showInvalidField('js-outbound', data.invalid_field) @enable(e) fail: => @showSlide('js-outbound') @showAlert('js-outbound', data.message_human || data.message ) + @showInvalidField('js-outbound', data.invalid_field) @enable(e) ) @@ -857,19 +873,24 @@ class ChannelEmail extends App.ControllerContent if data.result is 'ok' @navigate 'getting_started/agents' else - if count is 2 - @showAlert('js-verify', data.message_human || data.message ) - @delay( - => - @showSlide('js-intro') - @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) - - 2300 - ) + if data.source is 'inbound' || data.source is 'outbound' + @showSlide("js-#{data.source}") + @showAlert("js-#{data.source}", data.message_human || data.message ) + @showInvalidField("js-#{data.source}", data.invalid_field) else - if data.subject && @account - @account.subject = data.subject - @verify( @account, count + 1 ) + if count is 2 + @showAlert('js-verify', data.message_human || data.message ) + @delay( + => + @showSlide('js-intro') + @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) + + 2300 + ) + else + if data.subject && @account + @account.subject = data.subject + @verify( @account, count + 1 ) fail: => @showSlide('js-intro') @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) @@ -900,6 +921,13 @@ class ChannelEmail extends App.ControllerContent @formEnable(e) @$('.wizard-controls .btn').attr('disabled', false) + showInvalidField: (screen, fields) => + @$(".#{screen}").find('.form-group').removeClass('has-error') + return if !fields + for field, type of fields + if type + @$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error') + App.Config.set( 'getting_started/channel/email', ChannelEmail, 'Routes' ) diff --git a/app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco b/app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco index c5ec1433e..d2948c217 100644 --- a/app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco +++ b/app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco @@ -17,11 +17,11 @@