/***
CreatePageFromTemplate(templateName, buttonName, path, tags, fromTemplate)
MyMindtouch:
2011/01/28 - Added parameter inputWidth
2010/11/10 - Changes respect Mindtouch release 10.0.2 :
* Added Features
path parameter: You can post the new page to the desired path
tags parameter: Tags to add to the new created page
fromTemplate Parameter: if you pass it false, you can the origin (templateName) can be a normal page instead a template.
args: Args to pass to the new page created onLoad
* Solved some problems when paths and new page titles has especial chars ( à,è,ñ,...)
2010/11/15
* Added Features
searchSuggestion: If you want that the input box it's a Search Suggestion, by default it's fase.
searchSuggestionConstrained: If you want to constraint the searchSuggestion Box.
2010/12/29
* Added Features
titleLowerCase: Save the title on lower case, otherwise it saves it as given
***/
dekiapi();
jquery.ui('smoothness');
// + PARAMETERS
var par = {
buttonName: ( __request.args.buttonName ?? args.buttonName ?? $0 ?? '' ),
templateName: ( __request.args.templateName ?? args.templateName ?? $1 ?? '' ),
path: ( __request.args.path ?? args.path ?? page.path ),
tags: ( __request.args.tags ?? args.tags ?? []), /* It can use the page title as a tag name,
it search an replaces for text (page_title) */
args: ( __request.args.args ?? args.args ?? {} ),
searchSuggestion: ( __request.args.searchSuggestion ?? args.searchSuggestion?? false ),
searchSuggestionConstrained: ( __request.args.searchSuggestionConstrained ?? args.searchSuggestionConstrained?? null ),
fromTemplate: ( __request.args.fromTemplate?? args.fromTemplate ?? true ),
titleLowerCase: ( __request.args.titleLowerCase?? args.titleLowerCase ?? false),
inputWidth: (__request.args.inputWidth?? args.inputWidth ?? 100)
};
var buttontext = "Enter " .. string.tolower(par.buttonname) .. " name";
<div id="newpagediv">
<table id="newpagetable" style="width:100%;" class="table">
<tr>
<th id="nptth">
"Create " .. par.buttonname;
</th>
</tr>
<tr>
<td>
<div id="waitdiv">
template("MindTouch/Controls/WaitingIcon32x32");
<br />
"Please wait...";
</div>
<div id="creatediv">
if(par.searchSuggestion) {
template("DeveloperSite/SearchSuggestion", {
inputid: "pname",
constrained: par.searchSuggestionConstrained,
showfiles: false,
showcomments: false,
inputWidth: par.inputWidth
});
}
else
{
template("MindTouch/Controls/TextBox", {
id: "pname",
text: buttontext,
class: "",
width: par.inputWidth
});
}
<input type="hidden" value=(par.path) id="ppath"/>
<input type="hidden" value=((par.fromTemplate?'Template:':'') .. par.templatename) id="tp"/>
<input type="hidden" value=(site.uri) id="siteuri"/>
<input type="hidden" value=(String.Replace(uri.appendquery("http://dummy.com",par.args),"http://dummy.com","")) id="npargs" />
<input type="hidden" value=(Json.Emit(par.tags)) id="nptags"/>
<br />
<br />
<input type="button" value=(par.buttonname) ctor="
var working = false;
var tToLowerCase = {{ par.titleLowerCase }};
when($this.click) {
if (working == false) {
working = true;
#creatediv.hide();
#waitdiv.show();
@newpage({
siteuri: #siteuri.val(),
pname: MindTouch.Text.Utf8Encode(tToLowerCase?#pname.val().toLowerCase():#pname.val()), ppath: MindTouch.Text.Utf8Encode(#ppath.val()),
tpath: #tp.val(),
nptags: #nptags.val(),
npargs: #npargs.val()
});
};
}
when(@newpage) {
var page_path = @newpage.ppath + '/' + @newpage.pname;
var page_api = MindTouch.Deki.GetPageApi(Deki.Env.SiteApi, page_path);
MindTouch.Web.Get(page_api, null, function(xhr) {
if(xhr.status == '200') {
alert('That page already exists. Please choose a different name.');
#creatediv.show();
#waitdiv.hide();
#pname.val('Enter ' + {{ string.tolower(par.buttonname) }} + ' name');
working = false;
} else if(xhr.status == '404') {
var template_api = MindTouch.Deki.GetPageApi(Deki.Env.SiteApi, @newpage.tpath);
MindTouch.Deki.CreatePageFromTemplate(page_api, template_api, function() {
if (@newpage.nptags!='[]') {
@addtags({
siteuri: @newpage.siteuri,
ppath: @newpage.ppath,
pname: @newpage.pname,
nptags: @newpage.nptags,
npargs: @newpage.npargs
});
}
else
{
@loadnewpage({
siteuri: @newpage.siteuri,
ppath: @newpage.ppath,
pname: @newpage.pname,
npargs: @newpage.npargs
});
}
}, function() {
alert('Page create failed. Please try again.');
working = false;
});
}
});
};
when(@addtags) {
var titleParsed = @addtags.nptags.replace(/\\(page_title\\)/gi,#pname.val().toLowerCase());
titleParsed = @addtags.nptags.replace(/\\(page_title,3\\)/gi,#pname.val().substr(3).toLowerCase());
var currentTags = YAHOO.lang.JSON.parse(titleParsed || '[]')
if(!isArray(currentTags)) { currentTags = [ currentTags ]; }
var tags='<tags>';
var i;
for (i=0;i<currentTags.length;i=i+1) {
tags = tags +'<tag value=\"' + currentTags[i] + '\" />';
}
tags = tags + '</tags>';
// send AJAX request using jQuery
$.ajax({
// set the uri for the properties API of the current page
url: MindTouch.Deki.GetPageApi(Deki.Env.SiteApi, @addtags.ppath + '/' + @addtags.pname)+'/tags',
// set the request HTTP verb
type: 'PUT',
// set the value of the new property
data: tags,
//contentType: 'text/xml; charset=iso-8859-1',
contentType: 'text/xml; charset=utf-8',
processData: false,
// check outcome of the request
complete: function(xhr) {
// check the response status code
if(xhr.status == 200) {
@loadnewpage({
siteuri: @addtags.siteuri,
ppath: @addtags.ppath,
pname: @addtags.pname,
npargs: @addtags.npargs
});
} else {
alert('Unable to create the Tag. It may already exist (try deleting it) or you don\\'t have permission to create it.');
}
}
});
};
when(@loadnewpage) {
var newpath = (@loadnewpage.siteuri + #ppath.val() + '/' + (tToLowerCase?#pname.val().toLowerCase():#pname.val()) + #npargs.val());
window.location = newpath;
};
" />
</div>
</td>
</tr>
</table>
</div>
<script type="text/javascript">"
function isArray(obj) {
if (obj.constructor.toString().indexOf('Array') == -1)
return false;
else
return true;
}
"</script>
<div><style type="text/css">"
#pname {
font-style: italic;
color: #778899;
}
#newpagetable {
width: 100% !important;
}
#newpagetable #nptth {
text-align: center !important;
}
#waitdiv {
display: none;
text-align: center;
}
#creatediv {
text-align: center;
}
"</style></div>| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by