Wiki source code of Add a new category
Last modified by Ludovic Dubost on 2008/11/10 04:21
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | #set($space = "$!request.space") | ||
| 2 | #if("$!request.name" != '') | ||
| 3 | #if($space != "") | ||
| 4 | #set($newCategoryDoc = $xwiki.getDocument("${space}.${request.name}")) | ||
| 5 | #else | ||
| 6 | #set($newCategoryDoc = $xwiki.getDocument("${request.name}")) | ||
| 7 | #end | ||
| 8 | #if($newCategoryDoc.isNew()) | ||
| 9 | #set($newCategoryObj = $newCategoryDoc.newObject("Blog.CategoryClass")) | ||
| 10 | $newCategoryObj.set("name", $request.name) | ||
| 11 | $newCategoryObj.set("description", $request.description) | ||
| 12 | $newCategoryDoc.setParent($request.parent) | ||
| 13 | #set($content = "#includ") | ||
| 14 | #set($content = "${content}eForm('Blog.CategorySheet')") | ||
| 15 | $newCategoryDoc.setContent($content) | ||
| 16 | $newCategoryDoc.save() | ||
| 17 | #info("The category [$newCategoryDoc.name>$newCategoryDoc.fullName] has been created.") | ||
| 18 | #else | ||
| 19 | $response.setStatus(409) | ||
| 20 | #warning("The category [$newCategoryDoc.name>$newCategoryDoc.fullName] already exists.") | ||
| 21 | #end | ||
| 22 | #end | ||
| 23 | <form name="Add category" action="" method="post"> | ||
| 24 | <div> | ||
| 25 | #if($space != "") | ||
| 26 | <input type="hidden" name="space" value="$space"/> | ||
| 27 | #end | ||
| 28 | <dl> | ||
| 29 | <dt><label for="name">Name:</label></dt> | ||
| 30 | <dd><input type="text" name="name" style="width: 95%"/></dd> | ||
| 31 | #if("$!parentCategory" == "") | ||
| 32 | <dt><label for="parent">Parent category:</label></dt> | ||
| 33 | #set($sql = ", BaseObject obj where ") | ||
| 34 | #if($space != "") | ||
| 35 | #set($sql = "${sql}doc.space = '${space}' and ") | ||
| 36 | #end | ||
| 37 | #set($sql = "${sql}obj.name = doc.fullName and obj.className = 'Blog.CategoryClass' and doc.fullName <> 'Blog.CategoryTemplate' order by doc.name") | ||
| 38 | <dd><select name="parent" style="width: 95%"> | ||
| 39 | <option selected="selected" value="Blog.Categories">None</option> | ||
| 40 | #foreach($category in $xwiki.searchDocuments($sql)) | ||
| 41 | <option value="$category">$xwiki.getDocument($category).display('name', 'view')</option> | ||
| 42 | #end | ||
| 43 | </select></dd> | ||
| 44 | #else | ||
| 45 | <dt><input type="hidden" name="parent" value="$parentCategory"/></dt> | ||
| 46 | #end | ||
| 47 | <dt><label for="description">Description:</label></dt> | ||
| 48 | <dd><textarea name="description" style="width: 95%"></textarea></dd> | ||
| 49 | <dl> | ||
| 50 | <input type="submit" value="Add"/> | ||
| 51 | </div> | ||
| 52 | </form> |
