spurs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +118 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/spurs/icons/16x16/accept.png +0 -0
  5. data/app/assets/images/spurs/icons/16x16/delete.png +0 -0
  6. data/app/assets/images/spurs/icons/16x16/info.png +0 -0
  7. data/app/assets/images/spurs/icons/16x16/warning.png +0 -0
  8. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  9. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  10. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  11. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  12. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  13. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  14. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  15. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  16. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_222222_256x240.png +0 -0
  17. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_2e83ff_256x240.png +0 -0
  18. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_454545_256x240.png +0 -0
  19. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_888888_256x240.png +0 -0
  20. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_cd0a0a_256x240.png +0 -0
  21. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_f6cf3b_256x240.png +0 -0
  22. data/app/assets/javascripts/spurs/application.js +15 -0
  23. data/app/assets/javascripts/spurs/flashes.js.coffee +30 -0
  24. data/app/assets/javascripts/spurs/flashes.js.erb +32 -0
  25. data/app/assets/javascripts/spurs/sections.js.coffee +9 -0
  26. data/app/assets/javascripts/spurs/vars.js.coffee.erb +6 -0
  27. data/app/assets/javascripts/spurs/vars.js.erb +10 -0
  28. data/app/assets/javascripts/spurs.js +20 -0
  29. data/app/assets/stylesheets/spurs/application.css +13 -0
  30. data/app/assets/stylesheets/spurs/jquery-ui-theme.css +13 -0
  31. data/app/assets/stylesheets/spurs/jquery_ui_theme/jquery-ui-1.8.16.custom.css +1320 -0
  32. data/app/assets/stylesheets/spurs/jquery_ui_theme/jquery.ui.1.8.16.ie.css +6 -0
  33. data/app/assets/stylesheets/spurs/sections.css.sass +17 -0
  34. data/app/assets/stylesheets/spurs/vcenter.css.sass +11 -0
  35. data/app/assets/stylesheets/spurs.css +14 -0
  36. data/app/controllers/spurs/application_controller.rb +4 -0
  37. data/app/controllers/spurs/flashes_controller.rb +11 -0
  38. data/app/helpers/spurs/application_helper.rb +4 -0
  39. data/app/helpers/spurs/flashes_helper.rb +4 -0
  40. data/app/views/layouts/spurs/application.html.erb +14 -0
  41. data/app/views/spurs/flashes/add_message.js.erb +3 -0
  42. data/app/views/spurs/modals/spawn.js.erb +17 -0
  43. data/config/locales/en.yml +5 -0
  44. data/config/routes.rb +6 -0
  45. data/lib/spurs/engine.rb +10 -0
  46. data/lib/spurs/flash/builder.rb +55 -0
  47. data/lib/spurs/flash/controller_mods.rb +43 -0
  48. data/lib/spurs/flash/helper.rb +161 -0
  49. data/lib/spurs/flash.rb +54 -0
  50. data/lib/spurs/modal/builder.rb +118 -0
  51. data/lib/spurs/modal/controller_mods.rb +49 -0
  52. data/lib/spurs/modal/helper.rb +25 -0
  53. data/lib/spurs/modal.rb +16 -0
  54. data/lib/spurs/nav/builder.rb +213 -0
  55. data/lib/spurs/nav/helper.rb +42 -0
  56. data/lib/spurs/nav.rb +23 -0
  57. data/lib/spurs/popover/builder.rb +7 -0
  58. data/lib/spurs/popover/helper.rb +8 -0
  59. data/lib/spurs/popover.rb +5 -0
  60. data/lib/spurs/section/collapsible_section_builder.rb +31 -0
  61. data/lib/spurs/section/helper.rb +37 -0
  62. data/lib/spurs/section.rb +15 -0
  63. data/lib/spurs/version.rb +3 -0
  64. data/lib/spurs.rb +26 -0
  65. data/lib/tasks/spurs_tasks.rake +4 -0
  66. data/test/dummy/README.rdoc +261 -0
  67. data/test/dummy/Rakefile +7 -0
  68. data/test/dummy/app/assets/javascripts/application.js +15 -0
  69. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  70. data/test/dummy/app/controllers/application_controller.rb +3 -0
  71. data/test/dummy/app/helpers/application_helper.rb +2 -0
  72. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/test/dummy/config/application.rb +56 -0
  74. data/test/dummy/config/boot.rb +10 -0
  75. data/test/dummy/config/database.yml +25 -0
  76. data/test/dummy/config/environment.rb +5 -0
  77. data/test/dummy/config/environments/development.rb +37 -0
  78. data/test/dummy/config/environments/production.rb +67 -0
  79. data/test/dummy/config/environments/test.rb +37 -0
  80. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/test/dummy/config/initializers/inflections.rb +15 -0
  82. data/test/dummy/config/initializers/mime_types.rb +5 -0
  83. data/test/dummy/config/initializers/secret_token.rb +7 -0
  84. data/test/dummy/config/initializers/session_store.rb +8 -0
  85. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  86. data/test/dummy/config/locales/en.yml +5 -0
  87. data/test/dummy/config/routes.rb +4 -0
  88. data/test/dummy/config.ru +4 -0
  89. data/test/dummy/public/404.html +26 -0
  90. data/test/dummy/public/422.html +26 -0
  91. data/test/dummy/public/500.html +25 -0
  92. data/test/dummy/public/favicon.ico +0 -0
  93. data/test/dummy/script/rails +6 -0
  94. data/test/functional/spurs/flashes_controller_test.rb +9 -0
  95. data/test/integration/navigation_test.rb +10 -0
  96. data/test/spurs_test.rb +7 -0
  97. data/test/test_helper.rb +15 -0
  98. data/test/unit/helpers/spurs/flashes_helper_test.rb +6 -0
  99. metadata +224 -0
@@ -0,0 +1,6 @@
1
+
2
+ .ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-left, .ui-corner-bottom{ border-radius:0px;}
3
+ .ui-state-active,.ui-tabs-selected { border-radius:0px;}
4
+ .ui-tabs-selected { border-radius:0px;}
5
+ .ui-tabs .ui-tabs-nav li{ filter:none;}
6
+ .ui-tabs .ui-tabs-nav li a { border-radius:0px; }
@@ -0,0 +1,17 @@
1
+ .spurs_collapsible_section
2
+ padding: 5px
3
+ border: 1px solid #eee
4
+ margin: 10px 0px
5
+ .section_body
6
+ display: none
7
+ padding-top: 5px
8
+ .section_header
9
+ .section_toggle
10
+ float: right
11
+ &.open
12
+ .section_header
13
+ border-bottom: 1px solid #eee
14
+ padding-bottom: 5px
15
+ .section_body
16
+ display: block
17
+
@@ -0,0 +1,11 @@
1
+ .vcenter_outer
2
+ overflow: hidden
3
+ display: table
4
+ position: relative
5
+ text-align: center
6
+ &.full_width
7
+ width: 100%
8
+ > .middle
9
+ display: table-cell
10
+ vertical-align: middle
11
+ width: 100%
@@ -0,0 +1,14 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require ./spurs/sections
13
+ *= require ./spurs/vcenter
14
+ */
@@ -0,0 +1,4 @@
1
+ module Spurs
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Spurs
2
+ class FlashesController < ApplicationController
3
+ def create
4
+ respond_to do |format|
5
+ format.js {
6
+ render :file => 'spurs/flashes/add_message', :format => :js, :locals => {:_message => params[:message],:_flavor => params[:flavor]}
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Spurs
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Spurs
2
+ module FlashesHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Spurs</title>
5
+ <%= stylesheet_link_tag "spurs/application", :media => "all" %>
6
+ <%= javascript_include_tag "spurs/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ var _container = spurs.flashes.highest_priority_flash_container();
2
+ <%- to_render = spurs_alert(_message,:flavor => _flavor.to_s.parameterize.to_sym, :close_button => true, :builder => Spurs::Flash::Builder).html_safe%>
3
+ _container.append("<%=escape_javascript(to_render)%>");
@@ -0,0 +1,17 @@
1
+ <%-#create the modal container %>
2
+ var modal_container = tn.createEl('div');
3
+ $('body')[0].appendChild(modal_container);
4
+
5
+ <%-#put the partial in the modal%>
6
+ <%- modal_container_content =
7
+ escape_javascript(
8
+ spurs_modal modal_file_or_partial,
9
+ modal_object,
10
+ modal_options
11
+
12
+ )
13
+ %>
14
+ modal_container.innerHTML = "<%= modal_container_content %>";
15
+
16
+ <%-#activate the modal%>
17
+ $(modal_container.children[0]).modal();
@@ -0,0 +1,5 @@
1
+ en:
2
+ error: "error"
3
+ info: "info"
4
+ notice: "notice"
5
+ warning: "warning"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ namespace "spurs" do
3
+ resources :flashes, :only => [:create], :format => :js
4
+
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module Spurs
2
+
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Spurs
5
+
6
+
7
+ end
8
+
9
+
10
+ end
@@ -0,0 +1,55 @@
1
+ module Spurs
2
+ module Flash
3
+ class Builder
4
+ include ActionView::Helpers::TextHelper
5
+ include ActionView::Helpers::TagHelper
6
+ include ActionView::Helpers::AssetTagHelper
7
+
8
+ def build_alert(message,my_options)
9
+ if message == nil
10
+ raise "No message! #{my_options.to_json}"
11
+ end
12
+ my_content = String.new
13
+
14
+ if my_options[:close_button]
15
+ my_content.concat(content_tag(:a, "&#215;".html_safe, :class => :close, 'data-dismiss' => :alert))
16
+ end
17
+
18
+ header_content = my_options[:title]
19
+ if my_options[:title_icon]
20
+ header_content = content_tag(:img, nil, :src => "/assets/#{my_options[:title_icon]}", :style => "margin-bottom: 2px; margin-right: 5px; float: left").concat(header_content)
21
+ end
22
+
23
+ my_content.concat(alert_header_tag(header_content))
24
+
25
+ my_content.concat(content_tag(:p, message.to_s.html_safe))
26
+
27
+
28
+ alert_tag(my_content.html_safe, my_options)
29
+ end
30
+
31
+ private
32
+ def alert_header_tag(content, args={ })
33
+ my_args = { :class => "alert-heading" }.merge args
34
+ content_tag(:h4, content, my_args)
35
+ end
36
+
37
+ def alert_tag(content, args={ })
38
+ class_string = "alert"
39
+
40
+
41
+ if args[:flavor]
42
+ flavor_str = args[:flavor]
43
+ if flavor_str == :notice
44
+ flavor_str = :success
45
+ end
46
+ class_string.concat(" alert-#{flavor_str}")
47
+ end
48
+ if args[:block] != nil && args[:block] == true
49
+ class_string.concat(" alert-block")
50
+ end
51
+ content_tag(:div, content, :class => class_string)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ module Spurs
2
+ module Flash
3
+
4
+ module ControllerMods
5
+ def flash_addItem(list_name, message)
6
+ pluralized_list_name = list_name.to_s.pluralize.parameterize.to_sym
7
+ if flash[pluralized_list_name].nil?
8
+ flash[pluralized_list_name] = Array.new
9
+ end
10
+ flash[pluralized_list_name].push("<p>#{message}</p>")
11
+ end
12
+
13
+ #Array of
14
+ # name
15
+ # type (:link or :js)
16
+ # action
17
+ def flash_addItemWithActions(list_name, message, actions)
18
+ if flash[list_name].nil?
19
+ flash[list_name] = Array.new
20
+ end
21
+ flash_string = "<p>#{message}</p><div class=\"alert-actions\">"
22
+
23
+ actions.each do |action|
24
+ if action[:type] == :link
25
+ flash_string = flash_string + "<a class=\"btn small\" href=\"#{action[:action]}\">#{action[:name]}</a>"
26
+ end
27
+ end
28
+
29
+ flash_string = flash_string +"</div>"
30
+ flash[list_name].push(flash_string)
31
+ end
32
+
33
+ def flash_addModelErrors(model)
34
+ if flash[:errors].nil?
35
+ flash[:errors] = Array.new
36
+ end
37
+ model.errors.each do |k, errs|
38
+ flash[:errors].push("#{k.to_s} - #{errs.to_s}")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,161 @@
1
+ module Spurs
2
+ module Flash
3
+ module Helper
4
+ # the default css class of the container for flash messages
5
+ @@flashes_container_class = "spurs_flash_messages"
6
+
7
+
8
+ def self.flashes_container_class
9
+ @@flashes_container_class
10
+ end
11
+
12
+
13
+ # the prefix of the id for containers for flash messages
14
+ @@flashes_container_id_prefix = "spurs_flash_messages_"
15
+
16
+
17
+ def self.flashes_container_id_prefix
18
+ @@flashes_container_id_prefix
19
+ end
20
+
21
+
22
+ @@default_messages_options = {
23
+ :priority => 10,
24
+ :builder => Spurs::Flash::Builder
25
+ }
26
+
27
+
28
+ def self.default_messages_options
29
+ @@class.default_messages_options
30
+ end
31
+
32
+ def spurs_alert_box(options={ }, &block)
33
+ extra_class = options[:type] ? "alert-#{options[:type]}" : ""
34
+ alert_content = String.new
35
+ if options[:title]
36
+ alert_content.concat(content_tag(:h4, options[:title], :class => 'alert-heading'))
37
+ end
38
+ if block
39
+ block_content = capture(nil, &block)
40
+ alert_content.concat(block_content)
41
+ end
42
+ content_tag(:div, alert_content.html_safe, :class => "alert alert-block #{extra_class}")
43
+ end
44
+
45
+ ##
46
+ # Generate HTML for flash messages
47
+ # = Examples
48
+ #
49
+ # spurs_flash_helper
50
+ #
51
+ # = Options
52
+ #
53
+ # :priority - a numeric value that determines where new (usually dynamic) flash messages are placed. Defaults to 10
54
+ def spurs_flash_helper(options={ })
55
+
56
+ my_options = @@default_messages_options.merge(options)
57
+
58
+ #Rails.logger.debug("FLASH >>#{flash.to_json}")
59
+
60
+ message_hash = Hash.new()
61
+
62
+
63
+ flash.each do |fl|
64
+ process_flash_message(fl, message_hash)
65
+ end
66
+ flash.clear
67
+
68
+ #Rails.logger.info("MESSAGE HASH >>#{message_hash.to_json}")
69
+
70
+
71
+ #process the message hash now
72
+ content = String.new
73
+ message_hash.each do |k, v_arr|
74
+ v_arr.each do |v|
75
+ if v == nil
76
+ Rails.logger.warn("Flash key with no value: #{k.to_s} in flash hash #{v_arr.to_json}")
77
+ else
78
+ content << spurs_alert(v, :flavor => k, :builder => my_options[:builder], :title => k.to_s.singularize.tableize.to_sym.to_s.titlecase)
79
+ end
80
+ end
81
+ end
82
+
83
+ content_tag(:div, content.html_safe, :class => @@flashes_container_class, :id => "#{@@flashes_container_id_prefix}#{my_options[:priority]}")
84
+ end
85
+
86
+
87
+ def spurs_alert(message, options={ })
88
+
89
+ ## We shouldn't really need this if code is written properly
90
+ if message.is_a?(Array)
91
+ raise "Message shouldn't be an array #{message}"
92
+ end
93
+
94
+ #merge arguments with defaults
95
+ my_options = Spurs::Flash::default_args[:default].merge(options)
96
+
97
+ # make sure the flavor is a symbol
98
+ if my_options[:flavor] then
99
+ my_options[:flavor] = my_options[:flavor].to_s.singularize.parameterize.to_sym
100
+ end
101
+
102
+ # attempt to find the flavor in the list of known stuff
103
+ if Spurs::Flash::flavors.find_index(my_options[:flavor]) == nil
104
+ # didn't find it.
105
+ Rails.logger.warn("Unknown flash flavor \"#{my_options[:flavor]}\". Using a default instead")
106
+ my_options[:flavor] = Spurs::Flash::default_args[:default][:flavor]
107
+ end
108
+
109
+
110
+ if !my_options[:title_icon]
111
+ ico = Spurs::Flash::flavor_icons[my_options[:flavor]]
112
+ if ico then
113
+ my_options[:title_icon] = ico
114
+ end
115
+ end
116
+
117
+ if !my_options[:title]
118
+ t = Spurs::Flash::flavor_titles[my_options[:flavor]]
119
+ if t then
120
+ my_options[:title] = t
121
+ end
122
+ end
123
+
124
+ if !my_options[:builder]
125
+ raise "Null builder"
126
+ end
127
+
128
+ builder = my_options[:builder].new
129
+
130
+ begin
131
+ flash_content = builder.build_alert(message, my_options)
132
+ rescue => e
133
+ raise "Problem building flash message \nMessage: #{message.to_json}\nOptions: #{my_options.to_json}\nCause: #{e.message}\n\t#{e.backtrace}"
134
+ end
135
+
136
+ return flash_content
137
+ end
138
+
139
+
140
+ private
141
+ def process_flash_message(fl, message_hash)
142
+ raw_key = fl[0].to_s.parameterize.to_sym #normalize case
143
+ is_plural = raw_key.to_s.pluralize == raw_key.to_s
144
+
145
+ key = is_plural ? raw_key.to_s.singularize.to_s.parameterize.to_s : raw_key
146
+ # create the entry in the message hash if necessary
147
+ if !message_hash[key]
148
+ message_hash[key] = Array.new
149
+ end
150
+
151
+ if !is_plural
152
+ message_hash[key].push(fl[1])
153
+ else
154
+ (0..fl[1].size-1).each do |i|
155
+ message_hash[key].push(fl[1][i])
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,54 @@
1
+ module Spurs
2
+ module Flash
3
+ # Flavors of flash message that we know how to deal with
4
+ ##
5
+ @@flavors = [:error, :notice, :info, :warning]
6
+ @@flavor_titles = {
7
+ :error => I18n.t(:error, :default => "error").titlecase,
8
+ :notice => I18n.t(:notice, :default => "notice").titlecase,
9
+ :info => I18n.t(:info, :default => "info").titlecase,
10
+ :warning => I18n.t(:warning, :default => "warning").titlecase
11
+ }
12
+ @@flavor_icons = {
13
+ :error => "spurs/icons/16x16/delete.png",
14
+ :notice => "spurs/icons/16x16/accept.png",
15
+ :info => "spurs/icons/16x16/info.png",
16
+ :warning => "spurs/icons/16x16/warning.png"
17
+ }
18
+
19
+ def self.flavor_icons
20
+ @@flavor_icons
21
+ end
22
+
23
+ def self.flavor_titles
24
+ @@flavor_titles
25
+ end
26
+
27
+ @@default_args = {
28
+ :dynamic => {
29
+ :block => true,
30
+ :flavor => :info,
31
+ :lifetime => 5000,
32
+ :close_button => true
33
+ },
34
+ :default => {
35
+ :block => true,
36
+ :flavor => :info,
37
+ :lifetime => -1,
38
+ :close_button => true
39
+ }
40
+ }
41
+
42
+ def self.default_args
43
+ @@default_args
44
+ end
45
+
46
+ def self.flavors
47
+ @@flavors
48
+ end
49
+ end
50
+ end
51
+
52
+ require "spurs/flash/builder"
53
+ require "spurs/flash/helper"
54
+ require "spurs/flash/controller_mods"
@@ -0,0 +1,118 @@
1
+ module Spurs
2
+ module Modal
3
+ class Builder
4
+ include ActionView::Helpers::TagHelper
5
+
6
+
7
+
8
+ def build_modal(modal_id, content, options={ })
9
+
10
+ if !options[:class] then
11
+ options[:class] = ""
12
+ end
13
+ options[:class].concat(" modal fade #{modal_id}")
14
+
15
+ c = String.new
16
+
17
+ if options[:header]
18
+ header_options = options.delete(:header)
19
+ if header_options[:title]
20
+ c.concat(build_modal_title(header_options[:title], header_options[:icon]))
21
+ end
22
+ end
23
+
24
+
25
+ #body
26
+ c.concat(content_tag(:div, content, :class => "modal-body"))
27
+
28
+ if options[:actions]
29
+ actions_options = options.delete(:actions)
30
+ c.concat(build_modal_footer(actions_options).html_safe)
31
+ end
32
+
33
+
34
+ content_tag(:div, c.html_safe, :class => options[:class], 'data-modal-id' => "#{modal_id}")
35
+
36
+ end
37
+
38
+
39
+
40
+ private
41
+ def build_modal_title(title, icon)
42
+ c = String.new
43
+ if icon != nil
44
+ c.concat(content_tag(:img, '', :src => icon, :style => "float: left; margin-right: 10px; height: 36px").html_safe)
45
+ end
46
+ c.concat(content_tag(:h1, title))
47
+ content_tag(:div, c.html_safe, :class => "modal-header")
48
+ end
49
+
50
+
51
+
52
+ def build_modal_footer(actions)
53
+ c = String.new
54
+
55
+ left_content = "&nbsp;"
56
+ right_content = "&nbsp;"
57
+ center_content = "&nbsp;"
58
+
59
+ actions.each do |action|
60
+ class_str = "btn"
61
+ if action[:position]
62
+ if action[:position] == :left
63
+ left_content.concat(build_action_button(action))
64
+ else
65
+ if action[:position] == :right
66
+ right_content.concat(build_action_button(action))
67
+ else
68
+ if action[:position] == :center
69
+ center_content.concat(build_action_button(action))
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ left_area = content_tag(:div, left_content.html_safe, :style => "width: 32%; text-align: left; float: left")
77
+ right_area = content_tag(:div, right_content.html_safe, :style => "width: 32%; text-align: right; float: left")
78
+ middle_area = content_tag(:div, center_content.html_safe, :style => "width: 33%; text-align: center; float:left")
79
+
80
+ c.concat(left_area).concat(middle_area).concat(right_area)
81
+
82
+ content_tag(:div, c.html_safe, :class => "modal-footer")
83
+ end
84
+
85
+
86
+
87
+ def build_action_button(action)
88
+ class_str = "btn #{action[:class] ? action[:class] : ""} btn-large"
89
+
90
+ attrs = {
91
+ :onclick => ""
92
+ }
93
+
94
+ if action[:action]
95
+ if action[:action].kind_of?(Symbol)
96
+ case action[:action]
97
+ when :close_modal then
98
+ attrs[:onclick] = "m=$(this).closest('.modal');m.modal('hide')"
99
+ when :submit_form_and_close_modal then
100
+ attrs[:onclick] = "m=$(this).closest('.modal');m.find('.modal-body form').submit();m.modal('hide')"
101
+ else
102
+ raise "Unknown button action \"#{action[:action].to_json}\""
103
+ end
104
+ end
105
+ end
106
+
107
+ if attrs[:onclick] == ""
108
+ attrs.delete(:onclick)
109
+ end
110
+ attrs[:class] = class_str
111
+
112
+
113
+ content_tag(:a, action[:name].to_s.titlecase.html_safe, attrs)
114
+
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,49 @@
1
+ module Spurs
2
+ module Modal
3
+ module ControllerMods
4
+ extend ActiveSupport::Concern
5
+
6
+ def spawn_form_modal(title, partial, object, options={ })
7
+ opts = {
8
+ :actions => [
9
+ { :name => :cancel, :position => :left, :action => :close_modal, :class => "btn-large" },
10
+ { :name => :save, :position => :right, :action => :submit_form_and_close_modal, :class => "btn-primary btn-large" },
11
+ ]
12
+ }.merge(options)
13
+ logger.debug("spawn_form_modal options = #{opts.to_json}")
14
+
15
+ spawn_modal(title, partial, object, opts)
16
+ end
17
+
18
+
19
+
20
+ def spawn_close_modal(title, file, options={ })
21
+ opts[:content_options] = options
22
+ opts = {
23
+ :actions => [
24
+ { :name => :cancel, :position => :left, :action => :close_modal, :class => "btn-large" }
25
+ ]
26
+ }.merge(options)
27
+ logger.debug("spawn_close_modal options = #{opts.to_json}")
28
+ spawn_modal(title, file, nil, opts)
29
+ end
30
+
31
+
32
+
33
+ def spawn_modal(title, partial, object, options={ })
34
+ #options[:content_options] = options.clone
35
+ opts = {
36
+ :header => {
37
+ :title => title.titlecase,
38
+ :icon => options[:title_icon] ? options.delete(:title_icon) : nil
39
+ },
40
+
41
+ }.merge(options)
42
+ logger.debug("spawn_modal options = #{opts.to_json}")
43
+ render :file => "spurs/modals/spawn", :locals => { :modal_file_or_partial => partial,
44
+ :modal_object => object,
45
+ :modal_options => opts }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ require "spurs/modal/builder"
2
+ module Spurs
3
+ module Modal
4
+ module Helper
5
+ def spurs_modal(file_or_partial, object=nil, options={ })
6
+ opts = Spurs::Modal::default_options.merge(options)
7
+ builder_class = opts.delete(:builder)
8
+ builder = builder_class.new
9
+
10
+ modal_id = "modal_#{SecureRandom::hex(5)}"
11
+
12
+ options_for_content = options[:content_options] ? options.delete(:content_options) : { }
13
+
14
+ if object == nil
15
+ content = render :file => file_or_partial, :locals => options_for_content
16
+ else
17
+ content = render :object => object, :partial => file_or_partial, :locals => options_for_content
18
+ end
19
+
20
+
21
+ bm = builder.build_modal(modal_id, content, options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require "spurs/modal/helper"
2
+ require "spurs/modal/controller_mods"
3
+
4
+ module Spurs
5
+ module Modal
6
+
7
+
8
+ def self.default_options
9
+ {
10
+ :builder => Spurs::Modal::Builder
11
+ }
12
+ end
13
+
14
+
15
+ end
16
+ end