<commit_before>/* Application controller, overall control of shopping cart here
 * CartItem is passed in the router */
Photoworks.ApplicationController = Ember.ArrayController.extend({

	/* Return total number of items in cart */
	totalItems: function(){
		return this.get('cartItem').get('length');
	}.property('cartItem.@each'),
	
	/* Return total price in cart */
	totalPrice: function(){
		var cartItems = this.get('cartItem');
		return cartItems.reduce(function(prevValue, item){
			return prevValue + item.get('price');
			}, 0);
	}.property('cartItem.@each.price'),
	
	/* Used for the paypal form, index the cart items */
	assignIndex: function(){
		this.get('cartItem').map(function(item, index){
			Ember.set(item, 'index', index+1);
		});
	}.observes('cartItem.[]', 'firstObject', 'lastObject'),
	
	/* Actions hash */
	actions: {
		
		/* Clear all items from the cart */
		clearCart: function(){
			var cartItems = this.get('cartItem');
			cartItems.forEach(function(item){
				item.deleteRecord();
				item.save();
			});
		},
		
        /* When clicking the 'View Cart' link */
		toggleCart: function(){
			$('.cart').fadeToggle();
		},
		
        /* Button within the cart div */
		hideCart: function(){
			$('.cart').fadeOut();
		}
	}
});

/* Controller for individual items in the cart */
Photoworks.CartItemController = Ember.ObjectController.extend({

	actions: {
		removeFromCart: function(id){
			this.store.find('cartItem', id).then(function(item){
				item.deleteRecord();
				item.save();
			});
		}
	},
    
	/* For paypal checkout form */
	paypalFormItem: function() {
		var index = this.get('index');
		return 'item_name_' + index;
	}.property('index'),
	
	paypalFormAmount: function() {
		var index = this.get('index');
		return 'amount_' + index;
	}.property('index'),
	
	paypalFormTitle: function() {
		var title = this.get('title');
		var type = this.get('type');
		var size = this.get('size');
		return title + ' ' + size + ' ' + type;
	}.property('title', 'type', 'size')
});

Photoworks.GalleriesController = Ember.ArrayController.extend({
    
    actions: {
        /* Hide the galleries preview and transition to individual gallery */
        slideUp: function(id){
            $('.galleriesMain').slideUp();
            this.transitionToRoute('gallery', id);
        },
    },
});

/*Photoworks.GalleryController = Ember.ObjectController.extend();*/

/* Controller for individual thumbnails on the prints page */
Photoworks.ThumbController = Ember.ObjectController.extend({
	/* Return thumbnail */
	url: function(){
		var file = this.get('file');
        return thumbImg(file);
	}.property('file')
});

/* Controller for the large view ordering page */
Photoworks.OrderController = Ember.ObjectController.extend({
	init: function(){
		$('title').text('Order a Print');
	},
	actions: {
		addToCart: function() {
			var title = this.get('title');
			var type = this.get('type');
			var size = this.get('size');
			var price = this.get('price');
			if (price){
				var record = this.store.createRecord('cartItem', {
					title: title,
					type: type,
					size: size,
					price: price 
				});
				record.save();
				$('.added').fadeIn().delay(500).fadeOut();
				console.log('Added item: ' + title);
			} else {
				console.log('Please select a size');
				$('.errorSelect').fadeIn().delay(500).fadeOut();
			}
		}
	},
	
	/* Available print types, convert to model and have on per photo basis */
	types: [
		{type: "Print Only", id: 1},
		{type: "Matted Print", id: 2},
		{type: "Framed Print", id: 3},
		{type: "Metal Print", id: 4}
	],
	
	/* Store id of current print type selected */
	currentType: 1,
	
	/* Store id of current size selected */
	currentSize: 1,
    
	/* Return large image */
	url: function(){
		var file = this.get('file');
		return largeImg(file);
	}.property('file'),
	
	/* filter options depending on type selected */
	currentOptions: function(){
		var type = this.get('currentType');
		switch (type){
			case 1:
				return this.get('orderOptions').filterProperty('type', 'Print');
				break;
			case 2: 
				return this.get('orderOptions').filterProperty('type', 'Matted');
				break;
			case 3:<commit_msg>Use url’s from photos mode, add some transition effects.<commit_after>/* Application controller, overall control of shopping cart here
 * CartItem is passed in the router */
Photoworks.ApplicationController = Ember.ArrayController.extend({

	/* Return total number of items in cart */
	totalItems: function(){
		return this.get('cartItem').get('length');
	}.property('cartItem.@each'),
	
	/* Return total price in cart */
	totalPrice: function(){
		var cartItems = this.get('cartItem');
		return cartItems.reduce(function(prevValue, item){
			return prevValue + item.get('price');
			}, 0);
	}.property('cartItem.@each.price'),
	
	/* Used for the paypal form, index the cart items */
	assignIndex: function(){
		this.get('cartItem').map(function(item, index){
			Ember.set(item, 'index', index+1);
		});
	}.observes('cartItem.[]', 'firstObject', 'lastObject'),
	
	/* Actions hash */
	actions: {
		
		/* Clear all items from the cart */
		clearCart: function(){
			var cartItems = this.get('cartItem');
			cartItems.forEach(function(item){
				item.deleteRecord();
				item.save();
			});
		},
		
        /* When clicking the 'View Cart' link */
		toggleCart: function(){
			$('.cart').fadeToggle();
		},
		
        /* Button within the cart div */
		hideCart: function(){
			$('.cart').fadeOut();
		}
	}
});

/* Controller for individual items in the cart */
Photoworks.CartItemController = Ember.ObjectController.extend({

	actions: {
		removeFromCart: function(id){
			this.store.find('cartItem', id).then(function(item){
				item.deleteRecord();
				item.save();
			});
		}
	},
    
	/* For paypal checkout form */
	paypalFormItem: function() {
		var index = this.get('index');
		return 'item_name_' + index;
	}.property('index'),
	
	paypalFormAmount: function() {
		var index = this.get('index');
		return 'amount_' + index;
	}.property('index'),
	
	paypalFormTitle: function() {
		var title = this.get('title');
		var type = this.get('type');
		var size = this.get('size');
		return title + ' ' + size + ' ' + type;
	}.property('title', 'type', 'size')
});

Photoworks.GalleriesController = Ember.ArrayController.extend({
    
    actions: {
        /* Hide the galleries preview */
        slideUp: function(id){
            $('.galleriesMain').slideUp();
        }
    }
});

Photoworks.PhotoController = Ember.ObjectController.extend({
    actions: {
        showPhotos: function(){
            $('.allPhotos').fadeIn();
        }
    }
});

Photoworks.GalleryController = Ember.ObjectController.extend({
    actions: {
        hidePhotos: function(){
            $('.allPhotos').fadeOut();
        }
    }
});

/* Controller for the large view ordering page */
Photoworks.OrderController = Ember.ObjectController.extend({
	actions: {
		addToCart: function() {
			var title = this.get('title');
			var type = this.get('type');
			var size = this.get('size');
			var price = this.get('price');
			if (price){
				var record = this.store.createRecord('cartItem', {
					title: title,
					type: type,
					size: size,
					price: price 
				});
				record.save();
				$('.added').fadeIn().delay(500).fadeOut();
				console.log('Added item: ' + title);
			} else {
				console.log('Please select a size');
				$('.errorSelect').fadeIn().delay(500).fadeOut();
			}
		}
	},
	
	/* Available print types, convert to model and have on per photo basis */
	types: [
		{type: "Print Only", id: 1},
		{type: "Matted Print", id: 2},
		{type: "Framed Print", id: 3},
		{type: "Metal Print", id: 4}
	],
	
	/* Store id of current print type selected */
	currentType: 1,
	
	/* Store id of current size selected */
	currentSize: 1,
	
	/* filter options depending on type selected */
	currentOptions: function(){
		var type = this.get('currentType');
		switch (type){
			case 1:
				return this.get('orderOptions').filterProperty('type', 'Print');
				break;
			case 2: 
				return this.get('orderOptions').filterProperty('type', 'Matted');
				break;
			case 3:
{'fraction_non_alphanumeric': 0.16974624291697463, 'fraction_numerical': 0.004188223700418822, 'mean_word_length': 3.3048780487804876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6371125', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2485, 'n_words': 646}