Subversion Repositories SmartDukaan

Rev

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

Rev 35289 Rev 35458
Line 54... Line 54...
54
        bootbox.alert("Error occurred! Please contact your manager");
54
        bootbox.alert("Error occurred! Please contact your manager");
55
    }
55
    }
56
}
56
}
57
 
57
 
58
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
58
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
59
    if (typeof loaderDialogObj != "undefined") {
59
    if (typeof loaderDialogObj !== "undefined") {
60
        loaderDialogObj.modal('hide');
60
        loaderDialogObj.modal('hide');
61
        // $('div.modal-backdrop.fade').remove();
-
 
62
    }
61
    }
63
    if (jqxhr.status == 400) {
62
    if (jqxhr.status === 400) {
64
        // $('#error-prompt-model').modal();
-
 
65
        badRequestAlert(jqxhr);
63
        badRequestAlert(jqxhr);
66
    } else {
64
    } else {
67
        internalServerErrorAlert(jqxhr);
65
        internalServerErrorAlert(jqxhr);
68
    }
66
    }
69
});
67
});
70
 
68
 
71
$(document).ajaxSend(function (ev, req) {
69
$(document).ajaxSend(function (ev, req) {
72
    req.setRequestHeader('IdempotencyKey', IdempotencyKey);
70
    req.setRequestHeader('IdempotencyKey', IdempotencyKey);
73
});
71
});
74
 
72
 
75
$(document).ajaxSuccess(function () {
-
 
76
    IdempotencyKey = uuidv4();
-
 
77
    console.log('succcess handlor');
-
 
78
});
-
 
79
 
-
 
80
$(document).ajaxComplete(function () {
73
$(document).ajaxComplete(function () {
81
    if (typeof loaderDialogObj != "undefined") {
74
    if (typeof loaderDialogObj !== "undefined") {
82
        loaderDialogObj.modal('hide');
75
        loaderDialogObj.modal('hide');
83
        // $('div.modal-backdrop.fade').remove();
-
 
84
    }
76
    }
85
    IdempotencyKey = uuidv4();
77
    IdempotencyKey = uuidv4();
86
    console.log("idempotency key", IdempotencyKey = uuidv4());
-
 
87
});
78
});
88
 
79
 
89
function ajaxStartHandler() {
80
function ajaxStartHandler() {
90
    if (typeof loaderDialogObj != "undefined")
81
    if (typeof loaderDialogObj !== "undefined") {
91
        loaderDialogObj.modal('show');
82
        loaderDialogObj.modal('show');
-
 
83
    }
92
}
84
}
93
 
85
 
94
$(document).ajaxStart(ajaxStartHandler);
86
$(document).ajaxStart(ajaxStartHandler);
95
 
87
 
96
function doAjaxRequestWithParamsHandler(urlString, httpType, params, callback_function) {
88
function doAjaxRequestWithParamsHandler(urlString, httpType, params, callback_function) {
Line 249... Line 241...
249
function doAjaxPostDownload(urlString, data, fileName, callback) {
241
function doAjaxPostDownload(urlString, data, fileName, callback) {
250
    doAjaxDownload(urlString, "POST", data, fileName, callback);
242
    doAjaxDownload(urlString, "POST", data, fileName, callback);
251
}
243
}
252
 
244
 
253
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
245
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
254
    xhttp = new XMLHttpRequest();
246
    const xhttp = new XMLHttpRequest();
255
    if (typeof loaderDialogObj != "undefined")
247
    if (typeof loaderDialogObj !== "undefined") {
256
        loaderDialogObj.modal('show');
248
        loaderDialogObj.modal('show');
-
 
249
    }
257
    xhttp.onreadystatechange = function () {
250
    xhttp.onreadystatechange = function () {
258
        var a;
-
 
259
        if (xhttp.readyState === 2) {
251
        if (xhttp.readyState === 2) {
260
            if (xhttp.status == 200) {
-
 
261
                xhttp.responseType = "blob";
-
 
262
            } else {
-
 
263
                xhttp.responseType = "text";
-
 
264
            }
-
 
265
        } else if (xhttp.readyState === 4 && xhttp.status === 200) {
252
            xhttp.responseType = xhttp.status === 200 ? "blob" : "text";
266
            // Trick for making downloadable link
-
 
267
            if (typeof loaderDialogObj != "undefined") {
-
 
268
                loaderDialogObj.modal('hide');
-
 
269
                // $('div.modal-backdrop.fade').remove();
-
 
270
            }
-
 
271
 
-
 
272
            a = document.createElement('a');
-
 
273
            a.href = window.URL.createObjectURL(xhttp.response);
-
 
274
            // Give filename you wish to download
-
 
275
            a.download = fileName;
-
 
276
            a.style.display = 'none';
-
 
277
            document.body.appendChild(a);
-
 
278
            a.click();
-
 
279
        } else if (xhttp.readyState == 4 && xhttp.status === 400) {
253
        } else if (xhttp.readyState === 4) {
280
            if (typeof loaderDialogObj != "undefined") {
254
            if (typeof loaderDialogObj !== "undefined") {
281
                loaderDialogObj.modal('hide');
255
                loaderDialogObj.modal('hide');
282
                // $('div.modal-backdrop.fade').remove();
-
 
283
            }
256
            }
284
            badRequestAlert(xhttp);
257
            if (xhttp.status === 200) {
-
 
258
                const a = document.createElement('a');
285
        } else if (xhttp.readyState == 4 && xhttp.status === 500) {
259
                a.href = window.URL.createObjectURL(xhttp.response);
286
            if (typeof loaderDialogObj != "undefined") {
260
                a.download = fileName;
-
 
261
                a.style.display = 'none';
287
                loaderDialogObj.modal('hide');
262
                document.body.appendChild(a);
-
 
263
                a.click();
288
                // $('div.modal-backdrop.fade').remove();
264
                document.body.removeChild(a);
-
 
265
                window.URL.revokeObjectURL(a.href);
-
 
266
            } else if (xhttp.status === 400) {
-
 
267
                badRequestAlert(xhttp);
-
 
268
            } else if (xhttp.status === 500) {
-
 
269
                internalServerErrorAlert(xhttp);
289
            }
270
            }
290
            internalServerErrorAlert(xhttp);
-
 
291
        }
271
        }
292
    };
272
    };
293
    // Post data to URL which handles post request
273
    // Post data to URL which handles post request
294
    xhttp.open(httpType, urlString);
274
    xhttp.open(httpType, urlString);
295
 
275
 
296
    // if (IdempotencyKey) {
276
    // if (IdempotencyKey) {
297
    //     xhttp.setRequestHeader("IdempotencyKey", IdempotencyKey);
277
    //     xhttp.setRequestHeader("IdempotencyKey", IdempotencyKey);
298
    // }
278
    // }
299
 
279
 
300
    if (httpType == "POST") {
280
    if (httpType === "POST") {
301
        xhttp.setRequestHeader("Content-Type", "application/json");
281
        xhttp.setRequestHeader("Content-Type", "application/json");
302
    }
282
    }
303
    // You should set responseType as blob for binary responses
283
    // You should set responseType as blob for binary responses
304
    // xhttp.responseType = 'blob';
284
    // xhttp.responseType = 'blob';
305
    xhttp.send(data);
285
    xhttp.send(data);
Line 703... Line 683...
703
                    });
683
                    });
704
                    anySelected = true;
684
                    anySelected = true;
705
                }
685
                }
706
            });
686
            });
707
            if (anySelected && confirm("Are you sure want to notify?")) {
687
            if (anySelected && confirm("Are you sure want to notify?")) {
708
                $that = $(this);
688
                const $that = $(this);
709
                callback(itemQty, function () {
689
                callback(itemQty, function () {
710
                    $that.off('click');
690
                    $that.off('click');
711
                    modalObj.hide();
691
                    modalObj.hide();
712
                });
692
                });
713
            } else {
693
            } else {
714
                alert("Pls mention quantity");
694
                alert("Please mention quantity");
715
            }
695
            }
716
        });
696
        });
717
    });
697
    });
718
}
698
}
719
 
699
 
Line 726... Line 706...
726
        callback: callback,
706
        callback: callback,
727
        inputType: 'checkbox',
707
        inputType: 'checkbox',
728
    }
708
    }
729
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
709
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
730
        + catalogId + "&itemId=" + itemId, function (response) {
710
        + catalogId + "&itemId=" + itemId, function (response) {
731
        coloredItems = JSON.parse(response);
711
        const coloredItems = JSON.parse(response);
732
        inputOptions = [{
712
        const inputOptions = [{
733
            text: "All",
713
            text: "All",
734
            value: "0",
714
            value: "0",
735
            onclick: "toggleAll('itemIds')"
715
            onclick: "toggleAll('itemIds')"
736
        }];
716
        }];
737
        coloredItems.forEach(function (item) {
717
        coloredItems.forEach(function (item) {
Line 740... Line 720...
740
                value: item.id,
720
                value: item.id,
741
                selected: item.active
721
                selected: item.active
742
            });
722
            });
743
        });
723
        });
744
        bootBoxObj['inputOptions'] = inputOptions;
724
        bootBoxObj['inputOptions'] = inputOptions;
745
        promptObj = bootbox.prompt(bootBoxObj);
725
        const promptObj = bootbox.prompt(bootBoxObj);
746
        promptObj.modal('show')
726
        promptObj.modal('show');
747
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
727
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
748
            function (index, checkbox) {
728
            function (index, checkbox) {
749
                checkbox.checked = coloredItems[index].active;
729
                checkbox.checked = coloredItems[index].active;
750
            });
730
            });
751
    });
731
    });
752
}
732
}
753
 
733
 
754
function getHotdealsForItems(catalogId, itemId, description, callback) {
734
function getHotdealsForItems(catalogId, itemId, description, callback) {
755
    bootBoxObj = {
735
    const bootBoxObj = {
756
        size: "small",
736
        size: "small",
757
        className: "item-wrapper",
737
        className: "item-wrapper",
758
        title: description,
738
        title: description,
759
        callback: callback,
739
        callback: callback,
760
        inputType: 'checkbox',
740
        inputType: 'checkbox',
761
    }
741
    };
762
    doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
742
    doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
763
        + catalogId + "&itemId=" + itemId, function (response) {
743
        + catalogId + "&itemId=" + itemId, function (response) {
764
        coloredItems = JSON.parse(response);
744
        const coloredItems = JSON.parse(response);
765
        inputOptions = [{
745
        const inputOptions = [{
766
            text: "All",
746
            text: "All",
767
            value: "0",
747
            value: "0",
768
            onclick: "toggleAll('itemIds')"
748
            onclick: "toggleAll('itemIds')"
769
        }];
749
        }];
770
        coloredItems.forEach(function (item) {
750
        coloredItems.forEach(function (item) {
Line 773... Line 753...
773
                value: item.id,
753
                value: item.id,
774
                selected: item.hotDeals
754
                selected: item.hotDeals
775
            });
755
            });
776
        });
756
        });
777
        bootBoxObj['inputOptions'] = inputOptions;
757
        bootBoxObj['inputOptions'] = inputOptions;
778
        promptObj = bootbox.prompt(bootBoxObj);
758
        const promptObj = bootbox.prompt(bootBoxObj);
779
        promptObj.modal('show')
759
        promptObj.modal('show');
780
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
760
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
781
            function (index, checkbox) {
761
            function (index, checkbox) {
782
                checkbox.checked = coloredItems[index].hotDeals;
762
                checkbox.checked = coloredItems[index].hotDeals;
783
            });
763
            });
784
    });
764
    });
785
}
765
}
786
 
766
 
787
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
767
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
788
    function () {
768
    function () {
789
        if (this.value == "0") {
769
        if (this.value === "0") {
790
            $(this).closest('.item-wrapper').find("input[type='checkbox']")
770
            $(this).closest('.item-wrapper').find("input[type='checkbox']")
791
                .slice(1).prop('checked', $(this).prop('checked'));
771
                .slice(1).prop('checked', $(this).prop('checked'));
792
        }
772
        }
793
    });
773
    });
794
 
774
 
795
function getItemAheadOptions(jqElement, anyColor, callback) {
775
function getItemAheadOptions(jqElement, anyColor, callback) {
796
    console.log(anyColor)
-
 
797
    jqElement.typeahead('destroy').typeahead({
776
    jqElement.typeahead('destroy').typeahead({
798
        source: function (q, process) {
777
        source: function (q, process) {
799
            if (q.length >= 3) {
778
            if (q.length >= 3) {
800
                return $.ajax(context + "/item?anyColor=" + anyColor, {
779
                return $.ajax(context + "/item?anyColor=" + anyColor, {
801
                    global: false,
780
                    global: false,
Line 804... Line 783...
804
                    },
783
                    },
805
                    headers: {
784
                    headers: {
806
                        'IdempotencyKey': IdempotencyKey
785
                        'IdempotencyKey': IdempotencyKey
807
                    },
786
                    },
808
                    success: function (data) {
787
                    success: function (data) {
809
                        //IdempotencyKey = uuidv4();
-
 
810
                        queryData = JSON.parse(data);
788
                        const queryData = JSON.parse(data);
811
                        process(queryData);
789
                        process(queryData);
812
                    },
790
                    },
813
                });
791
                });
814
            }
792
            }
815
        },
793
        },
Line 835... Line 813...
835
                    },
813
                    },
836
                    headers: {
814
                    headers: {
837
                        'IdempotencyKey': IdempotencyKey
815
                        'IdempotencyKey': IdempotencyKey
838
                    },
816
                    },
839
                    success: function (data) {
817
                    success: function (data) {
840
                        //IdempotencyKey = uuidv4();
-
 
841
                        queryData = JSON.parse(data);
818
                        const queryData = JSON.parse(data);
842
                        process(queryData);
819
                        process(queryData);
843
                    },
820
                    },
844
                });
821
                });
845
            }
822
            }
846
        },
823
        },
Line 865... Line 842...
865
                        },
842
                        },
866
                        headers: {
843
                        headers: {
867
                            'IdempotencyKey': IdempotencyKey
844
                            'IdempotencyKey': IdempotencyKey
868
                        },
845
                        },
869
                        success: function (data) {
846
                        success: function (data) {
870
                            //IdempotencyKey = uuidv4();
-
 
871
                            queryData = JSON.parse(data);
847
                            const queryData = JSON.parse(data);
872
                            process(queryData);
848
                            process(queryData);
873
                        },
849
                        },
874
                    });
850
                    });
875
                }
851
                }
876
            },
852
            },
Line 1223... Line 1199...
1223
    $("#main-content").html(html);
1199
    $("#main-content").html(html);
1224
}
1200
}
1225
 
1201
 
1226
 
1202
 
1227
function objectifyForm(formArray) {
1203
function objectifyForm(formArray) {
1228
    //serialize data function
-
 
1229
    console.log('Row form  data ', formArray);
-
 
1230
    var returnArray = {};
1204
    const returnArray = {};
1231
    for (var i = 0; i < formArray.length; i++) {
1205
    for (let i = 0; i < formArray.length; i++) {
1232
        var name = formArray[i]['name'];
1206
        const name = formArray[i]['name'];
1233
        var value = formArray[i]['value'];
1207
        const value = formArray[i]['value'];
1234
        if (typeof returnArray[name] === 'undefined') {
1208
        if (typeof returnArray[name] === 'undefined') {
1235
            returnArray[name] = value.trim();
1209
            returnArray[name] = value.trim();
1236
        } else if (typeof returnArray[name] === 'object') {
1210
        } else if (Array.isArray(returnArray[name])) {
1237
            returnArray[name].push(value);
1211
            returnArray[name].push(value);
1238
        } else {
1212
        } else {
1239
            var a = returnArray[name];
-
 
1240
            returnArray[name] = [returnArray[name]];
1213
            returnArray[name] = [returnArray[name], value];
1241
            a.push(value);
-
 
1242
            returnArray[name] = a;
-
 
1243
        }
1214
        }
1244
    }
1215
    }
1245
    return returnArray;
1216
    return returnArray;
1246
}
1217
}
1247
 
1218