6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/views/components/pageflow/admin/add_membership_button.rb', line 6
def build(user, parent, entity_type)
if parent.is_a?(User)
button_label = I18n.t("pageflow.admin.#{entity_type}.add")
path = new_admin_user_membership_path(
parent, entity_type: to_class_name(entity_type)
)
data_tooltip = I18n.t("pageflow.admin.#{entity_type}."\
'none_addable_tooltip')
rel = "add_#{entity_type}_membership"
elsif parent.is_a?(Entry)
path = new_admin_entry_membership_path(
parent, entity_type: to_class_name(entity_type)
)
quota = Pageflow.config.quotas.get(:users, parent.account)
else
path = new_admin_account_membership_path(
parent, entity_type: to_class_name(entity_type)
)
end
unless parent.is_a?(User)
button_label = I18n.t('pageflow.admin.users.add')
data_tooltip = I18n.t('pageflow.admin.user.none_addable_tooltip')
rel = 'add_member'
end
if parent.is_a?(Entry) && parent.account.users.length < 2
render 'pageflow/admin/entries/cannot_add_user',
user: user,
parent: parent,
entity_type: entity_type,
quota: quota
elsif membership_possible_for(user, parent, entity_type)
para do
link_to(button_label, path, class: 'button', data: {rel: rel})
end
else
para(content_tag('a',
button_label,
class: 'button disabled',
data: {rel: rel}),
'data-tooltip' => data_tooltip)
render 'pageflow/admin/users/cannot_add',
user: user,
parent: parent,
entity_type: entity_type,
quota: quota
end
end
|