Improved @_fillUp of application model (get references based on confgure_attributes).

This commit is contained in:
Martin Edenhofer 2014-06-17 21:49:41 +02:00
parent 94429a38c1
commit 6a59aff4b6
9 changed files with 77 additions and 110 deletions

View file

@ -287,7 +287,21 @@ class App.Model extends Spine.Model
return true
@_fillUp: (data) ->
# nothing
# fill up via relations
if App[ @className ].configure_attributes
for attribute in App[ @className ].configure_attributes
if attribute.relation
if App[ attribute.relation ]
withoutId = attribute.name.substr( 0, attribute.name.length - 3 )
if attribute.name.substr( attribute.name.length - 3, attribute.name.length ) is '_id'
if data[attribute.name]
if App[ attribute.relation ].exists( data[attribute.name] )
item = App[ attribute.relation ].find( data[attribute.name] )
item = App[ attribute.relation ]._fillUp(item)
data[ withoutId ] = item
else
console.log("ERROR, cant find App.#{ attribute.relation }.find(#{ data[attribute.name] }) for '#{ data.constructor.className }' #{ data.displayName() }")
data
@search: (params) ->

View file

@ -17,10 +17,3 @@ class App.Channel extends App.Model
@configure_overview = [
'adapter', 'options::host', 'options::user', 'group'
]
@_fillUp: (data) ->
# group
data.group = App.Group.find( data.group_id )
data

View file

@ -131,8 +131,11 @@ class App.Overview extends App.Model
owner: 'Owner'
class: 'span4'
},
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', note: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'active', display: 'Active', tag: 'boolean', note: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
@configure_delete = true
@configure_overview = [

View file

@ -4,13 +4,17 @@ class App.PostmasterFilter extends App.Model
@url: @apiPath + '/postmaster_filters'
@configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 250, 'null': false, 'class': 'span4' },
{ name: 'channel', display: 'Channel', type: 'input', readonly: 1 },
{ name: 'match', display: 'Match all of the following', tag: 'postmaster_match' },
{ name: 'perform', display: 'Perform action of the following', tag: 'postmaster_set' },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true, 'class': 'span4' },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 250, 'null': false },
{ name: 'channel', display: 'Channel', type: 'input', readonly: 1 },
{ name: 'match', display: 'Match all of the following', tag: 'postmaster_match' },
{ name: 'perform', display: 'Perform action of the following', tag: 'postmaster_set' },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
@configure_delete = true
@configure_overview = [

View file

@ -3,10 +3,13 @@ class App.Role extends App.Model
@extend Spine.Model.Ajax
@url: @apiPath + '/roles'
@configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false, 'class': 'span4' },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true, 'class': 'span4' },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, null: true },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, null: false },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
@configure_overview = [
'name',

View file

@ -4,11 +4,14 @@ class App.Signature extends App.Model
@url: @apiPath + '/signatures'
@configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false, 'class': 'span4' },
{ name: 'body', display: 'Text', tag: 'textarea', limit: 250, 'null': true, 'class': 'span4', rows: 10 },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true, 'class': 'span4' },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false, 'class': 'span4' },
{ name: 'body', display: 'Text', tag: 'textarea', limit: 250, 'null': true, 'class': 'span4', rows: 10 },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true, 'class': 'span4' },
{ name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
@configure_overview = [
'name',

View file

@ -3,12 +3,12 @@ class App.Sla extends App.Model
@extend Spine.Model.Ajax
@url: @apiPath + '/slas'
@configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'span4' },
{ name: 'first_response_time', display: 'First Response Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' },
{ name: 'update_time', display: 'Update Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' },
{ name: 'close_time', display: 'Solution Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' },
{ name: 'condition', display: 'Conditions where SLA is used', tag: 'ticket_attribute_selection', null: true, class: 'span4' },
{ name: 'timezone', display: 'Timezone', tag: 'timezone', null: true, class: 'span4' },
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'first_response_time', display: 'First Response Time', tag: 'input', type: 'text', limit: 100, null: true, note: 'In minutes, only business times are counted.' },
{ name: 'update_time', display: 'Update Time', tag: 'input', type: 'text', limit: 100, null: true, note: 'In minutes, only business times are counted.' },
{ name: 'close_time', display: 'Solution Time', tag: 'input', type: 'text', limit: 100, null: true, note: 'In minutes, only business times are counted.' },
{ name: 'condition', display: 'Conditions where SLA is used', tag: 'ticket_attribute_selection', null: true },
{ name: 'timezone', display: 'Timezone', tag: 'timezone', null: true },
{
name: 'data'
display: 'Business Times'
@ -30,10 +30,12 @@ class App.Sla extends App.Model
priority: 'Priority'
group: 'Group'
owner: 'Owner'
class: 'span4'
},
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
{ name: 'active', display: 'Active', tag: 'boolean', note: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
{ name: 'active', display: 'Active', tag: 'boolean', note: 'boolean', 'default': true, 'null': false },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
@configure_delete = true
@configure_overview = [

View file

@ -4,11 +4,11 @@ class App.Ticket extends App.Model
@url: @apiPath + '/tickets'
@configure_attributes = [
{ name: 'number', display: '#', tag: 'input', type: 'text', limit: 100, null: true, read_only: true, style: 'width: 8%' },
{ name: 'customer_id', display: 'Customer', tag: 'input', type: 'text', limit: 100, null: false, class: 'span8', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', helpLink: '<a href="" class="customer_new">&raquo;</a>' },
{ name: 'organization_id', display: 'Organization', tagreadonly: 1 },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, limit: 100, null: false, class: 'span8', relation: 'Group', style: 'width: 10%' },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, limit: 100, null: true, class: 'span8', relation: 'User', style: 'width: 12%' },
{ name: 'title', display: 'Title', tag: 'input', type: 'text', limit: 100, null: false, class: 'span8' },
{ name: 'customer_id', display: 'Customer', tag: 'input', type: 'text', limit: 100, null: false, autocapitalize: false, relation: 'User' },
{ name: 'organization_id', display: 'Organization', relation: 'Organization', tagreadonly: 1 },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, limit: 100, null: false, relation: 'Group', style: 'width: 10%' },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, limit: 100, null: true, relation: 'User', style: 'width: 12%' },
{ name: 'title', display: 'Title', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'state_id', display: 'State', tag: 'select', multiple: false, null: false, relation: 'TicketState', default: 'new', class: 'medium', style: 'width: 12%' },
{ name: 'priority_id', display: 'Priority', tag: 'select', multiple: false, null: false, relation: 'TicketPriority', default: '2 normal', class: 'medium', style: 'width: 12%' },
{ name: 'last_contact', display: 'Last contact', type: 'time', null: true, style: 'width: 12%' },
@ -18,56 +18,11 @@ class App.Ticket extends App.Model
{ name: 'close_time', display: 'Close time', type: 'time', null: true, style: 'width: 12%' },
{ name: 'escalation_time', display: 'Escalation in', type: 'time', null: true, style: 'width: 12%', class: 'escalation' },
{ name: 'article_count', display: 'Article#', style: 'width: 12%' },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', style: 'width: 12%', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', style: 'width: 12%', readonly: 1 },
]
uiUrl: ->
'#ticket/zoom/' + @id
@_fillUp: (data) ->
# priority
data.priority = App.TicketPriority.find( data.priority_id )
# state
data.state = App.TicketState.find( data.state_id )
# group
data.group = App.Group.find( data.group_id )
# customer
if data.customer_id
if !App.User.exists( data.customer_id )
console.error("Can't find user for data.customer_id #{data.customer_id} for ticket #{data.id}")
else
data.customer = App.User.find( data.customer_id )
# organization_id
if data.organization_id
if !App.Organization.exists( data.organization_id )
console.error("Can't find user for data.organization_id #{data.organization_id} for ticket #{data.id}")
else
data.organization = App.Organization.find( data.organization_id )
# owner
if data.owner_id
if !App.User.exists( data.owner_id )
console.error("Can't find user for data.owner_id #{data.owner_id} for ticket #{data.id}")
else
data.owner = App.User.find( data.owner_id )
# add created & updated
if data.created_by_id
if !App.User.exists( data.created_by_id )
console.error("Can't find user for data.created_by_id #{data.created_by_id} for ticket #{data.id}")
else
data.created_by = App.User.find( data.created_by_id )
if data.updated_by_id
if !App.User.exists( data.updated_by_id )
console.error("Can't find user for data.updated_by_id #{data.updated_by_id} for ticket #{data.id}")
else
data.updated_by = App.User.find( data.updated_by_id )
data

View file

@ -3,15 +3,19 @@ class App.TicketArticle extends App.Model
@extend Spine.Model.Ajax
@url: @apiPath + '/ticket_articles'
@configure_attributes = [
{ name: 'ticket_id', display: 'TicketID', null: false, readonly: 1, },
{ name: 'from', display: 'From', tag: 'input', type: 'text', limit: 100, null: false, class: 'span8', },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span8', },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span8', },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span8', },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: false, class: 'span8', },
{ name: 'type_id', display: 'Type', tag: 'select', multiple: false, null: false, relation: 'TicketArticleType', default: '', class: 'medium' },
{ name: 'sender_id', display: 'Sender', tag: 'select', multiple: false, null: false, relation: 'TicketArticleSender', default: '', class: 'medium' },
{ name: 'internal', display: 'Visibility', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium' },
{ name: 'ticket_id', display: 'TicketID', null: false, readonly: 1, },
{ name: 'from', display: 'From', tag: 'input', type: 'text', limit: 100, null: false, },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: false, },
{ name: 'type_id', display: 'Type', tag: 'select', multiple: false, null: false, relation: 'TicketArticleType', default: '', class: 'medium' },
{ name: 'sender_id', display: 'Sender', tag: 'select', multiple: false, null: false, relation: 'TicketArticleSender', default: '', class: 'medium' },
{ name: 'internal', display: 'Visibility', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium' },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },
{ name: 'created_at', display: 'Created', type: 'time', readonly: 1 },
{ name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
]
uiUrl: ->
@ -20,20 +24,6 @@ class App.TicketArticle extends App.Model
objectDisplayName: ->
'Article'
@_fillUp: (data) ->
# add created & updated
if data.created_by_id
data.created_by = App.User.retrieve( data.created_by_id )
if data.updated_by_id
data.updated_by = App.User.retrieve( data.updated_by_id )
# add relations
data.type = App.TicketArticleType.find( data.type_id )
data.sender = App.TicketArticleSender.find( data.sender_id )
data
displayName: ->
if @subject
return @subject