Example #1
0
 public function _beforeToHtml()
 {
     $block_1 = new Mage_Core_Block_Text();
     $block_1->setText('The first sentence.');
     $this->setChild('the_first', $block_1);
     $block_2 = new Mage_Core_Block_Text();
     $block_2->setText('The second sentence .');
     $this->setChild('the_second', $block_2);
 }
 /**
  * Update specified argument
  *
  * @param Mage_Core_Block_Text $argument
  * @return Mage_Core_Block_Text
  */
 public function update($argument)
 {
     $calls = $argument->getUpdaterCall();
     if (true == empty($calls)) {
         $calls = array();
     }
     $calls[] = 'updater call';
     $argument->setUpdaterCall($calls);
     return $argument;
 }
 public function manejandobloquesAction()
 {
     $block_1 = new Mage_Core_Block_Text();
     $block_1->setText('Original Text');
     $block_2 = new Mage_Core_Block_Text();
     $block_2->setText('The second sentence.');
     $main_block = new Mage_Core_Block_Template();
     $main_block->setTemplate('nofrills/manejandobloques.phtml');
     $main_block->setChild('the_first', $block_1);
     $main_block->setChild('the_second', $block_2);
     $block_1->setText('Wait , I want this text instead .');
     echo $main_block->toHtml();
 }
 /**
  * Generate the JS required to load the update routine
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $current = str_replace('.', '_', Mage::helper('wordpress/system')->getExtensionVersion());
     $text = implode('', array('<script type="text/javascript">', sprintf("var WP_VERSION_LATEST = '%s';", $latestVersion = Mage::app()->getCache()->load('wordpress_integration_update' . $current)), sprintf("var WP_VERSION_CURRENT = '%s';", Mage::helper('wordpress/system')->getExtensionVersion()), sprintf("var WP_VERSION_LOOKUP_URL = '%s';", $this->getUrl('adminhtml/wordpress/checkVersion')), 'new fishpig.WP.Update();', '</script>'));
     $this->setText($text);
     return parent::_beforeToHtml();
 }
Example #5
0
 protected function _toHtml()
 {
     $this->setText('');
     $layout = $this->getLayout();
     foreach ($this->getChildNames() as $child) {
         $this->addText($layout->renderElement($child));
     }
     return parent::_toHtml();
 }
Example #6
0
 protected function _toHtml()
 {
     $this->setText('<' . $this->getTagName() . ' ');
     if ($this->getTagParams()) {
         foreach ($this->getTagParams() as $k => $v) {
             $this->addText($k . '="' . $v . '" ');
         }
     }
     $this->addText('>' . $this->getTagContents() . '</' . $this->getTagName() . '>' . "\r\n");
     return parent::_toHtml();
 }
Example #7
0
 protected function _toHtml()
 {
     $this->setText('');
     foreach ($this->getSortedChildren() as $name) {
         $block = $this->getLayout()->getBlock($name);
         if (!$block) {
             Mage::throwException(Mage::helper('core')->__('Invalid block: %s', $name));
         }
         $this->addText($block->toHtml());
     }
     return parent::_toHtml();
 }
Example #8
0
 protected function _toHtml()
 {
     if (!$this->getContentType()) {
         $this->setContentType('text/html; charset=utf-8');
     }
     $this->addText('<meta http-equiv="Content-Type" content="' . $this->getContentType() . '"/>' . "\n");
     $this->addText('<title>' . $this->getTitle() . '</title>' . "\n");
     $this->addText('<meta name="title" content="' . $this->getTitle() . '"/>' . "\n");
     $this->addText('<meta name="description" content="' . $this->getDescription() . '"/>' . "\n");
     $this->addText('<meta name="keywords" content="' . $this->getKeywords() . '"/>' . "\n");
     $this->addText('<meta name="robots" content="' . $this->getRobots() . '"/>' . "\n");
     return parent::_toHtml();
 }
Example #9
0
 protected function _toHtml()
 {
     $this->setText('<li');
     $params = $this->getLiParams();
     if (!empty($params) && is_array($params)) {
         foreach ($params as $key => $value) {
             $this->addText(' ' . $key . '="' . addslashes($value) . '"');
         }
     } elseif (is_string($params)) {
         $this->addText(' ' . $params);
     }
     $this->addText('>' . $this->getInnerText() . '</li>' . "\r\n");
     return parent::_toHtml();
 }
Example #10
0
 protected function _toHtml()
 {
     $this->setText('');
     foreach ($this->getSortedChildren() as $name) {
         $block = $this->getLayout()->getBlock($name);
         if (!$block) {
             Mage::throwException(Mage::helper('core')->__('Invalid block: %s', $name));
         }
         $move = ' move-xs';
         if (str_replace('.', '_', $name) == 'ev_leftmenu') {
             $move = ' catalog active';
         }
         if ($this->getNameInLayout() == 'left') {
             $this->addText('<div id="Navigation_panel_' . str_replace('.', '_', $name) . '" class="navigation_panel' . $move . '">');
         }
         $this->addText($block->toHtml());
         if ($this->getNameInLayout() == 'left') {
             $this->addText('</div>');
         }
     }
     return parent::_toHtml();
 }
Example #11
0
    protected function _toHtml()
    {
        $config = Mage::getSingleton('pap/config');
        if (!$config->getTrackClicks()) {
            return '';
        }
        ob_start();
        ?>
        <script type="text/javascript">
            (function () {
                var papDomain = (("https:" == document.location.protocol) ? "https://":"http://");papDomain+="<?php 
        echo preg_replace('~^(https?://)?~', '', $config->getRemotePath());
        ?>
";
                var papId = 'pap_x2s6df8d';
                // adjust the ID iff it would conflict with an existing element
                if ((function(elementId){var nodes=new Array();var tmpNode=document.getElementById(elementId);while(tmpNode){nodes.push(tmpNode);tmpNode.id="";tmpNode=document.getElementById(elementId);for(var x=0;x<nodes.length;x++){if(nodes[x]==tmpNode){tmpNode=false;}}}})('pap_x2s6df8d')) {papId += '_clicktrack';}
                document.write(unescape("%3Cscript id='pap_x2s6df8d' src='" + papDomain + "/scripts/<?php 
        echo $config->getTrackclickscript();
        ?>
' type='text/javascript'%3E%3C/script%3E"));
            })();
        </script>
        <?php 
        $script_block = ob_get_clean();
        $this->addText('
          <!-- BEGIN AFFILIATE TRACKING CODE -->
          ' . $script_block . '
          <script type="text/javascript">
          <!--
          papTrack();
          //-->
          </script>
          <!-- END AFFILIATE TRACKING CODE -->
        ');
        /* Asynchronous version. We can't use this currently because the tracking script uses document.write, and
           that causes problems if the page is already fully loaded. Chrome also has security issues with asynchronous
           document.write.
        
           QualityUnit has been asked to update the script to allow for this.
        
                $this->addText('
        <!-- BEGIN AFFILIATE TRACKING CODE -->
        <script type="text/javascript">
          (function() {
            var pap_script = document.createElement("script"); pap_script.type = "text/javascript"; pap_script.async = true;
            pap_script.id = "'.$id.'";
            pap_script.src = "'.$config->getRemotePath().'/scripts/'.$config->getTrackclickscript().'";
            var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(pap_script, s);
          })();
        
          var pap_script_init = function()
          {
            if(typeof papTrack == "function")
            {
              clearInterval(pap_script_init_interval);
              papTrack();
            }
          }
          pap_script_init_interval = setInterval("pap_script_init()", 100);
        </script>
        <!-- END AFFILIATE TRACKING CODE -->
                ');
        */
        return parent::_toHtml();
    }
Example #12
0
    protected function _toHtml()
    {
        $config = Mage::getSingleton('pap/config');
        if (!$config->getTrackSales('javascript')) {
            return '';
            // not allowed to track via Javascript
        }
        // Get the quote
        $quote = $this->getQuote();
        if ($quote) {
            // from there, get the quote ID
            if ($quote instanceof Mage_Sales_Model_Quote) {
                $quoteId = $quote->getId();
            } else {
                $quoteId = $quote;
            }
        } else {
            // Shouldn't happen, but Magento 1.4 has a bug that can cause problems
            // if the customer registers an account at checkout, so this will help
            // work around the problem.
            $quoteId = Mage::getSingleton('checkout/session')->getLastQuoteId();
        }
        if (!$quoteId) {
            return '';
        }
        // Get the order(s) for the quote
        $orders = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('quote_id', $quoteId)->load();
        // get raw data to submit from the collection of orders
        $items = array();
        foreach ($orders as $order) {
            if (!$order) {
                continue;
            }
            if (!$order instanceof Mage_Sales_Model_Order) {
                $order = Mage::getModel('sales/order')->load($order);
            }
            if (!$order) {
                continue;
            }
            $order = Mage::getModel('pap/pap')->getOrderSaleDetails($order);
            array_splice($items, -1, 0, $order);
        }
        ob_start();
        ?>
        <script type="text/javascript">
            (function () {
                var papDomain = (("https:" == document.location.protocol) ? "https://":"http://");papDomain+="<?php 
        echo preg_replace('~^(https?://)?~', '', $config->getRemotePath());
        ?>
";
                var papId = 'pap_x2s6df8d';
                // adjust the ID iff it would conflict with an existing element
                if ((function(elementId){var nodes=new Array();var tmpNode=document.getElementById(elementId);while(tmpNode){nodes.push(tmpNode);tmpNode.id="";tmpNode=document.getElementById(elementId);for(var x=0;x<nodes.length;x++){if(nodes[x]==tmpNode){tmpNode=false;}}}})('pap_x2s6df8d')) {papId += '_salestrack';}
                document.write(unescape("%3Cscript id='pap_x2s6df8d' src='" + papDomain + "/scripts/<?php 
        echo $config->getTracksalescript();
        ?>
' type='text/javascript'%3E%3C/script%3E"));
            })();
        </script>
        <?php 
        $script_block = ob_get_clean();
        // Build the script for this order information
        ob_start();
        ?>
          <?php 
        echo $script_block;
        ?>
          <script type="text/javascript">
          <?php 
        foreach ($items as $idx => $item) {
            $sale = "pap_sale" . $idx;
            // calculated var name for each part of the sale
            ?>
            var <?php 
            echo $sale;
            ?>
 = PostAffTracker.createSale();
            <?php 
            echo $sale;
            ?>
.setTotalCost('<?php 
            echo addslashes($item['totalcost']);
            ?>
');
            <?php 
            echo $sale;
            ?>
.setOrderID('<?php 
            echo addslashes($item['orderid']);
            ?>
');
            <?php 
            if ($item['data1']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setData1('<?php 
                echo addslashes($item['data1']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            if ($item['data2']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setData2('<?php 
                echo addslashes($item['data2']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            if ($item['data3']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setData3('<?php 
                echo addslashes($item['data3']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            if ($item['data4']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setData4('<?php 
                echo addslashes($item['data4']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            if ($item['data5']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setData5('<?php 
                echo addslashes($item['data5']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            echo $sale;
            ?>
.setProductID('<?php 
            echo addslashes($item['productid']);
            ?>
');
            <?php 
            if ($item['couponcode']) {
                ?>
 try {<?php 
                echo $sale;
                ?>
.setCoupon('<?php 
                echo addslashes($item['couponcode']);
                ?>
'); } catch (err) {} <?php 
            }
            ?>
            <?php 
            if ($item['affiliateid']) {
                ?>
 <?php 
                echo $sale;
                ?>
.setAffiliateID('<?php 
                echo addslashes($item['affiliateid']);
                ?>
'); <?php 
            }
            ?>
            <?php 
            echo $sale;
            ?>
.setCurrency('<?php 
            echo addslashes(Mage::app()->getStore()->getBaseCurrencyCode());
            ?>
');
          <?php 
        }
        ?>
          
          <?php 
        if ($config->getChannelID()) {
            ?>
 PostAffTracker.setChannel('<?php 
            echo addslashes($config->getChannelID());
            ?>
'); <?php 
        }
        ?>
          
          PostAffTracker.register();
          </script>        
        <?php 
        $text = ob_get_contents();
        ob_end_clean();
        $this->addText("\r\n         <!-- BEGIN AFFILIATE TRACKING CODE -->\r\n         " . $text . "\r\n         <!-- END AFFILIATE TRACKING CODE -->\r\n         ");
        return parent::_toHtml();
    }
Example #13
0
 /**
  * Add the JS
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $this->setText(sprintf("\n\t\t\t<script type=\"text/javascript\">\n\t\t\t\t//<![CDATA[\t\t\t\t\n\t\t\t\t\t(function() {\n\t\t\t\t\t\tvar create = {\n\t\t\t\t\t\t\tgo: function() {\n\t\t\t\t\t\t\t\tthis.attr = \$('splash_attribute_id');\n\t\t\t\t\t\t\t\tthis.opt = \$('splash_option_id');\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (!this.attr || !this.opt) {\n\t\t\t\t\t\t\t\t\tthrow 'Missing required input fields';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.name = \$('splash_display_name');\n\n\t\t\t\t\t\t\t\tthis.options = new Array();\n\t\t\t\t\t\t\t\tthis.onAttributeChange();\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.attr.observe('change', this.onAttributeChange.bindAsEventListener(this));\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.opt.observe('change', this.onOptionChange.bindAsEventListener(this));\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thasOptions: function() {\n\t\t\t\t\t\t\t\treturn typeof this.options[this.attr.getValue()] !== 'undefined';\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tupdateOptions: function() {\n\t\t\t\t\t\t\t\tthis.opt.options = null;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.opt.options[0] = new Option('%s', '');\n\n\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()].each(function(elem, ind) {\n\t\t\t\t\t\t\t\t\tthis.opt.options[ind+1] = new Option(elem.label, elem.value);\n\t\t\t\t\t\t\t\t}.bind(this));\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetOptions: function() {\n\t\t\t\t\t\t\t\tnew Ajax.Request('%s?attribute=' + this.attr.getValue(), {\n\t\t\t\t\t\t\t\t\tonSuccess: function(transport) {\n\t\t\t\t\t\t\t\t\t\tvar json = transport.responseText.evalJSON();\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (json.error) {\n\t\t\t\t\t\t\t\t\t\t\tthrow json.error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()] = new Array();\n\n\t\t\t\t\t\t\t\t\t\tjson.options.each(function(elem, ind) {\n\t\t\t\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()].push({'value': elem.value, 'label': elem.label});\n\t\t\t\t\t\t\t\t\t\t}.bind(this));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.updateOptions();\n\t\t\t\t\t\t\t\t\t}.bind(this)\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonAttributeChange: function() {\n\t\t\t\t\t\t\t\tif (this.hasOptions()) {\n\t\t\t\t\t\t\t\t\tthis.updateOptions();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthis.getOptions();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonOptionChange: function() {\n\t\t\t\t\t\t\t\tif (this.opt.getValue()) {\n\t\t\t\t\t\t\t\t\tif (this.name.getValue() === '') {\n\t\t\t\t\t\t\t\t\t\tthis.name.setValue(this.opt.options[this.opt.selectedIndex].label);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn create.go();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\talert(e);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t//]]>\n\t\t\t</script>\n\t\t", Mage::helper('adminhtml')->__('-- Please Select --'), Mage::getModel('adminhtml/url')->getUrl('*/*/options')));
     return parent::_prepareLayout();
 }
Example #14
0
    /**
     * Prepare and return block's html output
     *
     * @return string
     */
    protected function _toHtml()
    {
        if (!Mage::getStoreConfigFlag('google/analytics/active')) {
            return '';
        }
        $this->addText('
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var pageTracker = _gat._getTracker("' . $this->getAccount() . '");
pageTracker._trackPageview("' . $this->getPageName() . '");
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
        ');
        $this->addText($this->getQuoteOrdersHtml());
        if ($this->getGoogleCheckout()) {
            $protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http';
            $this->addText('<script src="' . $protocol . '://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>');
        }
        return parent::_toHtml();
    }
Example #15
0
    /**
     * Prepare and return block's html output
     *
     * @return string
     */
    protected function _toHtml()
    {
        if (!Mage::getStoreConfigFlag('google/analytics/active')) {
            return '';
        }
        $this->addText('
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
    (function() {
        var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
        ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
        (document.getElementsByTagName(\'head\')[0] || document.getElementsByTagName(\'body\')[0]).appendChild(ga);
    })();

    var _gaq = _gaq || [];
    _gaq.push(["_setAccount", "' . $this->getAccount() . '"]);
    _gaq.push(["_trackPageview", "' . $this->getPageName() . '"]);
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
        ');
        $this->addText($this->getQuoteOrdersHtml());
        if ($this->getGoogleCheckout()) {
            $protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http';
            $this->addText('<script src="' . $protocol . '://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>');
        }
        return parent::_toHtml();
    }
Example #16
0
 /**
  * @covers Mage_Core_Model_Layout::addBlock
  * @covers Mage_Core_Model_Layout::addOutputBlock
  * @covers Mage_Core_Model_Layout::getOutput
  * @covers Mage_Core_Model_Layout::removeOutputBlock
  */
 public function testGetOutput()
 {
     $blockName = 'block_' . __METHOD__;
     $expectedText = "some_text_for_{$blockName}";
     $block = new Mage_Core_Block_Text();
     $block->setText($expectedText);
     $this->_model->addBlock($block, $blockName);
     $this->_model->addOutputBlock($blockName);
     $this->assertEquals($expectedText, $this->_model->getOutput());
     $this->_model->removeOutputBlock($blockName);
     $this->assertEmpty($this->_model->getOutput());
 }
Example #17
0
 public function testToHtml()
 {
     $this->_block->setText('test');
     $this->assertEquals('test', $this->_block->toHtml());
 }
Example #18
0
 public function testAddBlock()
 {
     $this->assertInstanceOf('Mage_Core_Block_Text', $this->_layout->addBlock('Mage_Core_Block_Text', 'block1'));
     $block2 = new Mage_Core_Block_Text();
     $block2->setNameInLayout('block2');
     $this->_layout->addBlock($block2, '', 'block1');
     $this->assertTrue($this->_layout->hasElement('block1'));
     $this->assertTrue($this->_layout->hasElement('block2'));
     $this->assertEquals('block1', $this->_layout->getParentName('block2'));
 }
Example #19
0
 /**
  * Legacy fix that stops the HTML output from displaying
  *
  * @param string $fileName
  * @return string
  */
 public function fetchView($fileName)
 {
     return is_file($fileName) ? parent::fetchView($fileName) : '';
 }
 protected function _beforeToHtml()
 {
     $this->setText('You need the <a href="#">XML Sitemap</a> add-on.');
     return parent::_beforeToHtml();
 }
Example #21
0
 /**
  * Generate the JS required to load the update routine
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $this->setText(sprintf("<script type=\"text/javascript\">new fishpig.WP.Update('%s', '%s');</script>", $this->_getSourceUrl(), $this->_getVersion()));
     return parent::_beforeToHtml();
 }
Example #22
0
 public function testSetListCollection()
 {
     $this->assertEmpty($this->_child->getData('collection'));
     $this->_block->setListCollection();
     $this->assertNotEmpty($this->_child->getData('collection'));
 }
Example #23
0
    /**
     * Output the JS that controls the minigrids
     *
     * NOTE: We are breaking php runtime to fall into html directly
     * in this function instead of using a template to keep this module
     * succinct, contained, and to avoid rendering html/js via strings
     * as is the convention for form and form element renderers.
     *
     * @use (new baMiniGrid()).init(tbody, addRowButton, rowName, collectionData, rowData);
     * @return string
     */
    protected function _toHtml()
    {
        $html = parent::_toHtml();
        $successIcon = $this->getSkinUrl('images/success_msg_icon.gif');
        ob_start();
        ?>
<script type="text/javascript">

function baMiniGrid() {
    return {
        /**
         * @param tbody Body tag of grid table to insert rows into
         * @param addRowButton Button that adds rows to grid
         * @param rowName Unique name to give the grid rows. Used in name attribute
         * @param collectionData Object that has info on all prexisting grid rows
         * @param rowData Object containing the schema of the columns in each row
         */
        init : function(tbody, addRowButton, rowName, collectionData, rowData) {
            this.tbody = tbody;
            this.addRowButton = addRowButton;
            this.collectionData = collectionData;
            this.rowData = rowData;
            this.rowName = rowName;

            this.initRows();
            this.observeAddRowButton();
        },
        observeAddRowButton : function () {
            this.addRowButton.observe('click', function(ev){
                ev.stop();
                this.addRow();
            }.bind(this));
        },
        getNewRowId : function () {
            if (typeof this.rowId == "undefined") {
                this.rowId = 0;
            }
            return this.tbody.id+"-row-id-"+this.rowId++;
        },
        initRows : function () {
            if (!this.collectionData.length || this.collectionData.length < 1) {
                return;
            }
            this.collectionData.each(function(rowValues) {
                var row = this.getNewRow(rowValues);
                this.addRow(row);
            }.bind(this));
        },
        getNewRow : function (rowValues) {
            var rowId = this.getNewRowId();
            var rowName = this.rowName;

            var tr = new Element('tr', {id: rowId});
            var td, input;
            for (var field in this.rowData) {
                td = new Element('td');
                input = this.getInputTag(field, rowName, rowId);
                if (rowValues && typeof rowValues[field] != 'undefined') {
                    try {
                        input.value = rowValues[field];
                        delete rowValues[field];
                    }
                    catch (e) {
                        if (input.type == "file") {
                            var fileUploaded = new Element('div', {style:"float:left; width:16px; height:16px; background: url('<?php 
        echo $successIcon;
        ?>
') no-repeat 0 0;"});
                            var uploaded = new Element('p', {style:"float:left; margin:0 0 0 5px"}).update("File Uploaded.");
                            Element.insert(td, {bottom: fileUploaded});
                            Element.insert(td, {bottom: uploaded});
                            td.setAttribute("title", "File: " + rowValues[field]);
                        }
                    }
                }

                Element.insert(td, {bottom: input});
                Element.insert(tr, {bottom: td});
            }

            if (rowValues && typeof rowValues != 'undefined') {
                for (var field in rowValues) {
                    Element.insert(tr, {top: new Element('input', {name:this.rowName + "["+rowId+"]["+field+"]", type:"hidden", value:rowValues[field]})})
                }
            }

            var button = new Element('button', {type: 'button', style: 'width:50px;', title: 'Delete'}).update("<span>Delete</span>");
            button.className = "scalable delete icon-btn";
            button.observe('click', function(ev) {
                ev.stop();
                this.removeRow(rowId);
            }.bind(this));

            var buttonTd = new Element('td');
            Element.insert(buttonTd, {bottom: button});
            Element.insert(tr, {bottom: buttonTd});
            return tr;
        },
        getInputTag : function (field, rowName, rowId) {
            var input;
            if (this.rowData[field]['type'] == 'textarea' || this.rowData[field]['type'] == "select") {
                input = new Element(this.rowData[field]['type'], {style:"width:98%;",name: rowName + "["+rowId+"][" +field + "]"});
                input.addClassName("minigrid-field");
                input.addClassName("minigrid-field-" + field);
                if (typeof this.rowData[field]['options'] != 'undefined') {
                    var options = this.rowData[field]['options'];
                    if (Object.isArray(options)) {
                        options.each(function(value,opt){
                            var option = new Element('option', {value: opt}).update(value);
                            Element.insert(input, {bottom: option});
                        }.bind(this));
                    }
                    else {
                        for (var opt in options) {
                            var option = new Element('option', {value: opt}).update(options[opt]);
                            Element.insert(input, {bottom: option});
                        }
                    }
                }
                input.observe('focus', function(ev) {

                    var fields = document.getElementsByClassName("minigrid-field-" + field);

                    // Disable any options already selected in corresponding select boxes
                    for (var i=0; i < fields.length; i++) {
                        if(fields[i].getAttribute('name') != input.getAttribute('name')) {
                            if (fields[i].selectedIndex != '') {
                                input.options[fields[i].selectedIndex].disabled = true;
                            } else {
                                input.options[fields[i].selectedIndex].disabled = false;
                            }
                        }
                    }
                }.bind(this));
            }
            else {
                input = new Element('input', {style:"width:" + this.rowData[field]['width'],type: this.rowData[field]['type'], name: rowName + "["+rowId+"][" +field + "]"});
                input.addClassName("minigrid-field");
                input.addClassName("minigrid-field-" + field);
            }
            return input;
        },
        addRow : function (row) {
            row = row || this.getNewRow();
            if (typeof this.allRemoved != 'undefined' && this.allRemoved) {
                this.allRemoved.remove();
                delete this.allRemoved;
            }
            Element.insert(this.tbody, {bottom: row});
        },
        removeRow : function (rowId) {
            var row = $(rowId);
            if (typeof row != "undefined" && row) {
                row.remove();
                if (this.tbody.children.length == 0 ) {
                    this.allRemoved = new Element('input', {type:'hidden', name: this.rowName, value:''});
                    Element.insert(this.tbody, {bottom: this.allRemoved});
                }
            }
            return 1;
        }
    }
}
</script>
    <?php 
        return $html . ob_get_clean();
    }
Example #24
0
 public function testGetCacheKey()
 {
     $name = uniqid('block.');
     $block = new Mage_Core_Block_Text();
     $block->setNameInLayout($name);
     $key = $block->getCacheKey();
     $this->assertNotEmpty($key);
     $this->assertNotEquals('key', $key);
     $this->assertNotEquals($name, $key);
     $block->setCacheKey('key');
     $this->assertEquals('key', $block->getCacheKey());
 }
 /**
  * Set the HTML output
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $html = '<div id="%s">%s</div><script type="text/javascript">new Ajax.Updater("%s", "%s", {});</script>';
     $this->setText(sprintf($html, $this->getId(), $this->_getLoader(), $this->getId(), $this->getAjaxUrl()));
     return parent::_beforeToHtml();
 }
 /**
  * Processing block html after rendering
  *
  * @param   string $html
  * @return  string
  */
 protected function _afterToHtml($html)
 {
     return parent::_afterToHtml($html);
     // TODO: Change the autogenerated stub
 }
Example #27
0
 /**
  * Prepare and return block's html output
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (!Mage::getStoreConfigFlag('piwik/piwik/active')) {
         return '';
     }
     $html = '<!-- Piwik -->';
     $html .= '<script type="text/javascript">';
     $html .= '    var pkBaseURL = (("https:" == document.location.protocol) ? "https://' . $this->getPiwikUrl() . '" : "http://' . $this->getPiwikUrl() . '");';
     $html .= '    document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
     $html .= '</script>';
     $html .= '<script type="text/javascript">';
     $html .= '    try {';
     $html .= '        var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", ' . $this->getAccount() . ');';
     $html .= '        piwikTracker.trackPageView();';
     $html .= '        piwikTracker.enableLinkTracking();';
     $html .= '    } catch( err ) {}';
     $html .= '</script>';
     $html .= '<noscript><p><img src="http://' . $this->getPiwikUrl() . 'piwik.php?idsite=' . $this->getAccount() . '" style="border:0" alt=""/></p></noscript>';
     $html .= '<!-- End Piwik Tag -->';
     $this->addText($html);
     return parent::_toHtml();
 }