new GroupsAPI($rootScope, $http)

Warning! The SmartFlo™ APIs assume 2 global variables are set in $rootScope prior to using the APIs:

  1. $rootScope.credential
  2. set implicitely by the AuthAPI class upon success of the authenticate method
  3. $rootScope.site
  4. set by the calling application to the
    domain (e.g., www.smartflo.biz) or IP address of the target SmartFlo™ system, possibly when initializing the module that declares an API service

Example

//
// Warning! The global '$rootScope.site' field value must be set 
// to the target SmartFlo™ domain prior to using the SmartFlo™ APIs. In this 
// example it is set by the configuration block of the 'SFgroupsApi' 
// module.
//
angular.module('sf-groups', [])
     // inject API as a service
     .service('SFgroupsApi', ['$rootScope', '$http', GroupsAPI])
     .controller('SFgroupsCtrl', GroupsCtrl);
     .run(function ($rootScope, $location) { 
     // store the site for use by APIs
         $rootScope.site = $location.host();
         if ($location.port !== null & $location.port !== 80) {
         $rootScope.site += ':' + $location.port().toString();
    }
});

Parameters

Name Type Optional Description

$rootScope

object

 

The topmost parent scope in AngularJS.

$http

service

 

The core AngularJS service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

Copyright
© Chalex Corp. 2002 - 2017. All rights reserved.
Returns

class A constructor that will be instantiated.

Methods

deletePublicGroup(params, successHandler[, failureHandler]) → object

Deletes a public group.

Example

$scope.deletePublicGroup = function() {
    var param = {
        groupname: $scope.selectedPublicGroup
    };
    groupsApi.deletePublicGroup(param, deletePublicGroupHandler);
 };

function deletePublicGroupHandler(result){
    if (result.status === '0'){
        groupsApi.getPublicGroups(getPublicGroupsHandler);
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }  
}

Parameters

Name Type Optional Description

params

object

 

An object providing the selected public group that will be set for deletion.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::delete::publicgroups,
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
};

deleteUserFromPublicGroup(params, successHandler[, failureHandler]) → object

Deletes a user from a public group.

Example

$scope.deleteUserFromPublicGroup = function(){
    var param = {
        userid: $scope.selectedPublicGroupUser,
        groupname: $scope.selectedPublicGroup
    };
    groupsApi.deleteUserFromPublicGroup(param, deleteUserFromPublicGroupHandler);
};

function deleteUserFromPublicGroupHandler(result){
    if (result.status === '0'){
        console.log("delete user from public group");
        getPublicGroupUsers();
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }
}

Parameters

Name Type Optional Description

params

object

 

An object providing the selected public group and public group user that will be set for deletion. that will be set for deletion.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::delete::publicgroupuser",
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
};

deleteUserFromSystemGroup(params, successHandler[, failureHandler]) → object

Deletes a user from a system group.

Example

$scope.deleteUserFromSystemGroup = function(){
     var param = {
         userid: $scope.systemGroupUser,
         groupname: $scope.systemGroup
     };
     groupsApi.deleteUserFromSystemGroup(param, deleteUserFromSystemGroupHandler);
 };
 function deleteUserFromSystemGroupHandler(result) {
     if (result.status === '0'){
         console.log("User deleted");
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
 }

Parameters

Name Type Optional Description

params

object

 

An object providing the system group and system group user that will be set for deletion.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::delete::systemgroupuser"
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
};

getPublicGroups(successHandler[, failureHandler]) → object

Retrieves a list of public groups.

Example

groupsApi.getPublicGroups(getPublicGroupsHandler);

function getPublicGroupsHandler(result){
    if (result.status === '0'){
        $scope.publicGroups = result.publicGroups;
     } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
     }
}

Parameters

Name Type Optional Description

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::publicgroups",
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors",
     publicGroups: [an array of strings]
};

getPublicGroups(params, successHandler[, failureHandler]) → object

Retrieves a list of assignable users within the resource group that user belongs to.

Example

function getAssignableUsers(){
    var param = {
        affiliate: $rootScope.credential.affiliate
    };
    groupsApi.getAssignableUsers(param, getAssignableUsersHandler);
}

function getAssignableUsersHandler(result){
    if (result.status === '0'){
        $scope.assignableUsers = result.assignableUsers;
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }  
}

Parameters

Name Type Optional Description

params

object

 

An object providing the affiliate that the current user belongs to.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::assignableusers",
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors",
     assignableUsers: [Array of string elements]
};

getPublicGroupsUsers(params, successHandler[, failureHandler]) → object

Retrieves a list of public group users.

Example

function getPublicGroupUsers(){
     var params = {
         groupname: $scope.publicGroup  
     };
     groupsApi.getPublicGroupUsers(params, getPublicGroupUsersHandler);
 }

 function getPublicGroupUsersHandler(result){
     if (result.status === '0'){
         $scope.publicGroupUsers = result.publicGroupUsers;
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
 }

Parameters

Name Type Optional Description

params

object

 

An object providing the public group.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     status: ['0' for success, otherwise failure],
     statusMessage: [message indicating reason for status value],
     api: [the API that was called],
     publicGroupUsers: [an array of strings]
};

getSystemGroups(successHandler[, failureHandler]) → object

Retrieves a list of system groups.

Example

groupsApi.getSystemGroups(getSystemGroupsHandler);

function getSystemGroupsHandler(result){
    if (result.status === '0'){
        $scope.systemGroups = result.systemGroups;
     } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
     }
}

Parameters

Name Type Optional Description

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::systemgroups",
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors",
     systemGroups: [an array of strings]
};

getSystemGroupUsers(params, successHandler[, failureHandler]) → object

Retrieves a list of system group users.

Example

function getSystemGroupUsers(){
    var params = {
        groupname: $scope.systemGroup
    };
    groupsApi.getSystemGroupUsers(params, getSystemGroupUsersHandler);
}

function getSystemGroupUsersHandler(result){
    if (result.status === '0'){
        $scope.systemGroupUsers = result.systemGroupUsers;
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }  
}

Parameters

Name Type Optional Description

params

object

 

An object providing the system group.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::systemgroupusers",
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors",
     systemGroupUsers: [Array of strings elements]
};

postAddPublicGroup(params, successHandler[, failureHandler]) → object

Creates a new public group.

Example

$scope.addPublicGroup = function(publicGroup) {
     var params = {
         groupname: publicGroup
     };
     groupsApi.postAddPublicGroup(params, addPublicGroupHandler);
 };
 
 function addPublicGroupHandler(result){
     if (result.status === '0'){
         groupsApi.getPublicGroups(getPublicGroupsHandler);
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     } 
 }

Parameters

Name Type Optional Description

params

object

 

An object providing the name of the new public group. that will be set for deletion.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     status: ['0' for success, otherwise failure],
     statusMessage: [message indicating reason for status value],
     api: [the API that was called],
};

postAddUserToPublicGroup(params, successHandler[, failureHandler]) → object

Adds a user to a public group.

Example

$scope.addUserToPublicGroup = function(){
     var params = {
         userid: $scope.selectedPublicGroupUser,
         groupname: $scope.publicGroup
     };
     groupsApi.postAddUserToPublicGroup(params, addUserToPublicGroupHandler);
 };

 function addUserToPublicGroupHandler(result){
     if (result.status === '0'){
         console.log("add user to public group");
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
 }

Parameters

Name Type Optional Description

params

object

 

An object providing a public group and a user to added to that group.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     status: ['0' for success, otherwise failure],
     statusMessage: [message indicating reason for status value],
     api: [the API that was called],
};

postAddUserToSystemGroup(params, successHandler[, failureHandler]) → object

Adds a user to a system group.

Example

$scope.addUserToSystemGroup = function(){
      var params = {
         userid: $scope.selectedSystemGroupUser,
         groupname: $scope.systemGroup
      };
      groupsApi.postAddUserToSystemGroup(params, addUserToSystemGroupHandler);
 };

 function addUserToSystemGroupHandler(result){
     if (result.status === '0'){
         console.log("User added");
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
 }

Parameters

Name Type Optional Description

params

object

 

An object providing a system group and a user to be added to that group.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     status: ['0' for success, otherwise failure],
     statusMessage: [message indicating reason for status value],
     api: [the API that was called],
};