Subversion Repositories SmartDukaan

Rev

Rev 3440 | Rev 3462 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3440 Rev 3446
Line 1... Line 1...
1
$(function(){
1
$(function(){
2
	feedbacks = null;
2
	feedbacks = null;
3
	
3
	
-
 
4
	function getPriceAsInt(priceString)	{
-
 
5
		return parseInt(priceString.replace('Rs.', '').replace(',', ''));
-
 
6
	}
-
 
7
	
4
	function updateWithFeedback()	{
8
	function updateWithFeedback()	{
5
		$.ajax({
9
		$.ajax({
6
			url: '/feedback',
10
			url: '/feedback',
7
			type: 'GET',
11
			type: 'GET',
8
			success: function(data){
12
			success: function(data){
Line 14... Line 18...
14
//					console.log(tr);
18
//					console.log(tr);
15
					
19
					
16
					$.each(feedback, function(source, feedback_instruction){
20
					$.each(feedback, function(source, feedback_instruction){
17
						updateCellWithFeedback($(tr).children('td[source=' + source + ']')[0], feedback_instruction);
21
						updateCellWithFeedback($(tr).children('td[source=' + source + ']')[0], feedback_instruction);
18
					});
22
					});
-
 
23
					markBestPrice(tr);
19
				});
24
				});
20
			}
25
			}
21
		})
26
		})
22
	}
27
	}
23
	
28
	
24
	function updateCellWithFeedback(td, feedback)	{
29
	function updateCellWithFeedback(td, feedback)	{
25
		var anchor = $(td).children('.link-conflict');
30
		var anchor = $(td).children('.link-conflict');
26
		var source = $(td).attr('source');
31
		var source = $(td).attr('source');
27
		$(anchor).html('Filtered');
32
		$(anchor).html('Filtered');
28
		console.log(anchor);
-
 
29
		
33
		
30
		if(feedback.type == 'reject')	{
34
		if(feedback.type == 'reject')	{
31
			$(td).html('Not Found ' + $('<a>').append($(anchor).clone()).remove().html()).addClass('with-feedback');
35
			$(td).html('Not Found ' + $('<a>').append($(anchor).clone()).remove().html()).addClass('with-feedback');
32
			
36
			
33
		} else	{
37
		} else	{
Line 58... Line 62...
58
	});
62
	});
59
	
63
	
60
	updateWithFeedback();
64
	updateWithFeedback();
61
	
65
	
62
	function markBestPrice(trNode)	{
66
	function markBestPrice(trNode)	{
-
 
67
		$(trNode).children().removeClass('best');
63
		var tdBestPrice = $(trNode).children('td')[1];
68
		var tdBestPrice = $(trNode).children('td')[1];
64
		var saholicPrice = parseInt(tdBestPrice.innerHTML);
69
		var saholicPrice = parseInt(tdBestPrice.innerHTML);
65
		var bestPrice = saholicPrice;
70
		var bestPrice = saholicPrice;
66
 
71
		
67
		$(trNode).find('a[href!="#"]').each(function(index, a){
72
		$(trNode).find('a[href!="#"]').each(function(index, a){
68
			var price = parseInt(a.innerHTML);
73
			var price = getPriceAsInt(a.innerHTML);
69
			
74
 
70
			if (price < bestPrice)	{
75
			if (price < bestPrice)	{
71
				bestPrice = price;
76
				bestPrice = price;
72
				tdBestPrice = $(a).parent();
77
				tdBestPrice = $(a).parent();
73
			}
78
			}
74
		});
79
		});
Line 174... Line 179...
174
					
179
					
175
				}
180
				}
176
				var td = $('#' + feedback.entityId).children('td[source=' + feedback.source + ']')[0];
181
				var td = $('#' + feedback.entityId).children('td[source=' + feedback.source + ']')[0];
177
				updateCellWithFeedback(td, {type: feedback.type, selected_item: feedback.selected});
182
				updateCellWithFeedback(td, {type: feedback.type, selected_item: feedback.selected});
178
				showMsg(table, false, 'Your feedback has been saved successfully.');
183
				showMsg(table, false, 'Your feedback has been saved successfully.');
-
 
184
				markBestPrice($(td).parent());
179
			},
185
			},
180
			error: function(msg)	{
186
			error: function(msg)	{
181
				showMsg(table, true, 'Error! please try again.');
187
				showMsg(table, true, 'Error! please try again.');
182
			}
188
			}
183
		});
189
		});