...
Code Block |
---|
......
...
//Function called when there is a click of the
//submit button in new.esp page
$('#button').click(function() {
//Retrieve the input texts from the HTML
var title = $("#title").val();
var text = $("#editor1").val();
var editor_data = CKEDITOR.instances.editor1.getData();
text=editor_data;
var tagValues = $("#tags").val();
//Now create a list with tags
tagValues=tagValues.split(",");
for(var i=0; i<tagValues.length; i++) {
tagValues[i] = tagValues[i].replace(/ /g,'');
}
var token = new Array();
for(var i=0; i<tagValues.length; i++)
if(tagValues[i] != "")
token.push(tagValues[i]);
//Every information is stored in the "data" variable
//sling:resourceType tells the repository that this entry is a David one
//jcr:mixinTypes=mix:referenceable defines this entry as referenceable (see JCR)
var data="title="+title+"&text="+text+"&sling:resourceType=david&jcr:mixinTypes=mix:referenceable";
for (var j = 0 ; j < token.length ; j++){
data=data.concat("&tag="+token[j]);
}
//The current date will be used to create the folders
//in the Sling repository where we will put the content
var currentDate = new Date();
var year = currentDate.getYear()+1900;
var month = currentDate.getMonth()+1;
var day = currentDate.getDate()+1;
if (month<10)
month = "0" + month;
if (day<10)
day = "0" + day;
//The url is under the David root node /content/david
//created during the initial content loading
var url="/content/david/"+year+"/"+month+"/"+day+"/";
//Simple AJAX call to create a HTTP POST request
$.ajax({
type: "POST",
url: url,
data: data,
success: function(msg){
alert("Entry saved");
window.location = "/content/david.html";
},
error: function(msg){
alert("Error during save");
}
});
});
...
...
...
|
...
It's an unuseful script, because also this operation can call new.esp. There is a need of a bit refactory about it.
List existing entries
Once you saved some entries in David, you can see a complete list of articles using the script /apps/david/list.esp.
Firstly there is a JCR query to find all the items
Code Block |
---|
var queryManager = currentNode.getSession().getWorkspace().getQueryManager();
var query = queryManager.createQuery("/jcr:root/content/david/*/*/*/element(*, nt:unstructured) order by @created descending", "xpath");
var result = query.execute().getNodes();
|
In this way we have a variable result with a NodeIterator object. So we simply have to make a loop on this iterator and print its values
Code Block |
---|
<h3>Entries</h3>
<div>
<h3><a href='/content/david.pdf'>Export list</a></h3>
<%
while(result.hasNext()) {
post = result.nextNode()
%>
<h3> <a href="<%= post.getPath() %>.article"><%=post.title%></a> -
<a href="<%= post.getPath() %>.edit">EDIT</a> -
<a id="<%= post.getPath() %>" class="delete" href="#">DELETE</a> -
<a href="<%= post.getPath() %>.pdf"><img alt="Get pdf" src="/libs/images/pdf-icon.png"></a>
</h3>
<%
}
%>
</div>
|
ss
Delete existing entry
Generate the tags content structure
...