Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
27516 amit.gupta 1
$(function () {
24125 govind 2
 
27754 amit.gupta 3
    $(document).on('click', "#retailer-details-search-button", function () {
27516 amit.gupta 4
        searchContent = $("#retailer-details-search-text").val();
5
        if (typeof (searchContent) == "undefined" || !searchContent) {
6
            searchContent = "";
7
        }
8
        getRetailerDetailsByEmailIdOrMobileNumber(
9
            "retailer-details-container", searchContent);
10
    });
24159 tejbeer 11
 
27754 amit.gupta 12
    $(document).on('click', ".active-store", function () {
27516 amit.gupta 13
        storeInfo("main-content");
14
    });
27754 amit.gupta 15
    $(document).on('click', ".inactive-store", function () {
27516 amit.gupta 16
        inactiveStoreInfo("main-content");
17
    });
27754 amit.gupta 18
    $(document).on('click', ".retailer-info", function () {
27516 amit.gupta 19
        retailerInfo("main-content");
20
    });
24125 govind 21
 
27231 tejbeer 22
 
27754 amit.gupta 23
    $(document).on('click', ".partner-readonly-info", function () {
27516 amit.gupta 24
        partnerInfo("main-content")
27171 tejbeer 25
 
26
 
27516 amit.gupta 27
    });
27171 tejbeer 28
 
24125 govind 29
 
27755 amit.gupta 30
    $(document).on('click', ".partnerInfoReadOnly",
27516 amit.gupta 31
            function () {
24125 govind 32
 
27516 amit.gupta 33
                var fofoId = $('#fofo-users').val();
34
                loginAsPartnerReadonly(fofoId);
35
            });
27755 amit.gupta 36
    $(document).on('change', "#retailerAddressPinCode",
27516 amit.gupta 37
        function () {
27171 tejbeer 38
 
27516 amit.gupta 39
            var pincode = $('#retailerAddressPinCode').val();
24125 govind 40
 
27516 amit.gupta 41
            if (undefined != pincode) {
42
                doGetAjaxRequestHandler(context + "/postOffice?pinCode="
43
                    + pincode,
44
                    function (response) {
45
                        console.log(response.response.state);
46
                        $('#retailerAddressCity').find('option').not(':first').remove();
47
                        $('#retailerAddressState').val("");
48
                        $('#retailerAddressState').val(
49
                            response.response.state);
50
                        loadDistrictNames(response.response.state);
51
                        for (let city of response.response.cities) {
52
                            var opt = $("<option>").val(city).text(city);
53
                            $('#retailerAddressCity').append(opt);
24349 amit.gupta 54
 
27516 amit.gupta 55
                        }
24159 tejbeer 56
 
27516 amit.gupta 57
                    });
58
            }
59
        });
24159 tejbeer 60
 
27754 amit.gupta 61
    $(document).on("keyup", "#retailer-details-search-text", function (e) {
27516 amit.gupta 62
        var keyCode = e.keyCode || e.which;
63
        if (keyCode == 13) {
64
            $("#retailer-details-search-button").click();
65
        }
66
    });
24159 tejbeer 67
 
27754 amit.gupta 68
    $(document).on('click', ".deactivate-store", function () {
27516 amit.gupta 69
        var fofoId = $(this).data("fofoid");
70
        console.log(fofoId);
71
        if (confirm("Are you sure you want to deactivate store!") == true) {
72
            deactivateStore("main-content", fofoId);
73
        }
27171 tejbeer 74
 
27516 amit.gupta 75
    });
27754 amit.gupta 76
    $(document).on('click', ".login_as", function () {
27516 amit.gupta 77
        var fofoId = $('#partnerId').val();
78
        loginAsPartner(fofoId);
24159 tejbeer 79
 
27516 amit.gupta 80
    });
24159 tejbeer 81
 
27754 amit.gupta 82
    $(document).on('click', ".extend-billing", function () {
27516 amit.gupta 83
        var fofoId = $(this).data("fofoid");
84
        console.log(fofoId);
85
        if (confirm("Are you sure you want to extend Billing?")) {
86
            extendBilling($(this).parent(), fofoId);
87
        }
24159 tejbeer 88
 
27516 amit.gupta 89
    });
24159 tejbeer 90
 
27516 amit.gupta 91
    /*
27754 amit.gupta 92
     * $(document).on('change', '#retailerAddressState', function() { var stateName =
27516 amit.gupta 93
     * $(this).find('option:selected').text();
94
     *
95
     * loadDistrictNames(stateName); });
96
     */
24159 tejbeer 97
 
98
 
27754 amit.gupta 99
    $(document).on('click', "#location", function () {
27516 amit.gupta 100
        if ($(this).is(":checked")) {
101
 
102
            $("#divLocation").show();
103
 
104
        } else {
105
            $("#divLocation").hide();
106
        }
107
    });
108
 
27755 amit.gupta 109
    $(document).on('click', ".addlocationbutton",
27516 amit.gupta 110
        function () {
111
            var userId = $('#retailerId').text();
112
            var name = $('#personName').val();
113
            var line1 = $('#line1').val();
114
            var line2 = $('#line2').val();
115
            var city = $('#city').val();
116
            var state = $('#state').val();
117
            var pin = $('#pinCode').val();
118
 
119
            if (name === "" && line1 === "" && city === "" && pin === "") {
120
                alert("Field can't be empty");
121
                return;
122
            }
123
            if (name === "") {
124
                alert("name is required");
125
                return;
126
            }
127
            if (line1 === "") {
128
                alert("line1 is required");
129
                return;
130
            }
131
            if (city === "") {
132
                alert("city is required");
133
                return;
134
            }
135
            if (pin === "") {
136
                alert("pin is required");
137
                return;
138
            }
139
 
140
            var locationData = {};
141
            locationData['userId'] = $('#retailerId').text();
142
            locationData['name'] = $('#personName').val();
143
            locationData['line1'] = $('#line1').val();
144
            locationData['line2'] = $('#line2').val();
145
            locationData['city'] = $('#city').val();
146
            locationData['state'] = $('#state').val();
147
            locationData['pin'] = $('#pinCode').val();
148
 
149
            if (confirm("Are you sure you want to add location!") == true) {
150
                doPostAjaxRequestWithJsonHandler(context + "/addLocation",
151
                    JSON.stringify(locationData), function (response) {
152
                        if (response == 'true') {
153
                            alert("successfully Add");
154
                            $("#addLocationModal").modal('hide');
155
 
156
                        }
157
                    });
158
 
159
                return false;
160
            }
161
        });
162
 
23347 ashik.ali 163
});
164
 
23837 ashik.ali 165
function getDistance(lat1, lon1, lat2, lon2) {
27516 amit.gupta 166
    var deg2rad = 0.017453292519943295; // === Math.PI / 180
167
    var cos = Math.cos;
168
    lat1 *= deg2rad;
169
    lon1 *= deg2rad;
170
    lat2 *= deg2rad;
171
    lon2 *= deg2rad;
172
    var diam = 12742; // Diameter of the earth in km (2 * 6371)
173
    var dLat = lat2 - lat1;
174
    var dLon = lon2 - lon1;
175
    var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 176
 
27516 amit.gupta 177
    return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
24125 govind 178
}
23837 ashik.ali 179
 
24125 govind 180
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
27516 amit.gupta 181
    doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
182
        + emailIdOrMobileNumber, function (response) {
183
        $('#' + domId).html(response);
184
        if ($("#location").is(":checked")) {
27171 tejbeer 185
 
27516 amit.gupta 186
            $("#divLocation").show();
187
        }
188
    });
23347 ashik.ali 189
}
190
 
24125 govind 191
function updateRetailerDocument() {
27516 amit.gupta 192
    // $("#updateRetailerShopDocument0").click( function() {
193
    console.log("Update Retailer Document Clicked");
194
    // console.log(ownerId);
195
    var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
196
    console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
197
    var file = $('#retailerDocument')[0].files[0];
198
    console.log("file : " + file.name);
199
    uploadRetailerDocument("retailer-details-container", file,
200
        emailIdOrMobileNumber);
23347 ashik.ali 201
}
202
 
24125 govind 203
function updateRetailerShopDocument(ownerId) {
27516 amit.gupta 204
    // $("#updateRetailerShopDocument0").click( function() {
205
    console.log("Update Retailer Shop Document Clicked");
206
    console.log(ownerId);
207
    var shopSize = parseInt($("#shopDetailsSize").attr('size'));
208
    console.log("size : " + shopSize);
209
    for (var index = 0; index < shopSize; index++) {
210
        if ("updateRetailerShopDocument" + index == ownerId) {
211
            var emailIdOrMobileNumber = $('#retailer-details-search-text')
212
                .val();
213
            console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
214
            var shopId = $('#retailerShopDocument' + index).attr("shopId");
215
            console.log("shopId : " + shopId);
216
            var file = $('#retailerShopDocument' + index)[0].files[0];
217
            console.log("file : " + file.name);
218
            uploadRetailerShopDocument("retailer-details-container", file,
219
                emailIdOrMobileNumber, shopId);
220
        }
221
    }
23347 ashik.ali 222
}
223
 
24125 govind 224
function loadDistrictNames(stateName) {
27516 amit.gupta 225
    if (undefined != $("#districtName")) {
226
        doGetAjaxRequestHandler(
227
            context + "/district/all/stateName?stateName=" + stateName,
228
            function (response) {
229
                console.log(response);
230
                var districtMasters = response.response;
231
                // districtMasters = districtMasters.response;
232
                var districtNameElements = '<option value="" disabled selected>District Name</option>';
233
                for (index = 0; index < districtMasters.length; index++) {
234
                    districtNameElements = districtNameElements
235
                        + '<option value="'
236
                        + districtMasters[index].name + '">'
237
                        + districtMasters[index].name + '</option>';
238
                }
239
                $('#districtName').html(districtNameElements);
240
            });
241
    }
23347 ashik.ali 242
}
243
 
24125 govind 244
function retailerInfo(domId) {
27516 amit.gupta 245
    doGetAjaxRequestHandler(context + "/retailerInfo", function (response) {
246
        $('#' + domId).html(response);
24159 tejbeer 247
 
27516 amit.gupta 248
    });
24159 tejbeer 249
 
24125 govind 250
}
27231 tejbeer 251
 
27516 amit.gupta 252
function partnerInfo(domId) {
253
    doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function (response) {
254
        $('#' + domId).html(response);
255
 
256
    });
27231 tejbeer 257
}
27516 amit.gupta 258
 
24125 govind 259
function storeInfo(domId) {
27516 amit.gupta 260
    doGetAjaxRequestHandler(context + "/getAllStores", function (response) {
261
        $('#' + domId).html(response);
262
    });
24125 govind 263
}
27516 amit.gupta 264
 
24680 govind 265
function inactiveStoreInfo(domId) {
27516 amit.gupta 266
    doGetAjaxRequestHandler(context + "/getAllInactiveStores", function (
267
        response) {
268
        $('#' + domId).html(response);
269
    });
24680 govind 270
}
27516 amit.gupta 271
 
24125 govind 272
function deactivateStore(domId, fofoId) {
27516 amit.gupta 273
    doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
274
        function (response) {
275
            if (response == "true") {
276
                alert("successfully deactivated!");
277
                storeInfo(domId);
278
            }
24159 tejbeer 279
 
27516 amit.gupta 280
        });
24125 govind 281
}
27516 amit.gupta 282
 
24976 amit.gupta 283
function loginAsPartner(fofoId) {
27516 amit.gupta 284
    doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
285
        function (response) {
286
            window.create({
287
                "url": "/dashboard",
288
                "incognito": true
289
            });
290
        });
24976 amit.gupta 291
}
27231 tejbeer 292
 
293
function loginAsPartnerReadonly(fofoId) {
27516 amit.gupta 294
    doGetAjaxRequestHandler(context + "/login-as-partner-readonly?fofoId=" + fofoId,
295
        function (response) {
296
            window.create({
297
                "url": "/dashboard",
298
                "incognito": true
299
            });
300
        });
27231 tejbeer 301
}
27516 amit.gupta 302
 
24349 amit.gupta 303
function extendBilling(container, fofoId) {
27516 amit.gupta 304
    doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
305
        function (response) {
306
            if (isFinite(response)) {
307
                alert("successfully deactivated!");
308
                container.html("Billing extended upto "
309
                    + moment().add(1, 'day').format("DD-MM-YY")
310
                    + " Grace count(" + response + ")");
311
            }
312
        });
24349 amit.gupta 313
}
24159 tejbeer 314
 
315
function updateLocationButton(id) {
316
 
27516 amit.gupta 317
    var userId = id;
318
    var name = $('#personName').val();
319
    var line1 = $('#line1').val();
320
    var line2 = $('#line2').val();
321
    var city = $('#city').val();
322
    var state = $('#state').val();
323
    var pin = $('#pinCode').val();
324
    console.log(id);
325
    if (name === "" && line1 === "" && city === "" && pin === "") {
326
        alert("Field can't be empty");
327
        return;
328
    }
329
    if (name === "") {
330
        alert("name is required");
331
        return;
332
    }
333
    if (line1 === "") {
334
        alert("line1 is required");
335
        return;
336
    }
337
    if (city === "") {
338
        alert("city is required");
339
        return;
340
    }
341
    if (pin === "") {
342
        alert("pin is required");
343
        return;
344
    }
24159 tejbeer 345
 
27516 amit.gupta 346
    var changeLocationData = {};
24159 tejbeer 347
 
27516 amit.gupta 348
    changeLocationData['userId'] = id;
349
    changeLocationData['name'] = $('#personName').val();
350
    changeLocationData['line1'] = $('#line1').val();
351
    changeLocationData['line2'] = $('#line2').val();
352
    changeLocationData['city'] = $('#city').val();
353
    changeLocationData['state'] = $('#state').val();
354
    changeLocationData['pin'] = $('#pinCode').val();
24159 tejbeer 355
 
27516 amit.gupta 356
    console.log(changeLocationData);
24159 tejbeer 357
 
27516 amit.gupta 358
    if (confirm("Are you sure you want to add location!") == true) {
359
        doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
360
            .stringify(changeLocationData), function (response) {
361
            if (response == 'true') {
362
                alert("successfully Update");
24159 tejbeer 363
 
27516 amit.gupta 364
                $("#addLocationModal").modal('hide');
24159 tejbeer 365
 
27516 amit.gupta 366
            }
367
        });
24159 tejbeer 368
 
27516 amit.gupta 369
        return false;
370
    }
24159 tejbeer 371
 
372
}