Subversion Repositories SmartDukaan

Rev

Rev 27755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27754 amit.gupta 1
$(document).on('click', ".banner-listing", function() {
26958 tejbeer 2
	loadBannerListing("main-content");
3
});
4
 
27755 amit.gupta 5
$(document).on('click', "a.banner-listing-detail",
26958 tejbeer 6
		function() {
7
			var bannerListingId = $(this).data("id");
8
			doAjaxRequestHandler(
9
					`${context}/banner-listing/${bannerListingId}`, "GET",
10
					function(response) {
11
						$('.banner-products-container').html(response);
12
					});
13
 
14
		});
15
 
27755 amit.gupta 16
$(document).on('click', "a.banner-remove",
26958 tejbeer 17
		function() {
18
			var bannerId = $(this).data("bannerid");
19
			var bannerListingId = $(this).data("bannerlistingid");
20
 
21
			if (confirm("Are you sure you want to remove banner") == true) {
22
				doPostAjaxRequestHandler(context
23
						+ "/banner-listing-detail/remove?bannerId=" + bannerId
24
						+ "&bannerListingId=" + bannerListingId, function(
25
						response) {
26
					$('.banner-products-container').html(response);
27
 
28
				});
29
 
30
			}
31
 
32
		});
33
 
27755 amit.gupta 34
$(document).on('click', "#update-banner-rank",
26958 tejbeer 35
		function() {
36
			if (confirm("Are you sure you want to update ranks?")) {
37
				var bannerListingId = $(this).data("id");
38
				var bannerProductIds = [];
39
				$("#banner-product-listing-tbody").find("tr").each(function() {
40
					console.log(this);
41
					bannerProductIds.push($(this).data("id"));
42
				});
43
				doPostAjaxRequestWithJsonHandler(
44
						`${context}/banner-listing/order/${bannerListingId}`,
45
						JSON.stringify(bannerProductIds), function(response) {
46
							$('.banner-products-container').html(response);
47
						});
48
			}
49
		});
50
 
27755 amit.gupta 51
$(document).on('click', "#addBannerUrl",
26958 tejbeer 52
		function() {
53
			bannerUrl = $("#banner-url").val();
32595 ranu 54
			targetUrl = $("#target-url").val();
26958 tejbeer 55
			rank = $("#rank").val();
56
			bannerListingId = $(this).data("id");
26959 tejbeer 57
			mediaType = $("#media-type").val();
26958 tejbeer 58
 
59
			json = {
60
				bannerUrl : bannerUrl,
32595 ranu 61
				targetUrl: targetUrl,
26958 tejbeer 62
				rank : rank,
26959 tejbeer 63
				bannerListingId : bannerListingId,
64
				mediaType : mediaType
26958 tejbeer 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
 
27755 amit.gupta 102
$(document).on('mousedown', ".grab-banner",
26958 tejbeer 103
				function(e) {
104
					var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
105
					b.addClass("grabCursor").css("userSelect", "none");
106
					tr.addClass("grabbed");
107
					function move(e) {
108
						console.log(Math.abs(e.pageY - sy));
109
						if (!drag && Math.abs(e.pageY - sy) < 10)
110
							return;
111
						drag = true;
112
						tr.siblings().each(function() {
113
							var s = $(this), i = s.index(), y = s.offset().top;
114
							if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
115
								if (e.pageY <= y + (s.outerHeight() / 2))
116
									tr.insertBefore(s);
117
								else
118
									tr.insertAfter(s);
119
								return false;
120
							}
121
						});
122
					}
123
					function up(e) {
124
						if (drag && si != tr.index()) {
125
							drag = false;
126
							$("#update-banner-rank").prop('disabled', false);
127
						}
128
						$(document).unbind("mousemove", move).unbind("mouseup",
129
								up);
130
						b.removeClass("grabCursor").css("userSelect", "none");
131
						tr.removeClass("grabbed");
132
					}
133
					$(document).mousemove(move).mouseup(up);
134
				});