Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
30603 tejbeer 1
$(document).on('click', ".web-offers", function() {
2
	doAjaxRequestHandler(context + "/web-offers", "GET", function(response) {
28371 amit.gupta 3
		$('#main-content').html(response);
4
	});
5
});
30603 tejbeer 6
$(document).on('click', "a.web-offer-details", function() {
28371 amit.gupta 7
	var webOfferId = $(this).data("id");
30603 tejbeer 8
	doAjaxRequestHandler(`${context}/web-offer/${webOfferId}`, "GET", function(response) {
28371 amit.gupta 9
		$('.web-offer-products-container').html(response);
10
	});
30596 tejbeer 11
 
28371 amit.gupta 12
})
13
 
30596 tejbeer 14
 
30603 tejbeer 15
$(document).on('click', ".web-offer-id", function() {
30596 tejbeer 16
	var webOfferId = $(this).data("id");
30603 tejbeer 17
	doAjaxRequestHandler(`${context}/getwebOffer/${webOfferId}`, "GET", function(response) {
30596 tejbeer 18
		$('.web-offer-edit-container .modal-content').html(response);
19
	});
20
});
21
 
22
 
30603 tejbeer 23
$(document).on('click', ".updateWebOfferDuration", function() {
30596 tejbeer 24
	var webOfferId = $(this).data("id");
25
 
30605 tejbeer 26
	startDate = getDatesFromPicker('input[name="offerUpdatedateRange"]').startDate,
27
		endDate = getDatesFromPicker('input[name="offerUpdatedateRange"]').endDate
30596 tejbeer 28
	if (confirm("Are you sure you want to update offer!") == true) {
29
		doPostAjaxRequestHandler(context
30
			+ "/web-offer-duration/update?id="
30603 tejbeer 31
			+ webOfferId + "&startDate=" + startDate + "&endDate=" + endDate, function(response) {
32
				if (response == 'true') {
33
					alert("update successfully ");
30596 tejbeer 34
 
30603 tejbeer 35
					$('#main-content').html(response);
36
				}
37
			});
30596 tejbeer 38
 
39
		return false;
28371 amit.gupta 40
	}
30596 tejbeer 41
 
28371 amit.gupta 42
});
30596 tejbeer 43
 
44
 
30603 tejbeer 45
$(document).on('click', "#add-to-offer", function() {
30596 tejbeer 46
	var webOfferId = $(this).data("id");
28371 amit.gupta 47
	var entityIds = [entityId];
48
 
30596 tejbeer 49
	var entityIdTxt = $("#entityData").val();
50
	if (entityIdTxt.length > 0) {
51
		if (entityIdTxt.indexOf(",") > 0) {
28371 amit.gupta 52
			entityIds = entityIdTxt.split(",");
53
		}
54
	} else {
55
		alert("Please enter items");
56
		return;
57
	}
58
	json = [];
30596 tejbeer 59
	for (var e of entityIds) {
30603 tejbeer 60
		json.push({ webOfferId: webOfferId, entityId: e });
28371 amit.gupta 61
	}
62
	console.log(json);
63
	console.log(JSON.stringify(json))
30603 tejbeer 64
	doPostAjaxRequestWithJsonHandler(`${context}/web-offer-product/add`, JSON.stringify(json), function(response) {
28371 amit.gupta 65
		$('.web-offer-products-container').html(response);
66
	});
30596 tejbeer 67
 
28371 amit.gupta 68
});
69
 
30603 tejbeer 70
$(document).on('click', "a.product-remove", function() {
28371 amit.gupta 71
	var webOfferProductId = $(this).closest('tr').data("id");
72
	if (confirm("Are you sure you want to remove the Item!") == true) {
73
 
30603 tejbeer 74
		doDeleteAjaxRequestHandler(`${context}/web-offer-product/remove?webOfferProductId=${webOfferProductId}`, function(response) {
30596 tejbeer 75
			alert("Product removed successfully");
30603 tejbeer 76
			$('.web-offer-products-container').html(response);
30596 tejbeer 77
		});
28371 amit.gupta 78
	}
79
 
80
})
81
 
82
function addWebOffer() {
83
	webOfferTitle = $("#web-offer-title").val();
84
	smallText = $("#small-text").val();
85
	largeText = $("#large-text").val();
86
	smallBannerUrl = $("#offer-banner-small").val();
30596 tejbeer 87
 
88
	if (webOfferTitle === "") {
89
		alert("Title is required");
90
		return false;
91
	}
92
 
28371 amit.gupta 93
	var json = {
30596 tejbeer 94
		id: 0,
95
		title: webOfferTitle,
96
		smallText: smallText,
97
		largeText: largeText,
98
		smallBannerUrl: smallBannerUrl,
30605 tejbeer 99
		startDate: getDatesFromPicker('input[name="offerdateRange"]').startDate,
100
		endDate: getDatesFromPicker('input[name="offerdateRange"]').endDate
28371 amit.gupta 101
	}
30596 tejbeer 102
	if (confirm("Are you sure you want to add the offer!") == true) {
30603 tejbeer 103
		doPostAjaxRequestWithJsonHandler(context + "/web-offer/add", JSON.stringify(json), function(response) {
30596 tejbeer 104
			$('#main-content').html(response);
105
		});
106
	}
28371 amit.gupta 107
}
108
 
109
 
30603 tejbeer 110
$(document).on('mousedown', ".grab", function(e) {
30596 tejbeer 111
	var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
112
	b.addClass("grabCursor").css("userSelect", "none");
113
	tr.addClass("grabbed");
30599 amit.gupta 114
 
30596 tejbeer 115
	function move(e) {
116
		console.log(Math.abs(e.pageY - sy));
117
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
118
		drag = true;
30603 tejbeer 119
		tr.siblings().each(function() {
30596 tejbeer 120
			var s = $(this), i = s.index(), y = s.offset().top;
121
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
122
				if (e.pageY <= y + (s.outerHeight() / 2))
123
					tr.insertBefore(s);
124
				else
125
					tr.insertAfter(s);
126
				return false;
127
			}
128
		});
129
	}
30599 amit.gupta 130
 
30596 tejbeer 131
	function up(e) {
132
		if (drag && si != tr.index()) {
133
			drag = false;
134
			$(".update-rank").prop('disabled', false);
135
		}
136
		$(document).unbind("mousemove", move).unbind("mouseup", up);
137
		b.removeClass("grabCursor").css("userSelect", "none");
138
		tr.removeClass("grabbed");
139
	}
30599 amit.gupta 140
 
30596 tejbeer 141
	$(document).mousemove(move).mouseup(up);
28371 amit.gupta 142
});
143
 
30603 tejbeer 144
$(document).on('click', ".update-rank", function() {
28371 amit.gupta 145
	if (confirm("Are you sure you want to update ranks?")) {
146
		var webListingId = $(this).data("id");
147
		var webProductIds = [];
30603 tejbeer 148
		$("#web-product-listing-tbody").find("tr").each(function() {
28371 amit.gupta 149
			console.log(this);
150
			webProductIds.push($(this).data("id"));
151
		});
30603 tejbeer 152
		doPostAjaxRequestWithJsonHandler(`${context}/web-offer/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
28371 amit.gupta 153
			$('.web-offer-products-container').html(response);
154
		});
155
	}
156
});
157
 
158