JSMA categories

Overview

The JSMA categories provides functionality for finding, creating and deleting categories.

What can JSMA categories do for me?

The JSMA categories provides access to all the categories (JSMA category) in the database.

Index

Usage

writing data

Here is an example on how to write data to a JSMA categories:

...
var newCategory = categories.create({ name: 'Anhänger', flexAttributes: { description: 'Ein Anhänger' } }) // => category
...

reading data

Here is an example on how to read data from a JSMA categories:

function doGetCategoryEntries ()
{
    var result = {
      status : "OK",
      results : []
    };
    
    var filter = "*" + request.parameter("filter") + "*";

    var filteredCategories = categories.find(filter);
    var imageId;
    
    filteredCategories.forEach( function (category) {
      
      if (category.image) {
        imageId = category.image.uuid;
      }
      else {
        imageId = undefined;
      }
      
      result.results.push({
        display : category.title,
        imageId : imageId,
        value : category.name
      });
    });
    
    return result;
  };

Methods

The JSMA categories provides the following methods:

category categories.create(attributes)

Creates a new category in the database and returns it as a JSMA category.

Slice aware

This entity is slice aware, which means that to use this facility:

  • there must be a logged in user in the context of the execution
  • this user must be currently within a slice
  • this user must have the necessary privileges to edit the entity (IFE → System → Benutzer → Roles → Content-Management)

Example

...
var newCategory = categories.create({ name: 'Anhänger', flexAttributes: { description: 'Ein Anhänger' } }) // => category
...

Parameter attributes:object (required)

An object that may have the following optional keys:

  • namespace (the title of a namespace to which this category will be linked)
  • name
  • description
  • shortDescription
  • flexAttributes

categories.delete(category)

Deletes a category from the database.

Slice aware

This entity is slice aware, which means that to use this facility:

  • there must be a logged in user in the context of the execution
  • this user must be currently within a slice
  • this user must have the necessary privileges to edit the entity (IFE → System → Benutzer → Roles → Content-Management)

Example

...
categories.delete(category)
...

Parameter category:category (required)

A JSMA category.

category[] categories.find(query, [options])

Searches and returns a list of JSMA category from the Sphinx index.

Example

...
var filter = "*" + request.parameter("filter") + "*";

var filteredCategories = categories.find(filter, { limit: 5 }); // => [category0, category1, ...]
...

Parameter query:string (required)

The search term. May use Extended Sphinx Syntax (http://sphinxsearch.com/docs/archives/1.10/extended-syntax.html)

Parameter options:object (optional)

An object that may have the following optional keys:

  • limit:int (optional, default: 8)

category categories.findByName(name)

Retrieves a single JSMA category by name.

Example

...
function Category ( categoryName ) 
{
    this.categoryJsma = categories.findByName(categoryName);
    
    if (!this.categoryJsma) {
      throw Error("Category " + categoryName + " could not get resolved");

  ...
}
...

Parameter name:string (required)

The name of a JSMA category in the database.

category categories.findByUuid(uuid)

Retrieves a single JSMA category by uuid

Example

...
var categorySearched = categories.findByUuid('246E353D-D6C6-46CB-968E-164DF5CB679C'); // => category
...

Parameter uuid (required)

The uuid of a JSMA category.