Skip to content

Commit

Permalink
Initial Placetel integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
znuny-robo committed Oct 15, 2018
1 parent 402b28b commit 2711020
Show file tree
Hide file tree
Showing 12 changed files with 1,085 additions and 4 deletions.
158 changes: 158 additions & 0 deletions app/assets/javascripts/app/controllers/_integration/placetel.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
class Index extends App.ControllerIntegrationBase
featureIntegration: 'placetel_integration'
featureName: 'Placetel'
featureConfig: 'placetel_config'
description: [
['This service shows you contacts of incoming calls and a caller list in realtime.']
['Also caller id of outbound calls can be changed.']
]
events:
'click .js-select': 'selectAll'
'change .js-switch input': 'switch'

render: =>
super
new Form(
el: @$('.js-form')
)

new App.HttpLog(
el: @$('.js-log')
facility: 'placetel'
)

class Form extends App.Controller
events:
'submit form': 'update'
'click .js-inboundBlockCallerId .js-add': 'addInboundBlockCallerId'
'click .js-outboundRouting .js-add': 'addOutboundRouting'
'click .js-inboundBlockCallerId .js-remove': 'removeInboundBlockCallerId'
'click .js-outboundRouting .js-remove': 'removeOutboundRouting'

constructor: ->
super
@render()

currentConfig: ->
config = App.Setting.get('placetel_config')
if !config.outbound
config.outbound = {}
if !config.outbound.routing_table
config.outbound.routing_table = []
if !config.inbound
config.inbound = {}
if !config.inbound.block_caller_ids
config.inbound.block_caller_ids = []
config

setConfig: (value) ->
App.Setting.set('placetel_config', value, {notify: true})

render: =>
@config = @currentConfig()

@html App.view('integration/placetel')(
config: @config
placetel_token: App.Setting.get('placetel_token')
)

updateCurrentConfig: =>
config = @config
cleanupInput = @cleanupInput

# default caller_id
default_caller_id = @$('input[name=default_caller_id]').val()
config.outbound.default_caller_id = cleanupInput(default_caller_id)

# routing table
config.outbound.routing_table = []
@$('.js-outboundRouting .js-row').each(->
dest = cleanupInput($(@).find('input[name="dest"]').val())
caller_id = cleanupInput($(@).find('input[name="caller_id"]').val())
note = $(@).find('input[name="note"]').val()
config.outbound.routing_table.push {
dest: dest
caller_id: caller_id
note: note
}
)

# blocked caller ids
config.inbound.block_caller_ids = []
@$('.js-inboundBlockCallerId .js-row').each(->
caller_id = $(@).find('input[name="caller_id"]').val()
note = $(@).find('input[name="note"]').val()
config.inbound.block_caller_ids.push {
caller_id: cleanupInput(caller_id)
note: note
}
)

@config = config

update: (e) =>
e.preventDefault()
@updateCurrentConfig()
@setConfig(@config)

cleanupInput: (value) ->
return value if !value
value.replace(/\s/g, '').trim()

addInboundBlockCallerId: (e) =>
e.preventDefault()
@updateCurrentConfig()
element = $(e.currentTarget).closest('tr')
caller_id = element.find('input[name="caller_id"]').val()
note = element.find('input[name="note"]').val()
return if _.isEmpty(caller_id) || _.isEmpty(note)
@config.inbound.block_caller_ids.push {
caller_id: @cleanupInput(caller_id)
note: note
}
@render()

addOutboundRouting: (e) =>
e.preventDefault()
@updateCurrentConfig()
element = $(e.currentTarget).closest('tr')
dest = @cleanupInput(element.find('input[name="dest"]').val())
caller_id = @cleanupInput(element.find('input[name="caller_id"]').val())
note = element.find('input[name="note"]').val()
return if _.isEmpty(caller_id) || _.isEmpty(dest) || _.isEmpty(note)
@config.outbound.routing_table.push {
dest: dest
caller_id: caller_id
note: note
}
@render()

removeInboundBlockCallerId: (e) =>
e.preventDefault()
@updateCurrentConfig()
element = $(e.currentTarget).closest('tr')
element.remove()
@updateCurrentConfig()

removeOutboundRouting: (e) =>
e.preventDefault()
@updateCurrentConfig()
element = $(e.currentTarget).closest('tr')
element.remove()
@updateCurrentConfig()

class State
@current: ->
App.Setting.get('placetel_integration')

App.Config.set(
'IntegrationPlacetel'
{
name: 'Placetel'
target: '#system/integration/placetel'
description: 'VoIP service provider with realtime push.'
controller: Index
state: State
}
'NavBarIntegrations'
)
1 change: 1 addition & 0 deletions app/assets/javascripts/app/controllers/cti.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class App.CTI extends App.Controller
featureActive: =>
return true if @Config.get('sipgate_integration')
return true if @Config.get('cti_integration')
return true if @Config.get('placetel_integration')
false

render: ->
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/app/views/integration/cti.jst.eco
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<% end %>
<tr>
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my onw note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
Expand Down Expand Up @@ -70,7 +70,7 @@
<tr>
<td class="settings-list-control-cell"><input name="dest" value="" placeholder="49* or 3230123456789" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my onw note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
Expand Down
97 changes: 97 additions & 0 deletions app/assets/javascripts/app/views/integration/placetel.jst.eco
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<form>

<h2>Placetel <%- @T('Settings') %></h2>

<p><%- @T('You need to configure the Zammad endpoints in the %s', 'Placetel') %>:<p>

<div class="settings-entry">
<table class="settings-list" style="width: 100%;">
<thead>
<tr>
<th width="20%"><%- @T('Type') %>
<th width="80%"><%- @T('URL') %>
</thead>
<tbody>
<tr>
<td class="settings-list-row-control"><%- @T('Endpoint') %>
<td class="settings-list-control-cell"><input type="url" class="form-control form-control--small js-select" readonly value="<%- @C('http_type') %>://<%- @C('fqdn') %>/api/v1/placetel/<%= @placetel_token %>">
</tbody>
</table>
</div>

<h2><%- @T('Inbound') %></h2>

<p><%- @T('Blocked caller ids based on sender caller id.') %>

<div class="settings-entry">
<table class="settings-list js-inboundBlockCallerId" style="width: 100%;">
<thead>
<tr>
<th width="50%"><%- @T('Caller id to block') %>
<th width="40%"><%- @T('Note') %>
<th width="10%"><%- @T('Action') %>
</thead>
<tbody>
<% for row in @config.inbound.block_caller_ids: %>
<tr class="js-row">
<td class="settings-list-control-cell"><input name="caller_id" value="<%= row.caller_id %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="<%= row.note %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text js-remove"><%- @Icon('trash') %> <%- @T('Remove') %></div>
<% end %>
<tr>
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
</div>
<!-- disabled until api is supporting it
<h2><%- @T('Outbound') %></h2>

<p><%- @T('Set caller id of outbound calls based on destination caller id.') %>

<div class="settings-entry js-outboundRouting">
<table class="settings-list" style="width: 100%;">
<thead>
<tr>
<th width="30%"><%- @T('Destination caller id') %>
<th width="30%"><%- @T('Set outbound caller id') %>
<th width="30%"><%- @T('Note') %>
<th width="10%"><%- @T('Action') %>
</thead>
<tbody>
<% for row in @config.outbound.routing_table: %>
<tr class="js-row">
<td class="settings-list-control-cell"><input name="dest" value="<%= row.dest %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="caller_id" value="<%= row.caller_id %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="<%= row.note %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text js-remove"><%- @Icon('trash') %> <%- @T('Remove') %></div>
<% end %>
<tr>
<td class="settings-list-control-cell"><input name="dest" value="" placeholder="49* or 3230123456789" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
</div>

<p><%- @T('Default caller id.') %>

<div class="settings-entry">
<table class="settings-list" style="width: 100%;">
<thead>
<tr>
<th width="50%"><%- @T('Default caller id') %>
<th width="50%"><%- @T('Note') %>
</thead>
<tbody>
<tr>
<td class="settings-list-control-cell"><input name="default_caller_id" value="<%= @config.outbound.default_caller_id %>" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><%- @T('Default caller id for outbound calls.') %>
</tbody>
</table>
</div>
-->
<button type="submit" class="btn btn--primary js-submit"><%- @T('Save') %></button>
</form>
4 changes: 2 additions & 2 deletions app/assets/javascripts/app/views/integration/sipgate.jst.eco
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<% end %>
<tr>
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my onw note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
Expand Down Expand Up @@ -73,7 +73,7 @@
<tr>
<td class="settings-list-control-cell"><input name="dest" value="" placeholder="49* or 3230123456789" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="caller_id" value="" placeholder="4930609854189" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my onw note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-control-cell"><input name="note" value="" placeholder="<%- @Ti('my own note') %>" class="form-control form-control--small js-summary">
<td class="settings-list-row-control"><div class="btn btn--text btn--create js-add"><%- @Icon('plus-small') %> <%- @T('Add') %></div>
</tbody>
</table>
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/cti_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def index
name: 'sipgate.io',
enabled: Setting.get('sipgate_integration'),
url: '#system/integration/sipgate',
},
{
name: 'Placetel',
enabled: Setting.get('placetel_integration'),
url: '#system/integration/placetel',
}
]

Expand Down
Loading

0 comments on commit 2711020

Please sign in to comment.