window_rails 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -0,0 +1,9 @@
1
+ == v0.1.0
2
+ * Lots of cleanup
3
+ * Better builders available
4
+ * #observe_dynamically_loaded_field to watch things that have been inserted into the DOM
5
+ * Better window handling
6
+ * Default class set to alphacube
7
+
8
+ == v0.0.1
9
+ * Initial release
data/README.rdoc CHANGED
@@ -52,11 +52,11 @@ Rails to make it easy to use from a Rails app.
52
52
 
53
53
  == Documentation
54
54
 
55
- [WindowRails documentation]{http://chrisroberts.github.com/window_rails}
55
+ {WindowRails documentation}[http://chrisroberts.github.com/window_rails]
56
56
 
57
57
  == Bugs/Features
58
58
 
59
- [Issues]{http://github.com/chrisroberts/window_rails/issues}
59
+ {Issues}[http://github.com/chrisroberts/window_rails/issues]
60
60
 
61
61
  == Thanks
62
62
 
@@ -17,6 +17,9 @@ class WindowRailsController < ActionController::Base
17
17
  end
18
18
 
19
19
  # Opens a new window
20
+ # NOTE: It is important to note that the contents of the window will be opened
21
+ # within an IFrame. This means links within the window will not be able to
22
+ # communicate with the page around it (like closing the window)
20
23
  def open_window
21
24
  respond_to do |format|
22
25
  format.html do
@@ -24,7 +27,7 @@ class WindowRailsController < ActionController::Base
24
27
  end
25
28
  format.js do
26
29
  render :update do |page|
27
- page.activate_window({:url => params[:window_url]}, params[:window_options])
30
+ page.open_window({:url => params[:window_url]}, params[:window_options])
28
31
  end
29
32
  end
30
33
  end
@@ -794,7 +794,9 @@ Window.prototype = {
794
794
  this.options.showEffect(this.element);
795
795
 
796
796
  this._checkIEOverlapping();
797
- WindowUtilities.focusedWindow = this
797
+ WindowUtilities.focusedWindow = this;
798
+ // this.getContent().style.display = 'none';
799
+ this.getContent().style.scroll = 'auto';
798
800
  this._notify("onShow");
799
801
  },
800
802
 
data/install.rb CHANGED
@@ -20,7 +20,6 @@ def install_all
20
20
  install_javascripts
21
21
  install_themes
22
22
  install_version
23
- puts 'INSTALLED ALL'
24
23
  end
25
24
 
26
25
  ## Place version file and check for it. install if not found.
@@ -1,3 +1,3 @@
1
1
  module WindowRails
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,209 @@
1
+ module WindowRailsGenerators
2
+
3
+ include ActionView::Helpers::JavaScriptHelper
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ # msg:: Alert message
7
+ # options:: Hash of options values for the alert window
8
+ # Opens an alert window
9
+ def open_alert_window(msg, options={})
10
+ 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(',')}});"
12
+ end
13
+
14
+ # msg:: Confirmation message
15
+ # options:: Hash of options values for the confirmation window
16
+ # Opens a confirmation window
17
+ def open_confirm_window(msg, options={})
18
+ 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(',')}});"
20
+ end
21
+
22
+ # msg:: Information message
23
+ # options:: Hash of options values for info window
24
+ # Open an information window
25
+ def open_info_window(msg, options={})
26
+ 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(',')}});"
28
+ end
29
+
30
+ # Close an information window
31
+ def close_info_window
32
+ self << "Dialog.closeInfo();"
33
+ end
34
+
35
+ # Update the contents of an information window
36
+ def update_info_window(msg)
37
+ self << "Dialog.setInfoMessage('#{escape_javascript(msg)}');"
38
+ end
39
+
40
+ # content:: Updated content
41
+ # options:: Hash of options
42
+ # * window -> Name of the window to update (defaults to last window)
43
+ # * error -> Show error if window is not found (defaults false)
44
+ # Updates the window with the new content. If the content is a string, it will
45
+ # be placed into the window. If it is a Hash, it will be fed to render and the
46
+ # result will be placed in the window (basically an easy way to integrate partials:
47
+ # page.update_window(:partial => 'my_parital'))
48
+ def update_window(content, options={})
49
+ win = options.delete(:window)
50
+ error = options.delete(:error)
51
+ if(content.is_a?(Hash))
52
+ content = render(content)
53
+ end
54
+ self << check_for_window(win, error){ update_window_contents(content, win) }
55
+ end
56
+
57
+ def check_for_window(name, error)
58
+ if(name.blank?)
59
+ self << "if(Windows.windows.values().size() > 0){"
60
+ else
61
+ self << "if(Windows.existsByName('#{escape_javascript(name)}')){"
62
+ end
63
+ yield if block_given?
64
+ self << "}"
65
+ self << "else { alert('Unexpected error. Failed to locate window for output.'); }" if error
66
+ end
67
+
68
+ def else_block
69
+ self << "else {"
70
+ yield if block_given?
71
+ self << "}"
72
+ end
73
+
74
+ def update_window_contents(content, win)
75
+ unless(win.blank?)
76
+ self << "Windows.getWindowByName('#{escape_javascript(win)}').setHTMLContent('#{escape_javascript(content)}');"
77
+ else
78
+ self << "Windows.windows.values().last().setHTMLContent('#{escape_javascript(content)}');"
79
+ end
80
+ end
81
+
82
+ def focus_window(win)
83
+ unless(win.blank?)
84
+ self << "Windows.focus(Windows.getWindowByName('#{escape_javascript(win)}').getId());"
85
+ else
86
+ self << "Windows.focus(Windows.windows.values().last().getId());"
87
+ end
88
+ end
89
+
90
+ def create_window(content, win, options)
91
+ self << "var myWin = new Window({#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
92
+ self << "Windows.registerByName('#{escape_javascript(win)}', myWin);" unless win.blank?
93
+ self << "myWin.setHTMLContent('#{escape_javascript(content)}');" unless content.blank?
94
+ self << "myWin.setCloseCallback(function(win){ win.destroy(); return true; });"
95
+ end
96
+
97
+ def show_window(win, modal)
98
+ s = nil
99
+ unless(win.blank?)
100
+ s = "Windows.getWindowByName('#{escape_javascript(win)}')"
101
+ else
102
+ s = 'Windows.windows.values().last()'
103
+ end
104
+ self << "#{s}.showCenter(#{modal ? 'true' : 'false'});"
105
+ end
106
+
107
+ def apply_window_constraints(win, constraints)
108
+ opts = {:left => 0, :right => 0, :top => 0, :bottom => 0}
109
+ opts.merge!(constraints) if constraints.is_a?(Hash)
110
+ s = nil
111
+ unless(win.blank?)
112
+ s = "Windows.getWindowByName('#{escape_javascript(win)}')"
113
+ else
114
+ s = "Windows.windows.values().last()"
115
+ end
116
+ self << "#{s}.setConstraint(true, {#{opts.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
117
+ end
118
+
119
+ # content:: Content for window
120
+ # options:: Hash of options
121
+ # * modal -> Window should be modal
122
+ # * window -> Name to reference window (used for easy updating and closing)
123
+ # * constraints -> Hash containing top,left,right,bottom values for padding from edges. False value will turn off constraints (window can travel out of viewport)
124
+ # * url -> URL to load into the window
125
+ # * width -> Width of the window
126
+ # * height -> Height of the window
127
+ # * className -> Theme name for the window
128
+ # * no_update -> Set to true to force creation of a new window even if window of same name already exists (defaults to false)
129
+ # Creates a new window and displays it at the center of the viewport.
130
+ def open_window(content, options={})
131
+ modal = options.delete(:modal)
132
+ win = options.delete(:window)
133
+ constraints = options.delete(:constraints)
134
+ no_update = options.delete(:no_update)
135
+ options[:className] = 'alphacube' unless options[:className]
136
+ if(content.is_a?(Hash))
137
+ if(content[:url])
138
+ options[:url] = @context.url_for(content[:url])
139
+ content = nil
140
+ else
141
+ content = render(content)
142
+ end
143
+ end
144
+ options[:width] ||= 300
145
+ options[:height] ||= 200
146
+ output = []
147
+ if(no_update)
148
+ create_window(content, win, options)
149
+ unless(constraints == false)
150
+ apply_window_constraints(win, constraints)
151
+ end
152
+ show_window(win, modal)
153
+ else
154
+ check_for_window(win, false) do
155
+ update_window_contents(content, win)
156
+ focus_window(win)
157
+ end
158
+ else_block do
159
+ create_window(content, win, options)
160
+ unless(constraints == false)
161
+ apply_window_constraints(win, constraints)
162
+ end
163
+ show_window(win, modal)
164
+ end
165
+ end
166
+ end
167
+
168
+ # options:: Hash of options
169
+ # * :window -> name of window to close
170
+ # Close the window of the provided name or the last opened window
171
+ def close_window(options = {})
172
+ win = options.is_a?(Hash) ? options.delete(:window) : options.to_s
173
+ self << "var myWin = null;"
174
+ unless(win.blank?)
175
+ self << "myWin = Windows.getWindowByName('#{escape_javascript(win)}');"
176
+ else
177
+ self << "if(Windows.windows.values().last()){ myWin = Windows.windows.values().last(); }"
178
+ end
179
+ self << "if(myWin){ myWin.close(); }"
180
+ end
181
+
182
+ # Close all open windows
183
+ def close_all_windows
184
+ self << "Windows.closeAll();"
185
+ end
186
+
187
+ # args:: List of window names to refresh (All will be refreshed if :all is included)
188
+ # Refresh window contents
189
+ def refresh_window(*args)
190
+ self << "var myWin = null;"
191
+ if(args.include?(:all))
192
+ self << "Windows.windows.values().each(function(win){ win.refresh(); });"
193
+ else
194
+ args.each do |win|
195
+ self << "myWin = Windows.getWindowByName('#{escape_javascript(win.to_s)}');"
196
+ self << "if(myWin){ myWin.refresh(); }"
197
+ end
198
+ end
199
+ end
200
+
201
+ def observe_dynamically_loaded_field(field_id, options={})
202
+ f = options.delete(:function)
203
+ unless(f)
204
+ 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()})}"
205
+ end
206
+ self << "if($('#{escape_javascript(field_id.to_s)}')){ $('#{escape_javascript(field_id.to_s)}').observe('change', #{f}); }"
207
+ end
208
+
209
+ end
@@ -0,0 +1,10 @@
1
+ module WindowRailsView
2
+
3
+ # name:: Name of the link
4
+ # options:: Hash of optional values. These options are simply passed
5
+ # on to the activate_window method
6
+ def link_to_window(name, options={})
7
+ link_to_remote(name, :url => {:controller => :window_rails, :action => :open_window, :window_url => url_for(options.delete(:url)), :window_options => options})
8
+ end
9
+
10
+ end
data/lib/window_rails.rb CHANGED
@@ -1,160 +1,5 @@
1
- module WindowRailsView
2
-
3
- # name:: Name of the link
4
- # options:: Hash of optional values. These options are simply passed
5
- # on to the activate_window method
6
- def link_to_window(name, options={})
7
- link_to_remote(name, :url => {:controller => :window_rails, :action => :open_window, :window_url => url_for(options.delete(:url)), :window_options => options})
8
- end
9
-
10
- end
11
-
12
- module WindowRailsGenerators
13
-
14
- include ActionView::Helpers::JavaScriptHelper
15
- include ActionView::Helpers::UrlHelper
16
- include ActionView::Helpers::TagHelper
17
-
18
- # msg:: Alert message
19
- # options:: Hash of options values for the alert window
20
- # Opens an alert window
21
- def open_alert_window(msg, options={})
22
- options[:width] ||= 200
23
- self << "Dialog.alert('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(',')}});"
24
- end
25
-
26
- # msg:: Confirmation message
27
- # options:: Hash of options values for the confirmation window
28
- # Opens a confirmation window
29
- def open_confirm_window(msg, options={})
30
- options[:width] ||= 200
31
- self << "Dialog.confirm('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k)}:'#{escape_javascript(v)}'"}.join(',')}});"
32
- end
33
-
34
- # msg:: Information message
35
- # options:: Hash of options values for info window
36
- # Open an information window
37
- def open_info_window(msg, options={})
38
- self << "Dialog.info('#{escape_javascript(msg)}', {#{options.map{|k,v|"#{escape_javascript(k)}:'#{escape_javascript(v)}'"}.join(',')}});"
39
- end
40
-
41
- # Close an information window
42
- def close_info_window
43
- self << "Dialog.closeInfo();"
44
- end
45
-
46
- # Update the contents of an information window
47
- def update_info_window(msg)
48
- self << "Dialog.setInfoMessage('#{escape_javascript(msg)}');"
49
- end
50
-
51
- # content:: Updated content
52
- # options:: Hash of options
53
- # * window -> Name of the window to update (defaults to last window)
54
- # * error -> Show error if window is not found (defaults false)
55
- # Updates the window with the new content. If the content is a string, it will
56
- # be placed into the window. If it is a Hash, it will be fed to render and the
57
- # result will be placed in the window (basically an easy way to integrate partials:
58
- # page.update_window(:partial => 'my_parital'))
59
- def update_window(content, options={})
60
- win = options.delete(:window)
61
- error = options.delete(:error)
62
- if(content.is_a?(Hash))
63
- content = render(content)
64
- end
65
- content = escape_javascript(content)
66
- win = escape_javascript(win) if win
67
- if(win)
68
- self << "if(Windows.existsByName('#{win}')){"
69
- self << " Windows.getWindowByName('#{win}').setHTMLContent('#{content}');"
70
- self << "}"
71
- if(error)
72
- self << "else {"
73
- self << " alert('Unexpected error. Failed to locate correct window for output.');"
74
- self << "}"
75
- end
76
- else
77
- self << "Windows.windows.values().last().setHTMLContent('#{content}');"
78
- end
79
- end
80
-
81
- # content:: Content for window
82
- # options:: Hash of options
83
- # * modal -> Window should be modal
84
- # * window -> Name to reference window (used for easy updating and closing)
85
- # * constraints -> Hash containing top,left,right,bottom values for padding from edges. False value will turn off constraints (window can travel out of viewport)
86
- # * url -> URL to load into the window
87
- # * width -> Width of the window
88
- # * height -> Height of the window
89
- # * className -> Theme name for the window
90
- # Creates a new window and displays it at the center of the viewport.
91
- def open_window(content, options)
92
- modal = options.delete(:modal)
93
- win = options.delete(:window)
94
- constraints = options.delete(:constraints)
95
- if(content.is_a?(Hash))
96
- if(content[:url])
97
- options[:url] = url_for(content[:url])
98
- content = nil
99
- else
100
- content = render(content)
101
- end
102
- end
103
- options[:width] ||= 300
104
- options[:height] ||= 200
105
- content = escape_javascript(content) if content
106
- win = escape_javascript(win) if win
107
- self << "var myWin = new Window({#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});";
108
- unless(win.blank?)
109
- self << "Windows.registerByName('#{win}', myWin);"
110
- end
111
- if(content)
112
- self << "myWin.setHTMLContent('#{content}');"
113
- end
114
- unless(constraints == false)
115
- opts = {:left => 0, :right => 0, :top => 0, :bottom => 0}
116
- opts.merge!(constraints) if constraints.is_a?(Hash)
117
- self << "myWin.setConstraint(true, {#{opts.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
118
- end
119
- self << "myWin.setCloseCallback(function(win){ win.destroy(); return true; });"
120
- self << "myWin.showCenter(#{modal ? 'true' : 'false'});"
121
- end
122
-
123
- # options:: Hash of options
124
- # * :window -> name of window to close
125
- # Close the window of the provided name or the last opened window
126
- def close_window(options = {})
127
- win = options.delete(:window)
128
- win = escape_javascript(win) if win
129
- self << "var myWin = null;"
130
- if(win)
131
- self << "myWin = Windows.getWindowByName('#{win}');"
132
- else
133
- self << "if(Windows.windows.values().last()){ myWin = Windows.windows.values().last(); }"
134
- end
135
- self << "if(myWin){ myWin.close(); }"
136
- end
137
-
138
- # Close all open windows
139
- def close_all_windows
140
- self << "Windows.closeAll();"
141
- end
142
-
143
- # args:: List of window names to refresh (All will be refreshed if :all is included)
144
- # Refresh window contents
145
- def refresh_window(*args)
146
- self << "var myWin = null;"
147
- if(args.include?(:all))
148
- self << "Windows.windows.values().each(function(win){ win.refresh(); });"
149
- else
150
- args.each do |win|
151
- self << "myWin = Windows.getWindowByName('#{escape_javascript(win.to_s)}');"
152
- self << "if(myWin){ myWin.refresh(); }"
153
- end
154
- end
155
- end
156
-
157
- end
1
+ require 'window_rails/window_rails_view'
2
+ require 'window_rails/window_rails_generators'
158
3
 
159
4
  # Load everything into rails
160
5
  if(defined? Rails)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: window_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-03 00:00:00 -07:00
18
+ date: 2010-11-10 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -222,6 +222,8 @@ files:
222
222
  - files/themes/alert.css
223
223
  - lib/window_rails.rb
224
224
  - lib/window_rails/version.rb
225
+ - lib/window_rails/window_rails_view.rb
226
+ - lib/window_rails/window_rails_generators.rb
225
227
  has_rdoc: true
226
228
  homepage: http://github.com/chrisroberts/window_rails
227
229
  licenses: []