Class: Bowline::Binders::Base
- Inherits:
-
Object
- Object
- Bowline::Binders::Base
- Extended by:
- Async, Desktop::Bridge::ClassMethods, Watcher::Base
- Includes:
- Async
- Defined in:
- lib/bowline/binders.rb
Instance Attribute Summary (collapse)
-
- (Object) item
readonly
Instance of the bound class' record.
Class Method Summary (collapse)
-
+ (Object) bowline
JavaScript proxy to the Bowline object.
- + (Object) callback(result = nil)
-
+ (Object) callback_proc(proc = nil)
(also: callback_proc=)
:nodoc:.
-
+ (Object) created(item)
Add a new item to the binder, updating the HTML.
-
+ (Object) destroyed(item)
Remove an item from the binder, updating the HTML.
-
+ (Object) find(id)
Calls .find on the klass sent to the bind method.
-
+ (Object) initial
Called by a window's JavaScript whenever that window is bound to this Binder.
-
+ (Object) instance_invoke(id, method, *args)
:nodoc:.
-
+ (Object) items=(items)
Set the binder's items.
-
+ (Object) jquery
Javascript proxy to jQuery.
-
+ (Object) js_invoke(window, callback, method, *args)
:nodoc:.
-
+ (Object) klass
Returns class set by the 'bind' method.
-
+ (Object) logger
See Bowline::logger.
-
+ (Object) page
JavaScript proxy to the page.
-
+ (Object) populate(items = initial)
Populate initial items.
-
+ (Object) setup(window)
:nodoc:.
-
+ (Object) updated(item)
Update an item on the binder, updating the HTML.
-
+ (Object) windows(window = nil)
An array of window currently bound.
Instance Method Summary (collapse)
-
- (Base) initialize(id, *args)
constructor
:nodoc:.
Methods included from Desktop::Bridge::ClassMethods
Methods included from Watcher::Base
Constructor Details
- (Base) initialize(id, *args)
:nodoc:
244 245 246 |
# File 'lib/bowline/binders.rb', line 244 def initialize(id, *args) #:nodoc: @item = self.class.find(id) end |
Instance Attribute Details
- (Object) item (readonly)
Instance of the bound class' record
242 243 244 |
# File 'lib/bowline/binders.rb', line 242 def item @item end |
Class Method Details
+ (Object) bowline
JavaScript proxy to the Bowline object. See Bowline::Desktop::Proxy for more information. Example:
bowline.log("msg").call
223 224 225 |
# File 'lib/bowline/binders.rb', line 223 def bowline page.Bowline end |
+ (Object) callback(result = nil)
110 111 112 113 |
# File 'lib/bowline/binders.rb', line 110 def callback(result = nil) result = yield if block_given? callback_proc.call(result) end |
+ (Object) callback_proc(proc = nil) Also known as: callback_proc=
:nodoc:
104 105 106 107 |
# File 'lib/bowline/binders.rb', line 104 def callback_proc(proc = nil) #:nodoc: Thread.current[:callback] = proc if proc Thread.current[:callback] end |
+ (Object) created(item)
Add a new item to the binder, updating the HTML. This method is normally only called internally by the bound class's after_create callback.
175 176 177 178 179 180 181 |
# File 'lib/bowline/binders.rb', line 175 def created(item) bowline.created( name, item.id, item.to_js ).call end |
+ (Object) destroyed(item)
Remove an item from the binder, updating the HTML. This method is normally only called internally by the bound class's after_destroy callback.
197 198 199 200 201 202 |
# File 'lib/bowline/binders.rb', line 197 def destroyed(item) bowline.destroyed( name, item.id ).call end |
+ (Object) find(id)
Calls .find on the klass sent to the bind method. This is used internally, to find records when the page invoke instance methods.
163 164 165 |
# File 'lib/bowline/binders.rb', line 163 def find(id) klass.find(id) end |
+ (Object) initial
Called by a window's JavaScript whenever that window is bound to this Binder. This method populates the window's HTML with all bound class' records. Override this if you don't want to send all the class' records to the window. Example:
def initial
klass.all(:limit => 10)
end
157 158 |
# File 'lib/bowline/binders.rb', line 157 def initial end |
+ (Object) instance_invoke(id, method, *args)
:nodoc:
124 125 126 |
# File 'lib/bowline/binders.rb', line 124 def instance_invoke(id, method, *args) #:nodoc: self.new(id).send(method, *args) end |
+ (Object) items=(items)
Set the binder's items. This will replace all items, and update the HTML.
168 169 170 |
# File 'lib/bowline/binders.rb', line 168 def items=(items) bowline.replace(name, items.to_js).call end |
+ (Object) jquery
Javascript proxy to jQuery. See Bowline::Desktop::Proxy for more information. Example:
jquery.getJSON("http://example.com").call
231 232 233 |
# File 'lib/bowline/binders.rb', line 231 def jquery page.jQuery end |
+ (Object) js_invoke(window, callback, method, *args)
:nodoc:
115 116 117 118 119 120 121 122 |
# File 'lib/bowline/binders.rb', line 115 def js_invoke(window, callback, method, *args) #:nodoc: self.callback_proc = callback if method == :setup setup(window) else send(method, *args) end end |
+ (Object) klass
Returns class set by the 'bind' method
205 206 207 |
# File 'lib/bowline/binders.rb', line 205 def klass @klass || raise("klass not set - see bind method") end |
+ (Object) logger
See Bowline::logger
236 237 238 |
# File 'lib/bowline/binders.rb', line 236 def logger Bowline::logger end |
+ (Object) page
JavaScript proxy to the page. See Bowline::Desktop::Proxy for more information. Example:
page.myFunc(1,2,3).call
213 214 215 216 217 |
# File 'lib/bowline/binders.rb', line 213 def page Bowline::Desktop::Proxy.new( windows.length == 1 ? windows.first : windows ) end |
+ (Object) populate(items = initial)
Populate initial items
146 147 148 |
# File 'lib/bowline/binders.rb', line 146 def populate(items = initial) self.items = items if items end |
+ (Object) setup(window)
:nodoc:
138 139 140 141 142 143 |
# File 'lib/bowline/binders.rb', line 138 def setup(window) #:nodoc: Binders.active(self) windows(window) populate callback(true) end |
+ (Object) updated(item)
Update an item on the binder, updating the HTML. This method is normally only called internally by the bound class's after_update callback.
186 187 188 189 190 191 192 |
# File 'lib/bowline/binders.rb', line 186 def updated(item) bowline.updated( name, item.id, item.to_js ).call end |
+ (Object) windows(window = nil)
An array of window currently bound.
129 130 131 132 133 134 135 136 |
# File 'lib/bowline/binders.rb', line 129 def windows(window = nil) @windows ||= [] if window @windows << window @windows.uniq! end @windows end |