Subversion Repositories SmartDukaan

Rev

Rev 26959 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26958 tejbeer 1
$(".banner-listing").live('click', function() {
2
	loadBannerListing("main-content");
3
});
4
 
5
$("a.banner-listing-detail").live(
6
		'click',
7
		function() {
8
			var bannerListingId = $(this).data("id");
9
			doAjaxRequestHandler(
10
					`${context}/banner-listing/${bannerListingId}`, "GET",
11
					function(response) {
12
						$('.banner-products-container').html(response);
13
					});
14
 
15
		});
16
 
17
$("a.banner-remove").live(
18
		'click',
19
		function() {
20
			var bannerId = $(this).data("bannerid");
21
			var bannerListingId = $(this).data("bannerlistingid");
22
 
23
			if (confirm("Are you sure you want to remove banner") == true) {
24
				doPostAjaxRequestHandler(context
25
						+ "/banner-listing-detail/remove?bannerId=" + bannerId
26
						+ "&bannerListingId=" + bannerListingId, function(
27
						response) {
28
					$('.banner-products-container').html(response);
29
 
30
				});
31
 
32
			}
33
 
34
		});
35
 
36
$("#update-banner-rank").live(
37
		'click',
38
		function() {
39
			if (confirm("Are you sure you want to update ranks?")) {
40
				var bannerListingId = $(this).data("id");
41
				var bannerProductIds = [];
42
				$("#banner-product-listing-tbody").find("tr").each(function() {
43
					console.log(this);
44
					bannerProductIds.push($(this).data("id"));
45
				});
46
				doPostAjaxRequestWithJsonHandler(
47
						`${context}/banner-listing/order/${bannerListingId}`,
48
						JSON.stringify(bannerProductIds), function(response) {
49
							$('.banner-products-container').html(response);
50
						});
51
			}
52
		});
53
 
54
$("#addBannerUrl").live(
55
		'click',
56
		function() {
57
			bannerUrl = $("#banner-url").val();
58
			rank = $("#rank").val();
59
			bannerListingId = $(this).data("id");
60
 
61
			json = {
62
				bannerUrl : bannerUrl,
63
				rank : rank,
64
				bannerListingId : bannerListingId
65
 
66
			};
67
 
68
			console.log(json)
69
 
70
			doPostAjaxRequestWithJsonHandler(context
71
					+ "/banner-listing-detail/add", JSON.stringify(json),
72
					function(response) {
73
						$('.banner-products-container').html(response);
74
					});
75
 
76
		});
77
 
78
function loadBannerListing(domId) {
79
	doAjaxRequestHandler(context + "/banner-listing", "GET",
80
			function(response) {
81
				$('#' + domId).html(response);
82
			});
83
}
84
 
85
function addBannerListing() {
86
	pageUrl = $("#page-url").val();
87
	pageDescription = $("#page-description").val();
88
	websiteName = $("#website-name").val();
89
	json = {
90
		pageUrl : pageUrl,
91
		pageDescription : pageDescription,
92
		websiteName : websiteName
93
	};
94
 
95
	console.log(json)
96
	doPostAjaxRequestWithJsonHandler(context + "/banner-listing/add", JSON
97
			.stringify(json), function(response) {
98
		$('#main-content').html(response);
99
	});
100
}
101
 
102
$(".grab-banner")
103
		.live(
104
				'mousedown',
105
				function(e) {
106
					var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
107
					b.addClass("grabCursor").css("userSelect", "none");
108
					tr.addClass("grabbed");
109
					function move(e) {
110
						console.log(Math.abs(e.pageY - sy));
111
						if (!drag && Math.abs(e.pageY - sy) < 10)
112
							return;
113
						drag = true;
114
						tr.siblings().each(function() {
115
							var s = $(this), i = s.index(), y = s.offset().top;
116
							if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
117
								if (e.pageY <= y + (s.outerHeight() / 2))
118
									tr.insertBefore(s);
119
								else
120
									tr.insertAfter(s);
121
								return false;
122
							}
123
						});
124
					}
125
					function up(e) {
126
						if (drag && si != tr.index()) {
127
							drag = false;
128
							$("#update-banner-rank").prop('disabled', false);
129
						}
130
						$(document).unbind("mousemove", move).unbind("mouseup",
131
								up);
132
						b.removeClass("grabCursor").css("userSelect", "none");
133
						tr.removeClass("grabbed");
134
					}
135
					$(document).mousemove(move).mouseup(up);
136
				});