window_rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == v0.1.2
2
+ * Add rake task for install
3
+ * Pull window content from reference to prevent writing content multiple times
4
+
1
5
  == v0.1.1
2
6
  * Proper rails loading when included via gem
3
7
  * Fix for window jumping when constraints applied
data/README.rdoc CHANGED
@@ -13,6 +13,17 @@ After install, add these in the head of your application.html.erb file:
13
13
 
14
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
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:
24
+
25
+ rake window_rails:install
26
+
16
27
  === Basic examples to get you started
17
28
 
18
29
  ==== Linking to a window
data/init.rb CHANGED
@@ -1 +1,8 @@
1
- require 'window_rails'
1
+ require 'window_rails/window_rails_view'
2
+ require 'window_rails/window_rails_generators'
3
+
4
+ # Load everything into rails
5
+ if(defined? Rails)
6
+ ActionView::Base.send :include, WindowRailsView
7
+ ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.send :include, WindowRailsGenerators
8
+ end
data/lib/window_rails.rb CHANGED
@@ -1,9 +1 @@
1
- require 'window_rails/window_rails_view'
2
- require 'window_rails/window_rails_generators'
3
-
4
- # Load everything into rails
5
- if(defined? Rails)
6
- ActionView::Base.send :include, WindowRailsView
7
- ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.send :include, WindowRailsGenerators
8
- require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'install.rb') # Always included in case we are gem'ed
9
- end
1
+ require 'window_rails/version'
@@ -0,0 +1,7 @@
1
+ namespace :window_rails do
2
+ desc 'Install required library items'
3
+ task :install do
4
+ require File.join(File.dirname(__FILE__), '..', '..', 'install.rb')
5
+ end
6
+ end
7
+
@@ -1,3 +1,3 @@
1
1
  module WindowRails
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -37,7 +37,7 @@ module WindowRailsGenerators
37
37
  self << "Dialog.setInfoMessage('#{escape_javascript(msg)}');"
38
38
  end
39
39
 
40
- # content:: Updated content
40
+ # key:: Key of updated contents
41
41
  # options:: Hash of options
42
42
  # * window -> Name of the window to update (defaults to last window)
43
43
  # * error -> Show error if window is not found (defaults false)
@@ -45,13 +45,10 @@ module WindowRailsGenerators
45
45
  # be placed into the window. If it is a Hash, it will be fed to render and the
46
46
  # result will be placed in the window (basically an easy way to integrate partials:
47
47
  # page.update_window(:partial => 'my_parital'))
48
- def update_window(content, options={})
48
+ def update_window(key, options={})
49
49
  win = options.delete(:window)
50
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) }
51
+ self << check_for_window(win, error){ update_window_contents(key, win) }
55
52
  end
56
53
 
57
54
  # name:: Name of the window
@@ -76,15 +73,15 @@ module WindowRailsGenerators
76
73
  self << "}"
77
74
  end
78
75
 
79
- # content:: String content
76
+ # key:: Content key location
80
77
  # win:: Name of window
81
78
  # Updates the contents of the window. If no window name is provided, the topmost window
82
79
  # will be updated
83
- def update_window_contents(content, win=nil)
80
+ def update_window_contents(key, win=nil)
84
81
  unless(win.blank?)
85
- self << "Windows.getWindowByName('#{escape_javascript(win)}').setHTMLContent('#{escape_javascript(content)}');"
82
+ self << "Windows.getWindowByName('#{escape_javascript(win)}').setHTMLContent(window_rails_contents.get('#{key}'));"
86
83
  else
87
- self << "Windows.windows.values().last().setHTMLContent('#{escape_javascript(content)}');"
84
+ self << "Windows.windows.values().last().setHTMLContent(window_rails_contents.get('#{key}'));"
88
85
  end
89
86
  end
90
87
 
@@ -98,19 +95,15 @@ module WindowRailsGenerators
98
95
  end
99
96
  end
100
97
 
101
- # content:: String content
98
+ # key:: Content key location
102
99
  # win:: Name of window
103
100
  # options:: Options to be passed onto window
104
101
  # Creates a new window. Generally this should not be called,
105
102
  # rather #open_window should be used
106
- def create_window(content, win, options)
103
+ def create_window(key, win, options)
107
104
  self << "var myWin = new Window({#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
108
105
  self << "Windows.registerByName('#{escape_javascript(win)}', myWin);" unless win.blank?
109
- if(content.is_a?(Hash) && content[:url])
110
- self << "myWin.setAjaxContent('#{escape_javascript(content[:url])}');"
111
- elsif(!content.blank?)
112
- self << "myWin.setHTMLContent('#{escape_javascript(content.to_s)}');"
113
- end
106
+ self << "myWin.setHTMLContent(window_rails_contents.get('#{key}'));"
114
107
  self << "myWin.setCloseCallback(function(win){ win.destroy(); return true; });"
115
108
  end
116
109
 
@@ -180,20 +173,20 @@ module WindowRailsGenerators
180
173
  end
181
174
  options[:width] ||= 300
182
175
  options[:height] ||= 200
183
- output = []
176
+ key = store_content(content)
184
177
  if(no_update)
185
- create_window(content, win, options)
178
+ create_window(key, win, options)
186
179
  unless(constraints == false)
187
180
  apply_window_constraints(win, constraints)
188
181
  end
189
182
  show_window(win, modal)
190
183
  else
191
184
  check_for_window(win, false) do
192
- update_window_contents(content, win)
185
+ update_window_contents(key, win)
193
186
  focus_window(win)
194
187
  end
195
188
  else_block do
196
- create_window(content, win, options)
189
+ create_window(key, win, options)
197
190
  unless(constraints == false)
198
191
  apply_window_constraints(win, constraints)
199
192
  end
@@ -201,6 +194,15 @@ module WindowRailsGenerators
201
194
  end
202
195
  end
203
196
  end
197
+
198
+ def store_content(content)
199
+ self << "if(typeof(window_rails_contents) == 'undefined'){ var window_rails_contents = new Hash(); }"
200
+ key = rand.to_s
201
+ key.slice!(0,2)
202
+ c = content.is_a?(Hash) ? render(content) : content.to_s
203
+ self << "window_rails_contents.set('#{key}', '#{escape_javascript(c)}')"
204
+ key
205
+ end
204
206
 
205
207
  # options:: Hash of options
206
208
  # * :window -> name of window to close
@@ -249,4 +251,4 @@ module WindowRailsGenerators
249
251
  self << "if($('#{escape_javascript(field_id.to_s)}')){ $('#{escape_javascript(field_id.to_s)}').observe('change', #{f}); }"
250
252
  end
251
253
 
252
- end
254
+ end
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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-12-17 00:00:00 -08:00
18
+ date: 2011-01-24 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -223,6 +223,7 @@ files:
223
223
  - files/themes/alert.css
224
224
  - lib/window_rails.rb
225
225
  - lib/window_rails/version.rb
226
+ - lib/window_rails/tasks.rb
226
227
  - lib/window_rails/window_rails_view.rb
227
228
  - lib/window_rails/window_rails_generators.rb
228
229
  has_rdoc: true