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



49
50
51
# File 'app/models/adminpanel/gallery.rb', line 49

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

.form_attributesObject



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

def self.form_attributes
	[
		{'file' => {
			'type' => 'file_field',
			'name' => 'Archivo' }
		}
	]
end

.iconObject



53
54
55
# File 'app/models/adminpanel/gallery.rb', line 53

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



57
58
59
# File 'app/models/adminpanel/gallery.rb', line 57

def name
	File.basename(file.path)
end