General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
AnnotationCode
▼
:
Document Index
»
Page:
Macros
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Wiki Home
»
WebHome
»
Macros
Wiki source code of
Macros
Last modified by
Administrator
on 2011/11/06 20:09
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: 2: {{velocity filter="none" output="false"}} 3: #set($restURL = "${request.contextPath}/rest") 4: ## Retrieve the annotation class from the configuration 5: #set($config = 'AnnotationCode.AnnotationConfig') 6: #set($annotationClassDocName = $xwiki.getDocument($config).getObject($config).getProperty('annotationClass').value) 7: #set($annotationClass = $xwiki.getDocument("$!{annotationClassDocName}").getxWikiClass()) 8: ## 9: ## 10: ## Do not display these 'internal' properties in the form: 11: #set($hiddenProperties = ['selection', 'selectionLeftContext', 'selectionRightContext', 'originalSelection', 'target', 'date', 'author', 'state'])## TODO: 'color' 12: ## 13: ## 14: #* 15: * Display a box for creating an annotation 16: * 17: * @param $space the space of the annotated document 18: * @param $page the name of the annotated document 19: * @param $annData a map containing the mandatory selection-related fields 20: * @param $docWiki the wiki of the annotated document 21: * @param $docSpace the space of the annotated document 22: * @param $docPage the page of the annotated document 23: *# 24: #macro(displayCreateBox $docWiki $docSpace $docPage $annData) 25: <div class="annotation-box annotation-box-create"> 26: <form method="POST" action="${restURL}/wikis/${escapetool.url($docWiki)}/spaces/${escapetool.url($docSpace)}/pages/${escapetool.url($docPage)}/annotations?media=json"> 27: <div class="hidden"> 28: #foreach($field in $annData.keySet()) 29: <input type="hidden" name="${field}" value="$!{escapetool.xml($annData.get(${field}))}"/> 30: #end 31: </div> 32: #displayAnnotation($annData, 'create') 33: #displayAnnotationBoxButtons('create') 34: </form> 35: </div> 36: #end 37: #* 38: * Display a box for editing an annotation 39: * 40: * @param $target the annotated entity identifier 41: * @param $id the annotation identifier 42: * @param $docWiki the wiki of the annotated document 43: * @param $docSpace the space of the annotated document 44: * @param $docPage the page of the annotated document 45: *# 46: #macro(displayEditBox $id $docWiki $docSpace $docPage) 47: ## TODO: unhardcode this reference generation here when document reference will be available in velo. Or build Annotation velocity API for xwiki 48: #set($ann = $services.annotations.getAnnotation("${docWiki}:${docSpace}.${docPage}", $id)) 49: <div class="annotation-box annotation-box-edit"> 50: #if($ann) 51: #set($editURL = "${restURL}/wikis/" + $escapetool.url($docWiki) + "/spaces/" + $escapetool.url($docSpace) + "/pages/" + $escapetool.url($docPage) + "/annotation/" + $escapetool.url($ann.id) + "?method=PUT&media=json") 52: <form method='POST' action="${editURL}"> 53: #displayAnnotation($ann, 'edit') 54: #displayAnnotationBoxButtons('edit') 55: </form> 56: #else 57: <div class="box infomessage">$msg.get("annotations.action.edit.error.notfound")</div> 58: #end 59: </div> 60: #end 61: #* 62: * Display a box containing the annotation 63: * 64: * @param $target the annotated entity identifier 65: * @param $id the annotation identifier 66: * @param $docWiki the wiki of the annotated document 67: * @param $docSpace the space of the annotated document 68: * @param $docPage the page of the annotated document 69: *# 70: #macro(displayViewBox $id $docWiki $docSpace $docPage) 71: ## TODO: unhardcode this reference generation here when document reference will be available in velo. Or build Annotation velocity API for xwiki 72: #set($ann = $services.annotations.getAnnotation("${docWiki}:${docSpace}.${docPage}", $id)) 73: <div class="annotation-box annotation-box-view"> 74: #if ($ann) 75: #*<div class="links"> 76: <a href="#" class='annotation-view-hide'>$msg.get("annotations.action.view.hide.text")</a> 77: </div>*# 78: ##<div class="clearfloats"></div> 79: #displayAnnotation($ann $mode $docWiki $docSpace $docPage) 80: #else 81: <div class="box infomessage">$msg.get("annotations.action.view.error.notfound")</div> 82: #end 83: </div> 84: #end 85: ## 86: ## 87: ## 88: #* 89: * Display form buttons 90: * 91: * @param $mode 'create' or 'edit' 92: *# 93: #macro(displayAnnotationBoxButtons $mode) 94: <div class="buttons"> 95: <span class='buttonwrapper'><input type="submit" class='button' value='$msg.get("annotations.action.${mode}.submit.text")'/></span> 96: <span class='buttonwrapper'><input type="reset" class='button secondary' value='$msg.get("annotations.action.${mode}.cancel.text")'/></span> 97: </div> 98: #end 99: ## 100: ## 101: #** 102: * Display an annotation 103: * 104: * @param $ann the annotation object 105: * @param $mode view (default), list, create or edit 106: *# 107: #macro(displayAnnotation $ann $mode $docWiki $docSpace $docPage) 108: #if(!$listtool.contains(['view', 'list', 'create', 'edit'], "$!{mode}")) 109: #set($mode = 'view') 110: #end 111: <div class="annotation $!{ann.state}" id="annotation_${mode}_$!{ann.id}"> 112: <div class="annotationAvatar">#mediumUserAvatar($ann.author)</div> 113: <div class="annotationHeader"> 114: #displayAnnotationTitle($ann) 115: #displayAnnotationToolbox($ann $mode $docWiki $docSpace $docPage) 116: </div> 117: <div class="annotationContent"> 118: #displayAnnotationBody($ann $mode) 119: </div> 120: </div> 121: #end 122: ## 123: ## 124: #** 125: * Display the annotation title, containing author and date 126: * 127: * @param $ann the annotation object 128: *# 129: #macro(displayAnnotationTitle $ann) 130: <div class="annotationTitle"> 131: <span class="annotationAuthor">$!xwiki.getUserName($ann.author)</span>## 132: ## Do not indent this, or the comma will be misplaced 133: #if("$!{ann.date}" != '')<span class="sep">, </span><span class="annotationDate">$xwiki.formatDate($ann.date, "dd/MM/yyyy")</span>#end 134: </div> 135: #end 136: ## 137: ## 138: #** 139: * Display the annotation toolbox: 140: * - 'verify' button for modified annotations 141: * - 'edit' button for annotation authors and other users with edit rights, unless already editing 142: * - 'delete' button for annotation authors and other users with edit rights 143: * 144: * @param $ann the annotation object 145: * @param $mode view (default), list, create or edit 146: * @param $docWiki the wiki of the annotated document 147: * @param $docSpace the space of the annotated document 148: * @param $docPage the page of the annotated document 149: *# 150: #macro(displayAnnotationToolbox $ann $mode $docWiki $docSpace $docPage) 151: <span class="annotationTools"> 152: #if($mode != 'create' && $services.annotations.canEditAnnotation($ann.id, $docWiki, $docSpace, $docPage)) 153: #set($editURL = "${restURL}/wikis/" + $escapetool.url($docWiki) + "/spaces/" + $escapetool.url($docSpace) + "/pages/" + $escapetool.url($docPage) + "/annotation/" + $escapetool.url($ann.id) + "?method=PUT&media=json") 154: #if ("$!{ann.state}" == 'UPDATED') 155: <span class="tool accept"><a class="validate" href="${editURL}" title="$msg.get('annotations.action.validate.tooltip')">$msg.get('annotations.action.validate.text')</a></span> 156: #end 157: #if ($mode != 'edit') 158: ## use an edit url just for the fanciness of it, it won't really be used in this case. An edit form will be loaded 159: <span class="tool annotationEdit"><a class="edit" href="${editURL}" title="$msg.get('annotations.action.edit.tooltip')">$msg.get('annotations.action.edit.text')</a></span> 160: #end 161: #set($deleteURL = "${restURL}/wikis/" + $escapetool.url($docWiki) + "/spaces/" + $escapetool.url($docSpace) + "/pages/" + $escapetool.url($docPage) + "/annotation/" + $escapetool.url($ann.id) + "?method=DELETE&media=json") 162: <span class="tool delete"><a class="delete" href="${deleteURL}" title="$msg.get('annotations.action.delete.tooltip')">$msg.get('annotations.action.delete.text')</a></span> 163: #end 164: </span> 165: #end 166: ## 167: ## 168: #** 169: * Display the annotation body, containing all but the hidden fields. 170: * For annotation lists (which are not displayed near the actual annotation text), also display 171: * in a block quote the corresponding annotated extract. 172: * Depending on the mode, display for each field label + input (edit, create) or the field value (view, list). 173: * 174: * @param $ann the annotation object 175: * @param $mode view (default), list, create or edit 176: *# 177: #macro(displayAnnotationBody $ann $mode) 178: #if ($mode == 'list') 179: #if ($ann.state == 'ALTERED') 180: <div class="annotationOriginalSelection">$msg.get("annotations.altered.text")</div> 181: #end 182: <blockquote class="annotatedText">$!escapetool.xml($ann.selection)</blockquote> 183: #end 184: ## in view mode and list mode, also display the original selection of this annotation 185: #if (($mode == 'view' || $mode == 'list') && $ann.state == 'UPDATED') 186: <div class="annotationOriginalSelection">$msg.get("annotations.updated.text")</div> 187: <blockquote class="annotatedText originalAnnotatedText">$!escapetool.xml($ann.originalSelection)</blockquote> 188: #end 189: ## Fake object that allows to use the API to generate the display 190: #set($fakeObj = $doc.newObject($annotationClassDocName)) 191: #set($properties = $annotationClass.properties) 192: #if ($properties.size() == $hiddenProperties.size() + 1) 193: ## Do not show property labels if there's only one property to display 194: #set($prop = $annotationClass.get('annotation')) 195: #set($discard = $fakeObj.set($prop.name, "$!{ann.get($prop.name)}")) 196: <div class="annotationText"> 197: #if($mode == 'edit' || $mode == 'create') 198: $doc.displayEdit($prop, '', $fakeObj) 199: #else 200: $doc.displayView($prop, '', $fakeObj) 201: #end 202: </div> 203: #else 204: <dl> 205: #foreach($prop in $properties) 206: #if (!$listtool.contains($hiddenProperties, $prop.name)) 207: #set($discard = $fakeObj.set($prop.name, "$!{ann.get($prop.name)}")) 208: <dt class="annotationLabel"><label for="$prop.name">$prop.prettyName</label></dt> 209: #if($mode == 'edit' || $mode == 'create') 210: <dd>$doc.displayEdit($prop, '', $fakeObj)</dd> 211: #else 212: <dd>$doc.displayView($prop, '', $fakeObj)</dd> 213: #end 214: #end 215: #end 216: </dl> 217: #end 218: #end 219: {{/velocity}}