0

I have this function which is called after the button was clicked, I would like to disable the button until the alert comes up and to show a Loading Spin while it is not finished processing the feed. This is my function code:

jQuery.noConflict();

function generateFeed(feedId) {
    jQuery.ajax({
        url: "<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/index/generate/') ?>", 
        method: 'GET', 
        data: {FeedId : feedId}
    }).success(function() {
        alert ('Generation Successful!');
    }).error(function() {
        alert ('Generation Failed!');
    });

}

And the button is this:

$block->addButton('Generate', array(
'label'     => Mage::helper('adminhtml')->__('Generate Feed'),
'onclick'   => "generateFeed(" . $blockID . ")",
'class'     => 'go',
'index' => 'generate',
'name' => 'generate'
), -1);
1

Change Js function to:

function generateFeed(feedId, buttonId) {
    jQuery("#"+buttonId).attr('disabled', 'disabled');    
    jQuery("#"+buttonId).addClass('disabled');
    jQuery("#loading-mask").show();
    jQuery.ajax({
        url: "<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/index/generate/') ?>", 
        method: 'GET', 
        data: {FeedId : feedId}
    }).success(function() {
        alert ('Generation Successful!');
        jQuery("#"+buttonId).attr('disabled', 'false');
        jQuery("#"+buttonId).removeClass('disabled');
        jQuery("#loading-mask").hide();
    }).error(function() {
        alert ('Generation Failed!');
        jQuery("#"+buttonId).attr('disabled', 'false');
        jQuery("#"+buttonId).removeClass('disabled');
        jQuery("#loading-mask").hide();
    });

}

Change button to:

$block->addButton('Generate', array(
'label'     => Mage::helper('adminhtml')->__('Generate Feed'),
'onclick'   => "generateFeed(" . $blockID . ", this.id)",
'class'     => 'go',
'index' => 'generate',
'name' => 'generate'
), -1);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.