From d0a0ebdbc57ab296edba338e395e3176f5dab311 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 14 Oct 2012 23:00:33 +0200 Subject: [PATCH] Improved table view and added check of name presence of objects. --- .../_application_controller.js.coffee | 32 +++---------------- .../app/controllers/_channel/email.js.coffee | 20 ++++++++++-- .../app/models/application_model.js.coffee | 29 ++++++++++++++--- .../javascripts/app/models/group.js.coffee | 1 + .../app/models/organization.js.coffee | 4 ++- .../javascripts/app/models/user.js.coffee | 2 +- .../app/views/generic/table.jst.eco | 12 +++++-- app/assets/stylesheets/zzz.css | 8 +++++ app/models/channel/twitter2.rb | 4 +-- app/models/email_address.rb | 2 ++ app/models/group.rb | 1 + app/models/link.rb | 2 ++ app/models/organization.rb | 1 + app/models/overview.rb | 1 + app/models/postmaster_filter.rb | 1 + app/models/role.rb | 1 + app/models/signature.rb | 1 + app/models/store.rb | 11 ++++--- app/models/template.rb | 3 +- app/models/ticket.rb | 3 ++ app/models/ticket/article.rb | 3 ++ 21 files changed, 94 insertions(+), 48 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 257aa6716..1c7916319 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -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')( diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index 8bda184ad..d0def8ed8 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -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 = $('
') 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: => diff --git a/app/assets/javascripts/app/models/application_model.js.coffee b/app/assets/javascripts/app/models/application_model.js.coffee index c2db5ccb6..94aa6b0a5 100644 --- a/app/assets/javascripts/app/models/application_model.js.coffee +++ b/app/assets/javascripts/app/models/application_model.js.coffee @@ -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'] diff --git a/app/assets/javascripts/app/models/group.js.coffee b/app/assets/javascripts/app/models/group.js.coffee index 9161cd447..305c4e091 100644 --- a/app/assets/javascripts/app/models/group.js.coffee +++ b/app/assets/javascripts/app/models/group.js.coffee @@ -16,4 +16,5 @@ class App.Group extends App.Model ] @configure_overview = [ 'name', + 'active' ] diff --git a/app/assets/javascripts/app/models/organization.js.coffee b/app/assets/javascripts/app/models/organization.js.coffee index 44d8f7673..426a8f82d 100644 --- a/app/assets/javascripts/app/models/organization.js.coffee +++ b/app/assets/javascripts/app/models/organization.js.coffee @@ -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', ] diff --git a/app/assets/javascripts/app/models/user.js.coffee b/app/assets/javascripts/app/models/user.js.coffee index 8f4dbca9f..d5d49744c 100644 --- a/app/assets/javascripts/app/models/user.js.coffee +++ b/app/assets/javascripts/app/models/user.js.coffee @@ -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', ] diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index c50f3aa29..895b2f63c 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -16,18 +16,24 @@ <% position = 0 %> <% for object in @objects: %> <% position++ %> - + <% if @checkbox: %> <% end %> <% for row in @overview: %> + <% displayName = '' %> + <% if typeof object[row.name] is 'object': %> + <% displayName = object[row.name].displayNameLong() %> + <% else: %> + <% displayName = object[row.name] %> + <% end %> <% if row.link: %> - <%= object[row.name]['name'] %> + <%= displayName %> <% else: %> - 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 %> + 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 %> <% end %> <% end %> diff --git a/app/assets/stylesheets/zzz.css b/app/assets/stylesheets/zzz.css index f7e343b91..9f2bedd90 100644 --- a/app/assets/stylesheets/zzz.css +++ b/app/assets/stylesheets/zzz.css @@ -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; diff --git a/app/models/channel/twitter2.rb b/app/models/channel/twitter2.rb index 9b126535b..6b57476c1 100644 --- a/app/models/channel/twitter2.rb +++ b/app/models/channel/twitter2.rb @@ -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, diff --git a/app/models/email_address.rb b/app/models/email_address.rb index 153cfa3f3..73817e606 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -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 diff --git a/app/models/group.rb b/app/models/group.rb index 955e7f021..a98de29d9 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -5,4 +5,5 @@ class Group < ApplicationModel after_create :cache_delete after_update :cache_delete after_destroy :cache_delete + validates :name, :presence => true end diff --git a/app/models/link.rb b/app/models/link.rb index 61ad1e385..5322b8906 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -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 \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index 9b7e931d8..fa23bff35 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,3 +1,4 @@ class Organization < ApplicationModel has_and_belongs_to_many :users + validates :name, :presence => true end diff --git a/app/models/overview.rb b/app/models/overview.rb index 291bc0d06..78bf57c8c 100644 --- a/app/models/overview.rb +++ b/app/models/overview.rb @@ -3,4 +3,5 @@ class Overview < ApplicationModel store :order store :meta store :view + validates :name, :presence => true end \ No newline at end of file diff --git a/app/models/postmaster_filter.rb b/app/models/postmaster_filter.rb index 09fe4d72e..b484fa45f 100644 --- a/app/models/postmaster_filter.rb +++ b/app/models/postmaster_filter.rb @@ -1,4 +1,5 @@ class PostmasterFilter < ApplicationModel store :perform store :match + validates :name, :presence => true end diff --git a/app/models/role.rb b/app/models/role.rb index 39bd3cd25..f2e573cdb 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -3,4 +3,5 @@ class Role < ApplicationModel after_create :cache_delete after_update :cache_delete after_destroy :cache_delete + validates :name, :presence => true end diff --git a/app/models/signature.rb b/app/models/signature.rb index b6faa15aa..f4a1dee16 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -3,4 +3,5 @@ class Signature < ApplicationModel after_create :cache_delete after_update :cache_delete after_destroy :cache_delete + validates :name, :presence => true end diff --git a/app/models/store.rb b/app/models/store.rb index 3ba09fe2e..414d987fb 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -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 diff --git a/app/models/template.rb b/app/models/template.rb index e8b5ac872..36a7ebbad 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -1,3 +1,4 @@ class Template < ApplicationModel - store :options + store :options + validates :name, :presence => true end \ No newline at end of file diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 4ffad7f44..b5474ed00 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -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 \ No newline at end of file diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 678f9e4df..13d96bfdf 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -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