Subversion Repositories SmartDukaan

Rev

Rev 26958 | Rev 27754 | Go to most recent revision | Details | Compare with Previous | 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");
26959 tejbeer 60
			mediaType = $("#media-type").val();
26958 tejbeer 61
 
62
			json = {
63
				bannerUrl : bannerUrl,
64
				rank : rank,
26959 tejbeer 65
				bannerListingId : bannerListingId,
66
				mediaType : mediaType
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
 
104
$(".grab-banner")
105
		.live(
106
				'mousedown',
107
				function(e) {
108
					var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
109
					b.addClass("grabCursor").css("userSelect", "none");
110
					tr.addClass("grabbed");
111
					function move(e) {
112
						console.log(Math.abs(e.pageY - sy));
113
						if (!drag && Math.abs(e.pageY - sy) < 10)
114
							return;
115
						drag = true;
116
						tr.siblings().each(function() {
117
							var s = $(this), i = s.index(), y = s.offset().top;
118
							if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
119
								if (e.pageY <= y + (s.outerHeight() / 2))
120
									tr.insertBefore(s);
121
								else
122
									tr.insertAfter(s);
123
								return false;
124
							}
125
						});
126
					}
127
					function up(e) {
128
						if (drag && si != tr.index()) {
129
							drag = false;
130
							$("#update-banner-rank").prop('disabled', false);
131
						}
132
						$(document).unbind("mousemove", move).unbind("mouseup",
133
								up);
134
						b.removeClass("grabCursor").css("userSelect", "none");
135
						tr.removeClass("grabbed");
136
					}
137
					$(document).mousemove(move).mouseup(up);
138
				});