예제 #1
0
    /**
     * Method to get the user field input markup.
     *
     * @return  string  The field input markup.
     */
    protected function getInput()
    {
        $html = array();
        $groups = $this->getGroups();
        $excluded = $this->getExcluded();
        $link = 'index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id . (isset($groups) ? '&groups=' . base64_encode(json_encode($groups)) : '') . (isset($excluded) ? '&excluded=' . base64_encode(json_encode($excluded)) : '');
        // Initialize some field attributes.
        $attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
        $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
        // Initialize JavaScript field attributes.
        $onchange = (string) $this->element['onchange'];
        // Load the modal behavior script.
        WindwalkerScript::modal('.hasUserModal');
        JQueryScript::ui(array('effect'));
        // Build the script.
        $js = <<<JS
function jSelectUser_{$this->id}(id, title) {
\tvar input = jQuery('#{$this->id}_id');
\tvar oldId = input.val();

\tif (oldId != id) {
\t\tinput.val(id);
\t\tjQuery('#{$this->id}_name').val(title).removeClass('invalid').delay(300).effect('highlight');
\t}

\t{$onchange};

\tWindwalker.Modal.hide();
};
JS;
        // Add the script to the document head.
        $asset = Container::getInstance()->get('helper.asset');
        $asset->internalJS($js);
        // Load the current username if available.
        $table = JTable::getInstance('user');
        if ($this->value) {
            $table->load($this->value);
        } elseif (strtoupper($this->value) == 'CURRENT') {
            // 'CURRENT' is not a reasonable value to be placed in the html
            $this->value = JFactory::getUser()->id;
            $table->load($this->value);
        } else {
            $table->name = JText::_('JLIB_FORM_SELECT_USER');
        }
        // Create a dummy text field with the user name.
        $html[] = '<div class="input-append">';
        $html[] = '	<input type="text" id="' . $this->id . '_name" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"' . ' readonly' . $attr . ' />';
        // Create the user select button.
        if (!XmlHelper::getBool($this->element, 'readonly', false)) {
            $html[] = '		<a class="btn btn-primary hasUserModal modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
            $html[] = '<i class="icon-user"></i></a>';
        }
        $html[] = '</div>';
        // Create the real field, hidden, that stored the user id.
        $html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $this->value . '" />';
        return implode("\n", $html);
    }
    /**
     * quickadd
     *
     * @param string $selector
     * @param array  $options
     *
     * @return  void
     */
    public static function quickadd($selector, $options = array())
    {
        $asset = static::getAsset();
        if (!static::inited(__METHOD__)) {
            JQueryScript::ui(array('effect'));
            $asset->addJS('quickadd.min.js');
        }
        if (!static::inited(__METHOD__, func_get_args())) {
            $options = AssetManager::getJSObject($options);
            $js = <<<JS
jQuery(document).ready(function(\$) {
\t\$('{$selector}').quickadd({$options});
});
JS;
            $asset->internalJS($js);
        }
    }
예제 #3
0
    /**
     * Add jQuery highlight plugin.
     *
     * @param  string  $selector  The selector to make highlight.
     * @param  string  $text      The text to mark.
     * @param  array   $options   The options of this script.
     *
     * @see  http://bartaz.github.io/sandbox.js/jquery.highlight.html
     *
     * @return  void
     */
    public static function highlight($selector = '.hasHighlight', $text = null, $options = array())
    {
        $asset = static::getAsset();
        if (!static::inited(__METHOD__)) {
            JQueryScript::core();
            $asset->addJS('jquery/jquery.highlight.js');
        }
        if (!static::inited(__METHOD__, func_get_args()) && $selector && $text) {
            if (is_array($text)) {
                $text = implode(' ', $text);
            }
            $defaultOptions = array('element' => 'mark', 'className' => 'windwalker-highlight');
            $options = $asset::getJSObject(ArrayHelper::merge($defaultOptions, $options));
            $js = <<<JS
// Highlight Text
jQuery(document).ready(function(\$)
{
\t\$('{$selector}').highlight('{$text}', {$options});
});
JS;
            $asset->internalJS($js);
        }
    }
예제 #4
0
 /**
  * Set Script.
  *
  * @return void
  */
 public function setScript()
 {
     JQueryScript::ui(array('effect'));
     // Build the script.
     $script = array();
     $script[] = '    function jSelect' . ucfirst($this->component) . '_' . $this->id . '(id, title) {';
     $script[] = '        jQuery("#' . $this->id . '_id").val(id);';
     $script[] = '        jQuery("#' . $this->id . '_name").val(title);';
     $script[] = '        jQuery("#' . $this->id . '_name").delay(500).effect(\'highlight\');';
     $script[] = '        Windwalker.Modal.hide();';
     $script[] = '    }';
     // Add the script to the document head.
     $asset = Container::getInstance()->get('helper.asset');
     $asset->internalJS(implode("\n", $script));
 }