Subversion Repositories SmartDukaan

Rev

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

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