Skip to content

Commit ec9346f

Browse files
authored
Merge pull request eXist-db#185 from joewiz/xrx-edits
Review Beginner's Guide to XRX
2 parents ea57032 + 69e35da commit ec9346f

22 files changed

+681
-472
lines changed

src/main/xar-resources/data/beginners-guide-to-xrx-v4/beginners-guide-to-xrx-v4.xml

Lines changed: 370 additions & 178 deletions
Large diffs are not rendered by default.

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-11.txt

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@ declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
44

55
let $data-collection := '/db/apps/terms/data'
66
let $q := request:get-parameter('q', "")
7-
8-
(: put the search results into memory using the eXist any keyword ampersand equals comparison :)
97
let $search-results := collection($data-collection)/term[ft:query(*, $q)]
108
let $count := count($search-results)
11-
129
return
13-
<html>
14-
<head>
15-
<title>Term Search Results</title>
16-
</head>
17-
<body>
18-
<h3>Term Search Results</h3>
19-
<p><b>Search results for:</b>&quot;{$q}&quot; <b> In Collection: </b>{$data-collection}</p>
20-
<p><b>Terms Found: </b>{$count}</p>
21-
<ol>{
22-
for $term in $search-results
23-
let $id := $term/id
24-
let $term-name := $term/term-name/text()
25-
order by upper-case($term-name)
26-
return
27-
<li>
28-
<a href="../views/view-item.xq?id={$id}">{$term-name}</a>
29-
</li>
30-
}</ol>
31-
<a href="search-form.html">New Search</a>
32-
<a href="../index.html">App Home</a>
33-
</body>
34-
</html>
10+
<html>
11+
<head>
12+
<title>Term Search Results</title>
13+
</head>
14+
<body>
15+
<h3>Term Search Results</h3>
16+
<p><b>Search results for:</b> &quot;{$q}&quot;<b> in collection: </b>{$data-collection}</p>
17+
<p><b>Terms Found:</b> {$count}</p>
18+
<ol>
19+
{
20+
for $term in $search-results
21+
let $id := $term/id
22+
let $term-name := $term/term-name/text()
23+
order by upper-case($term-name)
24+
return
25+
<li>
26+
<a href="../views/view-item.xq?id={$id}">{$term-name}</a>
27+
</li>
28+
}
29+
</ol>
30+
<a href="search-form.html">New Search</a><br/>
31+
<a href="../index.html">App Home</a>
32+
</body>
33+
</html>

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-12.txt

Lines changed: 91 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,99 @@ declare option exist:serialize "method=xhtml media-type=text/xml indent=yes proc
55
let $new := request:get-parameter('new', '')
66
let $id := request:get-parameter('id', '')
77
let $data-collection := '/db/apps/terms/data'
8-
9-
(: Put in the appropriate file name. Use new-instance.xml for new forms and get the data
10-
from the data collection for updates. :)
11-
let $file := if ($new) then
8+
let $file :=
9+
if ($new ne '') then
1210
'new-instance.xml'
13-
else
11+
else
1412
concat('../data/', $id, '.xml')
15-
16-
let $form :=
17-
<html xmlns="http://www.w3.org/1999/xhtml"
18-
xmlns:xf="http://www.w3.org/2002/xforms"
19-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
20-
xmlns:ev="http://www.w3.org/2001/xml-events" >
21-
<head>
22-
<title>Edit Item</title>
23-
<style type="text/css">
24-
<![CDATA[
25-
@namespace xf url("http://www.w3.org/2002/xforms");
26-
27-
body {
28-
font-family: Helvetica, Ariel, Verdana, sans-serif;
29-
}
30-
31-
.term-name .xforms-value {width: 50ex;}
32-
.definition .xforms-value {
33-
height: 5em;
34-
width: 600px;
35-
}
36-
37-
/* align the labels but not the save label */
38-
xf|output xf|label, xf|input xf|label, xf|textarea xf|label, xf|select1 xf|label {
39-
display: inline-block;
40-
width: 14ex;
41-
text-align: right;
42-
vertical-align: top;
43-
margin-right: 1ex;
44-
font-weight: bold;
45-
}
46-
47-
xf|input, xf|select1, xf|textarea, xf|ouptut {
48-
display: block;
49-
margin: 1ex;
50-
}
51-
]]>
52-
</style>
53-
<xf:model>
54-
<xf:instance xmlns="" src="{$file}" id="save-data"/>
55-
<xf:submission id="save" method="post" action="{if ($new='true') then ('save-new.xq') else ('update.xq')}" instance="my-task" replace="all"/>
56-
</xf:model>
57-
</head>
58-
<body>
59-
<h1>Edit Term</h1>
60-
61-
{if ($id) then
13+
let $form :=
14+
<html xmlns="http://www.w3.org/1999/xhtml"
15+
xmlns:xf="http://www.w3.org/2002/xforms"
16+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
17+
xmlns:ev="http://www.w3.org/2001/xml-events">
18+
<head>
19+
<title>Edit Item</title>
20+
<style type="text/css">
21+
<![CDATA[
22+
@namespace xf url("http://www.w3.org/2002/xforms");
23+
24+
body {
25+
font-family: Helvetica, Ariel, Verdana, sans-serif;
26+
}
27+
28+
.term-name .xforms-value {width: 50ex;}
29+
.definition .xforms-value {
30+
height: 5em;
31+
width: 600px;
32+
}
33+
34+
/* align the labels but not the save label */
35+
xf|output xf|label, xf|input xf|label, xf|textarea xf|label, xf|select1 xf|label {
36+
display: inline-block;
37+
width: 14ex;
38+
text-align: right;
39+
vertical-align: top;
40+
margin-right: 1ex;
41+
font-weight: bold;
42+
}
43+
44+
xf|input, xf|select1, xf|textarea, xf|ouptut {
45+
display: block;
46+
margin: 1ex;
47+
}
48+
]]>
49+
</style>
50+
<xf:model>
51+
<xf:instance xmlns="" src="{$file}" id="save-data"/>
52+
<xf:submission id="save" method="post" action="{
53+
if ($new eq 'true') then
54+
'save-new.xq'
55+
else
56+
'update.xq'
57+
}" instance="my-task" replace="all"/>
58+
</xf:model>
59+
</head>
60+
<body>
61+
<h1>Edit Term</h1>
62+
{
63+
if ($id) then
6264
<xf:output ref="id" class="id">
6365
<xf:label>ID:</xf:label>
6466
</xf:output>
65-
else ()}
66-
67-
<xf:input ref="term-name" class="term-name">
68-
<xf:label>Term Name:</xf:label>
69-
</xf:input>
70-
71-
<xf:textarea ref="definition" class="definition">
72-
<xf:label>Definition:</xf:label>
73-
</xf:textarea>
74-
75-
<xf:select1 ref="publish-status-code">
76-
<xf:label>Status:</xf:label>
77-
<xf:item>
78-
<xf:label>Draft</xf:label>
79-
<xf:value>draft</xf:value>
80-
</xf:item>
81-
<xf:item>
82-
<xf:label>Under Review</xf:label>
83-
<xf:value>review</xf:value>
84-
</xf:item>
85-
<xf:item>
86-
<xf:label>Published</xf:label>
87-
<xf:value>published</xf:value>
88-
</xf:item>
89-
</xf:select1>
90-
91-
<xf:submit submission="save">
92-
<xf:label>Save</xf:label>
93-
</xf:submit>
94-
</body>
95-
</html>
96-
97-
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/rest/db/xforms/xsltforms/xsltforms.xsl"'}
98-
99-
return ($xslt-pi, $form)
67+
else
68+
()
69+
}
70+
<xf:input ref="term-name" class="term-name">
71+
<xf:label>Term Name:</xf:label>
72+
</xf:input>
73+
<xf:textarea ref="definition" class="definition">
74+
<xf:label>Definition:</xf:label>
75+
</xf:textarea>
76+
<xf:select1 ref="publish-status-code">
77+
<xf:label>Status:</xf:label>
78+
<xf:item>
79+
<xf:label>Draft</xf:label>
80+
<xf:value>draft</xf:value>
81+
</xf:item>
82+
<xf:item>
83+
<xf:label>Under Review</xf:label>
84+
<xf:value>review</xf:value>
85+
</xf:item>
86+
<xf:item>
87+
<xf:label>Published</xf:label>
88+
<xf:value>published</xf:value>
89+
</xf:item>
90+
</xf:select1>
91+
<xf:submit submission="save">
92+
<xf:label>Save</xf:label>
93+
</xf:submit>
94+
</body>
95+
</html>
96+
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/apps/xsltforms/xsltforms.xsl"'}
97+
return
98+
(
99+
(: Prevent betterFORM (still enabled by default) from intercepting the form, allowing XSLTForms to handle it :)
100+
request:set-attribute("betterform.filter.ignoreResponseBody", "true"),
101+
$xslt-pi,
102+
$form
103+
)

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-13.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<term>
2+
<id></id>
3+
<term-name></term-name>
4+
<definition></definition>
5+
<publish-status-code></publish-status-code>
6+
</term>
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
if ($id) then
2-
<xf:output ref="id" class="id">
3-
<xf:label>ID:</xf:label>
4-
</xf:output>
5-
else ()
1+
action="{
2+
if ($new='true') then
3+
'save-new.xq'
4+
else
5+
'update.xq'
6+
}"
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
let $xslt-pi := processing-instruction xml-stylesheet
2-
{'type="text/xsl" href="/exist/rest/db/xforms/xsltforms/xsltforms.xsl"'}
3-
return ($xslt-pi, $form)
1+
if ($id) then
2+
<xf:output ref="id" class="id">
3+
<xf:label>ID:</xf:label>
4+
</xf:output>
5+
else
6+
()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
let $debug := processing-instruction xsltforms-options {'debug="yes"'}
2-
return ($xslt-pi, $debug, $form)
1+
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/apps/xsltforms/xsltforms.xsl"'}
2+
return ($xslt-pi, $form)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let $debug := processing-instruction xsltforms-options {'debug="yes"'}
2+
return ($xslt-pi, $debug, $form)

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-18.txt

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-19.txt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,42 @@ xquery version "1.0";
22

33
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
44

5-
let $title := 'Update Confirmation'
5+
let $app-collection := '/db/apps/terms'
66
let $data-collection := '/db/apps/terms/data'
77

88
(: get the form data that has been "POSTed" to this XQuery :)
99
let $item := request:get-data()
1010

11-
(: log into the collection :)
12-
let $login := xmldb:login($data-collection, 'admin', 'myadminpassword')
11+
(: get the next ID from the next-id.xml file :)
12+
let $next-id-file-path := concat($app-collection, '/edit/next-id.xml')
13+
let $next-id := doc($next-id-file-path)/data/next-id/text()
14+
let $file := concat($next-id, '.xml')
1315

14-
(: get the id out of the posted document :)
15-
let $id := $item/term/id/text()
16+
(: log into the collection :)
17+
let $login := xmldb:login($app-collection, 'admin', 'myadminpassword')
1618

17-
let $file := concat($id, '.xml')
18-
19-
(: save the new file, overwriting the old one :)
19+
(: create the new file with a still-empty id element :)
2020
let $store := xmldb:store($data-collection, $file, $item)
21+
let $new-document := doc(concat($data-collection, '/', $file))
22+
23+
(: add the correct ID to the new document we just saved :)
24+
let $update-id := update value $new-document/term/id with $next-id
25+
26+
(: update the next-id.xml file :)
27+
let $new-next-id := update value $next-id with $next-id + 1
28+
29+
(: we need to return the original ID number in our results,
30+
but the previous update expression increased $next-id by 1 :)
31+
let $original-id := $next-id - 1
2132

2233
return
2334
<html>
2435
<head>
25-
<title>{$title}</title>
36+
<title>Save Conformation</title>
2637
</head>
2738
<body>
28-
<h1>{$title}</h1>
29-
<p>Item {$id} has been updated.</p>
39+
<a href="../index.xhtml">Term Home</a>
40+
<p>Term {$original-id} has been saved.</p>
41+
<a href="../views/list-items.xq">List all Terms</a>
3042
</body>
3143
</html>

0 commit comments

Comments
 (0)