Actions

The actions block consists of key-values pairs with key the action names:

  "actions" : {
    "insert" : {
      "groups"  : ["role1", "role2", ...], 
      "aliases" : ["name1", "name2", ...], 
      "validate": ["field1", "field2, ...], 
      "options  : ["no_db", "no_method"],
      "upload"  : {
        "html_field1" : {"filename1", "directory1"},
        "html_field2" : {"filename2", "directory2", "renamed2"}
      }
    }
    "topics" : { ... }
    ... 
}

Here is their explanations:

  • groups: array of roles,  which are allowed to run this action i.e. Access Control List (ACL).
    • Those roles who are not permitted to run the action will trigger error 404.
    • Roles having administrative privilege can run any action, not restricted by ACL.
  • aliases: array of alias names that the action may have.
  • validate: array of request variables which must exist. If empty, it will result in failure in the database operation.
  • options: may contain no_db or no_method. Genelet opens a database handler for each request, which comes with costs in speed and resource. If an action does not need database, just add no_db. If an action does not need to run the model, add no_method.

upload

Let’s start with an example. On HTML page, there are two files to upload, one image and one music. The form that is responsible for the uploading has the web action insert:

<input type=hidden name="action" value="insert" />
Title is: <input type=text name="title" />
...
Your image: <input type=file name="field1" />
Your MP3: <input type=file name="field2" />

 

To receive the uploading files, there needs to be an upload object in insert which follows:

"upload" : {
  "field1" : ["image_file", "/home/www/ht_docs/images"],
  "field2" : ["music_file", "/home/www/ht_docs/music", "kids.mp4"]
}

 

where the object keys are HTML input’s name, values are 3-element arrays.

After the server has received the uploading, the exact file names are saved in the incoming variables image_file and music_file, in the same way that the title input is saved in the incoming variable title. (Note that the incoming variables are collected in a hash map, named ARGS, which is language-dependent.)

The second element defines the directory for the file. In the above example, the image file is put under /home/www/ht_docs/images, and the music under /home/www/ht_docs/music.

You may override the server-assigned file name by the third element, like kids.mp4 in the music case. The element is optional.