71 row and col |
71 row and col |
72 """ |
72 """ |
73 instance = cls(req, rset) |
73 instance = cls(req, rset) |
74 instance.row = row |
74 instance.row = row |
75 instance.col = col |
75 instance.col = col |
|
76 instance.sel_kwargs = kwargs |
76 return instance |
77 return instance |
77 |
78 |
78 # Eproperties definition: |
79 # Eproperties definition: |
79 # key: id of the property (the actual EProperty key is build using |
80 # key: id of the property (the actual EProperty key is build using |
80 # <registry name>.<obj id>.<property id> |
81 # <registry name>.<obj id>.<property id> |
321 |
322 |
322 def __init__(self, req=None, rset=None, **kwargs): |
323 def __init__(self, req=None, rset=None, **kwargs): |
323 self.req = req |
324 self.req = req |
324 self.rset = rset |
325 self.rset = rset |
325 self.__dict__.update(kwargs) |
326 self.__dict__.update(kwargs) |
326 |
|
327 |
|
328 class ReloadableMixIn(object): |
|
329 """simple mixin for reloadable parts of UI""" |
|
330 |
|
331 def user_callback(self, cb, args, msg=None, nonify=False): |
|
332 """register the given user callback and return an url to call it ready to be |
|
333 inserted in html |
|
334 """ |
|
335 self.req.add_js('cubicweb.ajax.js') |
|
336 if nonify: |
|
337 _cb = cb |
|
338 def cb(*args): |
|
339 _cb(*args) |
|
340 cbname = self.req.register_onetime_callback(cb, *args) |
|
341 return self.build_js(cbname, html_escape(msg or '')) |
|
342 |
|
343 def build_update_js_call(self, cbname, msg): |
|
344 rql = html_escape(self.rset.printable_rql()) |
|
345 return "javascript:userCallbackThenUpdateUI('%s', '%s', '%s', '%s', '%s', '%s')" % ( |
|
346 cbname, self.id, rql, msg, self.__registry__, self.div_id()) |
|
347 |
|
348 def build_reload_js_call(self, cbname, msg): |
|
349 return "javascript:userCallbackThenReloadPage('%s', '%s')" % (cbname, msg) |
|
350 |
|
351 build_js = build_update_js_call # expect updatable component by default |
|
352 |
|
353 def div_id(self): |
|
354 return '' |
|
355 |
|
356 |
|
357 class ComponentMixIn(ReloadableMixIn): |
|
358 """simple mixin for component object""" |
|
359 __registry__ = 'components' |
|
360 __registerer__ = yes_registerer |
|
361 __selectors__ = (yes,) |
|
362 __select__ = classmethod(*__selectors__) |
|
363 |
|
364 def div_class(self): |
|
365 return '%s %s' % (self.propval('htmlclass'), self.id) |
|
366 |
|
367 def div_id(self): |
|
368 return '%sComponent' % self.id |
|
369 |
|
370 |
|
371 class Component(ComponentMixIn, AppObject): |
|
372 """base class for non displayable components |
|
373 """ |
|
374 |
|
375 class SingletonComponent(Component): |
|
376 """base class for non displayable unique components |
|
377 """ |
|
378 __registerer__ = priority_registerer |
|