/**
*
* 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.
*/
/**
A List of the login user's customers
@constructor
@property {Array} customers - Array of customers.
@see Resource
@example Load customers
var custList = new CustomerList();
custList.load({
onSuccess:function(){
alert('List Loaded \n'+custList.customers.length+' customers on list');
}
});
*/
function CustomerList(){
this.customers=[];
};
/**
Inherits Resource
@borrows Resource.js
*/
CustomerList.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
CustomerList.prototype.loadPreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
this.generateUrl=function () {
return context.link.customers;
};
};
/**
Overrides Resource's loadSet method to set local variables after request.
@method
@param {json} rObject - JSON representation of the loaded data.
@see Resource#loadSet
*/
CustomerList.prototype.loadSet = function (rObject) {
try{
var father = this;
father.customers = [];
var ent = this.getArray(rObject, "entry");
for (var i = 0; i < ent.length; i++) {
var c = new Customer();
c.id = ent[i].id;
c.title = ent[i].title;
c.status = c.termSearch('status',ent[i].category).label;
c.country = c.termSearch('country',ent[i].category).label;
c.renewalDate = new Date(c.termSearch('renewal_date',ent[i].category).label);
c.userCount = Number(c.termSearch('user_count',ent[i].category).label);
c.userCredit = Number(c.termSearch('users_credit',ent[i].category).label);
c.published = new Date(ent[i].published);
c.links = c.getArray(ent[i],"link");
/*var subs=new CustomerSubscriptionList();
subs.selfUrl = subs.linkSearch('subscription', c.links);
c.subscriptionList = subs;*/
/*var trk = new CustomerTrafficList();
trk.selfUrl = trk.linkSearch('traffic', c.links);
c.trafficList = trk;*/
/*var usrl=new UserList();
usrl.selfUrl = usrl.linkSearch('user', c.links);
c.userList = usrl;*/
/*var doml=new CustomerDomainList();
doml.selfUrl = doml.linkSearch('domains', c.links);
c.domainList = doml;*/
father.customers.push(c);
}
}catch (e) {
alert(e);//FIX
};
};
/**
Adds the customer filter
@param [string] customerId - id of the customer to filter
*/
CustomerList.prototype.addCustomerFilter = function (customerId) {
var opt = {};
opt.filter='ID';
opt.operator='EE';
opt.value=customerId;
this.addFilter(opt);
};
/**
Removes the customer filter
*/
CustomerList.prototype.removeCustomerFilter = function () {
this.removeFilter('ID');
};
/**
Adds the domain filter
@param [string] domain - domain value to filter
*/
CustomerList.prototype.addDomainFilter = function (domain) {
var opt = {};
opt.filter='DOMAIN';
opt.operator='EE';
opt.value=domain;
this.addFilter(opt);
};
/**
Removes the domain filter
*/
CustomerList.prototype.removeDomainFilter = function () {
this.removeFilter('DOMAIN');
};
/**
Adds the name filter
@param [string] name - name value to filter
*/
CustomerList.prototype.addNameFilter = function (name) {
var opt = {};
opt.filter='NAME';
opt.operator='EE';
opt.value=name;
this.addFilter(opt);
};
/**
Removes the name filter
*/
CustomerList.prototype.removeNameFilter = function () {
this.removeFilter('NAME');
};
/**
Adds the login filter
@param [string] name - name value to filter
*/
CustomerList.prototype.addLoginFilter = function (login) {
this.addFilter({filter:'LOGIN', operator:'EE', value:login});
};
/**
Removes the login filter
*/
CustomerList.prototype.removeLoginFilter = function () {
this.removeFilter('LOGIN');
};