window_rails 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/CHANGELOG.rdoc +3 -0
  2. data/LICENSE +1 -23
  3. data/README.rdoc +14 -26
  4. data/app/controllers/window_rails_controller.rb +19 -4
  5. data/lib/window_rails.rb +6 -2
  6. data/lib/window_rails/engine.rb +15 -0
  7. data/lib/window_rails/tasks.rb +65 -3
  8. data/lib/window_rails/version.rb +1 -1
  9. data/lib/window_rails/window_rails_generators.rb +225 -98
  10. data/lib/window_rails/window_rails_view.rb +35 -3
  11. data/rails/init.rb +1 -1
  12. metadata +24 -181
  13. data/files/javascripts/debug.js +0 -137
  14. data/files/javascripts/extended_debug.js +0 -113
  15. data/files/javascripts/tooltip.js +0 -241
  16. data/files/javascripts/window.js +0 -1882
  17. data/files/javascripts/window_effects.js +0 -157
  18. data/files/javascripts/window_ext.js +0 -115
  19. data/files/themes/alert.css +0 -119
  20. data/files/themes/alert/bottom.gif +0 -0
  21. data/files/themes/alert/bottom_left.gif +0 -0
  22. data/files/themes/alert/bottom_right.gif +0 -0
  23. data/files/themes/alert/left.gif +0 -0
  24. data/files/themes/alert/overlay.png +0 -0
  25. data/files/themes/alert/progress.gif +0 -0
  26. data/files/themes/alert/right.gif +0 -0
  27. data/files/themes/alert/top.gif +0 -0
  28. data/files/themes/alert/top_left.gif +0 -0
  29. data/files/themes/alert/top_right.gif +0 -0
  30. data/files/themes/alert_lite.css +0 -88
  31. data/files/themes/alphacube.css +0 -150
  32. data/files/themes/alphacube/bottom-left-c.gif +0 -0
  33. data/files/themes/alphacube/bottom-middle.gif +0 -0
  34. data/files/themes/alphacube/bottom-right-c.gif +0 -0
  35. data/files/themes/alphacube/button-close-focus.gif +0 -0
  36. data/files/themes/alphacube/button-max-focus.gif +0 -0
  37. data/files/themes/alphacube/button-min-focus.gif +0 -0
  38. data/files/themes/alphacube/frame-left.gif +0 -0
  39. data/files/themes/alphacube/frame-right.gif +0 -0
  40. data/files/themes/alphacube/left-top.gif +0 -0
  41. data/files/themes/alphacube/right-top.gif +0 -0
  42. data/files/themes/alphacube/top-middle.gif +0 -0
  43. data/files/themes/behavior.htc +0 -51
  44. data/files/themes/darkX.css +0 -121
  45. data/files/themes/darkX/button-close-focused.png +0 -0
  46. data/files/themes/darkX/button-maximize-focused.png +0 -0
  47. data/files/themes/darkX/button-minimize-focused.png +0 -0
  48. data/files/themes/darkX/frame-bottom-left-focused.png +0 -0
  49. data/files/themes/darkX/frame-bottom-mid-focused.png +0 -0
  50. data/files/themes/darkX/frame-bottom-right-focused.png +0 -0
  51. data/files/themes/darkX/frame-left-focused.png +0 -0
  52. data/files/themes/darkX/frame-right-focused.png +0 -0
  53. data/files/themes/darkX/titlebar-left-focused.png +0 -0
  54. data/files/themes/darkX/titlebar-mid-focused.png +0 -0
  55. data/files/themes/darkX/titlebar-right-focused.png +0 -0
  56. data/files/themes/debug.css +0 -25
  57. data/files/themes/default.css +0 -155
  58. data/files/themes/default/bottom_left.gif +0 -0
  59. data/files/themes/default/bottom_mid.gif +0 -0
  60. data/files/themes/default/bottom_right.gif +0 -0
  61. data/files/themes/default/bottom_right_resize.gif +0 -0
  62. data/files/themes/default/center_left.gif +0 -0
  63. data/files/themes/default/center_right.gif +0 -0
  64. data/files/themes/default/clear.gif +0 -0
  65. data/files/themes/default/close.gif +0 -0
  66. data/files/themes/default/inspect.gif +0 -0
  67. data/files/themes/default/maximize.gif +0 -0
  68. data/files/themes/default/minimize.gif +0 -0
  69. data/files/themes/default/overlay.png +0 -0
  70. data/files/themes/default/resize.gif +0 -0
  71. data/files/themes/default/sizer.gif +0 -0
  72. data/files/themes/default/top_left.gif +0 -0
  73. data/files/themes/default/top_mid.gif +0 -0
  74. data/files/themes/default/top_right.gif +0 -0
  75. data/files/themes/iefix/blank.gif +0 -0
  76. data/files/themes/iefix/iepngfix.css +0 -3
  77. data/files/themes/iefix/iepngfix.htc +0 -54
  78. data/files/themes/lighting.css +0 -960
  79. data/files/themes/lighting/background_buttons.gif +0 -0
  80. data/files/themes/lighting/bottom-left-blue.png +0 -0
  81. data/files/themes/lighting/bottom-left-darkblue.png +0 -0
  82. data/files/themes/lighting/bottom-left-green.png +0 -0
  83. data/files/themes/lighting/bottom-left-grey.png +0 -0
  84. data/files/themes/lighting/bottom-middle-blue.png +0 -0
  85. data/files/themes/lighting/bottom-middle-darkblue.png +0 -0
  86. data/files/themes/lighting/bottom-middle-green.png +0 -0
  87. data/files/themes/lighting/bottom-middle-grey.png +0 -0
  88. data/files/themes/lighting/bottom-right-blue.png +0 -0
  89. data/files/themes/lighting/bottom-right-darkblue.png +0 -0
  90. data/files/themes/lighting/bottom-right-green.png +0 -0
  91. data/files/themes/lighting/bottom-right-grey.png +0 -0
  92. data/files/themes/lighting/button-close-blue.png +0 -0
  93. data/files/themes/lighting/button-close-darkblue.png +0 -0
  94. data/files/themes/lighting/button-close-green.png +0 -0
  95. data/files/themes/lighting/button-close-grey.png +0 -0
  96. data/files/themes/lighting/button-maximize-blue.png +0 -0
  97. data/files/themes/lighting/button-maximize-darkblue.png +0 -0
  98. data/files/themes/lighting/button-maximize-green.png +0 -0
  99. data/files/themes/lighting/button-maximize-grey.png +0 -0
  100. data/files/themes/lighting/button-minimize-blue.png +0 -0
  101. data/files/themes/lighting/button-minimize-darkblue.png +0 -0
  102. data/files/themes/lighting/button-minimize-green.png +0 -0
  103. data/files/themes/lighting/button-minimize-grey.png +0 -0
  104. data/files/themes/lighting/left-blue.png +0 -0
  105. data/files/themes/lighting/left-darkblue.png +0 -0
  106. data/files/themes/lighting/left-green.png +0 -0
  107. data/files/themes/lighting/left-grey.png +0 -0
  108. data/files/themes/lighting/pngbehavior.htc +0 -67
  109. data/files/themes/lighting/right-blue.png +0 -0
  110. data/files/themes/lighting/right-darkblue.png +0 -0
  111. data/files/themes/lighting/right-green.png +0 -0
  112. data/files/themes/lighting/right-grey.png +0 -0
  113. data/files/themes/lighting/spinner.gif +0 -0
  114. data/files/themes/lighting/top-left-blue.png +0 -0
  115. data/files/themes/lighting/top-left-darkblue.png +0 -0
  116. data/files/themes/lighting/top-left-green.png +0 -0
  117. data/files/themes/lighting/top-left-grey.png +0 -0
  118. data/files/themes/lighting/top-middle-blue.png +0 -0
  119. data/files/themes/lighting/top-middle-darkblue.png +0 -0
  120. data/files/themes/lighting/top-middle-green.png +0 -0
  121. data/files/themes/lighting/top-middle-grey.png +0 -0
  122. data/files/themes/lighting/top-right-blue.png +0 -0
  123. data/files/themes/lighting/top-right-darkblue.png +0 -0
  124. data/files/themes/lighting/top-right-green.png +0 -0
  125. data/files/themes/lighting/top-right-grey.png +0 -0
  126. data/files/themes/mac_os_x.css +0 -333
  127. data/files/themes/mac_os_x/B.png +0 -0
  128. data/files/themes/mac_os_x/BL.png +0 -0
  129. data/files/themes/mac_os_x/BL_Main.png +0 -0
  130. data/files/themes/mac_os_x/BR.png +0 -0
  131. data/files/themes/mac_os_x/BR_Main.png +0 -0
  132. data/files/themes/mac_os_x/B_Main.png +0 -0
  133. data/files/themes/mac_os_x/L.png +0 -0
  134. data/files/themes/mac_os_x/L_Main.png +0 -0
  135. data/files/themes/mac_os_x/R.png +0 -0
  136. data/files/themes/mac_os_x/R_Main.png +0 -0
  137. data/files/themes/mac_os_x/T.png +0 -0
  138. data/files/themes/mac_os_x/TL.png +0 -0
  139. data/files/themes/mac_os_x/TL_Main.png +0 -0
  140. data/files/themes/mac_os_x/TR.png +0 -0
  141. data/files/themes/mac_os_x/TR_Main.png +0 -0
  142. data/files/themes/mac_os_x/T_Main.png +0 -0
  143. data/files/themes/mac_os_x/close.gif +0 -0
  144. data/files/themes/mac_os_x/maximize.gif +0 -0
  145. data/files/themes/mac_os_x/minimize.gif +0 -0
  146. data/files/themes/mac_os_x_dialog.css +0 -160
  147. data/files/themes/mac_os_x_dialog/B.png +0 -0
  148. data/files/themes/mac_os_x_dialog/BL.png +0 -0
  149. data/files/themes/mac_os_x_dialog/BR.png +0 -0
  150. data/files/themes/mac_os_x_dialog/L.png +0 -0
  151. data/files/themes/mac_os_x_dialog/R.png +0 -0
  152. data/files/themes/mac_os_x_dialog/T.png +0 -0
  153. data/files/themes/mac_os_x_dialog/TL.png +0 -0
  154. data/files/themes/mac_os_x_dialog/TR.png +0 -0
  155. data/files/themes/mac_os_x_dialog/bg.gif +0 -0
  156. data/files/themes/mac_os_x_dialog/close.gif +0 -0
  157. data/files/themes/mac_os_x_dialog/maximize.gif +0 -0
  158. data/files/themes/mac_os_x_dialog/minimize.gif +0 -0
  159. data/files/themes/nuncio.css +0 -164
  160. data/files/themes/nuncio/bottom_left.png +0 -0
  161. data/files/themes/nuncio/bottom_mid.png +0 -0
  162. data/files/themes/nuncio/bottom_right.png +0 -0
  163. data/files/themes/nuncio/center_left.png +0 -0
  164. data/files/themes/nuncio/center_right.png +0 -0
  165. data/files/themes/nuncio/close.png +0 -0
  166. data/files/themes/nuncio/minimize.png +0 -0
  167. data/files/themes/nuncio/overlay.png +0 -0
  168. data/files/themes/nuncio/top_left.png +0 -0
  169. data/files/themes/nuncio/top_mid.png +0 -0
  170. data/files/themes/nuncio/top_right.png +0 -0
  171. data/files/themes/spread.css +0 -108
  172. data/files/themes/spread/bottom-left-c.gif +0 -0
  173. data/files/themes/spread/bottom-middle.gif +0 -0
  174. data/files/themes/spread/bottom-right-c.gif +0 -0
  175. data/files/themes/spread/button-close-focus.gif +0 -0
  176. data/files/themes/spread/button-max-focus.gif +0 -0
  177. data/files/themes/spread/button-min-focus.gif +0 -0
  178. data/files/themes/spread/frame-left.gif +0 -0
  179. data/files/themes/spread/frame-right.gif +0 -0
  180. data/files/themes/spread/left-top.gif +0 -0
  181. data/files/themes/spread/right-top.gif +0 -0
  182. data/files/themes/spread/top-middle.gif +0 -0
  183. data/init.rb +0 -8
  184. data/install.rb +0 -31
  185. data/uninstall.rb +0 -9
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == v0.2.0
2
+ * Rebuild off jquery-ui dialogs
3
+
1
4
  == v0.1.4
2
5
  * Fix to #update_window method to accept content not key
3
6
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Current WindowRails License:
2
2
 
3
- Copyright (c) 2010 Chris Roberts <chrisroberts.code@gmail.com>
3
+ Copyright (c) 2011 Chris Roberts <chrisroberts.code@gmail.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -20,25 +20,3 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
20
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
-
24
- Original Prototype Window License:
25
-
26
- Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
27
-
28
- Permission is hereby granted, free of charge, to any person obtaining
29
- a copy of this software and associated documentation files (the
30
- "Software"), to deal in the Software without restriction, including
31
- without limitation the rights to use, copy, modify, merge, publish,
32
- distribute, sublicense, and/or sell copies of the Software, and to
33
- permit persons to whom the Software is furnished to do so, subject to
34
- the following conditions:
35
-
36
- The above copyright notice and this permission notice shall be
37
- included in all copies or substantial portions of the Software.
38
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,33 +1,26 @@
1
- == WindowRails
1
+ == WindowRails (for jQuery)
2
2
 
3
3
  WindowRails is a plugin for Rails that provides easy to use AJAXy windows. It is based
4
- completely on {Prototype Window}[http://prototype-window.xilinus.com/] with helpers for
5
- Rails to make it easy to use from a Rails app.
4
+ completely on {jquery-ui}[http://jquery-ui.com] and the [jQuery Window Plugin}[http://fstoke.me/jquery/window/]
5
+ with helpers for Rails to make it easy to use from a Rails app.
6
6
 
7
- == Configuration
7
+ == Requirements
8
8
 
9
- After install, add these in the head of your application.html.erb file:
9
+ * jQuery
10
+ * jQuery-UI with Dialog widget enabled
10
11
 
11
- <%= javascript_include_tag 'window_rails/window' %>
12
- <%= stylesheet_link_tag *%w(/themes/alphacube /themes/default /themes/alert) %>
13
-
14
- Alphacube is the default theme used by window_rails. Be sure to add the css link if you plan on using other themes.
15
-
16
- === Gem based installs
17
-
18
- Gem based installs (bundler) will need to run the install task. For rails versions < 3 the task
19
- must be added to the Rakefile:
20
-
21
- require 'window_rails/tasks'
22
-
23
- Then run the install:
12
+ == Installation
24
13
 
25
14
  rake window_rails:install
26
15
 
27
16
  === Basic examples to get you started
28
17
 
29
18
  ==== Linking to a window
30
- <%= link_to_window('Link', :url => {:controller => :my_controller, :action => :my_action}, :modal => true, :className => 'alphacube', :window => 'some_name') %>
19
+ ===== Load an entire HTML page into an IFrame
20
+ <%= link_to_window('Link', :iframe => {:controller => :my_controller, :action => :my_action}, :window => 'some_name') %>
21
+
22
+ ===== Load a partial page directly into the DOM within the window
23
+ <%= link_to_window('Link', :url => {:controller => :my_controller, :action => :my_action}, :width => 400, :height => 300, :window => 'some_name') %>
31
24
 
32
25
  ==== Opening a window via AJAX
33
26
  def open_my_window
@@ -35,7 +28,7 @@ Then run the install:
35
28
  format.html
36
29
  format.js do
37
30
  render :update do |page|
38
- page.open_window({:partial => 'my_partial'}, :modal => true, :width => 400, :height => 200, :window => 'my_window')
31
+ page.open_window({:partial => 'my_partial'}, :width => 400, :height => 200, :window => 'my_window')
39
32
  end
40
33
  end
41
34
  end
@@ -73,11 +66,6 @@ Then run the install:
73
66
 
74
67
  {Issues}[http://github.com/chrisroberts/window_rails/issues]
75
68
 
76
- == Thanks
77
-
78
- * Many thanks to Sébastien Gruhier (creator of {Prototype Window}[http://prototype-window.xilinus.com/])
79
-
80
69
  == License
81
70
 
82
- * Prototype Window was released under the MIT license
83
- * WindowRails continues on under the MIT license
71
+ * WindowRails is released under an MIT license
@@ -1,5 +1,7 @@
1
- class WindowRailsController < ActionController::Base
2
-
1
+ class WindowRailsController < ApplicationController
2
+
3
+ unloadable
4
+
3
5
  # Make sure we kick any thing out that is making a request other
4
6
  # than openning a new window
5
7
  before_filter :redirect_out, :except => :open_window
@@ -26,10 +28,23 @@ class WindowRailsController < ActionController::Base
26
28
  redirect_to '/'
27
29
  end
28
30
  format.js do
31
+ opts = {}
32
+ content = nil
33
+ if(params[:window_url].blank?)
34
+ content = {:url => params[:iframe_url]}
35
+ else
36
+ content = {:content_url => params[:window_url]}
37
+ end
38
+ base_key = params[:window_options] ? :window_options : 'window_options'
39
+ if(params[base_key])
40
+ params[base_key].keys.each do |key|
41
+ opts[key.to_sym] = params[base_key][key]
42
+ end
43
+ end
29
44
  render :update do |page|
30
- page.open_window({:url => params[:window_url]}, params[:window_options])
45
+ page.open_window(content, opts || {})
31
46
  end
32
47
  end
33
48
  end
34
49
  end
35
- end
50
+ end
data/lib/window_rails.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'window_rails/version'
2
2
 
3
- if(defined?(Rails))
4
- require File.join(File.dirname(__FILE__), '..', 'init')
3
+ if(defined?(Rails::Engine))
4
+ require 'window_rails/engine'
5
+ else
6
+ %w(window_rails_generators window_rails_view).each do |part|
7
+ require "window_rails/#{part}"
8
+ end
5
9
  end
@@ -0,0 +1,15 @@
1
+ module WindowRails
2
+ class Engine < Rails::Engine
3
+
4
+ rake_tasks do
5
+ require 'window_rails/tasks'
6
+ end
7
+
8
+ # We do all our setup in here
9
+ config.to_prepare do
10
+ %w(window_rails_generators window_rails_view).each do |part|
11
+ require "window_rails/#{part}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,69 @@
1
- namespace :window_rails do
2
- desc 'Install required library items'
1
+ require 'fileutils'
2
+
3
+ namespace :window_rails do
4
+
5
+ desc 'Install window_rails'
3
6
  task :install do
4
- require File.join(File.dirname(__FILE__), '..', '..', 'install.rb')
7
+ FileUtils.mkdir_p(File.join(Rails.root, 'public', 'window_rails'))
8
+ Rake::Task['window_rails:install_javascripts'].invoke
9
+ Rake::Task['window_rails:install_stylesheets'].invoke
10
+ Rake::Task['window_rails:install_assets'].invoke
11
+ Rake::Task['window_rails:install_version'].invoke
12
+ puts '*' * 50
13
+ puts 'WindowRails installation is complete.'
14
+ puts 'NOTE: Please refer to README file for any additional setup.'
15
+ puts '*' * 50
16
+ end
17
+
18
+ task :upgrade do
19
+ Rake::Task['window_rails:install_javascripts'].invoke
20
+ Rake::Task['window_rails:install_stylesheets'].invoke
21
+ Rake::Task['window_rails:install_assets'].invoke
22
+ puts 'WindowRails files have been updated to most current version'
23
+ end
24
+
25
+ task :install_javascripts do
26
+ install_items('javascripts')
27
+ end
28
+
29
+ task :install_stylesheets do
30
+ install_items('stylesheets')
5
31
  end
32
+
33
+ task :install_assets do
34
+ install_items('images')
35
+ end
36
+
37
+ task :install_version do
38
+ f = File.open(File.join(Rails.root, 'public', 'window_rails', 'version'), 'w')
39
+ f.write WindowRails::VERSION
40
+ f.close
41
+ puts 'Version file written'
42
+ end
43
+
44
+ desc 'Output current version information'
45
+ task :version do
46
+ asset_version = nil
47
+ if(File.exists?(File.join(Rails.root, 'public', 'window_rails', 'version')))
48
+ asset_version = File.read(File.join(Rails.root, 'public', 'window_rails', 'version')).strip
49
+ end
50
+ puts "Current WindowRails version: #{WindowRails::VERSION}"
51
+ puts "Current WindowRails assets version: #{asset_version}"
52
+ if(WindowRails::VERSION != asset_version.to_s)
53
+ puts "WARNING #{'*' * 50}"
54
+ puts 'WindowRails assets within project are out of date'
55
+ puts 'Please run: rake window_rails:upgrade'
56
+ puts "WARNING #{'*' * 50}"
57
+ end
58
+ end
59
+ end
60
+
61
+ def install_items(item)
62
+ FileUtils.mkdir_p(File.join(Rails.root, 'public', 'window_rails', item))
63
+ FileUtils.cp_r(
64
+ File.join(File.dirname(__FILE__), '..', '..', 'files', item, File::SEPARATOR, '.'),
65
+ File.join(Rails.root, 'public', 'window_rails', item)
66
+ )
67
+ puts "#{item.titleize} files installed."
6
68
  end
7
69
 
@@ -1,3 +1,3 @@
1
1
  module WindowRails
2
- VERSION = '0.1.5'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,5 +1,8 @@
1
+ require 'rails_javascript_helpers'
2
+
1
3
  module WindowRailsGenerators
2
-
4
+
5
+ include RailsJavaScriptHelpers
3
6
  include ActionView::Helpers::JavaScriptHelper
4
7
  include ActionView::Helpers::TagHelper
5
8
 
@@ -8,7 +11,27 @@ module WindowRailsGenerators
8
11
  # Opens an alert window
9
12
  def open_alert_window(msg, options={})
10
13
  options[:width] ||= 200
11
- self << "Dialog.alert('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(',')}});"
14
+ options[:modal] = true
15
+ options[:title] ||= 'Alert!'
16
+ options[:buttons] ||= {'OK' => 'function(){ jQuery(this).dialog("close");}'}
17
+ store_content(msg, 'alert_modal');
18
+ self << "
19
+ if(jQuery('#alert_modal').size() == 0){
20
+ jQuery('<div id=\"alert_modal\"></div>')
21
+ .html(window_rails_contents['alert_modal'])
22
+ .dialog(#{format_type_to_js(options)});
23
+ } else {
24
+ jQuery('#alert_modal')
25
+ .html(window_rails_contents['alert_modal'])
26
+ .dialog(#{format_type_to_js(options)}).focus();
27
+ }"
28
+ nil
29
+ end
30
+
31
+ # Closes alert window
32
+ def close_alert_window
33
+ self << 'jQuery("#alert_modal").dialog("close");'
34
+ nil
12
35
  end
13
36
 
14
37
  # msg:: Confirmation message
@@ -16,7 +39,21 @@ module WindowRailsGenerators
16
39
  # Opens a confirmation window
17
40
  def open_confirm_window(msg, options={})
18
41
  options[:width] ||= 200
19
- self << "Dialog.confirm('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(',')}});"
42
+ options[:modal] = true
43
+ options[:title] ||= 'Confirm'
44
+ options[:buttons] ||= {'OK' => 'function(){ jQuery(this).dialog("close");}'}
45
+ store_content(msg, 'confirmation_modal')
46
+ self << "
47
+ if(jQuery('#confirmation_modal').size() == 0){
48
+ jQuery('<div id=\"confirmation_modal\"></div>')
49
+ .html(window_rails_contents['confirmation_modal'])
50
+ .dialog(#{format_type_to_js(options)});
51
+ } else {
52
+ jQuery('#confirmation_modal')
53
+ .html(window_rails_contents['confirmation_modal'])
54
+ .dialog(#{format_type_to_js(options)}).focus();
55
+ }"
56
+ nil
20
57
  end
21
58
 
22
59
  # msg:: Information message
@@ -24,19 +61,62 @@ module WindowRailsGenerators
24
61
  # Open an information window
25
62
  def open_info_window(msg, options={})
26
63
  options[:width] ||= 200
27
- self << "Dialog.info('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(',')}});"
64
+ options[:modal] = true
65
+ options[:title] ||= 'Information'
66
+ options[:close_on_escape] = false
67
+ store_content(msg, 'information_modal')
68
+ self << "
69
+ if(jQuery('#information_modal').size() == 0){
70
+ jQuery('<div id=\"information_modal\"></div>')
71
+ .html(window_rails_contents['information_modal'])
72
+ .dialog(#{format_type_to_js(options)});
73
+ } else {
74
+ jQuery('#information_modal')
75
+ .html(window_rails_contents['information_modal'])
76
+ .dialog(#{format_type_to_js(options)}).focus();
77
+ }"
78
+ nil
28
79
  end
29
80
 
30
81
  # Close an information window
31
82
  def close_info_window
32
- self << "Dialog.closeInfo();"
83
+ self << 'jQuery("#information_modal").dialog("close");'
84
+ nil
33
85
  end
34
86
 
35
87
  # Update the contents of an information window
36
88
  def update_info_window(msg)
37
- self << "Dialog.setInfoMessage('#{escape_javascript(msg)}');"
89
+ self << 'jQuery("#information_modal").html(#{format_type_to_js(msg)});'
90
+ nil
38
91
  end
39
-
92
+
93
+ def window_setup
94
+ @set ||= false
95
+ unless(@set)
96
+ self << '
97
+ if(typeof(window.window_rails_windows) == "undefined") {
98
+ window.window_rails_windows = {};
99
+ } if(typeof(window_rails_windows_array) == "undefined") {
100
+ window.window_rails_windows_array = new Array();
101
+ }
102
+ '
103
+ end
104
+ @set = true
105
+ nil
106
+ end
107
+
108
+ def window(dom_id)
109
+ window_setup
110
+ unless(dom_id.blank?)
111
+ dom_id = dom_id.to_s.dup
112
+ dom_id.slice!(0) if dom_id.start_with?('#')
113
+ self << "window.window_rails_windows['#{dom_id}']"
114
+ else
115
+ self << "window.window_rails_windows[window.window_rails_windows_array[0]]"
116
+ end
117
+ self
118
+ end
119
+
40
120
  # content:: content
41
121
  # options:: Hash of options
42
122
  # * window -> Name of the window to update (defaults to last window)
@@ -49,7 +129,8 @@ module WindowRailsGenerators
49
129
  win = options.delete(:window)
50
130
  error = options.delete(:error)
51
131
  key = store_content(content)
52
- self << check_for_window(win, error){ update_window_contents(key, win) }
132
+ self << check_for_window(win, error){ update_window_contents(key, win, options) }
133
+ nil
53
134
  end
54
135
 
55
136
  # name:: Name of the window
@@ -57,67 +138,46 @@ module WindowRailsGenerators
57
138
  # Checks for a window of the given name. If a block is provided, it will be executed
58
139
  # if the window is found
59
140
  def check_for_window(name, error=true)
141
+ name = name.to_s.dup
142
+ name.slice!(0) if name.start_with?('#')
143
+ window_setup
60
144
  if(name.blank?)
61
- self << "if(Windows.windows.values().size() > 0){"
145
+ self << "if(window.window_rails_windows.length > 0){"
62
146
  else
63
- self << "if(Windows.existsByName('#{escape_javascript(name)}')){"
147
+ self << "if(window.window_rails_windows['#{name}']){"
64
148
  end
65
149
  yield if block_given?
66
150
  self << "}"
67
151
  self << "else { alert('Unexpected error. Failed to locate window for output.'); }" if error
68
- end
69
-
70
- # Simply wraps a block within an else statement
71
- def else_block
72
- self << "else {"
73
- yield if block_given?
74
- self << "}"
152
+ nil
75
153
  end
76
154
 
77
155
  # key:: Content key location
78
156
  # win:: Name of window
79
157
  # Updates the contents of the window. If no window name is provided, the topmost window
80
158
  # will be updated
81
- def update_window_contents(key, win=nil)
82
- unless(win.blank?)
83
- self << "Windows.getWindowByName('#{escape_javascript(win)}').setHTMLContent(window_rails_contents.get('#{key}'));"
84
- else
85
- self << "Windows.windows.values().last().setHTMLContent(window_rails_contents.get('#{key}'));"
86
- end
159
+ def update_window_contents(key, win, options)
160
+ window(win) << ".html(window.window_rails_contents[#{format_type_to_js(key.to_s)}]);"
161
+ nil
87
162
  end
88
163
 
89
164
  # win:: Name of window
90
165
  # Will focus the window. If no name provided, topmost window will be focused
91
166
  def focus_window(win=nil)
92
- unless(win.blank?)
93
- self << "Windows.focus(Windows.getWindowByName('#{escape_javascript(win)}').getId());"
94
- else
95
- self << "Windows.focus(Windows.windows.values().last().getId());"
96
- end
167
+ window(win) << '.dialog("focus");'
168
+ nil
97
169
  end
98
170
 
99
171
  # win:: Name of window
100
172
  # Will maximize the window. If no name provided, topmost window will be maximized
101
173
  def maximize_window(win=nil)
102
- check_for_window(name) do
103
- if(name)
104
- self << "Windows.getWindowByName('#{escape_javascript(win)}').maximize();"
105
- else
106
- self << "Windows.windows.values().last().maximize();"
107
- end
108
- end
174
+ # noop
109
175
  end
110
176
 
111
177
  # win:: Name of window
112
178
  # Will minimize the window. If no name provided, topmost window will be minimized
113
179
  def minimize_window(win)
114
- check_for_window(name) do
115
- if(name)
116
- self << "Windows.getWindowByName('#{escape_javascript(win)}').minimize();"
117
- else
118
- self << "Windows.windows.values().last().minimize();"
119
- end
120
- end
180
+ # noop
121
181
  end
122
182
 
123
183
  # key:: Content key location
@@ -126,10 +186,56 @@ module WindowRailsGenerators
126
186
  # Creates a new window. Generally this should not be called,
127
187
  # rather #open_window should be used
128
188
  def create_window(key, win, options)
129
- self << "var myWin = new Window({#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
130
- self << "Windows.registerByName('#{escape_javascript(win)}', myWin);" unless win.blank?
131
- self << "myWin.setHTMLContent(window_rails_contents.get('#{key}'));"
132
- self << "myWin.setCloseCallback(function(win){ win.destroy(); return true; });"
189
+ options[:auto_open] ||= false
190
+ options[:close] = "function(event,ui){
191
+ #{
192
+ if(options[:close])
193
+ "callback = #{options[:close]}; callback();"
194
+ end
195
+ }
196
+ jQuery('##{win}').dialog('destroy');
197
+ window.window_rails_windows['#{win}'] = null;
198
+ window.window_rails_windows_array.splice(window.window_rails_windows_array.indexOf('#{win}'), 1);
199
+ jQuery('##{win}').remove();
200
+ }"
201
+ unless(win.is_a?(String))
202
+ win = win.to_s
203
+ end
204
+ if(win.start_with?('#'))
205
+ win.slice!(0)
206
+ end
207
+ window_setup
208
+ self << "
209
+ if(jQuery('#window_rails_windows').size() == 0){
210
+ jQuery('body').append('<div id=\"window_rails_windows\" style=\"visibility:hidden;display:none;\"></div>');
211
+ }
212
+ if(jQuery('##{win}').size() == 0){
213
+ jQuery('#window_rails_windows').append('<div id=\"#{win}\"></div>');
214
+ }
215
+ window.window_rails_windows['#{win}'] = jQuery('##{win}');
216
+ window.window_rails_windows_array.push('#{win}');
217
+ "
218
+ if(key == :url)
219
+ options[:auto_open] = true
220
+ self << "
221
+ jQuery.get(
222
+ '#{options.delete(:url)}',
223
+ function(data){
224
+ window.window_rails_windows['#{win}']
225
+ .html(data)
226
+ .dialog(#{format_type_to_js(options)})
227
+ .dialog('open');
228
+ }
229
+ );
230
+ "
231
+ else
232
+ self << "
233
+ window.window_rails_windows['#{win}']
234
+ .html(window.window_rails_contents['#{key}'])
235
+ .dialog(#{format_type_to_js(options)});
236
+ "
237
+ end
238
+ nil
133
239
  end
134
240
 
135
241
  # win:: Name of window
@@ -137,30 +243,15 @@ module WindowRailsGenerators
137
243
  # Shows the window centered on the screen. If no window name is provided
138
244
  # it will default to the last created window. Generally this should not
139
245
  # be called, rather #open_window should be used
246
+ # NOTE: No modal mode currently
140
247
  def show_window(win, modal)
141
- s = nil
142
- unless(win.blank?)
143
- s = "Windows.getWindowByName('#{escape_javascript(win)}')"
144
- else
145
- s = 'Windows.windows.values().last()'
146
- end
147
- self << "#{s}.showCenter(#{modal ? 'true' : 'false'});"
148
- end
149
-
150
- # win:: Name of window
151
- # constraints:: Constaint hash {:left, :right, :top, :bottom}
152
- # Sets the constraints on the window. Generally this should not be used,
153
- # rather #open_window should be used
154
- def apply_window_constraints(win, constraints)
155
- opts = {:left => 0, :right => 0, :top => 0, :bottom => 0}
156
- opts.merge!(constraints) if constraints.is_a?(Hash)
157
- s = nil
158
- unless(win.blank?)
159
- s = "Windows.getWindowByName('#{escape_javascript(win)}')"
160
- else
161
- s = "Windows.windows.values().last()"
248
+ modal ||= false
249
+ check_for_window(win) do
250
+ window(win) << ".dialog('option', 'modal', #{format_type_to_js(modal)});"
251
+ window(win) << ".dialog('option', 'autoOpen', true);"
252
+ window(win) << '.dialog("open");'
162
253
  end
163
- self << "#{s}.setConstraint(true, {#{opts.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
254
+ nil
164
255
  end
165
256
 
166
257
  # content:: Content for window
@@ -171,7 +262,6 @@ module WindowRailsGenerators
171
262
  # * :iframe -> URL to load within an IFrame in the window
172
263
  # * :width -> Width of the window
173
264
  # * :height -> Height of the window
174
- # * :className -> Theme name for the window
175
265
  # * :no_update -> Set to true to force creation of a new window even if window of same name already exists (defaults to false)
176
266
  # Creates a new window and displays it at the center of the viewport. Content can be provided as
177
267
  # a string, or as a Hash. If :url is defined, the window will be loaded with the contents of the request. If not, the hash
@@ -183,14 +273,16 @@ module WindowRailsGenerators
183
273
  # be isolated from the current page, but this isolation means it cannot communicate with other windows on the page (including
184
274
  # its own).
185
275
  def open_window(content, options={})
186
- modal = options.delete(:modal)
187
- win = options.delete(:window)
188
- constraints = options.delete(:constraints)
189
- no_update = options.delete(:no_update)
190
- options[:className] = 'alphacube' unless options[:className]
276
+ key = nil
277
+ if(options[:iframe])
278
+ iframe = @context.url_for(options.delete(:iframe))
279
+ end
191
280
  if(content.is_a?(Hash))
192
281
  if(content[:url])
193
- options[:url] = @context.url_for(content[:url])
282
+ options[:iframe] = @context.url_for(content[:url])
283
+ content = nil
284
+ elsif(content[:content_url])
285
+ options[:url] = @context.url_for(content[:content_url])
194
286
  content = nil
195
287
  else
196
288
  content = @context.render(content)
@@ -198,34 +290,42 @@ module WindowRailsGenerators
198
290
  end
199
291
  options[:width] ||= 300
200
292
  options[:height] ||= 200
201
- key = store_content(content)
202
- if(no_update)
293
+ modal = options[:modal]
294
+ if(options[:on_close])
295
+ options[:close] = options.delete(:on_close)
296
+ end
297
+ if(options[:iframe])
298
+ key = :iframe
299
+ elsif(options[:url])
300
+ key = :url
301
+ else
302
+ key = store_content(content)
303
+ end
304
+ win = options.delete(:window) || "win_#{rand(99999)}"
305
+ if(options.delete(:no_update))
203
306
  create_window(key, win, options)
204
- unless(constraints == false)
205
- apply_window_constraints(win, constraints)
206
- end
207
307
  show_window(win, modal)
208
308
  else
209
309
  check_for_window(win, false) do
210
- update_window_contents(key, win)
310
+ update_window_contents(key, win, options)
211
311
  focus_window(win)
212
312
  end
213
313
  else_block do
214
314
  create_window(key, win, options)
215
- unless(constraints == false)
216
- apply_window_constraints(win, constraints)
217
- end
218
315
  show_window(win, modal)
219
316
  end
220
317
  end
318
+ nil
221
319
  end
222
320
 
223
- def store_content(content)
224
- key = rand.to_s
225
- key.slice!(0,2)
321
+ def store_content(content, key=nil)
322
+ unless(key)
323
+ key = rand.to_s
324
+ key.slice!(0,2)
325
+ end
226
326
  c = content.is_a?(Hash) ? @context.render(content) : content.to_s
227
- self << "if(typeof(window_rails_contents) == 'undefined'){ var window_rails_contents = new Hash(); }"
228
- self << "window_rails_contents.set('#{key}', '#{escape_javascript(c)}')"
327
+ self << "if(typeof(window.window_rails_contents) == 'undefined'){ window.window_rails_contents = {}; }"
328
+ self << "window.window_rails_contents[#{format_type_to_js(key.to_s)}] = #{format_type_to_js(c)};"
229
329
  key
230
330
  end
231
331
 
@@ -233,24 +333,37 @@ module WindowRailsGenerators
233
333
  # * :window -> name of window to close
234
334
  # Close the window of the provided name or the last opened window
235
335
  def close_window(options = {})
236
- win = options.is_a?(Hash) ? options.delete(:window) : options.to_s
237
- self << "var myWin = null;"
238
- unless(win.blank?)
239
- self << "myWin = Windows.getWindowByName('#{escape_javascript(win)}');"
336
+ win_name = if(options.is_a?(Hash))
337
+ (options[:window] || options[:name]).to_s
338
+ elsif(options.is_a?(Array))
339
+ options.map(&:to_s)
240
340
  else
241
- self << "if(Windows.windows.values().last()){ myWin = Windows.windows.values().last(); }"
341
+ options.to_s
342
+ end
343
+ win_name.each do |win|
344
+ window(win) << '.dialog("close");'
242
345
  end
243
- self << "if(myWin){ myWin.close(); }"
244
346
  end
245
347
 
246
348
  # Close all open windows
247
349
  def close_all_windows
248
- self << "Windows.closeAll();"
350
+ setup_windows
351
+ self << '
352
+ jQuery.each(
353
+ window_rails_windows_array,
354
+ function(name, win){
355
+ window.window_rails_windows[win].dialog("close");
356
+ }
357
+ );
358
+ '
249
359
  end
250
360
 
251
361
  # args:: List of window names to refresh (All will be refreshed if :all is included)
252
362
  # Refresh window contents
363
+ # NOTE: Currently does nothing
364
+ # NOTE: Deprecated (remaining temporarily for compatibility reasons)
253
365
  def refresh_window(*args)
366
+ return
254
367
  self << "var myWin = null;"
255
368
  if(args.include?(:all))
256
369
  self << "Windows.windows.values().each(function(win){ win.refresh(); });"
@@ -266,7 +379,10 @@ module WindowRailsGenerators
266
379
  # options:: Options
267
380
  # Helper for observing fields that have been dynamically loaed into the DOM. Works like
268
381
  # #observe_field but not as full featured.
269
- def observe_dynamically_loaded_field(field_id, options={})
382
+ # NOTE: Currently does nothing
383
+ # NOTE: Deprecated (remaining temporarily for compatibility reasons)
384
+ def observe_dynamically_loaded_field(field_id, options={}) # :nodoc
385
+ return
270
386
  f = options.delete(:function)
271
387
  unless(f)
272
388
  f = "function(event){ new Ajax.Request('#{escape_javascript(@context.url_for(options[:url]).to_s)}', {asynchronous:true, evalScripts:true,parameters:'#{escape_javascript(options[:with].to_s)}='+$('#{escape_javascript(options[:with].to_s)}').getValue()})}"
@@ -275,5 +391,16 @@ module WindowRailsGenerators
275
391
  end
276
392
  self << "if($('#{escape_javascript(field_id.to_s)}')){ $('#{escape_javascript(field_id.to_s)}').observe('change', #{f}); }"
277
393
  end
278
-
394
+
395
+ private
396
+
397
+ # Simply wraps a block within an else statement
398
+ def else_block
399
+ self << "else {"
400
+ yield if block_given?
401
+ self << "}"
402
+ nil
403
+ end
404
+
279
405
  end
406
+ ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.send :include, WindowRailsGenerators