[Checkins]
SVN: z3c.reference/branches/flash/src/z3c/reference/browser/
Added new test file
Roger Ineichen
roger at projekt01.ch
Wed Sep 5 04:21:32 EDT 2007
Log message for revision 79475:
Added new test file
Move picker.pt from demo to browser folder
Changed:
A z3c.reference/branches/flash/src/z3c/reference/browser/README.txt
A z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt
-=-
Added: z3c.reference/branches/flash/src/z3c/reference/browser/README.txt
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/README.txt (rev 0)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/README.txt 2007-09-05 08:21:30 UTC (rev 79475)
@@ -0,0 +1,77 @@
+=====================
+View Reference Widget
+=====================
+
+The following example shows a ViewReferenceWidget:
+
+ >>> import zope.interface
+ >>> from z3c.reference.browser.widget import ViewReferenceWidget
+ >>> from z3c.reference.schema import ViewReferenceField
+
+ >>> class IPage(zope.interface.Interface):
+ ... """Interface for a page."""
+ ...
+ ... intro = ViewReferenceField(title=u'Intro',
+ ... description=u'A intro text',
+ ... viewName=u'')
+
+Let's define the IPage object:
+
+ >>> class Page(object):
+ ...
+ ... zope.interface.implements(IPage)
+ ...
+ ... def __init__(self, name):
+ ... self.name = name
+
+Let's create a page:
+
+ >>> page = Page('Intro')
+
+Now let's setup a enviroment for use the widget like in a real application::
+
+ >>> from zope.app.testing import ztapi
+ >>> from zope.publisher.browser import TestRequest
+ >>> from z3c.reference.interfaces import IViewReferenceField
+ >>> from z3c.reference.schema import ViewReferenceField
+ >>> from z3c.reference.browser.widget import ViewReferenceWidget
+ >>> from zope.app.form.interfaces import IInputWidget
+
+Let's define a request and...
+
+ >>> request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
+
+let's initialize a ViewReferenceWidget with the right attributes::
+
+ >>> field = IPage['intro']
+ >>> widget = ViewReferenceWidget(field, request)
+
+Now let's see how such a widget looks like if we render them::
+
+ >>> print widget()
+ <a class="popupwindow" href="http://127.0.0.1/viewReferenceEditor.html"
+ id="field.intro.tag" name="field.intro" onclick="" title="Undefined"
+ rel="window">Undefined</a><input class="hiddenType" id="field.intro.view"
+ name="field.intro.view" type="hidden" value="" rel="window"
+ /><input class="hiddenType" id="field.intro.intid"
+ name="field.intro.intid" type="hidden" value="" rel="window" />
+
+If we store a empty request/form we will get the following error::
+
+ >>> widget.applyChanges(page)
+ Traceback (most recent call last):
+ ...
+ MissingInputError: ('field.intro', u'Intro', None)
+
+
+Before we can store a view reference, we need at least another object which
+our page can reference. Let's create a simple text object::
+
+ >>> class IText(zope.interface.Interface):
+ ... """Interface for a text object."""
+
+ >>> class Text(object):
+ ...
+ ... zope.interface.implements(IText)
+
+ >>> text = Text()
Property changes on: z3c.reference/branches/flash/src/z3c/reference/browser/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt (rev 0)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt 2007-09-05 08:21:30 UTC (rev 79475)
@@ -0,0 +1,189 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://namespaces.zope.org/i18n"
+ xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>demo picker</title>
+ <style type="text/css">
+ body {
+ margin: 0px;
+ padding: 0px;
+ height: 100%;
+ font-family: 'Trebuchet MS';
+ font-size: 10pt;
+ }
+
+ a {
+ color: #000;
+ }
+
+ a.ex1, a.ex2 {
+ color: #888;
+ text-decoration: none;
+ }
+
+ div {
+ margin: 0px;
+ }
+
+ div.float {
+ position: absolute;
+ padding: 0px 10px;
+ border: 0px solid #888;
+ border-right-width: 1px;
+ float:left;
+ height: 100%
+ }
+
+ div.picker {
+ width: 150px;
+ }
+
+ div.properties {
+ position: absolute;
+ left: 170px;
+ width: 200px;
+ }
+
+ div.image-tool {
+ position: absolute;
+ left: 390px;
+ width: 500px;
+ }
+
+ div.actions {
+ position: absolute;
+ left: 910px;
+ padding: 0px 10px;
+ }
+
+ h1 {
+ font-size: 12pt;
+ margin: 10px 0px;
+ }
+
+ label {
+ width: 80px;
+ }
+
+ input, textarea {
+ width: 196px;
+ }
+
+ </style>
+ <script src="jquery"
+ type="text/javascript"
+ tal:attributes="src context/++resource++jquery.js">
+ </script>
+ <script type="text/javascript"
+ tal:content="string:
+ function loadFlash() {
+ var url='${context/++resource++imagetool.swf}';
+ var img='${context/++resource++img.jpg}';
+ url = url + '?url=' + img;
+ var so = new SWFObject(url, 'image-tool', '100%', '490px', '8', 0x000000);
+ so.addParam('allowScriptAccess', 'sameDomain');
+ so.addParam('movie', url);
+ so.addParam('quality', 'high');
+ so.addVariable('crop_x', '100');
+ so.addVariable('crop_y', '100');
+ so.addVariable('crop_w', '100');
+ so.addVariable('crop_h', '100');
+ so.addVariable('original_w', '600');
+ so.addVariable('original_h', '400');
+ so.addVariable('zoomfactor', '0.33');
+ so.addVariable('rotation', '90');
+ var ok = so.write('flash-target');
+ }
+ ">
+ </script>
+ <script type="text/javascript">
+ $(document).ready(loadFlash);
+
+ // user selects an item
+ function setIntId(uid) {
+ // reset values
+ $("textarea").val("");
+ $("input[@type=text]").val("");
+ // set iniid of selected item
+ $("input[@name=intid]").val(uid);
+ // highlight selected item
+ $("a").attr("style", "");
+ $("a[@href*=" + uid + "]").attr("style","background-color: #888");
+ // show divs
+ $("div.properties").show();
+ // $("div.actions").show();
+ // $("div.image-tool").show();
+ }
+
+
+ $(document).ready(function(){
+ // pressed submit button
+ // return selected item to parent and close popup
+ $("input[@type=submit]").click(function() {
+ var intid = $("input[@name=intid]").val();
+ window.opener.setIntId(intid);
+ window.close();
+ });
+
+ $("a.target").click(function() {
+ $("div.actions").hide();
+ $("div.image-tool").hide();
+ $("a.ex1").show();
+ $("a.ex2").show();
+ window.resizeTo(171, 550);
+ window.resizeBy(220, 0);
+ });
+
+ $("a.ex1").click(function() {
+ $("a.ex1").hide();
+ $("div.image-tool").show();
+ window.resizeBy(520, 0);
+ });
+
+ $("a.ex2").click(function() {
+ $("a.ex2").hide();
+ $("div.actions").show();
+ window.resizeBy(220, 0);
+ });
+ });
+ </script>
+ </head>
+ <body>
+ <div class="picker float">
+ <input name="intid" type="hidden" value="None" />
+ <h1>Targets</h1>
+ <tal:block repeat="item view/items">
+ <a href="#" class="target"
+ tal:attributes="href string:JavaScript:setIntId(${item/uid})">
+ <span tal:replace="item/name" />
+ </a>
+ <br />
+ </tal:block>
+ </div>
+ <div class="properties float" style="display:none;">
+ <h1>
+ Properties
+ <a href="#" class="ex1">>></a>
+ </h1>
+ <label for="title">Title</label><br />
+ <input id="title" name="title" type="text" /><br />
+ <label for="description">Description</label><br />
+ <textarea id="description" name="description"
+ cols="20" rows="5"
+ >abcd</textarea>
+ </div>
+ <div class="image-tool float" style="display:none;">
+ <h1>
+ Image-Tool
+ <a href="#" class="ex2">>></a>
+ </h1>
+ <div id="flash-target"></div>
+ </div>
+ <div class="actions" style="display:none;">
+ <h1>Save</h1>
+ <input type="submit" value="add reference" />
+ </div>
+ </body>
+</html>
\ No newline at end of file
Property changes on: z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list