Class: Adminpanel::Gallery

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Base, Galleryzation
Defined in:
app/models/adminpanel/gallery.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.display_nameObject



51
52
53
# File 'app/models/adminpanel/gallery.rb', line 51

def self.display_name
  I18n.t('model.Gallery')
end

.form_attributesObject



40
41
42
43
44
45
46
47
48
49
# File 'app/models/adminpanel/gallery.rb', line 40

def self.form_attributes
  [
    {
      'file' => {
        'type' => 'file_field',
        'label' => I18n.t('model.attributes.file'),
      }
    }
  ]
end

.iconObject



55
56
57
# File 'app/models/adminpanel/gallery.rb', line 55

def self.icon
  'picture-o'
end

Instance Method Details

#move_to_better_positionObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/adminpanel/gallery.rb', line 12

def move_to_better_position
  if self.position > 1
    conflicting_gallery = Gallery.find_by_position(position - 1)
    self.update_attribute(:position, self.position - 1)
    conflicting_gallery.update_attribute(
      :position, conflicting_gallery.position + 1
      )
    true
  else
    false
  end
end

#move_to_worst_positionObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/adminpanel/gallery.rb', line 25

def move_to_worst_position
  records = self.class.count
  if self.position < records
    conflicting_gallery = Gallery.find_by_position(position + 1)
    update_attribute(:position, self.position + 1)
    conflicting_gallery.update_attribute(
      :position, conflicting_gallery.position - 1
      )
    true
  else
    false
  end
end

#nameObject



59
60
61
# File 'app/models/adminpanel/gallery.rb', line 59

def name
  File.basename(file.path)
end