Skip to content

Commit

Permalink
Input field appears in view mode. (#18)
Browse files Browse the repository at this point in the history
Input field appears in view mode. #17
* Spacing and minor code improvements
* Fixing the tests
  • Loading branch information
CostiChD authored and acotiuga committed Aug 20, 2018
1 parent 120d593 commit 50f2888
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 80 deletions.
Expand Up @@ -25,24 +25,15 @@

public class InPreparationStatusViewPage extends ViewPage
{

@FindBy(xpath = "//div[@class = 'xform']//dd[1]")
public WebElement pollName;

@FindBy(xpath = "//div[@class = 'xform']//dd[2]")
public WebElement pollDescription;

@FindBy(xpath = "//div[@class = 'xform']//dd[3]")
@FindBy(xpath = "//div[@class = 'xform']//dd[2]")
public WebElement pollStatus;

@FindBy(xpath = "//div[@class = 'xform']//dd[4]")
@FindBy(xpath = "//div[@class = 'xform']//dd[3]")
public WebElement pollProposals;

public String getPollName()
{
return pollName.getText();
}

public String getPollDescription()
{
return pollDescription.getText();
Expand Down
146 changes: 77 additions & 69 deletions application-xpoll-ui/src/main/resources/XPoll/XPollSheet.xml
Expand Up @@ -41,138 +41,146 @@
<hidden>true</hidden>
<content>{{velocity}}
#*
Displays the value of the name property as the title of the document. If value is empty (e.g. creation step), displays the document name.
Displays the value of the name property as the title of the document.
If value is empty (e.g. creation step), displays the document title.
*#
#macro(displayPollTitle)
#set($pollObj = $!doc.getObject('XPoll.XPollClass'))
#if("$!pollObj.getProperty('name').value" != '')
$doc.display('name')
#else
{{html}}&lt;input id="XPoll.XPollClass_${pollObj.number}_name" type="text" value="$escapetool.xml($doc.title)" size="30" name="XPoll.XPollClass_${pollObj.number}_name"&gt;&lt;/input&gt;{{/html}}
#macro (displayPollTitle)
#set ($pollObj = $!doc.getObject('XPoll.XPollClass'))
#if ("$!pollObj.getProperty('name').value" == '')
#set ($discard = $pollObj.set('name', $doc.title))
#end
$doc.display('name')
#end

#set($discard = $xwiki.jsx.use('XPoll.XPollJSExtension'))
#set($discard = $xwiki.ssx.use('XPoll.XPollSheet'))
#set ($discard = $xwiki.jsx.use('XPoll.XPollJSExtension'))
#set ($discard = $xwiki.ssx.use('XPoll.XPollSheet'))

#if($hasEdit &amp;&amp; $xcontext.action == 'view' &amp;&amp; $doc.getValue('status') == 'inpreparation')
#if ($hasEdit &amp;&amp; $xcontext.action == 'view' &amp;&amp; $doc.getValue('status') == 'inpreparation')
$services.localization.render('contrib.xpoll.preparation.hasRight')
#elseif(!$hasEdit)
#elseif (!$hasEdit)
$services.localization.render('contrib.xpoll.preparation.noRight')
#end

#if($xcontext.action == 'edit' || $doc.getValue('status') == 'inpreparation')
#if ($xcontext.action == 'edit' || $doc.getValue('status') == 'inpreparation')
{{html wiki='true'}}
#set($discard = $xwiki.ssx.use('AppWithinMinutes.ClassSheetGenerator'))
#set($discard = $doc.use('XPoll.XPollClass'))
#set ($discard = $xwiki.ssx.use('AppWithinMinutes.ClassSheetGenerator'))
#set ($discard = $doc.use('XPoll.XPollClass'))
## We don't have access to the form element to set the CSS class for the vertical form layout standard.
(% class="xform" %)
(((
; &lt;label for="XPoll.XPollClass_0_name"&gt;$doc.displayPrettyName('name', false, false)&lt;/label&gt;##
(% class="xHint" %)$services.localization.render('')
: #displayPollTitle()
; &lt;label for="XPoll.XPollClass_0_description"&gt;$doc.displayPrettyName('description', false, false)&lt;/label&gt;##
(% class="xHint" %)$services.localization.render('')
#if ($xcontext.action == 'edit')
; &lt;label for="XPoll.XPollClass_0_name"&gt;$doc.displayPrettyName('name', false, false)&lt;/label&gt;
: #displayPollTitle()
#end
; &lt;label for="XPoll.XPollClass_0_description"&gt;$doc.displayPrettyName('description', false, false)&lt;/label&gt;
: $doc.display('description')
; &lt;label for="XPoll.XPollClass_0_status"&gt;$doc.displayPrettyName('status', false, false)&lt;/label&gt;##
(% class="xHint" %)$services.localization.render('')
; &lt;label for="XPoll.XPollClass_0_status"&gt;$doc.displayPrettyName('status', false, false)&lt;/label&gt;
: $doc.display('status')
; &lt;label for="XPoll.XPollClass_0_proposals"&gt;$doc.displayPrettyName('proposals', false, false)&lt;/label&gt;##
; &lt;label for="XPoll.XPollClass_0_proposals"&gt;$doc.displayPrettyName('proposals', false, false)&lt;/label&gt;
(% class="xHint" %)$services.localization.render('XPoll.XPollClass_proposals_hint')
: $doc.display('proposals')
)))
{{/html}}
#else
$doc.display('description')

#set($status = $doc.getValue('status'))
#set($proposals = $doc.getValue('proposals'))
#if($status == 'inpreparation')
#set ($status = $doc.getValue('status'))
#set ($proposals = $doc.getValue('proposals'))
#if ($status == 'inpreparation')

#elseif($status == 'active')
#set($voteCount = {})
#foreach($proposal in $proposals)
#set($ok = $voteCount.put($proposal, 0))
#set ($voteCount = {})
#foreach ($proposal in $proposals)
#set ($ok = $voteCount.put($proposal, 0))
#end
#set($actionDoc = $xwiki.getDocument('XPoll.XPollService'))
#set($actionURL = $actionDoc.getURL('get', "xpage=plain&amp;outputSyntax=plain&amp;page=$escapetool.url($doc.fullName)"))
#set ($actionDoc = $xwiki.getDocument('XPoll.XPollService'))
#set ($queryString = $escapetool.url({
'xpage': 'plain',
'outputSyntax': 'plain',
'page': $doc.fullName
}))
#set ($actionURL = $actionDoc.getURL('get', $queryString))
{{html clean='false' wiki='true'}}
&lt;form id="xpollSaveForm" action="$actionURL" method="post"&gt;
(% class='xpoll' %)
## first table row
|= $services.localization.render('contrib.xpoll.user') #foreach($proposal in $proposals)|= $proposal #end

#set($foundUser = false)
#set ($foundUser = false)
## second table row
#foreach($obj in $doc.getObjects('XPoll.XPollVoteClass'))
#set($discard = $doc.use($obj))
#set($user = $doc.getValue('user'))
#if($user == $xcontext.user)
#set($foundUser = true)
#foreach ($obj in $doc.getObjects('XPoll.XPollVoteClass'))
#set ($discard = $doc.use($obj))
#set ($user = $doc.getValue('user'))
#if ($user == $xcontext.user)
#set ($foundUser = true)
#end
#set($votes = $doc.getValue('votes'))
#set ($votes = $doc.getValue('votes'))
|= $xwiki.getUserName($user)
#foreach($proposal in $proposals)
#set($checked = $votes.contains($proposal))
#if($checked)
#set($nbvotes = $voteCount.get($proposal))
#set($nbvotes = $nbvotes + 1)
#set($discard = $voteCount.put($proposal, $nbvotes))
#foreach ($proposal in $proposals)
#set ($checked = $votes.contains($proposal))
#if ($checked)
#set ($nbvotes = $voteCount.get($proposal))
#set ($nbvotes = $nbvotes + 1)
#set ($discard = $voteCount.put($proposal, $nbvotes))
#end ##
| &lt;input type="checkbox" name="${proposal.hashCode()}" #if($checked)CHECKED#end #if($xcontext.user != $user) disabled #end /&gt;
| &lt;input type="checkbox" name="${proposal.hashCode()}"
#if ($checked)CHECKED#end #if ($xcontext.user != $user) disabled #end /&gt;
#end ##
#if($user == $xcontext.user)
#if ($user == $xcontext.user)
|(% style="border: none;" %)
&lt;input type="submit" value="$services.localization.render("contrib.xpoll.vote.user.submit")" class="button" /&gt;##
#end

#end
#if(!$foundUser &amp;&amp; $xcontext.user != 'XWiki.XWikiGuest')
#if (!$foundUser &amp;&amp; $xcontext.user != 'XWiki.XWikiGuest')
|= $xwiki.getUserName($xcontext.user)
#foreach($proposal in $proposals)
#set($checked = false) ##
#foreach ($proposal in $proposals)
#set ($checked = false) ##
| &lt;input type="checkbox" name="${proposal.hashCode()}" #if($checked)CHECKED#end /&gt;
#end ##
|(% style="border: none;" %)
&lt;input type="submit" value="$services.localization.render("contrib.xpoll.vote.user.submit")" class="button" /&gt;
&lt;input type="submit" value="$services.localization.render("contrib.xpoll.vote.user.submit")"
class="button" /&gt;
#end
## third table row
|= $services.localization.render('contrib.xpoll.numberVotes') #foreach($proposal in $proposals)|= $!voteCount.get($proposal) #end
|= $services.localization.render('contrib.xpoll.numberVotes') #foreach ($proposal in $proposals)|= $!voteCount.get($proposal) #end
&lt;/form&gt;
{{/html}}
#elseif($status=="finished")
#elseif ($status=="finished")
$services.localization.render('contrib.xpoll.finish.message')
#set($voteCount = {})
#foreach($proposal in $proposals)
#set($ok = $voteCount.put($proposal, 0))
#set ($voteCount = {})
#foreach ($proposal in $proposals)
#set ($ok = $voteCount.put($proposal, 0))
#end
## first table row
|= $services.localization.render('contrib.xpoll.user') #foreach($proposal in $proposals)|= $proposal #end
|= $services.localization.render('contrib.xpoll.user') #foreach ($proposal in $proposals)|= $proposal #end

## second table row
#foreach($obj in $doc.getObjects('XPoll.XPollVoteClass'))
#set($discard = $doc.use($obj))
#set($user = $doc.getValue('user'))
#set($votes = $doc.getValue('votes'))
#foreach ($obj in $doc.getObjects('XPoll.XPollVoteClass'))
#set ($discard = $doc.use($obj))
#set ($user = $doc.getValue('user'))
#set ($votes = $doc.getValue('votes'))
|= {{html clean="false"}}$xwiki.getUserName($user){{/html}}##
#foreach($proposal in $proposals)
#set($checked = $votes.contains($proposal))
#if($checked)
#set($nbvotes = $voteCount.get($proposal))
#set($nbvotes = $nbvotes + 1)
#set($discard = $voteCount.put($proposal, $nbvotes))
#foreach ($proposal in $proposals)
#set ($checked = $votes.contains($proposal))
#if ($checked)
#set ($nbvotes = $voteCount.get($proposal))
#set ($nbvotes = $nbvotes + 1)
#set ($discard = $voteCount.put($proposal, $nbvotes))
#end ##
|= #if($xcontext.action == 'export')
#if($checked) X #end##
|= #if ($xcontext.action == 'export')
#if ($checked) X #end##
#else
{{html clean=="false"}}&lt;input type="checkbox" name="$proposal" #if($checked)CHECKED#end disabled /&gt;{{/html}}##
{{html clean=="false"}}
&lt;input type="checkbox" name="$proposal" #if ($checked)CHECKED#end disabled /&gt;
{{/html}}##
#end ##
#end

#end
## third table row
|= $services.localization.render('contrib.xpoll.numberVotes') ##
#foreach($proposal in $proposals)
#foreach ($proposal in $proposals)
|= $!voteCount.get($proposal)##
#end
#end
Expand Down

0 comments on commit 50f2888

Please sign in to comment.