friendly_extensions 0.0.65 → 0.0.66

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 599b81295e728316bffa52a91ee0f83cfe21a0fc
4
- data.tar.gz: e279fc4b1e79c9dd27f2e59bcc223b472e20620e
3
+ metadata.gz: beaab51fa38a34324b21d2870403e656aac2cb7b
4
+ data.tar.gz: 678e03682c2a930971c13bb10719e5ee8cc64255
5
5
  SHA512:
6
- metadata.gz: 29f70901e22e4edaff2566793f6d564606467fdeace229fcb910dc1c129f53b7fea4a866b9c3b64a30927f5142bb4c9b4f4980314e2aad1fba19193987105ad2
7
- data.tar.gz: 777f32151ae55d93267d001432a3d361f32bf72b193fbf9a480d4c29eca51c338fc7995533e00ba038cfdb8536548473d0d6850981830f57074b011b50b63eb7
6
+ metadata.gz: e125164853958b09b6be5ee0018aad8dfc6bd3c0f9f2e25fe23a495a7b1b9324195f9fa18d1badf903c3a10b698f789e9f01323c103d39398f410ba653d3c750
7
+ data.tar.gz: 3454e702a99f234eb593ad977c10e6c91389b86db06905e81617e4b478d2f57a66b6154b4ebf8114affb4128f978dc9aba0b59c4de2931d757d5bbbe5a21250c
@@ -0,0 +1,27 @@
1
+ module FriendsFormsHelper
2
+
3
+ def fieldset(title, options = {}, &block)
4
+ if options[:if].nil? || options[:if] == true
5
+ data_string = " "
6
+ if options[:data]
7
+ options[:data].each {|d,v| data_string << "#{d}='v' "}
8
+ end
9
+ concat raw("<fieldset id='#{options[:id]}' #{data_string} class='shadow #{options[:mainclass]}' #{("style='height: %spx'" % options[:height]) if options[:height]} style='#{options[:mainstyle]}'>")
10
+ concat raw("<legend class='#{options[:class]}' style='#{options[:style]}'>#{title}</legend><div class='fieldset-content'>")
11
+ yield
12
+ concat raw("</div></fieldset>")
13
+ end
14
+ end
15
+
16
+ def tooltip_box(tooltip)
17
+ "<span class='label-tooltip' title='#{tooltip}'>&nbsp;</span>".html_safe
18
+ end
19
+
20
+ def tooltip_content_box(name, options = {}, &block)
21
+ options[:default_class] ||= "icon-clue"
22
+ html = "<div class='tooltip-box'><div class='tooltip-box-label #{options[:default_class]}'>"
23
+ html << "#{name}<div class='tooltip-box-content #{options[:css]} box rounded shadow'>#{capture(&block)}</div></div></div>"
24
+ concat(html.html_safe)
25
+ end
26
+
27
+ end
@@ -0,0 +1,124 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module FriendsLabeledFormHelper
3
+
4
+ def self.included(arg)
5
+ ActionView::Helpers::FormBuilder.send(:include, FriendsLabeledFormBuilder)
6
+ end
7
+
8
+ def label_tag_for(object_name, method, options = {})
9
+ label_name = (options[:label].blank? ? method.to_label : options[:label])
10
+
11
+ label_name += options[:append] unless options[:append].nil?
12
+
13
+ label_text = "<span class='label-text'>#{label_name}</span>"
14
+
15
+ if options[:errors]
16
+ label_text << tooltip_box(options[:errors].to_text)
17
+ elsif ((options[:label].blank? && options[:tooltip].blank?) || !options[:tooltip].blank?) && options[:tooltip] != false
18
+ tooltip = (options[:tooltip] || method.to_label(:show_tooltip => true))
19
+ if !tooltip.blank? && options[:hide_tooltip] != true
20
+ # Setting Tooltip format for display in Browsertooltip
21
+ # line breaks in unicode
22
+ tooltip = tooltip.gsub(/\n|\<br(\ )?(\/)?\>/, "&#xA;")
23
+ # single to double quotes
24
+ tooltip = tooltip.gsub("'", '"')
25
+ label_text << tooltip_box(tooltip)
26
+ end
27
+ end
28
+
29
+
30
+ label_options = {}
31
+ label_options.merge!(:class => options[:class]) unless options[:class].blank?
32
+ label_options.merge!(:for => options[:for]) unless options[:for].blank?
33
+ label_options.merge!(:id => options[:id]) unless options[:id].blank?
34
+
35
+ return label(object_name, method, label_text.html_safe, label_options).html_safe
36
+ end
37
+
38
+ def labeled_text_field(object_name, method, options={})
39
+
40
+ if options[:id]
41
+ label_options = options.merge(:id => "label-#{options[:id]}")
42
+ else
43
+ label_options = options
44
+ end
45
+
46
+ html = label_tag_for(object_name, method, label_options)
47
+ if options[:password] && options.delete(:password)
48
+ html += password_field(object_name, method, options)
49
+ else
50
+ html += text_field(object_name, method, options)
51
+ end
52
+ return html.html_safe
53
+ end
54
+
55
+ def labeled_check_box(object_name, method, options={}, checked_value=1, unchecked_value=0)
56
+ method = method.to_s.to_sym
57
+ box_id = object_name.to_s+"_"+method.to_s
58
+
59
+ html = "<div class='cf labeled-check-box'>"
60
+ html += "<div class='checkbox-container'>#{check_box(object_name, method, options.merge!(:id => box_id), checked_value, unchecked_value)}</div>"
61
+ html += "<div class='checkbox-label-container'>#{label_tag_for(object_name, method, :label => options[:label], :tooltip => options[:tooltip], :class => "checkbox-label", :for => box_id, :errors => options[:errors])}</div>"
62
+ html += "</div>"
63
+
64
+ return html.html_safe
65
+ end
66
+
67
+
68
+
69
+ def labeled_radio_button(object_name, method, value, options = {})
70
+ options[:id] ||= "radio-#{method.to_s}-#{value.inspect}"
71
+ options[:label] ||= method.to_label
72
+ html = "<div class='cf labeled-radio-button'>"
73
+ html << radio_button(object_name, method, value, options.except(:label, :errors))
74
+ html << "&nbsp;"
75
+ html << label_tag_for(object_name, method, {:label => options[:label], :for => options[:id]})
76
+ html << "</div>"
77
+ return raw(html)
78
+ end
79
+
80
+ end
81
+
82
+ module FriendsLabeledFormBuilder
83
+
84
+ def label_tag_for(method, options = {})
85
+ @template.label_tag_for(@object_name, method, options)
86
+ end
87
+
88
+
89
+ def labeled_radio_button(method, value, options ={})
90
+ options[:checked] = (object.send(method) == value) if options[:checked].nil?
91
+
92
+ options[:class] ||= ""
93
+ options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
94
+ options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
95
+
96
+ @template.labeled_radio_button(@object_name, method, value, options)
97
+ end
98
+
99
+
100
+ def labeled_check_box(method, options = {}, checked_value=1, unchecked_value=0)
101
+
102
+ options[:class] ||= ""
103
+ options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
104
+ options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
105
+
106
+ options[:checked] ||= ((object.send(method) rescue false) || options[:checked])
107
+ @template.labeled_check_box(@object_name, method, options, checked_value, unchecked_value)
108
+ end
109
+
110
+
111
+ def labeled_text_field(method, options = {})
112
+
113
+ options[:value] ||= (object.send(method) rescue nil )
114
+ options[:class] ||= ""
115
+ options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
116
+
117
+ options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
118
+
119
+ @template.labeled_text_field(@object_name, method, options)
120
+ end
121
+
122
+ end
123
+
124
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class FriendsLabel < ActiveRecord::Base
3
+
4
+ validates_uniqueness_of :attribute_name
5
+
6
+
7
+
8
+ labels = {}
9
+
10
+ if self.table_exists?
11
+ concept_labels = FriendsLabel.all
12
+ concept_labels.each {|l| labels.merge!(l.attribute_name => {:label => l.label, :tooltip => l.tooltip, :docu_tooltip => l.tooltip_docu})}
13
+ end
14
+
15
+ LABELS = labels
16
+
17
+
18
+ def is_unset?
19
+ return (!(self.attribute_name == self.label)).to_s
20
+ end
21
+
22
+ end
@@ -0,0 +1,24 @@
1
+ states = [
2
+ "Baden-Württemberg" ,
3
+ "Bayern" ,
4
+ "Berlin " ,
5
+ "Brandenburg" ,
6
+ "Bremen " ,
7
+ "Hamburg " ,
8
+ "Hessen" ,
9
+ "Mecklenburg-Vorpommern",
10
+ "Niedersachsen" ,
11
+ "Nordrhein-Westfalen" ,
12
+ "Rheinland-Pfalz" ,
13
+ "Saarland" ,
14
+ "Sachsen" ,
15
+ "Sachsen-Anhalt" ,
16
+ "Schleswig-Holstein" ,
17
+ "Thüringen"
18
+ ]
19
+
20
+ GERMAN_STATES = states.map {|s| [s, states.index(s)+1]}
21
+ german_states_hash = {}
22
+ GERMAN_STATES.each {|s| german_states_hash.merge!(s[1] => s[0])}
23
+
24
+ GERMAN_STATES_HASH = german_states_hash
@@ -0,0 +1,13 @@
1
+ class CreateLabels < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table "friends_labels", :force => true do |t|
5
+ t.string "attribute_name"
6
+ t.string "label"
7
+ t.text "tooltip"
8
+ t.text "tooltip_docu"
9
+ t.text "search_tags"
10
+ end
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.65
4
+ version: 0.0.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Eck
@@ -31,6 +31,11 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - app/helpers/friends_forms_helper.rb
35
+ - app/helpers/friends_labeled_form_helper.rb
36
+ - app/models/friends_label.rb
37
+ - config/initializers/values.rb
38
+ - db/migrate/20140326005600_create_labels.rb
34
39
  - lib/alphanumeric.rb
35
40
  - lib/array.rb
36
41
  - lib/boolean.rb