/**
*
* 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 Web Interface List
@constructor
@property {Array} webInterfaces - Array of webInterfaces.
@see ProjectVersion
@see Resource
*/
function WebInterfaceList(){
var webInterfaces=[];
};
/**
@borrows
Inherits Resource
*/
WebInterfaceList.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
WebInterfaceList.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
*/
WebInterfaceList.prototype.loadSet = function (rObject) {
var father = this;
father.webInterfaces = [];
var ent=this.getArray(rObject, "entry");
for (var i = 0; i < ent.length; i++) {
var wi = new WebInterface();
wi.object = ent[i];
wi.id = ent[i].id;
wi.entries = wi.getArray(ent[i], "entry");
if(ent[i].author){
wi.author = new User();
wi.author.name = ent[i].author.name;
wi.author.selfUrl = ent[i].author.uri;
}
wi.categories = wi.getArray(ent[i], "category");
wi.links = wi.getArray(ent[i], "link");
wi.selfUrl = ent[i].content.src;
wi.rights = wi.object.rights;
wi.summary = ent[i].summary;
wi.title = ent[i].title;
wi.published = new Date(ent[i].published);
wi.updated = new Date(ent[i].updated);
if (wi.categories.length){
for (var j = 0 ; j<wi.categories.length;j++) {
if(wi.categories[j].term=="css"){
wi.css.push(wi.categories[j].label);
}else if(wi.categories[j].term=="tag"){
wi.tags.push(wi.categories[j].label);
}
}
}
var i18n1 = new I18n();
i18n1.selfUrl = wi.linkSearch("i18n",wi.getArray(wi.object, "link"));
i18n1.dicoUrl = wi.linkSearch("dico",wi.getArray(wi.object, "link"));
wi.i18n = i18n1;
father.webInterfaces.push(wi);
};
};
/**
Overrides Resource's savePreset method.
@method
@see Resource#savePreset
*/
WebInterfaceList.prototype.savePreset = function () {
/**
Overrides Resource's generateUrl method to return the Post url
@method
@see Resource#generateUrl
*/
this.generateUrl = function () {
return this.selfUrl;
};
};
/**
Create a new WebInterface.
@method
@param {object} options - options to be used during the call<br/>
@param {String} options.title - WebInterface title
@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#resourceSave
*/
WebInterfaceList.prototype.createWebInterface = function (options) {
var webInterface = new WebInterface();
var webInterfaceList = this;
webInterfaceList.selfUrl = context.link.customerConfig + "appli/";
/**
Overrides Resource's savePreset method.
@method
@see Resource#savePreset
*/
webInterfaceList.savePreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
webInterfaceList.generateUrl = function () {
return webInterfaceList.selfUrl;
};
};
var xmlOptions = {};
xmlOptions.title = options.title;
xmlOptions.rights=options.rights||'(c) RunMyProcess';
var cats = options.categories || [];
xmlOptions.categories = cats.concat(webInterface.getDefaultCategories());
var lnks = options.links || [];
xmlOptions.links = lnks.concat(webInterface.getDefaultLinks());
xmlOptions.summary = webInterface.summary;
xmlOptions.content = options.content;
xmlOptions.projectUrl = options.project.selfUrl;
xmlOptions.userUrl = options.userUrl || context.link.self;
xmlOptions.baseUrl = options.baseUrl;
webInterfaceList.xml = webInterface.generate_xml(xmlOptions).trim();
webInterfaceList.save(options);
};