/** * 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; }
/** * 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; }
/** * Method to test renderModal(). * * @return void * * @covers Windwalker\Helper\ModalHelper::renderModal */ public function testRenderModal() { // Reset Loaded $this->reflectedLoaded->setValue($this->originalLoaded); $selector = 'test-selector'; $option = array('title' => 'IM TITLE', 'footer' => '<h1>IM FOOTER</h1>', 'content' => '<h1>IM CONTENT</h1>'); $expected = <<<HTML <div class="modal hide fade {$selector}" id="{$selector}"> <div class="modal-header"> <button type="button" role="presentation" class="close" data-dismiss="modal">x</button> <h3>{$option['title']}</h3> </div> <div id="{$selector}-container" class="modal-body"> {$option['content']} </div> <div class="modal-footer"> {$option['footer']} </div> </div> HTML; $this->assertEquals($expected, ModalHelper::renderModal($selector, $option['content'], $option)); // Test if JHtmlBootstrap::modal did executed $this->assertArrayHasKey('JHtmlBootstrap::modal', $this->reflectedLoaded->getValue()); }