Class: Breeze::Card
Instance Attribute Summary
Attributes inherited from ActiveYaml
#data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ViewBase
#add_default_options, #get_translation, #has_option?, #header_text, #image_old, #last_update_for, #option, #option_definitions, #safe_options, #set_option, #swap_index_with, #text_text, #type_id, #update, #update_options
Methods inherited from ActiveBase
#add_save, #add_save!, #delete_save!, #edit_save, #edit_save!
Methods inherited from ActiveYaml
all, append, define_access, define_association, delete, fields, find, find_all, find_by, first, full_path, #id, #id=, #initialize, load_file, #persisted?, primary_key, reload, save_all, set_root_path, the_meta_class
Class Method Details
.new_card(card_template, section_id, index) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/breeze/card.rb', line 75
def self.new_card(card_template , section_id , index)
data = { section_id: section_id , index: index}
template = CardStyle.find_by_template( card_template )
template.fields.each do |key|
data[key.to_sym] = "NEW"
end
new_id = Card.append(data)
card = Card.new(data)
card.add_default_options(template.options_definitions)
card
end
|
Instance Method Details
#allowed_fields ⇒ Object
53
54
55
|
# File 'app/models/breeze/card.rb', line 53
def allowed_fields
super + [:section_id]
end
|
#change_name ⇒ Object
10
11
12
13
|
# File 'app/models/breeze/card.rb', line 10
def change_name
pagename = section ? section.page_name : section_id.to_s
"#{pagename}:#{}"
end
|
#delete(editor) ⇒ Object
71
72
73
|
# File 'app/models/breeze/card.rb', line 71
def delete(editor)
delete_save!(editor)
end
|
#delete_and_reset_index(editor) ⇒ Object
57
58
59
60
61
|
# File 'app/models/breeze/card.rb', line 57
def delete_and_reset_index(editor)
delete_save!(editor)
Section.find(section_id).reset_index
Card.save_all
end
|
#index_name ⇒ Object
67
68
69
|
# File 'app/models/breeze/card.rb', line 67
def index_name
"#{section.index}.#{self.index}"
end
|
#missing_translations ⇒ Object
15
16
17
18
19
20
21
|
# File 'app/models/breeze/card.rb', line 15
def missing_translations
sum = 0
Breeze.language_strings.each do |lang|
sum += 1 if get_translation(lang)&.is_old?
end
sum
end
|
#move_down ⇒ Object
31
32
33
|
# File 'app/models/breeze/card.rb', line 31
def move_down
swap_index_with(next_card)
end
|
#move_up ⇒ Object
27
28
29
|
# File 'app/models/breeze/card.rb', line 27
def move_up
swap_index_with(previous_card)
end
|
#next_card ⇒ Object
39
40
41
|
# File 'app/models/breeze/card.rb', line 39
def next_card
section.cards.find{|card| card.index == index + 1}
end
|
#object_type ⇒ Object
63
64
65
|
# File 'app/models/breeze/card.rb', line 63
def object_type
"Card"
end
|
#page ⇒ Object
23
24
25
|
# File 'app/models/breeze/card.rb', line 23
def page
section.page
end
|
#previous_card ⇒ Object
35
36
37
|
# File 'app/models/breeze/card.rb', line 35
def previous_card
section.cards.find{|card| card.index == index - 1}
end
|
#template ⇒ Object
card templates are stored in the section so the all cards have the same
45
46
47
|
# File 'app/models/breeze/card.rb', line 45
def template
section.card_template
end
|
#template_style ⇒ Object
49
50
51
|
# File 'app/models/breeze/card.rb', line 49
def template_style
CardStyle.find_by_template( self.template )
end
|