Subversion Repositories SmartDukaan

Rev

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