Subversion Repositories SmartDukaan

Rev

Rev 28371 | Rev 30599 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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