baasic-sdk-angularjs
Version:
AngularJS SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
192 lines (132 loc) • 5.22 kB
Markdown
# baasicTemplatingService
Baasic Templating Service provides an easy way to consume Baasic Templating REST API end-points. In order to obtain a needed routes `baasicTemplatingService` uses `baasicTemplatingRouteService`.
* * *
### baasicTemplatingService.find()
Returns a promise that is resolved once the find action has been performed. Success response returns a list of template resources matching the given criteria.
**Example**:
```js
baasicTemplatingService.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.get()
Returns a promise that is resolved once the get action has been performed. Success response returns the specified template resource.
**Example**:
```js
baasicTemplatingService.get('<template-id>')
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.create()
Returns a promise that is resolved once the create template action has been performed; this action creates a new template resource.
**Example**:
```js
baasicTemplatingService.create({
content : '<content>',
templateId : '<template-id>'
})
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.update()
Returns a promise that is resolved once the update template action has been performed; this action updates a template resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicTemplatingRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects:
```
var params = baasicApiService.removeParams(template);
var uri = params['model'].links('put').href;
```
**Example**:
```js
// template is a resource previously fetched using get action.
template.content = '<new-content>';
baasicTemplatingService.update(template)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.remove()
Returns a promise that is resolved once the remove action has been performed. This action will remove a template resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicTemplatingRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects:
```
var params = baasicApiService.removeParams(template);
var uri = params['model'].links('delete').href;
```
**Example**:
```js
// template is a resource previously fetched using get action.
baasicTemplatingService.remove(template)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.routeService()
Provides direct access to `baasicKeyValueRouteService`.
**Example**:
```js
baasicTemplatingService.routeService.get(expandObject);
```
### baasicTemplatingService.batch.create()
Returns a promise that is resolved once the create action has been performed; this action creates new template resources.
**Example**:
```js
baasicTemplatingService.batch.create([{
content : '<content>',
templateId : '<template-id>'
}])
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.batch.update()
Returns a promise that is resolved once the update action has been performed; this action updates specified template resources.
**Example**:
```js
baasicTemplatingService.batch.update(templates)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicTemplatingService.batch.remove()
Returns a promise that is resolved once the remove action has been performed. This action will remove template resources from the system if successfully completed.
**Example**:
```js
baasicTemplatingService.batch.remove(companyIds)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
* * *
**Notes:**
- Refer to the [REST API documentation](https://github.com/Baasic/baasic-rest-api/wiki) for detailed information about available Baasic REST API end-points.
- All end-point objects are transformed by the associated route service.