protected function getInlineJavaScript()
    {
        // Javascript is unnecessary when the parent flydown is empty, or when
        // it has a single value as in both cases the parent value never
        // changes.
        if ($this->hasEmptyParent() || $this->hasSingleParent()) {
            return;
        }

        $javascript = sprintf(
            "var %s_cascade = new SwatCascade('%s', '%s');",
            $this->id,
            $this->cascade_from->id,
            $this->id
        );

        $salt = $this->getForm()->getSalt();

        $flydown_value = $this->serialize_values
            ? $this->value
            : (string) $this->value;

        foreach ($this->options as $parent => $options) {
            if ($this->cascade_from->serialize_values) {
                $parent = SwatString::signedSerialize($parent, $salt);
            }

            if ($this->show_blank && count($options) > 0) {
                if ($this->serialize_values) {
                    $value = SwatString::signedSerialize(null, $salt);
                } else {
                    $value = '';
                }

                $blank_title =
                    $this->blank_title === null
                        ? Swat::_('choose one ...')
                        : $this->blank_title;

                $javascript .= sprintf(
                    "\n%s_cascade.addChild(%s, %s, %s);",
                    $this->id,
                    SwatString::quoteJavaScriptString($parent),
                    SwatString::quoteJavaScriptString($value),
                    SwatString::quoteJavaScriptString($blank_title)
                );
            }

            foreach ($options as $option) {
                if ($this->serialize_values) {
                    // if they are serialized, we want to compare the actual
                    // values
                    $selected =
                        $flydown_value === $option->value ? 'true' : 'false';

                    $value = SwatString::signedSerialize($option->value, $salt);
                } else {
                    // if they are not serialized, we want to compare the string
                    // value
                    $value = (string) $option->value;

                    $selected = $flydown_value === $value ? 'true' : 'false';
                }

                $javascript .= sprintf(
                    "\n%s_cascade.addChild(%s, %s, %s, %s);",
                    $this->id,
                    SwatString::quoteJavaScriptString($parent),
                    SwatString::quoteJavaScriptString($value),
                    SwatString::quoteJavaScriptString($option->title),
                    $selected
                );
            }
        }

        $javascript .= sprintf("\n%s_cascade.init();", $this->id);

        return $javascript;
    }