/**
*
* Copyright (C) 2021 Akorbi Digital RMP
*
* This file is part of RunMyProcess SDK-JS.
*
* RunMyProcess SDK-JS is free software: you can redistribute it and/or modify
* it under the terms of the Apache License Version 2.0 (the "License");
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
Create a new instance of Usage
@constructor
@property {Object} usage - the objects usage
@property {Array} links - Contains the array of links
@see ProjectApp
@see Resource
@example Load Usage
var u = new Usage();
u.load({
period : "current",
onSuccess : function(){
alert(JSON.stringify(u.usage));
}
});
*/
function Usage(){
this.usage = {};
this.links = [];
};
/**
@borrows
Inherits Resource
*/
Usage.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
Usage.prototype.loadPreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
this.generateUrl = function () {
return "logs/usage/"+context.customer_id+"/period/"+this.period;//HARDCODED
};
};
/**
Override Resource load method.
@method
@param {object} options - options to be used during the call<br/>
@param {string} options.period - the period to load
@param {Resource~onSuccess} options.onSuccess - a callback function called in case of a success
@param {Resource~onFailure} [options.onFailure] - a callback function called in case of a failure
@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
@see Resource#load
*/
Usage.prototype.load = function(options){
var loadOptions = {};
var father = this;
this.period = options.period;
father.pagination = {};//remove current pagination
father.filters = [];//remove current filters
father.orderBy = [];//remove current orderBy
father.mode = '';
father.parameters = [];
if(options.removeDefaultFilters) father.defaultFilters = [];
father.loadPreset();
if(!jQuery.isEmptyObject(options.pagination))father.pagination = options.pagination;
if(options.mode)father.mode = options.mode;
if(options.parameters)father.parameters = options.parameters;
if(options.filters)father.filters = options.filters;
if(options.orderBy)father.orderBy = options.orderBy;
loadOptions.onSuccess = function(rObject){
father.usage = rObject.usage;
father.links = rObject.links;
options.onSuccess(rObject);
};
loadOptions.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
loadOptions.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
father.straightLoad(loadOptions);
};