/**
 * DO NOT EDIT THIS FILE!
 * This is a generated file.  Your changes will be overwritten.
 */
var Accessory=DataModel.create("Accessory");
Object.extend(Accessory.prototype,{initialize:function(_1){
this.id="";
this.code="";
this.display_order="";
this.description="";
this.long_description="";
this.glossary_description="";
this.image_id="";
this.source="";
this.msrp=0;
this.excludes=[];
this.includes=[];
this.disclaimerId="";
this.isChecked=false;
Object.extend(this,_1);
this.register("Accessory",this);
},initWithXML:function(_2){
if(_2.nodeName=="accessory"){
this.id=_2.getAttribute("id");
this.display_order=parseInt(_2.getAttribute("display_order"));
$NL(_2.childNodes).elements().each(function(_3){
if(this.basic_assign(["code","description","long_description","glossary_description","image_id","source"],_3)){
}else{
if(this.float_assign(["msrp"],_3)){
}else{
switch(_3.nodeName){
case "excludedAccys":
$NL(_3.childNodes).elements().each(function(n){
this.excludes.push(this.object_lookup("Accessory",n.firstChild.data,true));
}.bind(this));
break;
case "includedAccys":
$NL(_3.childNodes).elements().each(function(n){
this.includes.push(this.object_lookup("Accessory",n.firstChild.data,true));
}.bind(this));
break;
case "disclaimers":
$NL(_3.childNodes).elements().each(function(n){
this.disclaimerId=n.firstChild.data;
}.bind(this));
break;
default:
break;
}
}
}
}.bind(this));
return true;
}else{
return false;
}
},loadAssociations:function(_7,_8){
}});

var ConflictState=Class.create();
Object.extend(ConflictState.prototype,{initialize:function(_1){
this.vehicle=_1;
this.clear();
},apply:function(){
if(this.validate()){
if(this.pkg!=this.vehicle.pkg||this.package_group!=this.vehicle.package_group){
PageController.package_selection_controller.setPackageGroup(this.package_group,this.pkg);
}
if(this.vehicle.exterior_color!=this.exterior_color){
PageController.exterior_color_controller.selectColor(this.exterior_color,true,false);
}
if(this.vehicle.interior_color!=this.interior_color){
PageController.interior_color_controller.selectColor(this.interior_color,true,false);
}
this.clear();
return true;
}else{
return false;
}
},set:function(_2,_3){
if(_2=="package"){
_2="pkg";
if(_3==null){
return this.setDefaultPackage();
}
}
if(!this.locks.include(_2)){
this[_2]=_3;
this.locks.push(_2);
return true;
}else{
return false;
}
},clear:function(){
this.package_group=this.vehicle.package_group;
this.pkg=this.vehicle.pkg;
this.exterior_color=this.vehicle.exterior_color;
this.interior_color=this.vehicle.interior_color;
this.locks=[];
this.errors=[];
},is_clean:function(){
return this.locks==0;
},update:function(){
if(this.is_clean()){
this.clear();
}
},clone:function(){
var cs=new ConflictState(this.vehicle);
cs.package_group=this.package_group;
cs.pkg=this.pkg;
cs.exterior_color=this.exterior_color;
cs.interior_color=this.interior_color;
cs.locks=this.locks;
return cs;
},validate:function(){
this.errors=[];
if(this.pkg.id){
if(this.locks.include("package_group")){
if(!this.package_group.packages.pluck("exterior_associations").flatten().pluck("id").include(this.exterior_color.id)){
this.errors.push("exterior_color");
}
}
if(!this.package_group.packages.include(this.pkg)){
if(this.locks.include("pkg")){
this.errors.push("package_group");
}else{
this.errors.push("pkg");
}
}
if(!this.pkg.exterior_associations.pluck("id").include(this.exterior_color.id)){
if(this.locks.include("exterior_color")){
this.errors.push("pkg");
}else{
this.errors.push("exterior_color");
}
}
if(!this.pkg.exterior_associations.pluck("interior_colors").flatten().include(this.interior_color.id)){
if(this.locks.include("interior_color")){
this.errors.push("pkg");
}else{
this.errors.push("interior_color");
}
}
var _5=[];
if(this.errors.include("pkg")){
_5=PageController.package_groups.pluck("packages").flatten().pluck("exterior_associations").flatten();
}else{
if(this.errors.include("exterior_color")){
_5=PageController.package_groups.pluck("packages").flatten().pluck("exterior_associations").flatten();
}else{
_5.push(this.pkg.exterior_associations.find(function(ea){
return ea.id==this.exterior_color.id;
}.bind(this)));
}
}
if(!_5.pluck("interior_colors").flatten().include(this.interior_color.id)){
if(this.locks.include("interior_color")){
this.errors.push("exterior_color");
}else{
this.errors.push("interior_color");
}
}
this.errors=this.errors.uniq();
}else{
if(this.package_group.name){
if(this.locks.include("package_group")){
if(!this.package_group.packages.pluck("exterior_associations").flatten().pluck("id").include(this.exterior_color.id)){
this.errors.push("exterior_color");
}
if(!this.package_group.packages.pluck("exterior_associations").pluck("interior_colors").flatten().include(this.interior_color.id)){
this.errors.push("interior_color");
}
}else{
this.errors.push("pkg");
}
}
var _7=PageController.package_groups.pluck("packages").flatten();
var _5=_7.pluck("exterior_associations").flatten().findAll(function(ec){
return ec.id==this.exterior_color.id;
}.bind(this));
if(!_5.pluck("interior_colors").flatten().include(this.interior_color.id)){
if(this.locks.include("interior_color")){
this.errors.push("exterior_color");
}else{
this.errors.push("interior_color");
}
}
}
return (this.errors.length<1);
},setDefaultPackage:function(){
var _9=this.package_group.packages.find(function(_a){
var _b=!_a.exterior_associations.pluck("id").uniq().include(this.exterior_color.id);
var _c=!_a.exterior_associations.pluck("interior_colors").flatten().uniq().include(this.interior_color.id);
if(!_b&&!_c){
return true;
}else{
return false;
}
}.bind(this));
if(_9){
this.pkg=_9;
}
}});

var Disclaimer=DataModel.create("Disclaimer");
Object.extend(Disclaimer.prototype,{initialize:function(_1){
this.id="";
this.symbol="";
this.description="";
this.usages=[];
this.usage_orders={};
Object.extend(this,_1||{});
this.register("Disclaimer",this);
},initWithXML:function(_2){
if(_2.nodeName=="disclaimer"){
$NL(_2.childNodes).elements().each(function(_3){
if(this.basic_assign(["id","symbol","description"],_3)){
}else{
if(_3.nodeName=="appUsages"){
$NL(_3.childNodes).elements().each(function(n){
this.usages.push(n.getAttribute("name").toLowerCase());
this.usage_orders[n.getAttribute("name").toLowerCase()]=parseInt(n.getAttribute("displayOrder"));
}.bind(this));
}
}
}.bind(this));
return true;
}else{
return false;
}
}});

var ExteriorAssociation=DataModel.create("ExteriorAssociation");
Object.extend(ExteriorAssociation.prototype,{initialize:function(id){
this.id=id;
this.exterior_color=null;
this.interior_colors=[];
}});

var ExteriorColor=DataModel.create("ExteriorColor");
Object.extend(ExteriorColor.prototype,{initialize:function(_1){
if(!_1){
var _1={};
}
this.id="";
this.name="";
this.is_available=false;
this.default_int_color=null;
this.conflicts=[];
this.swatch_img_id=null;
this.swatch_on_img_id=null;
this.preview_img_id=null;
var _2;
this.interior_color_ids=[];
this.interior_colors=[];
this.animation_key;
Object.extend(this,_1);
this.register("ExteriorColor",this);
},initWithXML:function(_3){
if(_3.nodeName=="exterior_color"){
this.id=_3.getAttribute("id");
$NL(_3.childNodes).elements().each(function(_4){
switch(_4.nodeName){
case "name":
this.name=_4.firstChild.data;
break;
case "is_available":
this.is_available=(_4.firstChild.data.toUpperCase()=="TRUE");
break;
case "off_swatch_image_id":
this.swatch_img_id=_4.firstChild.data;
break;
case "on_swatch_image_id":
this.swatch_on_img_id=_4.firstChild.data;
break;
case "model_color_image_id":
this.preview_img_id=_4.firstChild.data;
break;
case "unavailable_swatch_image_id":
this.unavailable_swatch_image_id=_4.firstChild.data;
break;
case "default_int_color":
this.default_int_color_id=$NL(_4.childNodes).elements().first().getAttribute("id");
break;
case "animation_key":
if(_4.firstChild){
this.animation_key=_4.firstChild.data;
}
break;
case "interiors":
$NL(_4.childNodes).elements().each(function(n){
this.interior_color_ids.push(n.firstChild.data);
}.bind(this));
break;
default:
break;
}
}.bind(this));
NotificationCenter.addSubscriber("Init Data Loaded",this,"loadAssociations");
return true;
}else{
return false;
}
},loadAssociations:function(_6,_7){
if(this.default_int_color_id){
this.default_int_color=_7.interior_colors.find(function(ec){
if(ec.id==this.default_ext_color_id){
return true;
}
}.bind(this));
}
this.interior_colors=this.interior_color_ids.collect(function(_9){
return _7.interior_colors.find(function(ec){
return ec.id==_9;
});
}.bind(this));
}});

var GlossaryTerm=DataModel.create("GlossaryTerm");
Object.extend(GlossaryTerm.prototype,{initialize:function(_1){
this.id="";
this.term="";
this.definition="";
Object.extend(this,_1||{});
this.register("GlossaryTerm",this);
},initWithXML:function(_2){
if(_2.nodeName=="glossary"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
if(this.basic_assign(["term","definition"],_3)){
}else{
switch(_3.nodeName){
default:
break;
}
}
}.bind(this));
return true;
}else{
return false;
}
}});

var InteriorColor=DataModel.create("InteriorColor");
Object.extend(InteriorColor.prototype,{initialize:function(_1){
this.id="";
this.name="";
this.is_available=false;
this.default_ext_color=null;
this.conflicts=[];
this.swatch_img_id=false;
this.swatch_on_img_id=false;
this.unavailable_swatch_image_id=false;
this.preview_img_id=false;
this.exterior_color_ids=[];
this.exterior_colors=[];
Object.extend(this,_1||{});
this.register("InteriorColor",this);
},initWithXML:function(_2){
if(_2.nodeName=="interior_color"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
switch(_3.nodeName){
case "name":
this.name=_3.firstChild.data;
break;
case "is_available":
this.is_available=(_3.firstChild.data.toUpperCase()=="TRUE");
break;
case "off_swatch_image_id":
this.swatch_img_id=_3.firstChild.data;
break;
case "on_swatch_image_id":
this.swatch_on_img_id=_3.firstChild.data;
break;
case "conflict_swatch_image_id":
Debug.log("Loading unavailable image: ",_3.firstChild.data);
this.unavailable_swatch_image_id=_3.firstChild.data;
break;
case "model_interior_image_id":
this.preview_img_id=_3.firstChild.data;
break;
case "default_ext_color":
this.default_ext_color_id=$NL(_3.childNodes).elements().first().getAttribute("id");
break;
case "interiors":
$NL(_3.childNodes).elements().each(function(n){
this.exterior_color_ids.push(n.firstChild.data);
}.bind(this));
break;
default:
break;
}
}.bind(this));
NotificationCenter.addSubscriber("Init Data Loaded",this,"loadAssociations");
return true;
}else{
return false;
}
},loadAssociations:function(_5,_6){
if(this.default_ext_color_id){
this.default_ext_color=_6.exterior_colors.find(function(ec){
if(ec.id==this.default_ext_color_id){
return true;
}
}.bind(this));
}
this.exterior_colors=PageController.exterior_colors.findAll(function(ec){
return ec.interior_colors.findByProperty("id",this.id);
}.bind(this));
}});

var Model=DataModel.create("Model");
Object.extend(Model.prototype,{initialize:function(_1){
this.id="";
this.name="";
this.price_high="";
this.price_low="";
this.msrp=0;
this.dph_fee=0;
this.year="";
this.series="";
this.features="";
this.disclaimer="";
this.title_media_id="";
Object.extend(this,_1||{});
},initWithXML:function(_2){
if(_2.nodeName=="model"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
if(_3.nodeName=="name"){
this.name=_3.firstChild.data;
}
if(_3.nodeName=="price_high"){
this.price_high=_3.firstChild.data;
}
if(_3.nodeName=="price_low"){
this.price_low=_3.firstChild.data;
}
if(_3.nodeName=="year"){
this.year=_3.firstChild.data;
}
if(_3.nodeName=="features"){
this.features=_3.firstChild.data;
}
}.bind(this));
return true;
}else{
return false;
}
}});

var Package=DataModel.create("Package");
Object.extend(Package.prototype,{initialize:function(_1){
this.id="";
this.name="";
this.msrp=0;
this.accessories=[];
this.included_features=[];
this.exterior_colors=[];
this.interior_colors=[];
this.exterior_associations=[];
this.package_group={};
Object.extend(this,_1||{});
this.register("Package",this);
},initWithXML:function(_2){
if(_2.nodeName=="package"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
if(this.basic_assign(["name","msrp"],_3)){
}else{
switch(_3.nodeName){
case "included_features":
$NL(_3.childNodes).elements().each(function(n){
this.included_features.push(n.firstChild.data);
}.bind(this));
break;
case "exterior_associations":
$NL(_3.childNodes).elements().each(function(_5){
this.exterior_associations.push(new ExteriorAssociation(_5.getAttribute("exterior_id")));
this.exterior_associations.last().exterior_color=ExteriorColor.getInstance(this.exterior_associations.last());
$NL(_5.childNodes).elements().each(function(n){
this.exterior_associations.last().interior_colors.push(n.firstChild.data);
}.bind(this));
}.bind(this));
break;
case "accessories":
$NL(_3.childNodes).elements().each(function(_7){
var _8=Accessory.getInstance(_7.firstChild.data);
if(_8){
this.accessories.push(_8);
}
}.bind(this));
break;
default:
break;
}
}
}.bind(this));
return true;
}else{
return false;
}
},getFullName:function(){
return this.package_group.name+(this.package_group.name!="Base Model"?" with Additional Options":"");
},getFullNamePlusPrice:function(){
return this.getFullName()+" $"+parseInt(this.package_group.msrp).moneyFormat();
},total_msrp:function(){
return parseInt(this.msrp)+parseInt(this.package_group.msrp);
},getCurrentExteriorAssociation:function(_9){
return this.exterior_associations.find(function(_a){
if(_a.id==_9){
return _a;
}
});
}});

var PackageGroup=DataModel.create("PackageGroup");
Object.extend(PackageGroup.prototype,{initialize:function(_1){
this.id="";
this.name="";
this.msrp=0;
this.packages={};
this.included_features=[];
this.base_accessory={};
this.accessories={};
this.packages=[];
Object.extend(this,_1||{});
},initWithXML:function(_2){
if(_2.nodeName=="package_group"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
if(this.basic_assign(["name","msrp"],_3)){
}else{
switch(_3.nodeName){
case "base_accessory_id":
break;
case "included_features":
$NL(_3.childNodes).elements().each(function(n){
this.included_features.push(n.firstChild.data);
}.bind(this));
break;
case "packages":
$NL(_3.childNodes).elements().each(function(p){
var po=new Package();
po.initWithXML(p);
po.package_group=this;
this.packages.push(po);
}.bind(this));
break;
default:
break;
}
}
}.bind(this));
NotificationCenter.addSubscriber("Init Data Loaded",this,this.loadAssociations);
return true;
}else{
return false;
}
},loadAssociations:function(){
}});

var Series=DataModel.create("Series");
Object.extend(Series.prototype,{initialize:function(_1){
this.id="";
this.name="";
this.year="";
this.series_group="";
this.models=[];
this.small_image_path="";
this.large_image_path="";
this.disclaimer="";
this.series_media_id="";
Object.extend(this,_1||{});
},initWithXML:function(_2){
if(_2.nodeName=="series"){
this.id=_2.getAttribute("id");
$NL(_2.childNodes).elements().each(function(_3){
if(_3.nodeName=="name"){
this.name=_3.firstChild.data;
}
if(_3.nodeName=="year"){
this.year=_3.firstChild.data;
}else{
if(_3.nodeName=="model_list"){
$NL(_3.childNodes).elements().each(function(_4){
var m=new Model();
if(m.initWithXML(_4)){
m.series=this;
this.models.push(m);
}
}.bind(this));
}
}
}.bind(this));
return true;
}else{
return false;
}
}});

var SeriesGroup=DataModel.create("SeriesGroup");
Object.extend(SeriesGroup.prototype,{initialize:function(_1){
if(!_1){
var _1={};
}
var id;
this.id=_1.id||"";
var _3;
this.name=_1.name||"";
var _4;
this.series_list=_1.series_list||[];
},initWithXML:function(_5){
if(_5.nodeName=="seriesgroup"){
this.id=_5.getAttribute("id");
$NL(_5.childNodes).elements().each(function(_6){
if(_6.nodeName=="name"){
this.name=_6.firstChild.data;
}else{
if(_6.nodeName=="series_list"){
$NL(_6.childNodes).elements().each(function(_7){
var s=new Series();
if(s.initWithXML(_7)){
s.series_group=this;
this.series_list.push(s);
}
}.bind(this));
}
}
}.bind(this));
return true;
}else{
return false;
}
}});

var Vehicle=DataModel.create("Vehicle");
Object.extend(Vehicle.prototype,{initialize:function(_1){
if(!_1){
var _1={};
}
this.id=_1.id||"";
this.name=_1.name||"";
this.pkg=_1.pkg||{};
this.package_group=_1.package_group||{};
this.userAccessories=_1.userAccessories||[];
this.extColor=_1.extColor||{};
this.intColor=_1.intColor||{};
this.totalMsrp=_1.totalMsrp||0;
this.fee=_1.fee||0;
this.model=_1.model||{};
this.conflict_state=new ConflictState(this);
NotificationCenter.addSubscriber("Interior Color Changed",this,"updateMSRP");
NotificationCenter.addSubscriber("Exterior Color Changed",this,"updateMSRP");
NotificationCenter.addSubscriber("Package Changed",this,"updateMSRP");
},initWithXML:function(_2){
return false;
},getSelectedAccessories:function(){
if(this.pkg.accessories){
return this.userAccessories.merge(this.pkg.accessories).unique();
}else{
return this.userAccessories;
}
},updateMSRP:function(){
this.totalMsrp=0;
NotificationCenter.sendNotification("MSRP Updated");
},totalMSRP:function(){
var _3=this.model.msrp;
_3+=this.pkg.id?this.pkg.total_msrp():0;
_3+=this.model.dph_fee;
return _3;
}});

