Select Document To Copy Snippet

Perhaps anyone can need this: With some changes of XWiki.CopyDocument, the selection of the source-document instead of writing is possible. The parameter 'sourcedoc' (used by Main.AllDocs, e.g.) is divided into space- and documentname.

Code

1 Copy a document

#set($sourcedoc = $request.sourcedoc)
#if ($request.selspace && $request.seldoc)
  #set($sourcedoc = $request.selspace + "." + $request.seldoc)
#end
#set($targetdoc = $request.targetdoc)
#set($language = $request.language)

#if ($targetdoc=="")
#set($targetdoc = $sourcedoc)
#end

#set($sourcewiki = $context.database)
#set($targetwiki = $context.database)

#if ($targetdoc)
Copying document $sourcedoc ($language) from $sourcewiki to $targetwiki: $xwiki.xWiki.copyDocument($sourcedoc, $targetdoc, $sourcewiki, $targetwiki, $language, false, $context.context)

[Source doc>$sourcewiki:$sourcedoc?language=$language] [Target doc>$targetwiki:$targetdoc?language=$language]
#end

<form action="">
<table>
<tr><td>Source Document:</td>
  <td>
  #set($spaces = $xwiki.spaces)
  #set($currentspace = ${doc.web})
  #set($currentdoc = "WebHome")
  #if ($request.sourcedoc && $request.sourcedoc.indexOf(".") > 0) 
    #set($currentspace = $request.sourcedoc.substring(0,$request.sourcedoc.indexOf(".")))
    #set($index = $request.sourcedoc.indexOf(".") + 1)
    #set($currentdoc = $request.sourcedoc.substring($index))
  #end
  #if ($request.selspace) #set($currentspace = $request.selspace) #end
  <select 
     name="selspace" 
     onchange="location='?selspace=' + this.value;">
    <option value="$!{request.selspace}">$!{request.selspace}</option>
    #foreach($space in $spaces)
      #if ($space == $currentspace)
        <option value="${space}" selected>${space}</option>
      #else
        <option value="${space}">${space}</option>
      #end
    #end 
  </select> <b>.</b> 
  <select name="seldoc">
    <option value="" selected="selected">-- N/A --</option>
    #foreach($subdoc in $xwiki.getSpaceDocsName("$currentspace"))
      #if ($currentdoc == ${subdoc}) 
        <option value="$subdoc" selected>$subdoc</option>
      #else
        <option value="$subdoc">$subdoc</option>
      #end
    #end
  </select>
  </td>
</tr>
<tr><td>Language:</td>
<td><input type="text" name="language" value="$!request.language" size="60" /></td></tr>
<tr><td>Target Doc:</td>
<td><input type="text" name="targetdoc" value="$!request.targetdoc" size="60" /></td></tr>
<tr><td><input type="submit" value="Copy" />
</td></tr>
</table>
</form>

Result

copydoc.png

Version 3.1 last modified by VincentMassol on 09/12/2007 at 15:08

Comments 0

No comments for this document

Attachments 1

Image
copydoc.png 1.1
PostedBy: VincentMassol on 09/12/2007 (16kb )

Creator: HanspeterKlapf on 2007/07/10 09:04
This wiki is licensed under a Creative Commons license
1.4.1.10194