The server reads files as an integral part of the server. Files read will then be parsed to see if they are pages or templates if they are of type .html, .htm, .dql and .page. If they are pages/templates they will be used as any other page and the resulting code generated is the page and not the source. Due to this we have another set of requests that manipulate files as they are. 

File manipulation

To manipulate a file on the server, you need to be logged in as a user with High security. The handling is done using the /filehandling/url. This handler support GET for reading PUT for updating, POST for creating and DELETE for deleting files.

Read a raw file

var url = '/filehandler/editor/pageeditor.html';
var options = {
  'url' : url,
  'type' : 'GET',
  'dataType' : 'text'
};
$.ajax(options).done(function(code,status,xhr){
  // the content of the file is now in code
  _this.myfilecontent = code;
}).fail(function(code,status,xhr){ //do error handling here
});

This reads a file as raw data from /static/editor/pageeditor.html in the application started using jquery

Write a raw file

var thecode = 'This is a text to put into the file\nSecond line\nThird line\n';
var url = '/filehandler/editor/';
var filename = 'pageeditor.html';
var fdata = new FormData();
fdata.append('file', new File([new Blob([thecode])],filename));
var options = {
  'url' : url,
  'data' : fdata,
  'processData' : false,
  'contentType' : false,
  'type' : 'POST'
};
$.ajax(options).done(function(jdata,status,xhr){
  // do some messaging if the write was ok
  if (jdata.result=='ok')
    $("#messages").html("The file was saved");
}).fail(function(code,status,xhr){ //do error handling here
});

This saves or creates a file as raw data from /static/editor/pageeditor.html in the application started using jquery

Delete the file

var url = '/filehandler/editor/pageeditor.html';
var options = {
  'url' : url,
  'type' : 'DELETE'
};
$.ajax(options).done(function(jdata,status,xhr){
  // do some messaging if the delete was ok
  if (jdata.result=='ok')
    $("#messages").html("The file was deleted");
}).fail(function(code,status,xhr){ //do error handling here
});

This deletes the file from /static/editor/pageeditor.html in the application started using jquery