Subversion Repositories SmartDukaan

Rev

Rev 29262 | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(document).on('click', '.send-notification', function() {

                loadNotificationPanel("main-content");
        });

        $(document).on('click', '.create-notification-button',
                                        function() {
                                                console.log(localStorage.getItem("notifyDocument"));
                                                var userIds = $('#fofo-users').val().concat(
                                                                $('#internal-users').val());
                                                console.log("multipleUsers", userIds);
                                                
                                                var stateIds = $('#state-users').val();
                                                
                                                console.log("stateIds"+stateIds);

                                                var campaignName = $('input[name="campaignName"]')
                                                                .val();
                                                var title = $('input[name="title"]').val();
                                                var message = $('input[name="message"]').val();
                                                var imageUrl = $('input[name="imageUrl"]').val();
                                                var type = $('#type').val();
                                                var expiryTime = $('#expireSat').val();

                                                var val = $("#selectedUrl").val();
                                                console.log(val);
                                                if (val == "other") {
                                                        url = $('input[name="url"]').val();
                                                } else {
                                                        url = val;
                                                }

                                                var messageType = $('#messageType').val();

                                                $('#showImage').on('change', function() {
                                                        this.value = this.checked ? true : false;
                                                }).change();

                                                if (campaignName === ""
                                                                && title === "" && message === ""
                                                                && expiryTime === "" && type === ""
                                                                && messageType === "") {
                                                        alert("Field can't be empty");
                                                        return;
                                                }
                                        
                                                if (campaignName === "") {
                                                        alert("Campaign name is required");
                                                        return;
                                                }
                                                if (title === "") {
                                                        alert("Title Name is required");
                                                        return;
                                                }
                                                if (message === "") {
                                                        alert("Message is required");
                                                        return;
                                                }
                                                if (expiryTime === "") {
                                                        alert("ExpiryTime is required");
                                                        return;
                                                }

                                                if (messageType === null) {
                                                        alert("message type is required");
                                                        return;
                                                }
                                                if (type === "") {
                                                        alert("type is required");
                                                        return;
                                                }
                                                if (type === "url") {
                                                        if (url === "") {
                                                                alert("url is required");
                                                                return;
                                                        }

                                                }

                                                var notificationData = {};
                                                
                                                notificationData['stateIds'] = $('#state-users').val();
                                                
                                                notificationData['userIds'] = $('#fofo-users').val()
                                                                .concat($('#internal-users').val());
                                                notificationData['campaignName'] = $(
                                                                'input[name="campaignName"]').val();
                                                notificationData['title'] = $('input[name="title"]')
                                                                .val();
                                                notificationData['message'] = $('#message').val();
                                                notificationData['imageUrl'] = $(
                                                                'input[name="imageUrl"]').val();
                                                notificationData['type'] = $('#type').val();
                                                notificationData['url'] = url;
                                                notificationData['expiresat'] = getDatesFromPicker('input[name="dateTime"]').startDate;
                                                notificationData['showImage'] = $(
                                                        'input[name="showImage"]').val();
                                                notificationData['documentId'] = localStorage
                                                                .getItem("notifyDocument");
                                                notificationData['messageType'] = $('#messageType')
                                                                .val();
                                                console.log(notificationData)

                                                if (confirm("Are you sure you want to send notification!") == true) {
                                                        doPostAjaxRequestWithJsonHandler(context
                                                                        + "/sendNotification", JSON
                                                                        .stringify(notificationData), function(
                                                                        response) {
                                                                if (response == 'true') {
                                                                        alert("successfully send");
                                                                        loadNotificationPanel("main-content");
                                                                        localStorage.removeItem("notifyDocument");
                                                                }
                                                        });

                                                        return false;
                                                }

                                        });

});

function loadNotificationPanel(domId) {
        localStorage.removeItem("notifyDocument");
        doGetAjaxRequestHandler(context + "/sendNotificationPanel", function(
                        response) {
                $('#' + domId).html(response);
                $("#url").hide();

        });

}

$(document)
                .on(
                                'input',
                                '#notifyDocument',
                                function() {
                                        if (confirm('Document has been selected, Do you want to upload ?')) {
                                                var fileSelector = $('#notifyDocument')[0];
                                                if (fileSelector != undefined
                                                                && fileSelector.files[0] != undefined) {
                                                        var url = context  + '/document-upload';

                                                        console.log(url);
                                                        var file = this.files[0];
                                                        doAjaxUploadRequestHandler(
                                                                        url,
                                                                        'POST',
                                                                        file,
                                                                        function(response) {
                                                                                console.log(response);
                                                                                var documentId = response.response.document_id;
                                                                                console.log("documentId : "
                                                                                                + documentId);
                                                                                localStorage.setItem("notifyDocument",
                                                                                                documentId);
                                                                                // $('#retailerDocument').attr("documentId",
                                                                                // localStorage.getItem("retailerDocument"));
                                                                                // return
                                                                                // documentId;
                                                                        });
                                                        // alert("Retailer Shop Document
                                                        // is required");
                                                }
                                        } else {
                                                // Do nothing!
                                        }
                                });

function changeUrl() {
        var val = $("#selectedUrl").val();
        console.log(val);
        if (val == "other") {
                $("#url").show();
        } else {
                $("#url").hide();
        }

}