new Category()

This class provides methods for working with categories.

Source:


Sample code

Create a category

var category = new BCAPI.Models.Category({name: 'Test Category6', parentId: 123456});
category.save()
    

Get a category's details

var category = new BCAPI.Models.Category({
    id: 123456
});
category.fetch({
    success: function (category) {
        console.log("Name: " + category.get('name') + " " +
            "ID: " + category.get('id') + " " +
            "parentId: " + category.get('parentId')
        );

    },
    error: function (data) {
        console.log('Encountered an error.')
    }
})

Update and delete operations are not supported

List all the categories

var categories = new BCAPI.Models.CategoryCollection();
categories.fetch({
    success: function (data) {
        data.each(function (category) {
            console.log(
                "Name: " + category.get('name') + " " +
                "ID: " + category.get('id') + " " +
                "parentId: " + category.get('parentId') + " " +
                "links: " + JSON.stringify(category.get('links'))
            );
        });
    },
    error: function (data) {
        console.log('Encountered an error.')
    }
})
Response
Name: Root ID: 14075 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/14075"
}]
Name: Company ID: 14606 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/14606"
}]
Name: Products ID: 14609 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/14609"
}]
Name: Solutions ID: 14610 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/14610"
}]
Name: Customers ID: 14744 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/14744"
}]
Name: Company1 Private ID: 155310 parentId: 14606 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155310"
}]
Name: Company2 Public ID: 155311 parentId: 14606 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155311"
}]
Name: My category ID: 155312 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155312"
}]
Name: My category2 ID: 155313 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155313"
}]
Name: My category3 ID: 155314 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155314"
}]
Name: My category4 ID: 155315 parentId: -1 links: [{
    "rel": "self",
    "uri": "https://api-ava.worldsecuresystems.com/api/v2/admin/sites/246884/categories/155315"
}]

Methods

destroy()

This method deletes a model using the api.

Source:

Example

var model = new PersonModel({id: 1});
model.destroy({
	success: function() {
		// do something when delete is successful.
	}
});

endpoint()

This method returns the correct endpoint for the category.

Source:

headers() → {Object}

This method returns the predefined headers which are automatically appended to ajax calls.

The default implementation delegates this to the model's method.

Source:

Returns

A list of headers appended to ajax calls.

Type: objectg

save()

This method change default Backbone save behaviour in order to simplify save invocation.

Source:

Example

var model = new PersonModel();
model.save({
	success: function(model, response) {
		// handle success logic in here
	}
});

sync(method, model, options) → {Promise}

Parameters

Name Type Description
method String

Http method used to persist the state of the current model.

options Object

Additional options which influence how http call will be done.

Source:

Returns

jQuery promise which can be used to determine when request is done.

Type: promise

urlRoot(modelEndpoint) → {string}

This method automatically builds absolute entry point url of the model.

This method accepts as parameter the model's endpoint. If this is not specified, then the endpoint method is called.

Parameters

Name Type Description
modelEndpoint String

The model's endpoint.

Source:

Returns

An absolute entry point API.

Type: string