Module: Crimagify::ApplicationHelper

Defined in:
app/helpers/crimagify/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#image_cropper(object, options, image_options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/crimagify/application_helper.rb', line 4

def image_cropper(object, options, image_options = {})
	image_options[:class] = "#{image_options[:class]} img_start"
	img = object.crimagify_images.where("image_name=?", options[:image_name])
	version_name = options[:ratio]
	if options[:label_title].nil?
		options[:label_title] == "Image"
	end
	if options[:choose_text].nil?
		options[:choose_text] == "Choose image"
	end
	if img == []
		url_image = "crimagify/no_selected_image.jpg"
	else
		url_image = img.first.image_url(options[:ratio]).to_s rescue ""
	end
	if url_image == ""
		if ENV['DEFAULT_IMAGE'].nil?
			url_image = "crimagify/no_selected_image.jpg"
		else
			url_image = ENV['DEFAULT_IMAGE'].to_s
		end
	end
	render(:partial => "crimagify/crop_partials/fields_cropper", :locals => { id_image: options[:image_name], url_image: url_image, image_options: image_options, version_name: version_name, label_title: options[:label_title], choose_text: options[:choose_text] })
end

#images_id(object) ⇒ Object



29
30
31
32
33
34
35
# File 'app/helpers/crimagify/application_helper.rb', line 29

def images_id(object)
	html = ""
	html << (:input, nil, :id => :parent, :name => :parent, :type => :hidden, :value => "#{object.class.name}")
	html << (:input, nil, :id => :parent_id, :name => :parent_id,  :type => :hidden, :value => "#{object.id}")
	html << (:input, nil, :id => :id_images, :name => :id_images, :type => :hidden, :value => "")
	return raw html
end


74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/crimagify/application_helper.rb', line 74

def link_to_add_fields(name, f, association)
  new_object = f.object.send(association).klass.new
  #data variables
  parent_object = f.object.class.name.underscore
  id = new_object.object_id
  tag_parent = association.to_s

  fields = f.fields_for(association, new_object, child_index: id) do |builder|
    render(association.to_s.singularize + "_fields", f: builder)
  end
    
  link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", ""), parent: tag_parent, parentobject: parent_object})
end

#nested_image_cropper(object, options, image_options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/crimagify/application_helper.rb', line 37

def nested_image_cropper(object, options, image_options = {})
	image_options[:class] = "#{image_options[:class]} img_start"
	img = object.crimagify_images.where("image_name=?", options[:image_name])
	version_name = options[:ratio]
	if options[:label_title].nil?
		options[:label_title] == "Image"
	end
	if options[:choose_text].nil?
		options[:choose_text] == "Choose image"
	end
	if img == []
		if ENV['DEFAULT_IMAGE'].nil?
			url_image = "crimagify/no_selected_image.jpg"
		else
			url_image = ENV['DEFAULT_IMAGE'].to_s
		end						
	else
		url_image = img.first.image_url(options[:ratio]).to_s rescue ""
	end
	if url_image == ""
		if ENV['DEFAULT_IMAGE'].nil?
			url_image = "crimagify/no_selected.jpg"
		else
			url_image = ENV['DEFAULT_IMAGE'].to_s
		end
	end
	render(:partial => "crimagify/crop_partials/nested_cropper", :locals => { id_image: options[:image_name], url_image: url_image, image_options: image_options, version_name: version_name, label_title: options[:label_title], choose_text: options[:choose_text]  })
end

#nested_images_id(object) ⇒ Object



66
67
68
69
70
71
72
# File 'app/helpers/crimagify/application_helper.rb', line 66

def nested_images_id(object)
	html = ""
	html << (:input, nil, :class => :parent, :name => :parent, :type => :hidden, :value => "#{object.class.name}")
	html << (:input, nil, :class => :parent_id, :name => :parent_id,  :type => :hidden, :value => "#{object.id}")
	html << (:input, nil, :class => :id_images, :name => :id_images, :type => :hidden, :value => "")
	return raw html
end