Added notification management.
This commit is contained in:
parent
8a9ddb6d5d
commit
e780d0d0af
2 changed files with 195 additions and 0 deletions
|
@ -0,0 +1,149 @@
|
|||
class Index extends App.Controller
|
||||
events:
|
||||
'submit form': 'update'
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
return if !@authenticate()
|
||||
@render()
|
||||
|
||||
render: =>
|
||||
|
||||
# matrix
|
||||
config = {}
|
||||
config['matrix'] = {}
|
||||
config['matrix']['create'] = {}
|
||||
config['matrix']['create']['name'] = 'new Ticket'
|
||||
config['matrix']['create']['criteria'] = {}
|
||||
config['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
config['matrix']['create']['criteria']['owned_by_nobody'] = true
|
||||
config['matrix']['create']['criteria']['no'] = false
|
||||
config['matrix']['create']['channel'] = {}
|
||||
config['matrix']['create']['channel']['email'] = true
|
||||
config['matrix']['create']['channel']['online'] = false
|
||||
config['matrix']['update'] = {}
|
||||
config['matrix']['update']['name'] = 'Ticket update'
|
||||
config['matrix']['update']['criteria'] = {}
|
||||
config['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
config['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
config['matrix']['update']['criteria']['no'] = false
|
||||
config['matrix']['update']['channel'] = {}
|
||||
config['matrix']['update']['channel']['email'] = true
|
||||
config['matrix']['update']['channel']['online'] = false
|
||||
config['matrix']['move_into'] = {}
|
||||
config['matrix']['move_into']['name'] = 'Ticket moved into my group'
|
||||
config['matrix']['move_into']['criteria'] = {}
|
||||
config['matrix']['move_into']['criteria']['owned_by_me'] = true
|
||||
config['matrix']['move_into']['criteria']['owned_by_nobody'] = true
|
||||
config['matrix']['move_into']['criteria']['no'] = false
|
||||
config['matrix']['move_into']['channel'] = {}
|
||||
config['matrix']['move_into']['channel']['email'] = true
|
||||
config['matrix']['move_into']['channel']['online'] = false
|
||||
config['matrix']['escalation'] = {}
|
||||
config['matrix']['escalation']['name'] = 'Ticket escalation'
|
||||
config['matrix']['escalation']['criteria'] = {}
|
||||
config['matrix']['escalation']['criteria']['owned_by_me'] = true
|
||||
config['matrix']['escalation']['criteria']['owned_by_nobody'] = true
|
||||
config['matrix']['escalation']['criteria']['no'] = false
|
||||
config['matrix']['escalation']['channel'] = {}
|
||||
config['matrix']['escalation']['channel']['email'] = true
|
||||
config['matrix']['escalation']['channel']['online'] = false
|
||||
|
||||
user_config = @Session.get('preferences').notification_config
|
||||
if user_config
|
||||
config = $.extend(true, {}, config, user_config)
|
||||
console.log('oo', config)
|
||||
# groups
|
||||
groups = []
|
||||
group_ids = @Session.get('group_ids')
|
||||
if group_ids
|
||||
for group_id in group_ids
|
||||
group = App.Group.find(group_id)
|
||||
groups.push group
|
||||
|
||||
@html App.view('profile/notification')( groups: groups, config: config )
|
||||
|
||||
update: (e) =>
|
||||
|
||||
#notification_config
|
||||
e.preventDefault()
|
||||
params = {}
|
||||
params.notification_config = {}
|
||||
|
||||
form_params = @formParam(e.target)
|
||||
console.log('P',form_params)
|
||||
for key, value of form_params
|
||||
if key is 'group_ids'
|
||||
if typeof value isnt 'object'
|
||||
value = [value]
|
||||
params.notification_config[key] = value
|
||||
else
|
||||
area = key.split('.')
|
||||
if value is 'true'
|
||||
value = true
|
||||
if area[0] is 'matrix'
|
||||
if area[2] is 'criteria'
|
||||
if !params.notification_config[area[0]]
|
||||
params.notification_config[area[0]] = {}
|
||||
if !params.notification_config[area[0]][area[1]]
|
||||
params.notification_config[area[0]][area[1]] = {}
|
||||
if !params.notification_config[area[0]][area[1]][area[2]]
|
||||
params.notification_config[area[0]][area[1]][area[2]] = {
|
||||
owned_by_me: false
|
||||
owned_by_nobody: false
|
||||
no: false
|
||||
}
|
||||
params.notification_config[area[0]][area[1]][area[2]][area[3]] = value
|
||||
if area[2] is 'channel'
|
||||
if !params.notification_config[area[0]]
|
||||
params.notification_config[area[0]] = {}
|
||||
if !params.notification_config[area[0]][area[1]]
|
||||
params.notification_config[area[0]][area[1]] = {}
|
||||
if value is 'online'
|
||||
params.notification_config[area[0]][area[1]][area[2]] = {
|
||||
email: false
|
||||
online: true
|
||||
}
|
||||
else
|
||||
params.notification_config[area[0]][area[1]][area[2]] = {
|
||||
email: true
|
||||
online: false
|
||||
}
|
||||
console.log('P2',params)
|
||||
|
||||
@formDisable(e)
|
||||
|
||||
# get data
|
||||
@ajax(
|
||||
id: 'preferences'
|
||||
type: 'PUT'
|
||||
url: @apiPath + '/users/preferences'
|
||||
data: JSON.stringify({user:params})
|
||||
processData: true
|
||||
success: @success
|
||||
error: @error
|
||||
)
|
||||
|
||||
success: (data, status, xhr) =>
|
||||
App.User.full(
|
||||
App.Session.get( 'id' ),
|
||||
=>
|
||||
App.Event.trigger( 'ui:rerender' )
|
||||
App.Event.trigger( 'ui:page:rerender' )
|
||||
@notify(
|
||||
type: 'success'
|
||||
msg: App.i18n.translateContent( 'Successfully!' )
|
||||
)
|
||||
,
|
||||
true
|
||||
)
|
||||
|
||||
error: (xhr, status, error) =>
|
||||
@render()
|
||||
data = JSON.parse( xhr.responseText )
|
||||
@notify(
|
||||
type: 'error'
|
||||
msg: App.i18n.translateContent( data.message )
|
||||
)
|
||||
|
||||
App.Config.set( 'Notifications', { prio: 2600, name: 'Notifications', parent: '#profile', target: '#profile/notifications', role: ['Agent'], controller: Index }, 'NavBarProfile' )
|
|
@ -0,0 +1,46 @@
|
|||
<h2><%- @T( 'Notifications' ) %></h2>
|
||||
|
||||
<form>
|
||||
|
||||
<h3><%- @T( 'Matrix' ) %></h3>
|
||||
|
||||
<div class="settings-entry">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><%- @T('On') %></td><td colspan="3"><%- @T('Criteria') %></td><td colspan="2"><%- @T('Channel') %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><%- @T('Owned by me') %></td><td><%- @T('Owned by nobody') %></td><td><%- @T('no criteria') %></td><td><%- @T('Email & Online') %></td><td><%- @T('Online') %></td>
|
||||
</tr>
|
||||
<% if @config.matrix: %>
|
||||
<% for key, value of @config.matrix: %>
|
||||
<tr>
|
||||
<td><%= value.name %></td>
|
||||
<td><input type="checkbox" name="matrix.<%= key %>.criteria.owned_by_me" value="true" <% if value.criteria.owned_by_me: %>checked<% end %>/></td>
|
||||
<td><input type="checkbox" name="matrix.<%= key %>.criteria.owned_by_nobody" value="true" <% if value.criteria.owned_by_nobody: %>checked<% end %>/></td>
|
||||
<td><input type="checkbox" name="matrix.<%= key %>.criteria.no" value="true" <% if value.criteria.no: %>checked<% end %>/></td>
|
||||
<td><input type="radio" name="matrix.<%= key %>.channel" value="email" <% if value.channel.email: %>checked<% end %>/></td>
|
||||
<td><input type="radio" name="matrix.<%= key %>.channel" value="online" <% if value.channel.online: %>checked<% end %>/></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<h3><%- @T( 'Groups' ) %></h3>
|
||||
|
||||
<div class="settings-entry">
|
||||
<table class="table">
|
||||
<% if @groups: %>
|
||||
<% for group in @groups: %>
|
||||
<tr>
|
||||
<td><%= group.displayName() %></td><td><input type="checkbox" name="group_ids" value="<%= group.id %>" checked/></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn--primary"><%- @T( 'Submit' ) %></button>
|
||||
</form>
|
Loading…
Reference in a new issue