Source: Customer/Domain.js

/**
 *
 * @author Malcolm Haslam <mhaslam@runmyprocess.com>
 *
 * Copyright (C) 2013 Fujitsu RunMyProcess
 *
 * 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 Domain
  	@constructor
	@property {String} title - the title of the
	@property {Object} customer - the customer of the domain
	@property {Date} updated - string representing the updated date
	@property {String} allowSDC - allows SWC
	@property {String} defaultVal - is default true/false
	@property {String} SDCLogin - SDC login user true/false
	@property {String} SDCPassword - SDC password
	@see CustomerDomainList
	@see Resource
*/
function Domain(){
	this.title;
	this.customer = {};
	this.updated = new Date();
	this.allowSDC;
	this.defaultVal;
	this.SDCLogin;
	this.SDCPassword;
};
/**
	 @borrows
	 Inherits Resource
*/
Domain.prototype = new  Resource();
/**
	Overrides Resource's loadPreset method.
	@method
	@see Resource#loadPreset
*/
Domain.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
*/
Domain.prototype.loadSet = function (rObject) {
	this.title = this.object.title;
	var cust = new Customer();
	cust.selfUrl = this.linkSearch('customer', this.links);
	this.customer = cust;
	this.updated = new Date(this.object.updated);
	this.allowSDC = this.termSearch('allow_sdc',this.entries[0].category).label;
	this.defaultVal = this.termSearch('default',this.entries[0].category).label;
	this.SDCLogin=this.termSearch('sdc_login',this.entries[0].category).label;
};
/**
 Overrides Resource's loadPreset method.
	@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
	@see Resource#update
*/
Domain.prototype.update = function (options) {
	var father = this;
	father.updatePreset = function () {
		father.generateUrl = function () {
			return father.selfUrl;
		};
		father.xml = father.generate_xml(options).trim();
	};
	father.resourceUpdate(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 {String} [options.baseUrl] - base URL. If not set the current base URL will be used
 */
Domain.prototype.generate_xml = function (options) {
	var v_baseUrl = this.baseUrl || RMPApplication.getBaseUrl();
	var v_title = this.title;
	var v_allowSDC = this.allowSDC || 'false';
	var v_default = this.defaultVal || 'false';
	var v_login = this.SDCLogin || '';
	var v_psw = this.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 + '"/>';
		if (v_psw!==''){
			xml=xml
			+ '<category term="sdc_pwd" label="' + v_psw + '"/>';
		}
	}
	xml=xml
	+ '</entry>'
	+ '</feed>';

	return xml;
};