public function _toHtml()
 {
     return '<input type="hidden" id="' . $this->getElement()->getHtmlId() . '"/>' . parent::_toHtml();
 }
 public function _toHtml()
 {
     $script = "<script type=\"text/javascript\">\n                require([\n                    'prototype',\n                    'domReady!'\n                ], function () {\n                    \$\$('.admin__control-table tr td:first-child select').each(function(item) {\n                        doUpdateWithValues(item);\n                    });\n\n                    \$\$('.admin__control-table tr td:first-child select').each(function(item) {\n                        Event.observe(item,'change', function(){\n                            doUpdate(item);\n                        });\n                    });\n\n                    \$\$('.admin__control-table button.action-add').each(function(item) {\n                         Event.observe(item,'click', function(){\n                            \$\$('.admin__control-table tr td:first-child select').each(function(item) {\n                                 Event.observe(item,'change', function(){\n                                    doUpdate(item);\n                                });\n                            });\n                            \$\$('.admin__control-table tr td select').each(function(item) {\n                                Event.observe(item,'change', function(){\n                                     if(item.readAttribute('title') == 'conditions'){\n                                        doUpdateForCondition(item);\n                                     }\n                                });\n                            });\n                        });\n                    });\n\n                    function doUpdate(item){\n                        var url = '" . $this->getUrl('dotdigitalgroup_email/rules/ajax') . "';\n                        var cond = item.up(1).down().next();\n                        var condName = cond.down().readAttribute('name');\n                        var value = item.up(1).down().next(1);\n                        var valueName = value.down().readAttribute('name');\n                        var attribute = item.value;\n                        new Ajax.Request(url, {\n                            method: 'post',\n                            parameters: {\n                                attribute: attribute,\n                                condition: condName,\n                                value: valueName\n                            },\n                            onSuccess: function(transport){\n                                var json = transport.responseJSON;\n                                cond.update(json.condition);\n                                value.update(json.cvalue);\n\n                                \$\$('.admin__control-table tr td select').each(function(item) {\n                                    Event.observe(item,'change', function(){\n                                         if(item.readAttribute('title') == 'conditions'){\n                                            doUpdateForCondition(item);\n                                         }\n                                    });\n                                });\n                            }\n                        });\n                    }\n\n                    function doUpdateWithValues(item){\n                        var url = '" . $this->getUrl('dotdigitalgroup_email/rules/selected') . "';\n                        var arrayKey = item.up(1).readAttribute('id');\n                        var cond = item.up(1).down().next();\n                        var condName = cond.down().readAttribute('name');\n                        var value = item.up(1).down().next(1);\n                        var valueName = value.down().readAttribute('name');\n                        var attribute = item.value;\n                        var ruleId = \$('rule_id').value;\n                        new Ajax.Request(url, {\n                            method: 'post',\n                            parameters: {\n                                attribute: attribute,\n                                condition: condName,\n                                value: valueName,\n                                arraykey: arrayKey,\n                                ruleid: ruleId\n                            },\n                            onSuccess: function(transport){\n                                var json = transport.responseJSON;\n                                cond.update(json.condition);\n                                value.update(json.cvalue);\n\n                                \$\$('.admin__control-table tr td select').each(function(item) {\n                                    Event.observe(item,'change', function(){\n                                         if(item.readAttribute('title') == 'conditions'){\n                                            doUpdateForCondition(item);\n                                         }\n                                    });\n                                });\n                            }\n                        });\n                    }\n\n                    function doUpdateForCondition(item){\n                        var url = '" . $this->getUrl('dotdigitalgroup_email/rules/value') . "';\n                        var attribute = item.up(1).down();\n                        var attributeValue = attribute.down().value;\n                        var value = item.up().next();\n                        var valueName = value.down().readAttribute('name');\n                        var condValue = item.value;\n                        new Ajax.Request(url, {\n                            method: 'post',\n                            parameters: {\n                                attributeValue: attributeValue,\n                                value: valueName,\n                                condValue: condValue\n                            },\n                            onSuccess: function(transport){\n                                var json = transport.responseJSON;\n                                value.update(json.cvalue);\n                            }\n                        });\n                    }\n                });\n            </script>";
     return '<input type="hidden" id="' . $this->getElement()->getHtmlId() . '"/>' . parent::_toHtml() . $script;
 }