Subversion Repositories SmartDukaan

Rev

Rev 27754 | Rev 32595 | 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();
54
			rank = $("#rank").val();
55
			bannerListingId = $(this).data("id");
26959 tejbeer 56
			mediaType = $("#media-type").val();
26958 tejbeer 57
 
58
			json = {
59
				bannerUrl : bannerUrl,
60
				rank : rank,
26959 tejbeer 61
				bannerListingId : bannerListingId,
62
				mediaType : mediaType
26958 tejbeer 63
 
64
			};
65
 
66
			console.log(json)
67
 
68
			doPostAjaxRequestWithJsonHandler(context
69
					+ "/banner-listing-detail/add", JSON.stringify(json),
70
					function(response) {
71
						$('.banner-products-container').html(response);
72
					});
73
 
74
		});
75
 
76
function loadBannerListing(domId) {
77
	doAjaxRequestHandler(context + "/banner-listing", "GET",
78
			function(response) {
79
				$('#' + domId).html(response);
80
			});
81
}
82
 
83
function addBannerListing() {
84
	pageUrl = $("#page-url").val();
85
	pageDescription = $("#page-description").val();
86
	websiteName = $("#website-name").val();
87
	json = {
88
		pageUrl : pageUrl,
89
		pageDescription : pageDescription,
90
		websiteName : websiteName
91
	};
92
 
93
	console.log(json)
94
	doPostAjaxRequestWithJsonHandler(context + "/banner-listing/add", JSON
95
			.stringify(json), function(response) {
96
		$('#main-content').html(response);
97
	});
98
}
99
 
27755 amit.gupta 100
$(document).on('mousedown', ".grab-banner",
26958 tejbeer 101
				function(e) {
102
					var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
103
					b.addClass("grabCursor").css("userSelect", "none");
104
					tr.addClass("grabbed");
105
					function move(e) {
106
						console.log(Math.abs(e.pageY - sy));
107
						if (!drag && Math.abs(e.pageY - sy) < 10)
108
							return;
109
						drag = true;
110
						tr.siblings().each(function() {
111
							var s = $(this), i = s.index(), y = s.offset().top;
112
							if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
113
								if (e.pageY <= y + (s.outerHeight() / 2))
114
									tr.insertBefore(s);
115
								else
116
									tr.insertAfter(s);
117
								return false;
118
							}
119
						});
120
					}
121
					function up(e) {
122
						if (drag && si != tr.index()) {
123
							drag = false;
124
							$("#update-banner-rank").prop('disabled', false);
125
						}
126
						$(document).unbind("mousemove", move).unbind("mouseup",
127
								up);
128
						b.removeClass("grabCursor").css("userSelect", "none");
129
						tr.removeClass("grabbed");
130
					}
131
					$(document).mousemove(move).mouseup(up);
132
				});