/**
*
* 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 a customer domains
@constructor
@property {Array} domains - Array of domains.
@see Customer
@see Resource
*/
function CustomerDomainList(){
this.domains = [];
};
/**
@borrows
Inherits Resource
*/
CustomerDomainList.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
CustomerDomainList.prototype.loadPreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
this.generateUrl=function () {
return this.selfUrl;
};
};
/**
Overrides Resource's loadSet method to set local variables after request.
@method
@param {json} rObject - JSON representation of the loaded data.
@see Resource#loadSet
*/
CustomerDomainList.prototype.loadSet = function (rObject) {
var father = this;
father.domains = [];
var ent = this.getArray(rObject, "entry");
for (var i = 0; i < ent.length; i++) {
var dmn = new Domain();
dmn.id = ent[i].id;
dmn.categories = dmn.getArray(ent[i], "category");
dmn.title = ent[i].title;
dmn.links = dmn.getArray(ent[i], "link");
dmn.selfUrl = ent[i].content.src;
father.domains.push(dmn);
}
};
/**
Overrides Resource's savePreset method.
@method
@see Resource#savePreset
*/
CustomerDomainList.prototype.savePreset = function () {
/**
Overrides Resource's generateUrl method to return the Post url
@method
@see Resource#generateUrl
*/
this.generateUrl = function () {
return this.selfUrl;
};
};
/**
Creates a new Delegation.
@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
@param {Domain} options.domain - the domain object with the values to create a new domain
@param {String} options.domain.title - the title of the
@param {String} [options.domain.allowSDC] - allows SWC true/false defaults to false
@param {String} [options.domain.defaultVal] - is default true/false defaults to false
@param {String} [options.domain.SDCLogin] - SDC login user
@param {String} [options.domain.SDCPassword] - SDC password
@example Create a Domain
function createDelegation(delegationList){//delegation list object
var new_domain = new Domain;
new_domain.title = 'test_domain';
new_domain.allowSDC = 'true';
new_domain.defaultVal = 'false';
new_domain.SDCLogin = 'foo';
new_domain.SDCPassword = 'bar'
delegationList.save({
onSuccess:function(){
alert("CREATED!");
},
domain:new_domain
})
}
*/
CustomerDomainList.prototype.save = function (options) {
this.xml = this.generate_xml(options).trim();
this.resourceSave(options);
};
/**
Generates a save/update xml to be posted to the server
@method
@param {object} options - options to be used during the call<br/>
@param {Domain} options.domain - the domain object with the values to create a new domain
@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
*/
CustomerDomainList.prototype.generate_xml = function (options) {
var v_baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
var v_title = options.domain.title;
var v_allowSDC = options.domain.allowSDC || 'false';
var v_default = options.domain.defaultVal || 'false';
var v_login = options.domain.SDCLogin || '';
var v_psw = options.domain.SDCPassword || '';
var xml = '<?xml version="1.0" encoding="UTF-8"?> '
+ '<feed xml:base="' + v_baseUrl
+ '" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2005/Atom"> '
+ '<title>' + v_title + '</title> '
+ '<rights>(c) RunMyProcess</rights> '
+ '<entry>'
+ '<title>' + v_title + '</title>'
+ '<category term="allow_sdc" label="' + v_allowSDC + '"/>'
+ '<category term="default" label="' + v_default + '"/>';
if (v_allowSDC==='true'){
xml=xml
+ '<category term="sdc_login" label="' + v_login + '"/>'
+ '<category term="sdc_pwd" label="' + v_psw + '"/>';
}
xml=xml
+ '</entry>'
+ '</feed>';
return xml;
};