Browse Source

Added group change of email channels.

Martin Edenhofer 9 years ago
parent
commit
33b0cc5163

+ 95 - 1
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]

+ 27 - 123
app/assets/javascripts/app/views/channel/email_account_overview.jst.eco

@@ -53,13 +53,20 @@
 
         <% if !_.isEmpty(channel.last_log_in): %>
         <div>
-        <%- @T('Notice') %>:<br>
-        <%= channel.last_log_in %>
+          <%- @T('Notice') %>:<br>
+          <%= channel.last_log_in %>
         </div>
         <% end %>
 
-        <br>
+        <hr>
 
+        <div>
+          <%- @T('Destination Group') %>:<br>
+          <a href="#" class="js-channelGroupChange"><%= channel.group %></a>
+        </div>
+
+      </div>
+      <div class="action-block">
         <%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %>:<br>
         <a class="js-editOutbound" href="#">
           <% if channel.options.outbound && channel.options.outbound.options: %>
@@ -70,13 +77,14 @@
         </a>
         <% if !_.isEmpty(channel.last_log_out): %>
         <div>
-        <%- @T('Notice') %>:<br>
-        <%= channel.last_log_out %>
+          <%- @T('Notice') %>:<br>
+          <%= channel.last_log_out %>
         <div>
         <% end %>
-      </div>
-      <div class="action-block">
-        <%- @T('Email Adresses') %>:
+
+        <hr>
+
+        <%- @T('Email Address') %>:
         <ul class="list">
         <% if !_.isEmpty(channel.email_addresses): %>
           <% for email_address in channel.email_addresses: %>
@@ -95,6 +103,7 @@
         <% end %>
         </ul>
         <a class="text-muted js-emailAddressNew" href="#" title="<%- @Ti('New Email Address') %>">+ <%- @T('Add Email') %></a>
+
       </div>
     </div>
     <div class="action-controls">
@@ -104,88 +113,14 @@
   <% end %>
 <% end %>
 
-<!--
-<% if _.isEmpty(@account_channels): %>
-  <p><%- @T('You have no configured account right now.') %></p>
-<% else: %>
-  <table class="table table-hover table-fluid user-list">
-    <thead>
-      <tr>
-        <th><%- @T('Inbound') %></th>
-        <th><%- @T('Outbound') %></th>
-        <th><%- @T('Email Adresses') %></th>
-        <th><%- @T('Action') %></th>
-      </tr>
-    </thead>
-    <tbody>
-    <% for channel in @account_channels: %>
-      <tr data-id="<%- channel.id %>">
-        <td class="noTruncate">
-          <div class="horizontal">
-            <%- @Icon('status', channel.status_in + " inline") %>
-            <a class="flex js-editInbound" href="#">
-            <%= channel.options.inbound.options.user %><br>
-            <%= channel.options.inbound.options.host %> (<%= channel.options.inbound.adapter %>)
-            </a>
-          </div>
-        </td>
-        <td class="noTruncate">
-          <div class="horizontal">
-            <%- @Icon('status', channel.status_out + " inline") %>
-            <a class="flex js-editOutbound" href="#">
-              <% if channel.options.outbound && channel.options.outbound.options: %>
-                <%= channel.options.outbound.options.user %><br>
-                <%= channel.options.outbound.options.host %>
-              <% end %>
-              (<%= channel.options.outbound.adapter %>)
-            </a>
-          </div>
-        </td>
-        <td class="noTruncate">
-          <ul class="list">
-          <% if !_.isEmpty(channel.email_addresses): %>
-            <% for email_address in channel.email_addresses: %>
-              <li class="list-item" data-id="<%= email_address.id %>">
-                <div class="list-item-name">
-                  <a href="" class="js-emailAddressEdit"><%= email_address.email %></a>
-                </div>
-                <div class="list-item-delete js-delete">
-                  <%- @Icon('diagonal-cross') %>
-                </div>
-            <% end %>
-          <% else: %>
-            <li class="list-item"><%- @T('none') %>
-          <% end %>
-          </ul>
-          <a class="text-muted js-emailAddressNew" href="#" title="<%- @Ti('New Email Address') %>">+ <%- @Ti('Add Email') %></a>
-        </td>
-        <td class="noTruncate">
-          <a href="#" data-type="delete" title="<%- @Ti('Delete') %>"><%- @Icon('trash') %></a>
-        </td>
-      </tr>
-      <% if !_.isEmpty(channel.last_log_in): %>
-      <tr>
-        <td colspan="4"><%= channel.last_log_in %></td>
-      </tr>
-      <% end %>
-      <% if !_.isEmpty(channel.last_log_out): %>
-      <tr>
-        <td colspan="4"><%= channel.last_log_out %></td>
-      </tr>
-      <% end %>
-  <% end %>
-    </tbody>
-  </table>
-<% end %>
--->
 <a class="btn btn--success js-channelNew"><%- @T('New') %></a>
 
 <% if !_.isEmpty(@notification_channels) && !App.Config.get('system_online_service'): %>
   <h2><%- @T('Email Notification') %></h2>
   <% for channel in @notification_channels: %>
     <div class="action" data-id="<%- channel.id %>">
-      <div class="action-flow">
-        <div class="action-block">
+      <div class="action-flow" style="width: 100%;">
+      <div class="action-block" style="width: 50%;">
 
           <%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %>:<br>
           <a class="js-editNotificationOutbound" href="#">
@@ -204,46 +139,15 @@
           <% end %>
 
         </div>
+        <div class="action-block" style="width: 50%;">
+
+          <%- @T('Email Address') %>:
+          <ul class="list">
+            <li class="list-item"><%= @config.notification_sender %>
+          </ul>
+
+        </div>
       </div>
     </div>
   <% end %>
 <% end %>
-
-<!--
-<% if !_.isEmpty(@notification_channels) && !App.Config.get('system_online_service'): %>
-  <table class="table table-hover user-list">
-    <thead>
-      <tr>
-        <th><%- @T('Outbound') %></th>
-      </tr>
-    </thead>
-    <tbody>
-    <% for channel in @notification_channels: %>
-      <tr data-id="<%- channel.id %>">
-        <td class="noTruncate">
-          <div class="horizontal">
-            <%- @Icon('status', channel.status_out + " inline") %>
-            <a class="flex js-editNotificationOutbound" href="#">
-              <% if channel.options.outbound && channel.options.outbound.options: %>
-                <%= channel.options.outbound.options.user %><br>
-                <%= channel.options.outbound.options.host %>
-              <% end %>
-              (<%= channel.options.outbound.adapter %>)
-            </a>
-          </div>
-      </tr>
-      <% if channel.status_in is 'error': %>
-      <tr>
-        <td colspan="1"><%= channel.last_log_in %></td>
-      </tr>
-      <% end %>
-      <% if channel.status_out is 'error': %>
-      <tr>
-        <td colspan="1"><%= channel.last_log_out %></td>
-      </tr>
-      <% end %>
-    <% end %>
-    </tbody>
-  </table>
-<% end %>
--->

+ 1 - 14
app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco

@@ -14,20 +14,7 @@
     <div class="modal-body">
       <div class="wizard-body vertical justified">
         <div class="alert alert--danger hide" role="alert"></div>
-        <fieldset>
-          <div class="form-group">
-            <label><%- @T('Full Name') %></label>
-            <input type="text" class="form-control" value="" name="realname" placeholder="<%- @Ti('Organization Support') %>" required>
-          </div>
-          <div class="form-group">
-            <label><%- @T('Email') %></label>
-            <input type="email" class="form-control" value="" name="email" placeholder="<%- @Ti('support@example.com') %>" required autocomplete="off">
-          </div>
-          <div class="form-group">
-            <label><%- @T('Password') %></label>
-            <input type="password" class="form-control" name="password" value="" required autocomplete="new-password">
-          </div>
-        </fieldset>
+        <div class="base-settings"></div>
       </div>
     </div>
     <div class="modal-footer">

+ 33 - 1
app/controllers/channels_controller.rb

@@ -5,6 +5,29 @@ class ChannelsController < ApplicationController
 
 =begin
 
+Resource:
+POST /api/v1/channels/group/{id}.json
+
+Response:
+{}
+
+Test:
+curl http://localhost/api/v1/group/channels.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST '{group_id:123}'
+
+=end
+
+  def group_update
+    return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    return if !check_access
+
+    channel = Channel.find(params[:id])
+    channel.group_id = params[:group_id]
+    channel.save
+    render json: {}
+  end
+
+=begin
+
 Resource:
 DELETE /api/v1/channels/{id}.json
 
@@ -64,6 +87,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
       not_used_email_address_ids: not_used_email_address_ids,
       channel_driver: {
         email: EmailHelper.available_driver,
+      },
+      config: {
+        notification_sender: Setting.get('notification_sender'),
       }
     }
   end
@@ -144,6 +170,11 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
       return
     end
 
+    # fallback
+    if !params[:group_id]
+      params[:group_id] = Group.first.id
+    end
+
     # update account
     if channel_id
       channel = Channel.find(channel_id)
@@ -152,6 +183,7 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
           inbound: params[:inbound],
           outbound: params[:outbound],
         },
+        group_id: params[:group_id],
         last_log_in: nil,
         last_log_out: nil,
         status_in: 'ok',
@@ -168,12 +200,12 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
         inbound: params[:inbound],
         outbound: params[:outbound],
       },
+      group_id: params[:group_id],
       last_log_in: nil,
       last_log_out: nil,
       status_in: 'ok',
       status_out: 'ok',
       active: true,
-      group_id: Group.first.id,
     )
 
     # remember address && set channel for email address

+ 1 - 0
config/routes/channel.rb

@@ -10,6 +10,7 @@ Zammad::Application.routes.draw do
   match api_path + '/channels/email_notification',    to: 'channels#email_notification',  via: :post
 
   # channels
+  match api_path + '/channels/group/:id',             to: 'channels#group_update', via: :post
   match api_path + '/channels/:id',                   to: 'channels#destroy', via: :delete
 
 end