Created
January 31, 2014 10:00
-
-
Save kreshikhin/8729345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;function Product(data, parent){ | |
var self = this; | |
$.extend(self, new Model()); | |
self.id = ko.observable("#id"); | |
// model properties | |
self.title = ko.observable("#title"); | |
self.article = ko.observable("#article"); | |
self.brand = ko.observable("#brand"); | |
self.category = ko.observable(new Category()); | |
self.description = ko.observable("#description"); | |
self.price = ko.observable("#price"); | |
self.href = ko.observable("#href"); | |
self.nearby = ko.observable(''); | |
// model objects | |
self.photo_id = ko.observable("#id"); | |
self.photo = ko.observable(new Photo({}, self)); | |
// model collections | |
self.photos = ko.observableArray([]); | |
self.features = ko.observableArray([]); | |
self.textures = ko.observableArray([]); | |
self.sizes = ko.observableArray([]); | |
self.setResources('products', | |
{photos: Photo, textures: Texture}); | |
self.setEmbedded({sizes: Size}); | |
self.setCollections({features: Feature}); | |
self.detectChangesIn(['title', 'article', 'brand', 'price', | |
'description', 'deactivated', 'photo_id', 'photo', | |
'photos', 'sizes', 'textures']); | |
self.excluded.subscribe(function(excluded){ | |
parent.test_excluded(); | |
}); | |
self.feature_view_mode = ko.observable('rolled-up'); | |
self.roll_up_features = function(){self.feature_view_mode('rolled-up');}; | |
self.roll_out_features = function(){self.feature_view_mode('rolled-out');}; | |
self.size_view_mode = ko.observable('rolled-up'); | |
self.roll_up_sizes = function(){self.size_view_mode('rolled-up');}; | |
self.roll_out_sizes = function(){self.size_view_mode('rolled-out');}; | |
self.texture_view_mode = ko.observable('rolled-up'); | |
self.roll_up_textures = function(){self.texture_view_mode('rolled-up');}; | |
self.roll_out_textures = function(){self.texture_view_mode('rolled-out');}; | |
self.setMain = function(){ | |
var mainPhoto = this; | |
self.photo(mainPhoto); | |
self.photo_id(mainPhoto.id()); | |
}; | |
// data methods | |
self.setData = function(data){ | |
self.insensibly(function(){ | |
self.id(data.id); | |
self.category(new Category(data.category)); | |
self.photo_id(data.photo_id); | |
self.title(data.title); | |
self.article(data.article); | |
self.brand(data.brand); | |
self.deactivated(data.deactivated); | |
self.description(data.description); | |
self.price(data.price); | |
self.href(data.href); | |
self.nearby(data.nearby); | |
console.log(data.href); | |
self.features([]); | |
$.each(data.features || [], function(index, feature){ | |
self.features.push(new Feature(feature, self)); | |
}); | |
self.sizes([]); | |
$.each(data.sizes || [], function(index, size_data){ | |
self.sizes.push(new Size(size_data)); | |
}); | |
}); | |
}; | |
self.getData = function(){ | |
return { | |
id: self.id(), | |
photo_id: self.photo_id(), | |
title: self.title(), | |
article: self.article(), | |
brand: self.brand(), | |
description: self.description(), | |
deactivated: self.deactivated(), | |
price: self.price(), | |
//sizes: self.sizes(), | |
// collecitons | |
category_id: self.category() && self.category().id(), | |
features: self.getValues(self.features(), 'title'), | |
// object coleections | |
photo_ids: self.getIds(self.photos()), | |
texture_ids: self.getIds(self.textures()) | |
}; | |
}; | |
if(data){ | |
self.setData(data); | |
}; | |
}; | |
Product.getName = function(){ return 'product'; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment