display update and cancel button after clicking edit button

we have marketplace site, where each seller/vendor have their own account. they can see list of products. sku ,qty in their account.

now its displaying like this : image 1 =http://prnt.sc/8wm25g

a)if we click on edit button, than only “Update” & “cancel” button should visible and “Edit” button should hide.

b)Later if we click on “cancel” button, than “Update & cancel” button should hide and “Edit” button should visible.

<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>
      <input type = "text" id = "qty_<?php echo $products->getId(); ?>" name = "qty" value = "<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>" style = "display:none"/>



    <span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
            <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
        </span>  

        <br/>
        <button id="update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateField('<?php echo $products->getId(); ?>'); return false;" >
            <span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
        </button>

        <button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;">
            <span><span><?php echo $helper->__('Cancel') ?></span></span>
        </button>

    <script type = "text/javascript" >

            var $wk_jq = jQuery.noConflict();

            function hideReset(product_id) {
                var editLink = "#edit_link_"+ product_id;
                var updateButton = "#update_button_"+ product_id;
                var resetButton = "#reset_button"+ product_id;

                $wk_jq(editLink).show();
                $wk_jq(updateButton).hide();
                $wk_jq(resetButton).hide();
            }
             function showField(product_id)
            {
                var qtyId = '#qty_'+ product_id;

                var editLink = "#edit_link_"+ product_id;
                var updateButton = "#update_button_"+ product_id;
                var resetButton = "#reset_button"+ product_id;

                $wk_jq(qtyId).toggle()

                $wk_jq(editLink).hide();
                $wk_jq(updateButton).show();
                $wk_jq(resetButton).show();

                $qty = $wk_jq(qtyId).val();


            }
            function updateField(product_id)
            {
                var qtyId = '#qty_'+ product_id;

                var editLink = "#edit_link_"+ product_id;
                var updateButton = "#update_button_"+ product_id;
                var resetButton = "#reset_button"+ product_id;
            var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';

                $wk_jq(qtyId).toggle()

                $wk_jq(editLink).hide();
                $wk_jq(updateButton).show();
                $wk_jq(resetButton).show();

                $qty = $wk_jq(qtyId).val();

                new Ajax.Request(url, {
                    method: 'post',
                    parameters: {id: product_id, qty: $qty},
            onComplete: function (transport) {


                    alert(transport.responseText);
            $wk_jq(qtyId).setValue($qty);

                }
                });
            }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s