Exemplo n.º 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);
    }
Exemplo n.º 2
0
    /**
     * Method to get the field input markup.
     *
     * @return  string  The field input markup.
     */
    public function getInput()
    {
        // Load the modal behavior script.
        WindwalkerScript::modal('.hasFinderModal');
        if (!static::$initialised) {
            $this->setScript();
        }
        // Setup variables for display.
        // ================================================================
        $html = array();
        $disabled = XmlHelper::getBool($this->element, 'disabled');
        $readonly = XmlHelper::getBool($this->element, 'readonly');
        $link = $this->getLink();
        $title = $this->getTitle();
        // Set Title
        // ================================================================
        if (empty($title)) {
            $title = \JText::_(XmlHelper::get($this->element, 'select_label', 'LIB_WINDWALKER_FORMFIELD_FINDER_SELECT_FILE'));
        }
        $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
        // The text field.
        // ================================================================
        $preview = $this->getPreview();
        // The current user display field.
        $html[] = '<span class="' . (!$disabled && !$readonly ? 'input-append' : '') . '">';
        $html[] = '<input type="text" class="finder-item-name ' . (!$disabled && !$readonly ? 'input-medium ' . $this->element['class'] : $this->element['class']) . '" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="35" />';
        if (!$disabled && !$readonly) {
            $html[] = '<a class="hasFinderModal btn btn-primary" title="' . JText::_('LIB_WINDWALKER_FORMFIELD_FINDER_BROWSE_FILES') . '"  href="' . $link . '&amp;' . JSession::getFormToken() . '=1">
							<i class="icon-picture"></i> ' . JText::_('LIB_WINDWALKER_FORMFIELD_FINDER_BROWSE_FILES') . '</a>';
        }
        $html[] = '</span>';
        // The  class='required' for client side validation
        // ================================================================
        $class = '';
        if ($this->required) {
            $class = ' class="required modal-value"';
        }
        // Velue store input
        $disabled_attr = $disabled ? ' disabled="true" ' : '';
        $html[] = '<input type="hidden" id="' . $this->id . '"' . $class . ' name="' . $this->name . '" value="' . $this->value . '" ' . $disabled_attr . ' />';
        $html = implode("\n", $html);
        $options = array('text' => array('clear_title' => JText::_('LIB_WINDWALKER_FORMFIELD_FINDER_SELECT_FILE')));
        $this->initScript('#' . $this->id, $options);
        if (!$disabled && !$readonly) {
            $html .= '<a class="btn btn-danger hasTooltip clear-button" title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="javascript: void(0)">';
            $html .= '<i class="icon-remove"></i></a>';
        }
        // Image Preview
        // ================================================================
        $html = $html . $preview;
        return $html;
    }
Exemplo n.º 3
0
 /**
  * Add an quick add button & modal
  *
  * @return mixed
  */
 public function quickadd()
 {
     // Prepare Element
     $readonly = $this->getElement('readonly', false);
     $disabled = $this->getElement('disabled', false);
     if ($readonly || $disabled) {
         return;
     }
     $task = $this->getElement('task', $this->view_item . '.ajax.quickadd');
     $quickadd = $this->getElement('quickadd', false);
     $table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
     $key_field = $this->getElement('key_field', 'id');
     $value_field = $this->getElement('value_field', 'title');
     $formpath = $this->getElement('quickadd_formpath', "administrator/components/{$this->extension}/model/form/{$this->view_item}.xml");
     $quickadd_handler = $this->getElement('quickadd_handler', $this->extension);
     $title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
     $qid = $this->id . '_quickadd';
     if (!$quickadd) {
         return '';
     }
     // Set AKQuickAddOption
     $config['task'] = $task;
     $config['quickadd_handler'] = $quickadd_handler;
     $config['extension'] = $this->extension;
     $config['component'] = $this->component;
     $config['table'] = $table_name;
     $config['model_name'] = $this->view_item;
     $config['key_field'] = $key_field;
     $config['value_field'] = $value_field;
     $config['joomla3'] = JVERSION >= 3;
     WindwalkerScript::quickadd('#' . $qid, $config);
     // Load Language & Form
     LanguageHelper::loadLanguage('com_' . $this->component, null);
     $formpath = str_replace(JPATH_ROOT, '', $formpath);
     $content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
     // Prepare HTML
     $html = '';
     $button_title = $title;
     $modal_title = $button_title;
     $button_class = 'btn btn-small btn-success quickadd_buttons';
     $footer = "<button class=\"btn\" type=\"button\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
     $footer .= "<button class=\"btn btn-primary\" type=\"submit\">" . JText::_('JSUBMIT') . "</button>";
     $html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
     $html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
     return $html;
 }