Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
29951 amit.gupta 1
$(function () {
30252 amit.gupta 2
	$(document).on('click', ".price-circular", function () {
3
		loadPriceCircular("main-content");
4
	});
28102 tejbeer 5
 
30252 amit.gupta 6
	$(document).on('click', ".partner-price-circular", function () {
28134 tejbeer 7
 
30252 amit.gupta 8
		bootbox.confirm({
9
			message: "<div class = 'disclosurehindata'> <img src='resources/images/disclosure.png' style='width:100%'> </div>"
10
			,
11
			buttons: {
12
				confirm: {
13
					label: 'I agree',
14
					className: 'btn-success'
15
				},
16
				cancel: {
17
					label: 'I disagree',
18
					className: 'btn-danger'
19
				}
20
			},
21
			callback: function (result) {
22
				if (result == true) {
23
					loadPartnerPriceCircular("main-content");
24
				}
25
			}
26
		});
28134 tejbeer 27
 
30252 amit.gupta 28
	});
28102 tejbeer 29
 
30252 amit.gupta 30
	$(document).on('click', ".submit-circular-request", function () {
31
		let brand = $("#brands").val();
32
		let priceCircularUrl = `${context}/priceCircularByBrand?brand=${brand}`;
33
		if (typeof partnerId == "number") {
34
			priceCircularUrl = `${priceCircularUrl}&fofoId=${partnerId}`;
35
		}
36
		doGetAjaxRequestHandler(priceCircularUrl,
37
			function (response) {
38
				console.log(response)
39
				$('.price-circular-container').html(response);
40
			});
41
	});
28102 tejbeer 42
 
30252 amit.gupta 43
	$(document).on('click', ".download-nlc", function () {
44
		let brand = $("#brands").val();
45
		let downloadNlcUrl = `${context}/downloadNlcByBrand?brand=${brand}`;
46
		if (typeof partnerId == "number") {
47
			downloadNlcUrl = `${downloadNlcUrl}&fofoId=${partnerId}`;
48
		}
49
		doAjaxGetDownload(downloadNlcUrl, `${brand}-nlc.csv`);
50
	});
28102 tejbeer 51
 
30252 amit.gupta 52
 
28102 tejbeer 53
});
54
 
55
function loadPriceCircular(domId) {
30252 amit.gupta 56
	doGetAjaxRequestHandler(context + "/priceCircular",
57
		function (response) {
58
			$('#' + domId).html(response);
59
		});
28102 tejbeer 60
}
61
 
62
function loadPartnerPriceCircular(domId) {
30252 amit.gupta 63
	doGetAjaxRequestHandler(context + "/partnerPriceCircular",
64
		function (response) {
65
			$('#' + domId).html(response);
66
		});
35501 ranu 67
}
68
 
69
$(document).on('click', ".today-offer", function () {
70
    let fofoId = $(this).data('fofoid');
71
    loadTodayOfferVM("main-content", fofoId);
72
});
73
 
74
// Main function called to load the shell
75
function loadTodayOfferVM(domId, fofoId) {
76
    doGetAjaxRequestHandler(context + `/todayOffer?fofoId=${fofoId}`, function (response) {
77
        // Load the brand tabs
78
        $('#' + domId).html(response);
79
 
80
        // AUTO-LOAD Samsung immediately after tabs are ready
81
        loadBrandOffers("Motorola", fofoId);
82
    });
83
}
84
 
85
 
86
// Click listener for tabs
87
$(document).on('click', ".brand-tab", function () {
88
    let fofoId = $(this).data('fofoid');
89
    let brand = $(this).data("brand");
90
    loadBrandOffers(brand, fofoId);
91
});
92
 
93
 
94
// Function to handle the actual data loading
95
function loadBrandOffers(brandName, fofoId) {
96
 
97
 
98
    // 1. Show the loader immediately
99
    const loaderHtml = `
100
        <center><div class="loader-wrapper">
101
            <i class="fa fa-spinner fa-spin fa-4x"></i>
102
            <span class="loader-text">Loading offers for ${brandName}...</span>
103
        </div></center>`;
104
 
105
    $('.today-offer-container').html(loaderHtml);
106
 
107
    // 2. Prepare the URL
108
    let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
109
    if (typeof partnerId == "number") {
110
        todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
111
    }
112
 
113
    // 3. Hit the API
114
    doGetAjaxRequestHandler(todayOfferUrl, function (response) {
115
        // Success: The loader is replaced by the actual table response
116
        $('.today-offer-container').html(response);
117
 
118
        // Update Active Tab UI
119
        $(".brand-tabs li").removeClass("active");
120
        $(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
121
    });
122
}
123
 
124
 
125
$(document).on('click', '.today-offer-view', function () {
126
    let offerId = $(this).data("offerid");
127
    doGetAjaxRequestHandler(`${context}/getOfferMargins?offerId=${offerId}`, function (data) {
128
        $('#todayOfferDescription .modal-content').html(data);
129
        $("#todayOfferDescription").modal('show');
130
    });
131
});
132
 
133
 
134
$(document).on('click', '.today-fofo-offer', function () {
135
    let fofoId = $(this).data("fofoid");
136
    doGetAjaxRequestHandler(`${context}/todayFofoOffer?fofoId=${fofoId}`, function (data) {
137
        $(".today-fofo-offer-view").show();
138
        $(".fofo-summry-view").hide();
139
        $('.today-fofo-offer-view').html(data);
140
        // AUTO-LOAD Samsung immediately after tabs are ready
141
        loadFofoBrandOffers("Motorola", fofoId);
142
    });
143
});
144
 
145
 
35502 ranu 146
$(document).on('click', '.fofo-stock-info', function () {
147
 
148
	$(".today-fofo-offer-view").hide();
149
	$(".fofo-summry-view").show();
150
});
151
 
152
 
35501 ranu 153
$(document).on('click', ".fofo-brand-tab", function () {
154
    let fofoId = $(this).data('fofoid');
155
    let brand = $(this).data("brand");
156
    loadFofoBrandOffers(brand, fofoId);
157
});
158
 
159
 
160
// Function to handle the actual data loading
161
function loadFofoBrandOffers(brandName, fofoId) {
162
 
163
 
164
    // 1. Show the loader immediately
165
    const loaderHtml = `
166
        <center><div class="loader-wrapper">
167
            <i class="fa fa-spinner fa-spin fa-4x"></i>
168
            <span class="loader-text">Loading offers for ${brandName}...</span>
169
        </div></center>`;
170
 
171
    $('.today-fofo-offer-container').html(loaderHtml);
172
 
173
    // 2. Prepare the URL
174
    let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
175
    if (typeof partnerId == "number") {
176
        todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
177
    }
178
 
179
    // 3. Hit the API
180
    doGetAjaxRequestHandler(todayOfferUrl, function (response) {
181
        // Success: The loader is replaced by the actual table response
182
        $('.today-fofo-offer-container').html(response);
183
 
184
        // Update Active Tab UI
185
        $(".brand-tabs li").removeClass("active");
186
        $(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
187
    });
28102 tejbeer 188
}