Improved table view and added check of name presence of objects.

This commit is contained in:
Martin Edenhofer 2012-10-14 23:00:33 +02:00
parent cf6340a212
commit d0a0ebdbc5
21 changed files with 94 additions and 48 deletions

View file

@ -78,7 +78,7 @@ class App.Controller extends Spine.Controller
table: (data) ->
overview = data.overview || data.model.configure_overview || []
attributes = data.attributes || data.model.configure_attributes
attributes = data.attributes || data.model.configure_attributes || {}
header = data.header
# define normal header
@ -123,42 +123,18 @@ class App.Controller extends Spine.Controller
# check if info for each col. is already there
for row in dataTypesForCols
# check if info is a object
if typeof object[row.name] is 'object'
if !object[row.name]
object[row.name] = {
name: '-',
}
# if no content exists, try firstname/lastname
if !object[row.name]['name']
if object[row.name]['realname']
object[row.name]['name'] = object[row.name]['realname']
# if info isnt a object, create one
else if typeof object[row.name] isnt 'object'
object[row.name] = {
name: object[row.name],
}
# fallback if it's something else
else
object[row.name] = {
name: '????',
}
# execute callback on content
if row.callback
object[row.name]['name'] = row.callback( object[row.name]['name'] )
object[row.name] = row.callback( object[row.name] )
# lookup relation
if !object[row.name]['name']
if !object[row.name]
rowWithoutId = row.name + '_id'
for attribute in attributes
if rowWithoutId is attribute.name
if attribute.relation && App[attribute.relation]
record = App.Collection.find( attribute.relation, object[rowWithoutId] )
object[row.name]['name'] = record.name
object[row.name] = record.name
@log 'table', 'header', header, 'overview', dataTypesForCols, 'objects', objects
table = App.view('generic/table')(

View file

@ -126,6 +126,9 @@ class App.ChannelEmailFilterEdit extends App.ControllerModal
@formValidate( form: e.target, errors: errors )
return false
# disable form
@formDisable(e)
# save object
object.save(
success: =>
@ -215,6 +218,9 @@ class App.ChannelEmailAddressEdit extends App.ControllerModal
@formValidate( form: e.target, errors: errors )
return false
# disable form
@formDisable(e)
# save object
object.save(
success: =>
@ -304,6 +310,9 @@ class App.ChannelEmailSignatureEdit extends App.ControllerModal
@formValidate( form: e.target, errors: errors )
return false
# disable form
@formDisable(e)
# save object
object.save(
success: =>
@ -326,7 +335,7 @@ class App.ChannelEmailInbound extends App.Controller
render: =>
channels = App.Channel.all()
@log 'llllll', channels
html = $('<div></div>')
data = []
for channel in channels
@ -334,6 +343,7 @@ class App.ChannelEmailInbound extends App.Controller
channel.host = channel.options['host']
channel.user = channel.options['user']
data.push channel
@log 'llllll222', data
table = @table(
header: ['Host', 'User', 'Adapter', 'Active'],
@ -374,7 +384,7 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
]
if @object
@html App.view('generic/admin/edit')(
head: 'Channel'
head: 'Email Channel'
)
@form = new App.ControllerForm(
el: @el.find('#object_edit'),
@ -383,7 +393,7 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
)
else
@html App.view('generic/admin/new')(
head: 'Channel'
head: 'Email Channel'
)
@form = new App.ControllerForm(
el: @el.find('#object_new'),
@ -409,6 +419,7 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
password: params['password'],
ssl: params['ssl'],
},
active: params['active'],
)
# validate form
@ -420,6 +431,9 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
@formValidate( form: e.target, errors: errors )
return false
# disable form
@formDisable(e)
# save object
object.save(
success: =>

View file

@ -13,16 +13,35 @@ class App.Model extends Spine.Model
return name
return '???'
displayNameLong: ->
return @name if @name
if @firstname
name = @firstname
if @lastname
if name
name = name + ' '
name = name + @lastname
if @note
name = "#{name} (#{@note})"
return name
return '???'
@validate: ( data = {} ) ->
return if !data['model'].configure_attributes
# check attributes/each attribute of object
errors = {}
for attribute in data['model'].configure_attributes
if !attribute.readonly
# check required
if 'null' of attribute && !attribute[null] && !data['params'][attribute.name]
errors[attribute.name] = 'is required'
# only if attribute is not read only
if !attribute.readonly
# check required // if null is defined && null is false
if 'null' of attribute && !attribute[null]
# key exists not in hash || value is '' || value is undefined
if !( attribute.name of data['params'] ) || data['params'][attribute.name] is '' || data['params'][attribute.name] is undefined
errors[attribute.name] = 'is required'
# check confirm password
if attribute.type is 'password' && data['params'][attribute.name] && "#{attribute.name}_confirm" of data['params']

View file

@ -16,4 +16,5 @@ class App.Group extends App.Model
]
@configure_overview = [
'name',
'active'
]

View file

@ -10,5 +10,7 @@ class App.Organization extends App.Model
{ name: 'active', display: 'Active', tag: 'boolean', note: 'boolean', 'default': true, 'null': false, 'class': 'span4' },
]
@configure_overview = [
'name', 'shared',
'name',
'shared',
'active',
]

View file

@ -26,5 +26,5 @@ class App.User extends App.Model
]
@configure_overview = [
# 'login', 'firstname', 'lastname', 'email', 'updated_at',
'login', 'firstname', 'lastname'
'login', 'firstname', 'lastname', 'active',
]

View file

@ -16,18 +16,24 @@
<% position = 0 %>
<% for object in @objects: %>
<% position++ %>
<tr class="item" data-id="<%= object.id %>" data-position="<%= position %>" >
<tr class="item <% if object.active is false: %>not-active<% end %>" data-id="<%= object.id %>" data-position="<%= position %>" >
<% if @checkbox: %>
<td>
<input type="checkbox" value="<%= object.id %>" name="bulk"/>
</td>
<% end %>
<% for row in @overview: %>
<% displayName = '' %>
<% if typeof object[row.name] is 'object': %>
<% displayName = object[row.name].displayNameLong() %>
<% else: %>
<% displayName = object[row.name] %>
<% end %>
<td>
<% if row.link: %>
<a href="#" data-type="edit"><%= object[row.name]['name'] %></a>
<a href="#" data-type="edit"><%= displayName %></a>
<% else: %>
<span <% if row.class: %>class="<%= row.class %>"<% end %> <% if row.data && row.data.id: %>data-id="<%= object[row.name]['id'] %>"<% end %>><% if row.translate: %><%- T(object[row.name]['name']) %><% else if row.callback: %><%- object[row.name]['name'] %><% else: %><%= object[row.name]['name'] %><% end %></span>
<span <% if row.class: %>class="<%= row.class %>"<% end %> <% if row.data && row.data.id: %>data-id="<%= object[row.name].id %>"<% end %>><% if row.translate: %><%- T(displayName) %><% else if row.callback: %><%- displayName %><% else: %><%= displayName %><% end %></span>
<% end %>
</td>
<% end %>

View file

@ -239,6 +239,14 @@ footer {
text-decoration: line-through;
}
.not-active {
text-decoration: line-through;
}
.not-active a {
color: #bbb;
}
.customer-info {
width:86%;
padding-top: 5px;

View file

@ -251,7 +251,7 @@ class Channel::Twitter2
)
end
def send(attr, notification = false)
# logger.debug('tweeeeettttt!!!!!!')
channel = Channel.where( :area => 'Twitter::Inbound', :active => true ).first
@ -272,7 +272,7 @@ class Channel::Twitter2
# puts dm.inspect
return dm
end
if atts[:type] == 'twitter status'
message = client.update(
atts[:body].to_s,

View file

@ -3,4 +3,6 @@ class EmailAddress < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :realname, :presence => true
validates :email, :presence => true
end

View file

@ -5,4 +5,5 @@ class Group < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end

View file

@ -173,7 +173,9 @@ class Link < ActiveRecord::Base
end
class Link::Type < ActiveRecord::Base
validates :name, :presence => true
end
class Link::Object < ActiveRecord::Base
validates :name, :presence => true
end

View file

@ -1,3 +1,4 @@
class Organization < ApplicationModel
has_and_belongs_to_many :users
validates :name, :presence => true
end

View file

@ -3,4 +3,5 @@ class Overview < ApplicationModel
store :order
store :meta
store :view
validates :name, :presence => true
end

View file

@ -1,4 +1,5 @@
class PostmasterFilter < ApplicationModel
store :perform
store :match
validates :name, :presence => true
end

View file

@ -3,4 +3,5 @@ class Role < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end

View file

@ -3,4 +3,5 @@ class Signature < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end

View file

@ -1,10 +1,11 @@
require 'digest/md5'
class Store < ActiveRecord::Base
store :preferences
belongs_to :store_object, :class_name => 'Store::Object'
belongs_to :store_file, :class_name => 'Store::File'
store :preferences
belongs_to :store_object, :class_name => 'Store::Object'
belongs_to :store_file, :class_name => 'Store::File'
validates :filename, :presence => true
def self.add(data)
data = data.stringify_keys
@ -71,10 +72,12 @@ class Store < ActiveRecord::Base
class Object < ActiveRecord::Base
validates :name, :presence => true
end
class File < ActiveRecord::Base
before_validation :add_md5
validates :name, :presence => true
private
def add_md5

View file

@ -1,3 +1,4 @@
class Template < ApplicationModel
store :options
store :options
validates :name, :presence => true
end

View file

@ -403,12 +403,14 @@ class Ticket < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end
class StateType < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end
class State < ApplicationModel
@ -416,5 +418,6 @@ class Ticket < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
validates :name, :presence => true
end
end

View file

@ -173,8 +173,11 @@ class Ticket::Article < ApplicationModel
end
class Sender < ApplicationModel
validates :name, :presence => true
end
class Type < ApplicationModel
validates :name, :presence => true
end
end