Example #1
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;
 }
Example #2
0
    /**
     * Add an quick add button & modal
     *
     * @return string
     */
    public function quickadd()
    {
        // Prepare Element
        $readonly = $this->getElement('readonly', false);
        $disabled = $this->getElement('disabled', false);
        if ($readonly || $disabled) {
            return false;
        }
        $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 '';
        }
        // Prepare Script & Styles
        /** @var Windwalker\Helper\AssetHelper $asset */
        $asset = Container::getInstance($quickadd_handler)->get('helper.asset');
        $asset->addJs('js/quickadd.js');
        // 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;
        $config = HtmlHelper::getJSObject($config);
        $script = <<<QA
        window.addEvent('domready', function(){
            var AKQuickAddOption = {$config} ;
            AKQuickAdd.init('{$qid}', AKQuickAddOption);
        });
QA;
        $asset->internalJS($script);
        // 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 delicious green light fltlft quickadd_button';
        $footer = "<button class=\"btn delicious\" type=\"button\" onclick=\"\$\$('#{$qid} input', '#{$qid} select').set('value', '');AKQuickAdd.closeModal('{$qid}');\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
        $footer .= "<button class=\"btn btn-primary delicious blue\" type=\"submit\" onclick=\"AKQuickAdd.submit('{$qid}', event);\">" . 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;
    }
Example #3
0
 /**
  * Configure the toolbar button set.
  *
  * @param   array   $buttonSet Customize button set.
  * @param   object  $canDo     Access object.
  *
  * @return  array
  */
 protected function configureToolbar($buttonSet = array(), $canDo = null)
 {
     $buttonSet = array();
     $buttonSet['import_per_item'] = array('handler' => function () {
         JToolBarHelper::custom('item.saveall', 'new', 'new', 'COM_FBIMPORTER_IMPORT', true);
     }, 'access' => 'core.create', 'priority' => 1000);
     $buttonSet['import_as_one_article'] = array('handler' => function () {
         \Windwalker\Helper\ModalHelper::modal('saveAsCombinedModal');
         $bar = JToolbar::getInstance('toolbar');
         $option = array('class' => 'btn btn-small btn-success toolbar', 'icon' => 'icon-new icon-white');
         $title = JText::_('COM_FBIMPORTER_IMPORT_AS_COMBINED');
         $dhtml = \Windwalker\Helper\ModalHelper::modalLink($title, 'saveAsCombinedModal', $option);
         $bar->appendButton('Custom', $dhtml, 'new');
     }, 'access' => 'core.create', 'priority' => 800);
     $buttonSet['refresh'] = array('handler' => function () {
         JToolBarHelper::custom('items.refresh', 'refresh', 'refresh', 'COM_FBIMPORTER_REFRESH', false);
     }, 'priority' => 600);
     $buttonSet['option'] = array('handler' => 'preferences', 'access' => 'core.edit', 'priority' => 100);
     return $buttonSet;
 }
    /**
     * Method to test getQuickaddForm().
     *
     * @return void
     *
     * @covers Windwalker\Helper\ModalHelper::getQuickaddForm
     */
    public function testGetQuickaddForm()
    {
        $id = 'stubQuickaddForm';
        $pathToQuickaddForm = 'libraries/windwalker/test/Helper/stub/stubQuickaddForm.xml';
        $text = \JText::_('LIB_WINDWALKER_QUICKADD_HOTKEY_DESC');
        $expectedForm = <<<HTML
<div class="alert alert-info">{$text}</div><div class="control-group" id="{$id}_title-wrap">
\t<div class="control-label">
\t\t<label id="{$id}_title-lbl" for="{$id}_title" class="required">
\tstub_label<span class="star">&#160;*</span></label>
\t</div>
\t<div class="controls">
\t\t<input type="text" name="{$id}[title]" id="{$id}_title" value="" class="input-xlarge required" required aria-required="true" />
\t</div>
</div>
HTML;
        $this->assertStringSafeEquals($expectedForm, ModalHelper::getQuickaddForm($id, $pathToQuickaddForm));
    }