~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/doc/lazr-js-widgets.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-02-15 02:07:37 UTC
  • mfrom: (12344.2.16 daily-ajax)
  • Revision ID: launchpad@pqm.canonical.com-20110215020737-5mzlcotobwen1pej
[r=deryck, lifeless,
        wgrant][bug=673530][incr] Add a popup choice widget for the build
        frequency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
 
269
269
If the field is optional, a "Remove" link is shown.  The "Remove" text is
270
270
customizable thought the "remove_button_text" parameter.
 
271
 
 
272
 
 
273
BooleanChoiceWidget
 
274
-------------------
 
275
 
 
276
This widget provides a simple popup with two options for the user to choose
 
277
from.
 
278
 
 
279
    >>> from lp.app.browser.lazrjs import BooleanChoiceWidget
 
280
 
 
281
As with the other widgets, this one requires a context object and a Bool type
 
282
field.  The rendering of the widget hooks up to the lazr ChoiceSource with the
 
283
standard patch plugin.
 
284
 
 
285
The surrounding tag is customisable, and a prefix may be given.  The prefix is
 
286
passed through to the ChoiceSource and is rendered as part of the widget, but
 
287
isn't updated when the value changes.
 
288
 
 
289
If the user does not have edit rights, the widget just renders the text based
 
290
on the current value of the field on the object:
 
291
 
 
292
    >>> login(ANONYMOUS)
 
293
    >>> from lp.registry.interfaces.person import IPerson
 
294
    >>> hide_email = IPerson['hide_email_addresses']
 
295
    >>> widget = BooleanChoiceWidget(
 
296
    ...     eric, hide_email, 'span',
 
297
    ...     false_text="Don't hide it",
 
298
    ...     true_text="Keep it secret",
 
299
    ...     prefix="My email: ")
 
300
    >>> print widget()
 
301
    <span id="edit-hide_email_addresses">
 
302
    My email: <span class="value">Don't hide it</span>
 
303
    </span>
 
304
 
 
305
If the user has edit rights, an edit icon is rendered and some javascript is
 
306
rendered to hook up the widget.
 
307
 
 
308
    >>> login_person(eric)
 
309
    >>> print widget()
 
310
    <span id="edit-hide_email_addresses">
 
311
    My email: <span class="value">Don't hide it</span>
 
312
      <span>
 
313
        &nbsp;
 
314
        <a class="editicon sprite edit"
 
315
           href="http://launchpad.dev/~eric/+edit"></a>
 
316
      </span>
 
317
    </span>
 
318
    <script>
 
319
    LPS.use('lp.app.choice', function(Y) {
 
320
    ...
 
321
    </script>
 
322
 
 
323
 
 
324
Changing the edit link
 
325
**********************
 
326
 
 
327
The edit link can be changed in exactly the same way as for the
 
328
TextLineEditorWidget above.