Subversion Repositories SmartDukaan

Rev

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

Rev 35340 Rev 35360
Line -... Line 1...
-
 
1
function loadPendingTrialForms(domId) {
-
 
2
    doGetAjaxRequestHandler(context + "/trial/pending", function (response) {
-
 
3
        $('#' + domId).html(response);
-
 
4
    });
-
 
5
}
-
 
6
 
1
$(function () {
7
$(function () {
2
    $(document).on('click', ".trial_users", function () {
8
    $(document).on('click', ".trial_users", function () {
3
        loadPendingTrialForms("main-content");
9
        loadPendingTrialForms("main-content");
4
    });
10
    });
5
    $(document).on('click', ".verified_trial_users", function () {
11
    $(document).on('click', ".verified_trial_users", function () {
6
        loadVerifiedTrialForms("main-content");
12
        loadVerifiedTrialForms("main-content");
7
    });
13
    });
8
 
14
 
9
    $(document).on('click', ".mk_trial_create", function () {
15
    $(document).on('click', ".mk_trial_create", function () {
10
        let trialFormId = $(this.closest('tr')).data('id');
16
        let trialFormId = $(this).closest('tr').data('id');
11
    });
17
    });
12
 
18
 
13
    $(document).on('click', ".mk_trial_cancel", function () {
19
    $(document).on('click', ".mk_trial_cancel", function () {
14
        let trialFormId = $(this.closest('tr')).data('id');
20
        let trialFormId = $(this).closest('tr').data('id');
15
        cancelTrialForm(trialFormId);
21
        cancelTrialForm(trialFormId);
16
    });
22
    });
-
 
23
    $(document).on('click', ".approve-trial", function () {
-
 
24
        let trialFormId = $(this).closest('tr').data('id');
-
 
25
        approveTrialForm(trialFormId);
-
 
26
    });
-
 
27
    $(document).on('click', ".converted", function () {
-
 
28
        let trialFormId = $(this).closest('tr').data('id');
-
 
29
        convertedToFranchise(trialFormId);
-
 
30
    });
17
 
31
 
18
    function loadPendingTrialForms(domId) {
-
 
19
        doGetAjaxRequestHandler(context + "/trial/pending", function (response) {
-
 
20
            $('#' + domId).html(response);
-
 
21
        });
-
 
22
    }
-
 
23
 
32
 
24
    function loadVerifiedTrialForms(domId) {
33
    function loadVerifiedTrialForms(domId) {
25
        doGetAjaxRequestHandler(context + "/trial/verified", function (response) {
34
        doGetAjaxRequestHandler(context + "/trial/verified", function (response) {
26
            $('#' + domId).html(response);
35
            $('#' + domId).html(response);
27
        });
36
        });
Line 35... Line 44...
35
 
44
 
36
    function cancelTrialForm(trialFormId) {
45
    function cancelTrialForm(trialFormId) {
37
        if (confirm("Are you sure you want to cancel this trial?")) {
46
        if (confirm("Are you sure you want to cancel this trial?")) {
38
            doPostAjaxRequestHandler(`${context}/trial/cancel/${trialFormId}`, function (response) {
47
            doPostAjaxRequestHandler(`${context}/trial/cancel/${trialFormId}`, function (response) {
39
                if (response == "true") {
48
                if (response == "true") {
-
 
49
                    $('.modal-backdrop').remove();
-
 
50
                    $('body').removeClass('modal-open');
-
 
51
                    $('body').css('padding-right', '');
40
                    loadPendingTrialForms("main-content");
52
                    loadPendingTrialForms("main-content");
41
                }
53
                }
42
            });
54
            });
43
        }
55
        }
44
    }
56
    }
-
 
57
 
-
 
58
    function approveTrialForm(trialFormId) {
-
 
59
        if (confirm("Are you sure you want to approve this trial?")) {
-
 
60
            doPostAjaxRequestHandler(`${context}/trial/approve/${trialFormId}`, function (response) {
-
 
61
                if (response == "true") {
-
 
62
                    $('.modal-backdrop').remove();
-
 
63
                    $('body').removeClass('modal-open');
-
 
64
                    $('body').css('padding-right', '');
-
 
65
                    loadVerifiedTrialForms("main-content");
-
 
66
                }
-
 
67
            });
-
 
68
        }
-
 
69
    }
-
 
70
 
-
 
71
    function convertedToFranchise(trialFormId) {
-
 
72
        if (confirm("Are you sure you want to mark as converted?")) {
-
 
73
            doPostAjaxRequestHandler(`${context}/trial/convertToFranchise/${trialFormId}`, function (response) {
-
 
74
                if (response == "true") {
-
 
75
                    $('.modal-backdrop').remove();
-
 
76
                    $('body').removeClass('modal-open');
-
 
77
                    $('body').css('padding-right', '');
-
 
78
                    loadVerifiedTrialForms("main-content");
-
 
79
                }
-
 
80
            });
-
 
81
        }
-
 
82
    }
45
});
83
});
46
$(document).on('click', '.openBrandModal', function () {
84
$(document).on('click', '.openBrandModal', function () {
47
    let trialFormId = $(this).data('id');
85
    let trialFormId = $(this).data('id');
48
    console.log("trialFormId sent:", trialFormId);
86
    console.log("trialFormId sent:", trialFormId);
49
    $('#brandPotentialForm input[name="trialFormId"]').val(trialFormId);
87
    $('#brandPotentialForm input[name="trialFormId"]').val(trialFormId);
50
});
88
});
-
 
89
$(document).on('click', '.openUserBrandPotential', function () {
-
 
90
    let trialFormId = $(this).data('id');
-
 
91
    loadUserBrandPotential(trialFormId);
-
 
92
});
51
 
93
 
52
 
94
 
53
function saveBrandPotential() {
95
function saveBrandPotential() {
54
 
96
 
55
    let params = {};
97
    let params = {};
Line 72... Line 114...
72
 
114
 
73
    doPostAjaxRequestWithParamsHandler(
115
    doPostAjaxRequestWithParamsHandler(
74
        context + "/trial/brand-Potential",
116
        context + "/trial/brand-Potential",
75
        params,
117
        params,
76
        function (response) {
118
        function (response) {
-
 
119
            $('#brandPotentialModal').one('hidden.bs.modal', function () {
-
 
120
                $('.modal-backdrop').remove();
-
 
121
                $('body').removeClass('modal-open');
-
 
122
                $('body').css('padding-right', '');
-
 
123
                loadPendingTrialForms("main-content");
-
 
124
                alert("Verified - Brand Potential Saved Successfully");
-
 
125
            });
77
            $('#brandPotentialModal').modal('hide');
126
            $('#brandPotentialModal').modal('hide');
78
            loadPendingTrialForms("main-content");
-
 
79
            alert("Verifed - Brand Potential Saved Successfully");
-
 
80
        }
127
        }
81
    );
128
    );
82
 
129
 
83
}
130
}
84
 
131
 
-
 
132
function saveAsmBm() {
-
 
133
 
-
 
134
    let params = {};
-
 
135
 
-
 
136
    params["trialFormId"] = $('#brandPotentialForm input[name="trialFormId"]').val();
-
 
137
 
-
 
138
    let abm = $('#asmBmForm select[name="asm"]').val();
-
 
139
    let bm = $('#asmBmForm select[name="bm"]').val();
-
 
140
 
-
 
141
    if (abm && bm) {
-
 
142
        params["asmId"] = abm;
-
 
143
        params["bmId"] = bm;
-
 
144
    } else {
-
 
145
        alert("Please select both ASM and BM");
-
 
146
        return;
-
 
147
    }
-
 
148
 
-
 
149
    console.log("PARAMS SENT:", params);
-
 
150
 
-
 
151
    doPostAjaxRequestWithParamsHandler(
-
 
152
        context + "/trial/asm-bm",
-
 
153
        params,
-
 
154
        function (response) {
-
 
155
            alert("ASM BM Saved Successfully");
-
 
156
        }
-
 
157
    );
-
 
158
}
-
 
159
 
-
 
160
function loadUserBrandPotential(trialFormId) {
-
 
161
 
-
 
162
    doGetAjaxRequestHandler(
-
 
163
        context + "/trial/userBrandPotential/" + trialFormId,
-
 
164
        function (res) {
-
 
165
 
-
 
166
            console.log("RAW RESPONSE:", res);
-
 
167
 
-
 
168
            // Ensure JSON
-
 
169
            if (typeof res === "string") {
-
 
170
                try {
-
 
171
                    res = JSON.parse(res);
-
 
172
                } catch (e) {
-
 
173
                    console.error("JSON parse failed:", e);
-
 
174
                    return;
-
 
175
                }
-
 
176
            }
-
 
177
 
-
 
178
            $('#brandPotentialRows').empty();
-
 
179
 
-
 
180
            let data = res.response;
-
 
181
 
-
 
182
            if (!Array.isArray(data) || data.length === 0) {
-
 
183
                $('#brandPotentialRows').append(`
-
 
184
                    <tr>
-
 
185
                        <td colspan="4" class="text-center">
-
 
186
                            No Brand Potential Data Available
-
 
187
                        </td>
-
 
188
                    </tr>
-
 
189
                `);
-
 
190
                $('#brandPotentialModal').modal('show');
-
 
191
                return;
-
 
192
            }
-
 
193
 
-
 
194
            data.forEach(function (item) {
-
 
195
                let createdDate = formatDateArray(item.createdAt);
-
 
196
 
-
 
197
                let rowHtml = `
-
 
198
                    <tr>
-
 
199
                        <td>${item.trialFormId}</td>
-
 
200
                        <td>${item.brandName}</td>
-
 
201
                        <td>${item.potential}</td>
-
 
202
                        <td>${createdDate}</td>
-
 
203
                    </tr>
-
 
204
                `;
-
 
205
 
-
 
206
                $('#brandPotentialRows').append(rowHtml);
-
 
207
            });
-
 
208
 
-
 
209
            $('#brandPotentialModal').modal('show');
-
 
210
        }
-
 
211
    );
-
 
212
}
-
 
213
 
-
 
214
function formatDateArray(arr) {
-
 
215
    if (!arr || arr.length < 6) return "";
-
 
216
 
-
 
217
    let year = arr[0];
-
 
218
    let month = arr[1];
-
 
219
    let day = arr[2];
-
 
220
    let hour = arr[3];
-
 
221
    let min = arr[4];
-
 
222
    let sec = arr[5];
-
 
223
 
-
 
224
    return `${year}-${pad(month)}-${pad(day)} ${pad(hour)}:${pad(min)}:${pad(sec)}`;
-
 
225
}
-
 
226
 
-
 
227
function pad(v) {
-
 
228
    return (v < 10 ? "0" : "") + v;
-
 
229
}