PCN Object
by hansenmc
JavaScript
function log(msg)
{
$("body").append("<div>"+msg+"</div>");
}
var PCN = new (function() {
this.offices = [
{
name: "JITF-CT",
isProduction: true,
isDI: true,
GUID: "asdf",
aliases: ["JITF", "DCTC", "JITF-CT"]},
{
name: "CMS",
isProduction: true,
isDI: true,
GUID: "asdf",
aliases:[]},
{
name: "ZZZ1",
isProduction: false,
isDI: true,
GUID: "asdf",
aliases: []}
];
this.productionOffices = null;
this.getProductionOffices = function()
{
if( this.productionOffices === null )
{
log("calculating productionOffices...");
//Cache the productionOffice info, so we don't have to re-calculate every time
this.productionOffices = $.grep(this.offices, function(obj, index) {
return obj.isProduction === true;
});
}
return this.productionOffices;
};
this.productionOfficeNames = null;
this.getProductionOfficeNames = function()
{
if( this.productionOfficeNames === null )
{
log("calculating productionOfficeNames...");
this.productionOfficeNames = $.map(this.getProductionOffices(), function(obj, index) {
return obj.name;
});
}
return this.productionOfficeNames;
};
this.getOfficeByName = function(officeName){
var selectedOffice = {};
var offices = $.grep(this.offices,
function(obj, key)
{
return ($.inArray(officeName,obj.aliases) > -1);
}
);
if (offices.length == 1){
selectedOffice = offices[0];
}
return selectedOffice;
};
this.init= function() {
//pre-calculate office...