Subversion Repositories SmartDukaan

Rev

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