Subversion Repositories SmartDukaan

Rev

Rev 34405 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
34387 vikas.jang 1
 
2
function initializeSelect(selector, type='catalogs') {
3
    if (type === 'catalogs') {
4
        $(selector).multiselect('destroy');
5
        $(selector).multiselect({
6
            includeSelectAllOption: false,
7
            multiple: false,
8
            maxHeight: 200,
9
            buttonWidth: '100%',
10
            numberDisplayed: 1,
11
            nonSelectedText: '-- Select One --',
12
            nSelectedText: ' - Selected',
13
            enableFiltering: true,
14
            enableCaseInsensitiveFiltering: true
15
        });
16
    } else {
17
        $(selector).select2({
18
            placeholder: "Select or add new",
19
            tags: true,
20
            createTag: params => ({ id: params.term, text: params.term, newOption: true }),
21
            templateResult: data => data.newOption ? $('<span class="new-option">Add: ' + data.text + '</span>') : data.text,
22
        });
23
    }
24
}
25
 
26
function validateRequiredFields(fields) {
27
    let isValid = true;
28
    fields.each(function () {
29
        if (!$(this).val()) {
30
            isValid = false;
31
            $(this).addClass('is-invalid');
32
        } else {
33
            $(this).removeClass('is-invalid');
34
        }
35
    });
36
    return isValid;
37
}
38
 
39
$(document).on('click', ".liquidation-list", function () {
40
    doGetAjaxRequestHandler(context + "/liquidation", (response) => {
41
            $('#main-content').html(response);
42
            initializeSelect('#warehouseId, #catalogId, #status')
43
            $('#liquidation-table').DataTable();
44
 
45
        });
46
});
47
 
48
$(document).on('click', ".save-liquidation", function () {
49
    const params = serializeFormToJson('form#biddingForm');
50
    doAjaxRequestWithJsonHandler(context + "/liquidation", "POST", JSON.stringify(params), (response) => {
51
        if (response) {
52
            $('.liquidation-list').trigger('click');
53
            $('#manageLiquidationModal').modal('hide');
54
            alert("Saved successfully");
55
        } else {
56
            alert("Something went wrong!");
57
        }
58
    });
59
});
60
 
61
$(document).on('click', ".delete-liquidation", function() {
62
    const id = parseInt($(this).data('id')) || 0;
63
    if (confirm("Are you sure you want to delete this record")) {
64
        if (id > 0) {
65
            doDeleteAjaxRequestHandler(`${context}/liquidation/${id}`, (response) => {
66
                if (response) {
67
                    $(this).parent('td').closest('tr').remove();
68
                    $('.liquidation-list').trigger('click');
69
                    alert("Deleted successfully");
70
                } else {
71
                    alert("Something went wrong!");
72
                }
73
            });
74
        } else {
75
            $(this).parent('td').closest('tr').remove();
76
        }
77
    }
78
});
79
 
80
 
81
$(document).on('change', "#warehouseId", function() {
82
    doAjaxRequestWithJsonHandler(`${context}/liquidation/warehouse/${$(this).val()}`, "GET", null, (response) => {
83
        if (response) {
84
            $('#catalogId').html("");
85
            let options = `<option value="">Select</option>`;
86
            if (response.products.length){
87
                response.products.forEach(product => {
88
                    options+= `<option value="${product.catalogId}">${product.brand + ' ' +product.modelNumber + ' ('+product.shaholicNetAvailability+')'}</option>`;
89
                });
90
            }
91
            $('#catalogId').html(options);
92
            initializeSelect('#catalogId');
93
            console.log("Warehouse response: ",response)
94
        } else {
95
            alert("Something went wrong!");
96
        }
97
    });
98
    loadCatalogOptions($(this).val(), 'select#super_catalog_name', 'superCatalogs');
99
});
100
 
101
function editLiquidation(id) {
102
    doGetAjaxRequestHandler(`${context}/liquidation/${id}`, (response) => {
103
        if (response){
104
            $('#manageLiquidationModal').modal('show');
105
            let names = Object.keys(response);
106
            if (names.length){
107
                names.forEach(name => {
108
                    console.log("map",$(`#${name}`).val(response[name]))
109
                    $(`#${name}`).val(response[name]);
110
                })
111
            }
112
        }
113
        //initializeSelect('#warehouseId, #catalogId, #status')
114
    });
115
}
116
 
117
function deleteLiquidation(id) {
118
 if (confirm("Are you sure want to delete this?")){
119
     console.log(`${id} Call delete method here`);
120
 }
121
}