muck-engine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +23 -0
  3. data/Rakefile +67 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/muck/base_controller.rb +24 -0
  6. data/app/helpers/muck_custom_form_builder.rb +186 -0
  7. data/app/helpers/muck_engine_helper.rb +60 -0
  8. data/app/models/country.rb +13 -0
  9. data/app/models/language.rb +3 -0
  10. data/app/models/state.rb +13 -0
  11. data/app/views/forms/_base_field.html.erb +11 -0
  12. data/app/views/forms/_color_picker_field.html.erb +27 -0
  13. data/app/views/forms/_default.html.erb +1 -0
  14. data/app/views/forms/_field.html.erb +3 -0
  15. data/app/views/forms/_field_with_tips.html.erb +4 -0
  16. data/app/views/forms/_menu_field.erb +4 -0
  17. data/app/views/forms/_menu_field.html.erb +3 -0
  18. data/app/views/forms/_tips.html.erb +7 -0
  19. data/app/views/layouts/admin.html.erb +39 -0
  20. data/app/views/layouts/default.html.erb +39 -0
  21. data/app/views/shared/_error_box.html.erb +7 -0
  22. data/app/views/shared/_field_error.html.erb +3 -0
  23. data/app/views/shared/_flash_error_box.html.erb +4 -0
  24. data/app/views/shared/_flash_messages.html.erb +7 -0
  25. data/app/views/shared/_growl.html.erb +11 -0
  26. data/app/views/shared/_growl_box.html.erb +3 -0
  27. data/app/views/shared/_no_result.html.erb +1 -0
  28. data/db/migrate/20090402234137_create_languages.rb +18 -0
  29. data/db/migrate/20090426041056_create_countries.rb +15 -0
  30. data/db/migrate/20090426041103_create_states.rb +18 -0
  31. data/install.rb +1 -0
  32. data/lib/action_controller/muck_application.rb +74 -0
  33. data/lib/active_record/muck_model.rb +34 -0
  34. data/lib/muck-engine.rb +5 -0
  35. data/locales/en.yml +17 -0
  36. data/public/images/arrow_down.gif +0 -0
  37. data/public/images/arrow_left.gif +0 -0
  38. data/public/images/arrow_right.gif +0 -0
  39. data/public/images/arrow_up.gif +0 -0
  40. data/public/images/icons/accept.png +0 -0
  41. data/public/images/icons/add.png +0 -0
  42. data/public/images/icons/delete.png +0 -0
  43. data/public/images/icons/vote.png +0 -0
  44. data/public/images/loading.gif +0 -0
  45. data/public/images/spinner.gif +0 -0
  46. data/public/javascripts/application.js +76 -0
  47. data/public/javascripts/fancyzoom.min.js +1 -0
  48. data/public/javascripts/jquery/jquery-ui.js +273 -0
  49. data/public/javascripts/jquery/jquery.form.js +637 -0
  50. data/public/javascripts/jquery/jquery.jgrowl.js +2 -0
  51. data/public/javascripts/jquery/jquery.js +19 -0
  52. data/public/javascripts/jquery/jquery.tips.js +69 -0
  53. data/public/stylesheets/admin.css +12 -0
  54. data/public/stylesheets/blueprint/ie.css +26 -0
  55. data/public/stylesheets/blueprint/liquid_screen.css +203 -0
  56. data/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  57. data/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  58. data/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  59. data/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
  60. data/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
  61. data/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
  62. data/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
  63. data/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  64. data/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  65. data/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  66. data/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  67. data/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  68. data/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  69. data/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  70. data/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  71. data/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
  72. data/public/stylesheets/blueprint/plugins/link-icons/screen.css +40 -0
  73. data/public/stylesheets/blueprint/plugins/liquid/liquid.css +134 -0
  74. data/public/stylesheets/blueprint/plugins/liquid/src/liquid.css +197 -0
  75. data/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
  76. data/public/stylesheets/blueprint/plugins/rtl/screen.css +109 -0
  77. data/public/stylesheets/blueprint/print.css +30 -0
  78. data/public/stylesheets/blueprint/screen.css +251 -0
  79. data/public/stylesheets/blueprint/src/forms.css +49 -0
  80. data/public/stylesheets/blueprint/src/grid.css +213 -0
  81. data/public/stylesheets/blueprint/src/grid.png +0 -0
  82. data/public/stylesheets/blueprint/src/ie.css +59 -0
  83. data/public/stylesheets/blueprint/src/print.css +85 -0
  84. data/public/stylesheets/blueprint/src/reset.css +38 -0
  85. data/public/stylesheets/blueprint/src/typography.css +105 -0
  86. data/public/stylesheets/jquery/cupertino/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png +0 -0
  87. data/public/stylesheets/jquery/cupertino/images/ui-bg_diagonals-thick_15_444444_40x40.png +0 -0
  88. data/public/stylesheets/jquery/cupertino/images/ui-bg_glass_100_f0f0f0_1x400.png +0 -0
  89. data/public/stylesheets/jquery/cupertino/images/ui-bg_glass_50_99c2ff_1x400.png +0 -0
  90. data/public/stylesheets/jquery/cupertino/images/ui-bg_glass_55_fbf5d0_1x400.png +0 -0
  91. data/public/stylesheets/jquery/cupertino/images/ui-bg_glass_80_e6e6e6_1x400.png +0 -0
  92. data/public/stylesheets/jquery/cupertino/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  93. data/public/stylesheets/jquery/cupertino/images/ui-bg_highlight-hard_100_f9f9f9_1x100.png +0 -0
  94. data/public/stylesheets/jquery/cupertino/images/ui-bg_highlight-soft_100_e7eef3_1x100.png +0 -0
  95. data/public/stylesheets/jquery/cupertino/images/ui-icons_222222_256x240.png +0 -0
  96. data/public/stylesheets/jquery/cupertino/images/ui-icons_2694e8_256x240.png +0 -0
  97. data/public/stylesheets/jquery/cupertino/images/ui-icons_2e83ff_256x240.png +0 -0
  98. data/public/stylesheets/jquery/cupertino/images/ui-icons_72a7cf_256x240.png +0 -0
  99. data/public/stylesheets/jquery/cupertino/images/ui-icons_888888_256x240.png +0 -0
  100. data/public/stylesheets/jquery/cupertino/images/ui-icons_cd0a0a_256x240.png +0 -0
  101. data/public/stylesheets/jquery/cupertino/images/ui-icons_ffffff_256x240.png +0 -0
  102. data/public/stylesheets/jquery/cupertino/jquery-ui-1.7.1.custom.css +404 -0
  103. data/public/stylesheets/jquery/redmond/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  104. data/public/stylesheets/jquery/redmond/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
  105. data/public/stylesheets/jquery/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  106. data/public/stylesheets/jquery/redmond/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  107. data/public/stylesheets/jquery/redmond/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  108. data/public/stylesheets/jquery/redmond/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  109. data/public/stylesheets/jquery/redmond/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  110. data/public/stylesheets/jquery/redmond/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  111. data/public/stylesheets/jquery/redmond/images/ui-icons_217bc0_256x240.png +0 -0
  112. data/public/stylesheets/jquery/redmond/images/ui-icons_2e83ff_256x240.png +0 -0
  113. data/public/stylesheets/jquery/redmond/images/ui-icons_469bdd_256x240.png +0 -0
  114. data/public/stylesheets/jquery/redmond/images/ui-icons_6da8d5_256x240.png +0 -0
  115. data/public/stylesheets/jquery/redmond/images/ui-icons_cd0a0a_256x240.png +0 -0
  116. data/public/stylesheets/jquery/redmond/images/ui-icons_d8e7f3_256x240.png +0 -0
  117. data/public/stylesheets/jquery/redmond/images/ui-icons_f9bd01_256x240.png +0 -0
  118. data/public/stylesheets/jquery/redmond/jquery-ui-1.7.1.custom.css +404 -0
  119. data/public/stylesheets/jquery/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  120. data/public/stylesheets/jquery/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  121. data/public/stylesheets/jquery/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  122. data/public/stylesheets/jquery/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  123. data/public/stylesheets/jquery/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  124. data/public/stylesheets/jquery/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  125. data/public/stylesheets/jquery/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  126. data/public/stylesheets/jquery/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  127. data/public/stylesheets/jquery/smoothness/images/ui-icons_222222_256x240.png +0 -0
  128. data/public/stylesheets/jquery/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  129. data/public/stylesheets/jquery/smoothness/images/ui-icons_454545_256x240.png +0 -0
  130. data/public/stylesheets/jquery/smoothness/images/ui-icons_888888_256x240.png +0 -0
  131. data/public/stylesheets/jquery/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  132. data/public/stylesheets/jquery/smoothness/jquery-ui-1.7.1.custom.css +404 -0
  133. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  134. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  135. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  136. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  137. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  138. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  139. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  140. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  141. data/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  142. data/public/stylesheets/jquery/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  143. data/public/stylesheets/jquery/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  144. data/public/stylesheets/jquery/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  145. data/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  146. data/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  147. data/public/stylesheets/jquery/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  148. data/public/stylesheets/reset.css +0 -0
  149. data/public/stylesheets/styles.css +76 -0
  150. data/rails/init.rb +3 -0
  151. data/tasks/languages.txt +183 -0
  152. data/test/muck_engine_test.rb +8 -0
  153. data/test/test_helper.rb +3 -0
  154. data/uninstall.rb +1 -0
  155. metadata +207 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ MuckEngine
2
+ ==========
3
+ The muck engine is forms the basis for the muck framework and includes basic functionality utilized by the various muck engines.
4
+
5
+ The easiest way to get started with muck is to generate your application using a template:
6
+ $ rails <your-app> -m http://github.com/jbasdf/rails-templates/raw/master/muck.rb
7
+
8
+ Add optional functionality with the following command:
9
+ $ rake rails:template LOCATION=http://github.com/jbasdf/rails-templates/raw/master/mucktoo.rb
10
+
11
+ Layout
12
+ =======
13
+ The muck template will build your basic application and construct all the needed files and configuration.
14
+
15
+ If you build your own layout be sure to include the following script in your layout or the javascript in the system won't work:
16
+ <script type="text/javascript" language="JavaScript">
17
+ <%= yield :javascript %>
18
+ </script>
19
+
20
+
21
+
22
+
23
+ Copyright (c) 2009 Justin Ball, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the muck-engine plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the muck-engine plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'MuckEngine'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+
26
+ begin
27
+ require 'jeweler'
28
+ Jeweler::Tasks.new do |gemspec|
29
+ gemspec.name = "muck-engine"
30
+ gemspec.summary = "The base engine for the muck system. Contains common tables, custom for, css and javascript."
31
+ gemspec.email = "justinball@gmail.com"
32
+ gemspec.homepage = "http://github.com/technicalpickles/the-perfect-gem"
33
+ gemspec.description = "The base engine for the muck system. Contains common tables, custom for, css and javascript."
34
+ gemspec.authors = ["Justin Ball"]
35
+ gemspec.files.include %w( lib/muck-engine.rb )
36
+ gemspec.rubyforge_project = 'muck-engine'
37
+ end
38
+ rescue LoadError
39
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
40
+ end
41
+
42
+ # rubyforge tasks
43
+ begin
44
+ require 'rake/contrib/sshpublisher'
45
+ namespace :rubyforge do
46
+
47
+ desc "Release gem and RDoc documentation to RubyForge"
48
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
49
+
50
+ namespace :release do
51
+ desc "Publish RDoc to RubyForge."
52
+ task :docs => [:rdoc] do
53
+ config = YAML.load(
54
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
55
+ )
56
+
57
+ host = "#{config['username']}@rubyforge.org"
58
+ remote_dir = "/var/www/gforge-projects/muck-engine/"
59
+ local_dir = 'rdoc'
60
+
61
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
62
+ end
63
+ end
64
+ end
65
+ rescue LoadError
66
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
67
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,24 @@
1
+ class Admin::Muck::BaseController < ApplicationController
2
+
3
+ before_filter :login_required
4
+ before_filter :admin_access?
5
+
6
+ protected
7
+
8
+ def get_user
9
+ @user = current_user
10
+ end
11
+
12
+ def authorized?
13
+ admin?
14
+ end
15
+
16
+ def permission_denied
17
+ respond_to do |format|
18
+ format.html do
19
+ redirect_to home_path
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,186 @@
1
+ class MuckCustomFormBuilder < ActionView::Helpers::FormBuilder
2
+
3
+ helpers = field_helpers +
4
+ %w(date_select datetime_select time_select collection_select) +
5
+ %w(select country_select time_zone_select) -
6
+ %w(hidden_field label fields_for)
7
+
8
+ helpers.each do |name|
9
+ define_method name do |field, *args|
10
+ options = args.detect {|argument| argument.is_a?(Hash)} || {}
11
+
12
+ render_field_template(name, field, options) do
13
+ super
14
+ end
15
+ end
16
+ end
17
+
18
+ def render_field_template(name, field, options)
19
+
20
+ tippable = !options[:tip].nil?
21
+
22
+ # used by country, state and other selects to specify a different id
23
+ field_id = options[:field_id]
24
+
25
+ local_options = {
26
+ :extra_html => options.delete(:extra_html),
27
+ :tip => options.delete(:tip),
28
+ :tip_title => options.delete(:tip_title),
29
+ :tip_key => options.delete(:tip_key),
30
+ :tip_position => options.delete(:tip_position) || 'right',
31
+ :wrapper_id => options.delete(:wrapper_id),
32
+ :pre_html => options.delete(:pre_html),
33
+ :hide_required => options.delete(:hide_required),
34
+ :hide_control_error => options.delete(:hide_control_error),
35
+ :css_class => options.delete(:css_class)
36
+ }
37
+
38
+ type = options.delete(:type)
39
+ type ||= :tippable if tippable
40
+
41
+ if !options[:label_class].nil?
42
+ label_options = { :class => options.delete(:label_class) }
43
+ else
44
+ label_options = { }
45
+ end
46
+
47
+ if local_options[:hide_required]
48
+ required = false
49
+ label_text = options[:label]
50
+ else
51
+ required = required_field?(field)
52
+ label_text = (options[:label] || field.to_s.camelize)
53
+ label_text = label_text + required_mark(field) if required
54
+ end
55
+ label_name = options.delete(:label)
56
+
57
+ is_checkbox = false
58
+ is_checkbox = true if %w(check_box).include?(name)
59
+
60
+ options[:class] ||= ''
61
+ options[:class] << add_space_to_css(options) + 'tip-field' if tippable
62
+ options[:class] << add_space_to_css(options) + "required-value" if required
63
+
64
+ if type == :choose_menu
65
+ options[:label_class] = 'desc'
66
+ end
67
+
68
+ locals = {
69
+ :field_element => yield,
70
+ :field_name => field_id || field_name(field),
71
+ :label_name => options.delete(:required_label) || label_name || '',
72
+ :label_element => label(field, label_text, label_options),
73
+ :is_checkbox => is_checkbox,
74
+ :required => required
75
+ }.merge(local_options)
76
+
77
+ if object.nil?
78
+ locals[:value] = ''
79
+ locals[:id] = ''
80
+ else
81
+ locals[:value] = object.send(field)
82
+ locals[:id] = object.id
83
+ end
84
+
85
+ if has_errors_on?(field)
86
+ locals.merge!(:error => error_message(field, options))
87
+ end
88
+
89
+ @template.capture do
90
+
91
+ if type == :tippable
92
+ @template.render :partial => 'forms/field_with_tips', :locals => locals
93
+ elsif type == :choose_menu
94
+ @template.render :partial => 'forms/menu_field', :locals => locals
95
+ elsif type == :color_picker
96
+ @template.render :partial => 'forms/color_picker_field', :locals => locals
97
+ elsif type == :default
98
+ @template.render :partial => 'forms/default', :locals => locals
99
+ else
100
+ @template.render :partial => 'forms/field', :locals => locals
101
+ end
102
+ end
103
+ end
104
+
105
+ # creates a select control with states. Default id is 'states'. If 'retain' is passed for the class value the value of this
106
+ # control will be written into a cookie with the key 'states'.
107
+ def state_select(method, options = {}, html_options = {}, additional_state = nil)
108
+ country_id_field_name = options.delete(:country_id) || 'country_id'
109
+ country_id = get_instance_object_value(country_id_field_name)
110
+ @states = country_id.nil? ? [] : (additional_state ? [additional_state] : []) + State.find(:all, :conditions => ["country_id = ?", country_id], :order => "name asc")
111
+ self.menu_select(method, 'Choose State', @states, options.merge(:prompt => 'Please select a state', :wrapper_id => 'states-container'), html_options.merge(:id => 'states'))
112
+ end
113
+
114
+ # creates a select control with countries. Default id is 'countries'. If 'retain' is passed for the class value the value of this
115
+ # control will be written into a cookie with the key 'states'.
116
+ def country_select(method, options = {}, html_options = {}, additional_country = nil)
117
+ @countries ||= (additional_country ? [additional_country] : []) + Country.find(:all, :order => 'sort, name asc')
118
+ self.menu_select(method, 'Choose Country', @countries, options.merge(:prompt => 'Please select a country', :wrapper_id => 'countries-container'), html_options.merge(:id => 'countries'))
119
+ end
120
+
121
+ def get_instance_object_value(field_name)
122
+ obj = object || @template.instance_variable_get("@#{@object_name}")
123
+ obj.send(field_name) rescue nil
124
+ end
125
+
126
+ def menu_select(method, label, collection, options = {}, html_options = {})
127
+
128
+ # this code will look for a cookie that matches the control and set the value to the cookie value
129
+ # if html_options.has_key?(:class)
130
+ # if html_options[:class].include?('retain')
131
+ # id = html_options[:id]
132
+ # @object.send("#{method}=", @template.cookies[id]) if @template.cookies.has_key? id
133
+ # end
134
+ # end
135
+ if !options[:tip].nil?
136
+ html_options[:class] ||= ''
137
+ html_options[:class] << add_space_to_css(html_options) + 'tip-field'
138
+ end
139
+ self.collection_select(method, collection, :id, :name, options.merge(:object => @object, :label => label, :type => :choose_menu, :label_class => 'desc', :field_id => html_options[:id]), html_options)
140
+ end
141
+
142
+ private
143
+
144
+ def add_space_to_css(options)
145
+ options[:class].empty? ? '' : ' '
146
+ end
147
+
148
+ def error_message(field, options)
149
+ if has_errors_on?(field)
150
+ errors = object.errors.on(field)
151
+ errors.is_a?(Array) ? errors.to_sentence : errors
152
+ else
153
+ ''
154
+ end
155
+ end
156
+
157
+ def has_errors_on?(field)
158
+ !(object.nil? || object.errors.on(field).blank?)
159
+ end
160
+
161
+ def field_name(field)
162
+ # TODO figure out if there is a built in method that does this.
163
+ "#{@object_name.to_s}_#{field.to_s}"
164
+ end
165
+
166
+ def required_mark(field)
167
+ required_field?(field) ? " <em id=\"#{field_name(field)}-label-required\">(required)</em>" : ''
168
+ end
169
+
170
+ def required_field?(field)
171
+ reflect_on = object.class if !object.blank?
172
+ if reflect_on.blank?
173
+ reflect_on = @object_name.to_s.camelize.constantize rescue nil
174
+ end
175
+ if !reflect_on.blank?
176
+ reflect_on.reflect_on_validations_for(field).map(&:macro).include?(:validates_presence_of)
177
+ else
178
+ false
179
+ end
180
+ end
181
+
182
+ def load_states
183
+ @states = State.find(:all, :order => "name" ).map {|u| [u.name, u.id] }
184
+ end
185
+
186
+ end
@@ -0,0 +1,60 @@
1
+ module MuckEngineHelper
2
+
3
+ def custom_form_for(record_or_name_or_array, *args, &proc)
4
+ options = args.detect { |argument| argument.is_a?(Hash) }
5
+ if options.nil?
6
+ options = {:builder => MuckCustomFormBuilder}
7
+ args << options
8
+ end
9
+ options[:builder] = MuckCustomFormBuilder unless options.nil?
10
+ form_for(record_or_name_or_array, *args, &proc)
11
+ end
12
+
13
+ def output_errors(title, options = {}, fields = nil)
14
+ fields = [fields] unless fields.is_a?(Array)
15
+ flash_html = render(:partial => 'shared/flash_messages')
16
+ field_errors = render(:partial => 'shared/field_error', :collection => fields)
17
+ css_class = "class=\"#{options[:class]}\"" unless options[:class].nil?
18
+
19
+ if !flash_html.empty? && field_errors.empty?
20
+ # only flash. Don't render the
21
+ render(:partial => 'shared/flash_error_box', :locals => {:flash_html => flash_html, :css_class => css_class})
22
+ elsif !field_errors.empty?
23
+ # field errors and/or flash
24
+ render(:partial => 'shared/error_box', :locals => {:title => title,
25
+ :flash_html => flash_html,
26
+ :field_errors => field_errors,
27
+ :css_class => css_class,
28
+ :extra_html => options[:extra_html]})
29
+ else
30
+ #nothing
31
+ ''
32
+ end
33
+ end
34
+
35
+ def error_styles
36
+ if GlobalConfig.growl_all_messages
37
+ ' style="display:none;" '
38
+ end
39
+ end
40
+
41
+ def icon(object, size = :icon)
42
+ return "" if object.blank? || object.photo.blank?
43
+ link_to(image_tag(object.photo.url(size), :class => size), object, { :title => object.full_name })
44
+ end
45
+
46
+ def secure_mail_to(email)
47
+ mail_to email, nil, :encode => 'javascript'
48
+ end
49
+
50
+ # Used inside of format.js to return a message to the client.
51
+ # If jGrowl is enabled the message will show up as a growl instead of a popup
52
+ def page_alert(page, message, title = '')
53
+ if GlobalConfig.growl_enabled
54
+ page << "jQuery.jGrowl.error('" + message + "', {header:'" + title + "'});"
55
+ else
56
+ page.alert(message)
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,13 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: countries
4
+ #
5
+ # id :integer(4) not null, primary key
6
+ # name :string(128) default(""), not null
7
+ # abbreviation :string(3) default(""), not null
8
+ # sort :integer(4) default(1000), not null
9
+ #
10
+
11
+ class Country < ActiveRecord::Base
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class Language < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,13 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: states
4
+ #
5
+ # id :integer(4) not null, primary key
6
+ # name :string(128) default(""), not null
7
+ # abbreviation :string(3) default(""), not null
8
+ # country_id :integer(8) not null
9
+ #
10
+
11
+ class State < ActiveRecord::Base
12
+ belongs_to :country
13
+ end
@@ -0,0 +1,11 @@
1
+ <%= pre_html %>
2
+ <% if is_checkbox -%>
3
+ <%= field_element %>
4
+ <%= label_element %>
5
+ <% else -%>
6
+ <%= label_element %>
7
+ <%= field_element %>
8
+ <% end -%>
9
+ <% if required -%><div id="<%= field_name %>_required" class="required-tip" style="display:none;"><em><%= I18n.t(:please_enter_a_value, :label => label_name, :scope => [:muck, :users, :forms, :_base_field]) %></em></div><% end -%>
10
+ <% if !hide_control_error && defined? error -%><div class="form_error_message"><%= error %></div><% end -%>
11
+ <%= extra_html %>
@@ -0,0 +1,27 @@
1
+ <% color = value
2
+ html_id = '_' + id.to_s + '_' + field_name %>
3
+ <div <%= wrapper_id.nil? ? '' : "id=\"#{wrapper_id}\"" -%> class="form-row color-selector-container">
4
+ <%= render :partial => 'forms/base_field', :locals => local_assigns %>
5
+ <div id="colorSelector<%=html_id%>" class="color-selector">
6
+ <div id="colorSelectorDisplay<%=html_id%>" style="background-color:#<%=color%>;"></div>
7
+ </div>
8
+ <script type="text/javascript" language="JavaScript">
9
+ jQuery(document).ready(function() {
10
+ jQuery('#colorSelector<%=html_id%>').ColorPicker({
11
+ color: '#<%=color%>',
12
+ onShow: function (colpkr) {
13
+ jQuery(colpkr).fadeIn(100);
14
+ return false;
15
+ },
16
+ onHide: function (colpkr) {
17
+ jQuery(colpkr).fadeOut(100);
18
+ return false;
19
+ },
20
+ onChange: function (hsb, hex, rgb) {
21
+ jQuery('#colorSelectorDisplay<%=html_id%>').css('backgroundColor', '#' + hex);
22
+ jQuery('#<%=field_name%>').val(hex);
23
+ }
24
+ });
25
+ });
26
+ </script>
27
+ </div>