From 33b0cc51638532a8b87b5699b733d0d0514b4d1c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 11 Sep 2015 17:22:58 +0200 Subject: [PATCH] Added group change of email channels. --- .../app/controllers/_channel/email.js.coffee | 96 ++++++++++- .../channel/email_account_overview.jst.eco | 150 ++++-------------- .../channel/email_account_wizard.jst.eco | 15 +- app/controllers/channels_controller.rb | 34 +++- config/routes/channel.rb | 1 + 5 files changed, 157 insertions(+), 139 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index 31665de21..9e7079093 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -217,6 +217,7 @@ class App.ChannelEmailAccountOverview extends App.Controller events: 'click .js-channelNew': 'wizard' 'click .js-channelDelete': 'delete' + 'click .js-channelGroupChange': 'group_change' 'click .js-editInbound': 'edit_inbound' 'click .js-editOutbound': 'edit_outbound' 'click .js-emailAddressNew': 'email_address_new' @@ -250,7 +251,12 @@ class App.ChannelEmailAccountOverview extends App.Controller # get channels account_channels = [] for channel_id in data.account_channel_ids - account_channels.push App.Channel.fullLocal(channel_id) + account_channel = App.Channel.fullLocal(channel_id) + if account_channel.group_id + account_channel.group = App.Group.find(account_channel.group_id).displayName() + else + account_channel.group = '-' + account_channels.push account_channel for channel in account_channels email_addresses = App.EmailAddress.search( filter: { channel_id: channel.id } ) @@ -271,6 +277,7 @@ class App.ChannelEmailAccountOverview extends App.Controller not_used_email_addresses: not_used_email_addresses notification_channels: notification_channels accounts_fixed: data.accounts_fixed + config: data.config ) wizard: (e) => @@ -317,6 +324,16 @@ class App.ChannelEmailAccountOverview extends App.Controller callback: @load ) + group_change: (e) => + e.preventDefault() + id = $(e.target).closest('.action').data('id') + item = App.Channel.find(id) + new App.ChannelEmailEdit( + container: @el.closest('.content') + item: item + callback: @load + ) + email_address_new: (e) => e.preventDefault() channel_id = $(e.target).closest('.action').data('id') @@ -364,6 +381,60 @@ class App.ChannelEmailAccountOverview extends App.Controller channelDriver: @channelDriver ) +class App.ChannelEmailEdit extends App.ControllerModal + constructor: -> + super + + @head = 'Channel' + @button = true + @close = true + @cancel = true + + configureAttributesBase = [ + { name: 'group_id', display: 'Destination Group', tag: 'select', null: false, relation: 'Group', nulloption: true }, + ] + @form = new App.ControllerForm( + model: + configure_attributes: configureAttributesBase + className: '' + params: @item + ) + + @content = @form.form + @show() + + onSubmit: (e) => + e.preventDefault() + + # get params + params = @formParam(e.target) + + # validate form + errors = @form.validate( params ) + + # show errors in form + if errors + @log 'error', errors + @formValidate( form: e.target, errors: errors ) + return false + + # disable form + @formDisable(e) + + # update + @ajax( + id: 'channel_group_update' + type: 'POST' + url: "#{@apiPath}/channels/group/#{@item.id}" + data: JSON.stringify( params ) + processData: true + success: (data, status, xhr) => + @callback() + @hide() + fail: => + @enable(e) + ) + class App.ChannelEmailAccountWizard extends App.Wizard elements: '.modal-body': 'body' @@ -402,6 +473,9 @@ class App.ChannelEmailAccountWizard extends App.Wizard @render() + if @channel + @$('.js-goToSlide[data-slide=js-intro]').addClass('hidden') + @el.modal keyboard: true show: true @@ -420,6 +494,21 @@ class App.ChannelEmailAccountWizard extends App.Wizard @html App.view('channel/email_account_wizard')() @showSlide('js-intro') + # base + configureAttributesBase = [ + { name: 'realname', display: 'Department Name', tag: 'input', type: 'text', limit: 160, null: false, placeholder: 'Organization Support', autocomplete: 'off' }, + { name: 'email', display: 'User', tag: 'input', type: 'email', limit: 120, null: false, placeholder: 'support@example.com', autocapitalize: false, autocomplete: 'off', }, + { name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, + { name: 'group_id', display: 'Destination Group', tag: 'select', null: false, relation: 'Group', nulloption: true }, + ] + new App.ControllerForm( + el: @$('.base-settings'), + model: + configure_attributes: configureAttributesBase + className: '' + params: @account.meta + ) + # outbound configureAttributesOutbound = [ { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound }, @@ -638,6 +727,11 @@ class App.ChannelEmailAccountWizard extends App.Wizard if @channel account.channel_id = @channel.id + if account.meta.group_id + account.group_id = account.meta.group_id + else if @channel.group_id + account.group_id = @channel.group_id + if !account.email && @channel email_addresses = App.EmailAddress.search( filter: { channel_id: @channel.id } ) if email_addresses && email_addresses[0] diff --git a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco index 4e141f717..641f62d96 100644 --- a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco +++ b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco @@ -53,13 +53,20 @@ <% if !_.isEmpty(channel.last_log_in): %>
- <%- @T('Notice') %>:
- <%= channel.last_log_in %> + <%- @T('Notice') %>:
+ <%= channel.last_log_in %>
<% end %> -
+
+
+ <%- @T('Destination Group') %>:
+ <%= channel.group %> +
+ + +
<%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %>:
<% if channel.options.outbound && channel.options.outbound.options: %> @@ -70,13 +77,14 @@ <% if !_.isEmpty(channel.last_log_out): %>
- <%- @T('Notice') %>:
- <%= channel.last_log_out %> + <%- @T('Notice') %>:
+ <%= channel.last_log_out %>
<% end %> -
-
- <%- @T('Email Adresses') %>: + +
+ + <%- @T('Email Address') %>:
    <% if !_.isEmpty(channel.email_addresses): %> <% for email_address in channel.email_addresses: %> @@ -95,6 +103,7 @@ <% end %>
+ <%- @T('Add Email') %> +
@@ -104,88 +113,14 @@ <% end %> <% end %> - <%- @T('New') %> <% if !_.isEmpty(@notification_channels) && !App.Config.get('system_online_service'): %>

<%- @T('Email Notification') %>

<% for channel in @notification_channels: %>
-
-
+
+
<%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %>:
@@ -204,46 +139,15 @@ <% end %>
+
+ + <%- @T('Email Address') %>: +
    +
  • <%= @config.notification_sender %> +
+ +
<% end %> <% end %> - - \ No newline at end of file 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 c1593121a..df2bf5953 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 @@ -14,20 +14,7 @@