Subversion Repositories SmartDukaan

Rev

Rev 32595 | 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();
35375 aman 58
            isTrial = $("#is-trial").prop('checked');
26958 tejbeer 59
 
35375 aman 60
            json = {
26958 tejbeer 61
				bannerUrl : bannerUrl,
32595 ranu 62
				targetUrl: targetUrl,
26958 tejbeer 63
				rank : rank,
26959 tejbeer 64
				bannerListingId : bannerListingId,
35375 aman 65
                mediaType: mediaType,
66
                trial: isTrial
26958 tejbeer 67
 
68
			};
69
 
70
			console.log(json)
71
 
72
			doPostAjaxRequestWithJsonHandler(context
73
					+ "/banner-listing-detail/add", JSON.stringify(json),
74
					function(response) {
75
						$('.banner-products-container').html(response);
76
					});
77
 
78
		});
79
 
80
function loadBannerListing(domId) {
81
	doAjaxRequestHandler(context + "/banner-listing", "GET",
82
			function(response) {
83
				$('#' + domId).html(response);
84
			});
85
}
86
 
87
function addBannerListing() {
88
	pageUrl = $("#page-url").val();
89
	pageDescription = $("#page-description").val();
90
	websiteName = $("#website-name").val();
91
	json = {
92
		pageUrl : pageUrl,
93
		pageDescription : pageDescription,
94
		websiteName : websiteName
95
	};
96
 
97
	console.log(json)
98
	doPostAjaxRequestWithJsonHandler(context + "/banner-listing/add", JSON
99
			.stringify(json), function(response) {
100
		$('#main-content').html(response);
101
	});
102
}
103
 
27755 amit.gupta 104
$(document).on('mousedown', ".grab-banner",
26958 tejbeer 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
				});