kevinlinxp
12/31/2016 - 9:41 AM

jQuery:ajax

jQuery:ajax

// Ajax Delete
var deleteDeployment = function (deploymentId, name, id) {

    if (!window.confirm('About to delete process definition "' + name + '", id: ' + id + ', confirm operation?')) {
        return;
    }

    jQuery.ajax('${deleteURLPrefix}' + deploymentId, {
        type: "DELETE",
        dataType: "json",
        success: function (data, textStatus, jqXHR) {
            alert(data['msg']);
            jQuery('#deployment-' + data['deploymentId']).fadeOut(800, function () {
                $(this).remove();
            })
            // jQuery('#deployment-' + data['deploymentId'] + ' td').animate({'line-height': 0}, 800, 'swing', function () {
            //     jQuery('#deployment-' + data['deploymentId']).remove();
            // });
        },
        error: function (/*jqXHR*/ jqXHR, /*String*/ textStatus, /*String*/ errorThrown) {
            alert('Sorry, an server error happened', errorThrown);
        }
    });
}

// Ajax get to generate form fields
var generateMeterInputs = function (data) {
    data.forEach(function(meterDetail, $index){
        var element = $('<div class="field required meterDetail"></div>').insertBefore('#btnSubmit');
        element.append($('<label>Meter Reading for #' + meterDetail.serial + '</label>'));
        element.append($('<input name="meterDetailList['+$index+'].reading" type="text" class="medsmall" />'));
        element.append($('<input name="meterDetailList['+$index+'].id" type="hidden" class="medsmall" value="' + meterDetail.id + '"/>'));
    });
}


$('#accountFromDropdown').on('change', function($event){
    console.log($event);
    var selectedValue = $event.target.value;
    if (selectedValue) {
        $.get('${metersURL}', {'accountId': selectedValue}, function (data, textStatus, jqXHR) {
            clearMetersInput();
            generateMeterInputs(data);
        });
    } else {
        clearMetersInput();
    }
});