FatPhone installer requires creation of elements, as well as assets. But XMLPost does not create those elements, at least for Templates, so the installer has to create those elements calling directly CatalogManager .
I wrote a Javascript class that does just this: interfaces with CatalogManager for creating and querying rows. Since this class is useful by itself, I am writing this post as documentation for general usage.
Code is available in the FatPhone github public repository: the file is named catalogmanager.js. It is released under the GPL. You can download and use in your project freely. There is also a test html page to test and call it interactively.
Now, 2 important warnings:
It can also already perform generic queries, but the returned result is just the HTML of the response. I should parse the HTML and return the answer in json format to be more useful.
To summarize the available functions:
var cm = new CatalogManager(url)
where url is the Fatwire ContentServer base url (tipically http://www.yoursite.com/cs/),
cm.login(username, password, loginFunction, errorFunction)
where username and password are your FatWire credentials. If login is ok, loginFunction is called, otherwise errorFunction is called.
Once you are logged on , you can execute calls. The simplest call is:
cm.selectRow(tablename, where, what, callbackFunction)
this will perform a query on the given tablename, specifying a where condition and what (fields) to search for. The callbackFunction will be called with the result.
For example,
cm.selectRow(Page, "id", "name='Home'", alert)
will show in an alert box the result of searching the Page table for records with name Home, and will return his id. A simple regular expression can extract the id from the returned result. I do exactly this in the installer, you can check the source code of install.js to see an example.
In an ideal world, I should parse the returned html in a structured javascript object (an array of maps, for example). If you want to improve the code before I will do it... your help is appreciated.
cm.checkExist(tablename, selwhere, found, notFound)
This function perform a limited parsing of the result to see if the row in tablename, specified in the selwhere, was found or not. The appropriate callback function is called according to the result.
cm.addRow(tablename, data, nextStep)
tablename is a string, the name of a row, while data must be a map. For example, this call create a new Element in the ElementCatalog (assuming that elementName, fileBody, fileName and fileFolder are defined, of course):
cm.addRow("ElementCatalog", { "elementname" : elementName, "url" : fileBody, "url_file" : fileName, "url_folder" : fileFolder }, nextStep)
The function nextStep is called with a status object passed as the first parameter. The status is a map that has at least 3 keys:
cm.editRow(tablename, data, nextStep)
tablename is a string, the name of a row, while data must be a map and nextStep is a function called with the status of the result.
Both data and the return status have the same format as in addRow, except that the data must specify the id field to make the call work.
cm.deleteRow(tablename, data, nextStep)
tablename is a string, the name of a row, while data must be a map and nextStep is a function called with the status of the result.
Both data and the return status have the same format as in addRow, except that the data must specify an id field to make the call work successfully. Actually, in the delete the id is the only required field, any other field in this call is just ignored