Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update Person view to use Organization model

  • Loading branch information...
commit 60acd3a54845bcd5782b5bb51d67a7c1961d656d 1 parent 2b8be7e
@cthielen cthielen authored
View
21 app/assets/javascripts/models/entity.js.coffee
@@ -44,6 +44,7 @@ DssRm.Models.Entity = Backbone.Model.extend(
@group_operatorships = new DssRm.Collections.Entities if @group_operatorships is `undefined`
@group_memberships = new Backbone.Collection if @group_memberships is `undefined`
@role_assignments = new DssRm.Collections.RoleAssignments if @role_assignments is `undefined`
+ @organizations = new Backbone.Collection if @organizations is `undefined`
# Reset nested collection data
@favorites.reset @get("favorites")
@@ -51,6 +52,7 @@ DssRm.Models.Entity = Backbone.Model.extend(
@group_operatorships.reset @get("group_operatorships")
@group_memberships.reset @get("group_memberships")
@role_assignments.reset @get("role_assignments")
+ @organizations.reset @get("organizations")
# Enforce the design pattern by removing from @attributes what is represented in a nested collection
delete @attributes.favorites
@@ -58,6 +60,7 @@ DssRm.Models.Entity = Backbone.Model.extend(
delete @attributes.group_operatorships
delete @attributes.group_memberships
delete @attributes.role_assignments
+ delete @attributes.organizations
toJSON: ->
if @type() is EntityTypes.group
@@ -109,6 +112,10 @@ DssRm.Models.Entity = Backbone.Model.extend(
entity_id: membership.get('entity_id')
group_id: membership.get('group_id')
_destroy: membership.get('_destroy')
+ # if @organizations.length
+ # json.organizations_attributes = @organizations.map (organization) ->
+ # id: organization.get('id')
+ # _destroy: organization.get('_destroy')
if @group_operatorships.length
json.group_operatorships_attributes = @group_operatorships.map (operatorship) ->
id: operatorship.get('id')
@@ -184,13 +191,13 @@ DssRm.Models.Entity = Backbone.Model.extend(
group.get('calculated') == true
)
- ouGroupMemberships: ->
- unless @group_memberships
- return []
-
- @group_memberships.filter( (group) ->
- group.get('ou') == true
- )
+ # ouGroupMemberships: ->
+ # unless @group_memberships
+ # return []
+ #
+ # @group_memberships.filter( (group) ->
+ # group.get('ou') == true
+ # )
nonOuGroupMemberships: ->
unless @group_memberships
View
26 app/assets/javascripts/views/person_show.js.coffee
@@ -77,20 +77,18 @@ class DssRm.Views.PersonShow extends Backbone.View
membership = @model.group_memberships.get(item.id)
membership.set('_destroy', true)
- @$("input[name=ou_group_memberships]").tokenInput Routes.ous_path(),
+ @$("input[name=ou_group_memberships]").tokenInput Routes.organizations_path(),
crossDomain: false
defaultText: ""
theme: "facebook"
- disabled: @readonly
+ disabled: true #@readonly
onAdd: (item) =>
- @model.group_memberships.add
- group_id: item.id
- entity_id: @model.get('id')
+ @model.organizations.add
+ id: item.id
name: item.name
- calculated: false
onDelete: (item) =>
- membership = @model.group_memberships.get(item.id)
- membership.set('_destroy', true)
+ organization = @model.organizations.get(item.id)
+ organization.set('_destroy', true)
initializeRolesTab: ->
@$("#add_role_assignment_application_search").typeahead
@@ -199,13 +197,13 @@ class DssRm.Views.PersonShow extends Backbone.View
ou_group_membership_tokeninput = @$("input[name=ou_group_memberships]")
ou_group_membership_tokeninput.tokenInput "clear"
- _.each @model.ouGroupMemberships(), (membership) =>
- unless membership.get('_destroy')
+ @model.organizations.each (organization) =>
+ unless organization.get('_destroy')
ou_group_membership_tokeninput.tokenInput "add",
- id: membership.get('id')
- name: membership.get('name')
- readonly: @readonly || membership.get('calculated')
- class: (if membership.get('calculated') then "calculated" else "")
+ id: organization.get('id')
+ name: organization.get('name')
+ readonly: true #@readonly || membership.get('calculated')
+ class: "calculated" #class: (if membership.get('calculated') then "calculated" else "")
# Roles tab
$rolesTab = @$("div#role_assignments")
View
13 app/models/person.rb
@@ -28,23 +28,14 @@ class Person < Entity
validates :loginid, :presence => true, :uniqueness => true
- attr_accessible :first, :last, :loginid, :email, :phone, :address, :type, :favorite_ids, :group_memberships_attributes,
- :group_ownerships_attributes, :group_operatorships_attributes, :role_assignments_attributes, :active
+ attr_accessible :first, :last, :loginid, :email, :phone, :address, :type, :favorite_ids, :group_memberships_attributes, :group_ownerships_attributes, :group_operatorships_attributes, :role_assignments_attributes, :active
before_save :set_name_if_blank
after_save :recalculate_group_rule_membership
after_save :touch_caches_as_needed
def as_json(options={})
- { :id => self.id, :name => self.name, :type => 'Person', :email => self.email, :loginid => self.loginid, :first => self.first,
- :last => self.last, :email => self.email, :phone => self.phone, :address => self.address, :byline => self.byline, :active => self.active,
- :role_assignments => self.role_assignments.includes(:role).map{ |a| { id: a.id, calculated: a.parent_id?, entity_id: a.entity_id,
- role_id: a.role.id, token: a.role.token, application_name: a.role.application.name,
- application_id: a.role.application_id, name: a.role.name, description: a.role.description } },
- :favorites => self.favorites.map{ |f| { id: f.id, name: f.name, type: f.type } },
- :group_memberships => self.group_memberships.includes(:group).map{ |m| { id: m.id, group_id: m.group.id, name: m.group.name, ou: m.group.ou?, calculated: m.calculated } },
- :group_ownerships => self.group_ownerships.includes(:group).map{ |o| { id: o.id, group_id: o.group.id, name: o.group.name } },
- :group_operatorships => self.group_operatorships.includes(:group).map{ |o| { id: o.id, group_id: o.group.id, name: o.group.name } }
+ { :id => self.id, :name => self.name, :type => 'Person', :email => self.email, :loginid => self.loginid, :first => self.first, :last => self.last, :email => self.email, :phone => self.phone, :address => self.address, :byline => self.byline, :active => self.active, :role_assignments => self.role_assignments.includes(:role).map{ |a| { id: a.id, calculated: a.parent_id?, entity_id: a.entity_id, role_id: a.role.id, token: a.role.token, application_name: a.role.application.name, application_id: a.role.application_id, name: a.role.name, description: a.role.description } }, :favorites => self.favorites.map{ |f| { id: f.id, name: f.name, type: f.type } }, :group_memberships => self.group_memberships.includes(:group).map{ |m| { id: m.id, group_id: m.group.id, name: m.group.name, ou: m.group.ou?, calculated: m.calculated } }, :group_ownerships => self.group_ownerships.includes(:group).map{ |o| { id: o.id, group_id: o.group.id, name: o.group.name } }, :group_operatorships => self.group_operatorships.includes(:group).map{ |o| { id: o.id, group_id: o.group.id, name: o.group.name } }, :organizations => self.organizations.map{ |o| { id: o.id, name: o.name } }
}
end
View
2  config/initializers/last_updated.rb
@@ -1 +1 @@
-LAST_UPDATED = 'Tue Feb 25 19:53:48 PST 2014'
+LAST_UPDATED = 'Wed Feb 26 11:41:01 PST 2014'
Please sign in to comment.
Something went wrong with that request. Please try again.