bhf 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,5 +12,12 @@ module Bhf
12
12
  }
13
13
  end
14
14
 
15
+ def is_image?(file)
16
+ ['.png', '.jpg', '.jpeg', '.gif', '.svg'].each do |file_extention|
17
+ return true if file.downcase.include? file_extention
18
+ end
19
+ false
20
+ end
21
+
15
22
  end
16
23
  end
@@ -1,3 +1,3 @@
1
- %ul
1
+ %ul.basic_info_list
2
2
  - @config.pages.each do |page|
3
3
  %li= link_to t("bhf.pages.navigation.#{page}", :default => page.capitalize), bhf_page_path(page)
@@ -1,5 +1,16 @@
1
- = node f, field do
2
- - file = f.object.send(field.name)
3
- - if file.is_a? String
4
- = image_tag f.object.send(field.name), :class => 'uploaded_image'
5
- = f.file_field field.name
1
+ - # no file upload on ajax submit :(
2
+ - unless @quick_edit
3
+ = node f, field do
4
+ = f.fields_for field.name do |f_file|
5
+ - file = f.object.send(field.name)
6
+ - if file.is_a?(String)
7
+ - if is_image?(file)
8
+ = image_tag file, :class => 'uploaded_image'
9
+ - else
10
+ = link_to file, file, :class => 'uploaded_file'
11
+ - unless file.blank?
12
+ .file_delete
13
+ = f_file.check_box :delete
14
+ = f_file.label :delete, t('bhf.helpers.file.delete')
15
+
16
+ = f_file.file_field :file
@@ -14,4 +14,3 @@
14
14
  = f.hidden_field :per_page, :value => get_value(:per_page, p)
15
15
  = f.hidden_field :order, :value => get_value(:order, p)
16
16
  = f.hidden_field :direction, :value => get_value(:direction, p)
17
-
@@ -7,7 +7,7 @@
7
7
  %link{:href => '/favicon.ico', :rel => 'icon', :type => 'image/x-icon'}
8
8
  = stylesheet_link_tag(['bhf'] + Bhf::Engine.config.css.to_a)
9
9
  = javascript_include_tag 'bhf'
10
- =# javascript_include_tag 'bhf/mootools-core-1.3.1-full-compat-yc.js', 'bhf/mootools-more-1.3.1.1.js', 'bhf/mootools_rails_driver-0.4.1.js', 'bhf/class/BrowserUpdate', 'bhf/class/Ajaxify', 'bhf/class/AjaxEdit', 'bhf/class/MooEditable', 'bhf/class/Datepicker', 'bhf/class/MultipleFields', 'bhf/bhf_application'
10
+ =# javascript_include_tag 'bhf/mootools-core-1.3.2-full-compat-yc.js', 'bhf/mootools-more-1.3.2.1.js', 'bhf/mootools_rails_driver-0.4.1.js', 'bhf/class/BrowserUpdate', 'bhf/class/Ajaxify', 'bhf/class/AjaxEdit', 'bhf/class/MooEditable', 'bhf/class/Datepicker', 'bhf/class/MultipleFields', 'bhf/bhf_application'
11
11
  %body
12
12
  %header
13
13
  %h1= link_to image_tag('logo_bhf.png'), root_url
@@ -25,7 +25,9 @@ de:
25
25
  validation:
26
26
  header: "Durch diese Fehler konnte %{name} nicht gespeichert werden:"
27
27
  error: Fehler
28
-
28
+ file:
29
+ delete: Datei löschen
30
+
29
31
  quick_edit:
30
32
  buttons:
31
33
  cancel: Abbrechen
@@ -28,6 +28,8 @@ en:
28
28
  validation:
29
29
  header: "%{error} prohibited this %{name} from being saved:"
30
30
  error: error
31
+ file:
32
+ delete: Delete file
31
33
 
32
34
  quick_edit:
33
35
  buttons:
@@ -0,0 +1,41 @@
1
+ module Bhf
2
+ module ActiveRecord
3
+ module Object
4
+ extend ActiveSupport::Concern
5
+
6
+ def to_bhf_s
7
+ return title if self.respond_to? :title
8
+ return name if self.respond_to? :name
9
+
10
+ if self.respond_to? :attributes
11
+ return title if attributes['title']
12
+ return name if attributes['name']
13
+ return "#{self.class.to_s.humanize} ID: #{send(self.class.primary_key)}" if attributes[self.class.primary_key]
14
+ end
15
+
16
+ self.to_s.humanize
17
+ end
18
+
19
+ module ClassMethods
20
+ def bhf_default_search(search_params)
21
+ return if (search_term = search_params[:text]).blank?
22
+ where_statement = []
23
+ columns_hash.each_pair do |name, props|
24
+ is_number = search_term.to_i.to_s == search_term || search_term.to_f.to_s == search_term
25
+
26
+ if props.type == :string || props.type == :text
27
+ where_statement << "#{name} LIKE '%#{search_term}%'"
28
+ elsif props.type == :integer && is_number
29
+ where_statement << "#{name} = #{search_term.to_i}"
30
+ elsif props.type == :float && is_number
31
+ where_statement << "#{name} = #{search_term.to_f}"
32
+ end
33
+ end
34
+
35
+ where_statement.join(' OR ')
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,45 @@
1
+ module Bhf
2
+ module ActiveRecord
3
+ module Upload
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_save :bhf_upload
8
+ cattr_accessor :bhf_upload_settings
9
+ end
10
+
11
+ module ClassMethods
12
+ def setup_upload(settings)
13
+ self.bhf_upload_settings = settings.each_with_object([]) do |s, obj|
14
+ obj << {:path => '', :name => :file}.merge(s)
15
+ end
16
+ end
17
+ end
18
+
19
+ def bhf_upload
20
+ self.class.bhf_upload_settings.each do |settings|
21
+ name_was = send("#{settings[:name]}_was")
22
+ param_name = read_attribute(settings[:name])
23
+ file_string = if param_name && param_name[:delete].to_i != 0
24
+ # File.delete(settings[:path] + name_was.to_s) if File.exist?(settings[:path] + name_was.to_s)
25
+ nil
26
+ else
27
+ file = param_name && param_name[:file]
28
+ if file.is_a? ActionDispatch::Http::UploadedFile
29
+ # File.delete(settings[:path] + name_was.to_s) if File.exist?(settings[:path] + name_was.to_s)
30
+
31
+ filename = Time.now.to_i.to_s+'_'+file.original_filename.downcase.sub(/[^\w\.\-]/,'_')
32
+ path = File.join(settings[:path], filename)
33
+ File.open(path, 'w') { |f| f.write(file.read) }
34
+ filename
35
+ else
36
+ name_was
37
+ end
38
+ end
39
+ write_attribute settings[:name], file_string
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -104,7 +104,7 @@ module Bhf
104
104
  @b_p.template.bhf_page_path(
105
105
  @platform.page_name,
106
106
  @b_p.template.params.merge(@platform.name => platform_params)
107
- ), attributes
107
+ ), {:class => 'page_number'}.merge(attributes)
108
108
  )
109
109
  end
110
110
 
data/lib/bhf.rb CHANGED
@@ -4,7 +4,8 @@ end
4
4
 
5
5
  require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
6
6
  require 'bhf/i18n'
7
- require 'bhf/active_record'
7
+ require 'bhf/active_record/active_record'
8
+ require 'bhf/active_record/upload'
8
9
  require 'bhf/view_helpers'
9
10
  require 'bhf/data'
10
11
  require 'bhf/platform'
@@ -15,6 +16,5 @@ require 'bhf/form'
15
16
  ::I18n.send :include, Bhf::I18nTranslationFallbackHelper
16
17
 
17
18
  ::ActiveRecord::Base.send :include, Bhf::ActiveRecord::Object
18
- ::ActiveRecord::Base.send :extend, Bhf::ActiveRecord::Self
19
19
 
20
20
  ::ActionView::Base.send :include, Bhf::ViewHelpers::ActionView
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file