/**
*
* 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 LaneList
@constructor
@property {Array} lanes - Array of lanes.
@property {Array} pools - Array of pools.
@see Resource
@example Load Lanes
var laneList = new LaneList();
laneList.load({
onSuccess:function(){
alert("lanes:"+laneList.lanes.length+" pools:"+laneList.pools.length);
}
});
*/
function LaneList(){
this.lanes = [];
this.pools = [];
};
/**
@borrows
Inherits Resource
*/
LaneList.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
LaneList.prototype.loadPreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
this.generateUrl = function () {
return this.selfUrl||context.link.lane;
};
};
/**
Overrides Resource's loadSet method to set local variables after request.
@method
@param {json} rObject - JSON representation of the loaded data.
@see Resource#loadSet
*/
LaneList.prototype.loadSet = function (rObject) {
var father = this;
var ent=this.getArray(rObject, "entry");
var pList = new LanePoolList();
var plLinks = [];
father.lanes = [];
for (var i = 0; i < ent.length; i++) {
//LANES
var lane = new Lane();
lane.object = ent[i];
lane.id = ent[i].id;
lane.title = ent[i].title;
lane.categories = lane.getArray(ent[i], "category");
lane.isEverybody = lane.termSearch('allow_everybody',ent[i].category).label;
lane.type = lane.termSearch('context',ent[i].category).label;
lane.links = lane.getArray(ent[i], "link");
lane.selfUrl = ent[i].content.src;
lane.rights = lane.object.rights;
lane.author.name = ent[i].author.name;
lane.author.selfUrl = ent[i].author.uri;
if (ent[i].content){
lane.script = ent[i].content.P_value;
}
father.lanes.push(lane);
//END LANES
//POOLS
var llinks=father.getArray(ent[i], "link");
plLinks.push(father.linkSearch('pool',llinks));
//END POOLS
}
var unqLinks = plLinks.filter(function(elem, pos) {
return plLinks.indexOf(elem) === pos;
});
for (var i = 0; i < unqLinks.length; i++) {
var pl=new Pool();
pl.selfUrl = unqLinks[i];
pList.pools.push(pl);
};
this.pools = pList.pools;
};
/**
Load pools in a serialized manner
@method
@param {object} options - options to be used during the call<br/>
@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
*/
LaneList.prototype.loadPoolsSerialized = function (options) {
var father = this;
function serialLoad(i){
try{
var lOptions = {};
lOptions.onSuccess = function(){
if (i < ps.length-1){
serialLoad(i+1);
}else{
options.onSuccess();
}
};
lOptions.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
lOptions.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
ps[i].load(lOptions);
}catch (e) {
options.eObject=e;
father.errorManager(options);
};
};
var ps = father.pools;
serialLoad(0);
};