THIS TEMPLATE IS CURRENTLY IN BETA PLEASE REPORT ALL TROUBLES
I created this template because someone on the forums asked how you can create a button that will force a page to move without using the Move Page Dialog. I decided that this would be some nice functionality to automate page workflows and would also be a great example of how to use the Move Page API with jQuery. All questions and comments should be directed to this forum thread.
Please note that the redirects from a moved page may get in the way of some of what you want to do. I have not yet figured out how to stop the redirects from happening.
| Version | Date | Author | Description |
| 0.9b | 11/18/2009 | rberinger | Initial Release |
For all the examples on this page, the code is shown before the working example. The code is shown with the syntax extension, and looks like this:
MovePage()
This means that the actual code on the page should be enclosed in a DekiScript block. If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above.
| Name | Type | Default | Description |
| page | str? | page.path | The Path of the page to move |
| title | str? | n/a | New Page Title (renameing) |
| moveto | str? | n/a | The root path to move the page to (This should be the path only without the page title) |
| action | str? | follow | What do do after the move (refresh, follow or nothing) |
| text | str? | Move Page | Text to place on the button |
All questions and comments should be directed to this forum thread.
Thanks to sego for challenging me to create this template
// AUTHOR: rberinger
// Version: 0.9b (Currently Beta)
// Date: 11/18/2009
dekiapi();
var PageToMove = ($0 ?? $page ?? page.path);
var NewPageTitle = ($1 ?? $title ?? '');
var MoveTo = ($2 ?? $moveto ?? '');
var Action = ($3 ?? $action ?? 'follow'); // refresh, follow, ''
var ButtonText = ($4 ?? $text ?? 'Move Page');
if(string.startswith(PageToMove, '/')) {
let PageToMove = string.substr(PageToMove, 1);
}
// Get the page that we are moving
var p = wiki.getpage(PageToMove);
// The new page path
if(string.LastIndexOf(MoveTo, '/') != (#MoveTo - 1) ) {
let MoveTo ..= '/';
}
// We need to get our page title whether new or old
var ttl = ((NewPageTitle != '') ? NewPageTitle : p.title);
// The pageid of the page to be moved
var pageID = p.id;
// Account for special characters
let ttl = string.replace(ttl, ' ', '_');
let ttl = string.replace(ttl, '/', '//');
// Append the page title to the path
var NewTitle = MoveTo ..ttl;
// Lets make sure we are not trying to move the page again
// We have to check this way due to possible page redirects that may exist
if(p.path != NewTitle) {
<input id=(@id) class="MoveButton" type="button" value=(ButtonText) ctor="when($this.click) { MovePage(PageToMoveID, NewLoc, MoveAction) }" />
}
<html><head>
<script type="text/javascript">"
var NewLoc = "..json.emit(NewTitle)..";
var PageToMoveID = "..json.emit(pageID)..";
var MoveAction = "..json.emit(string.ToLower(Action))..";
"</script>
<script type="text/javascript">"
var MovePage = function(pidToMove, NewPath, ActionAfterMove) {
var Site_API = "..json.emit(site.api)..";
var Site_URI = "..json.emit(site.uri)..";
var Url = Site_API + '/pages/' + pidToMove + '/move?to=' + NewPath;
Deki.$.ajax({
type: 'POST',
url: Url,
complete: function(data, result){
if(result == 'success') {
if(ActionAfterMove == 'refresh') {
window.location = window.location;
} else if(ActionAfterMove == 'follow') {
location.replace( Site_URI + NewPath );
} else if(ActionAfterMove == '') {
}
} else {
alert( 'Move Failed' );
}
}
});
}
"</script>
</head></html>
This has not been extensively tested as of yet and I'm sure I did not account for every possible scenerio so please test in your environment with some test pages prior to using in production.
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by