Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added generic listview and itemview/edit form #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
70 changes: 70 additions & 0 deletions view/templates/_itemview/_view.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* <%= viewFolderName %>/view.html.php
*
* View and display logic for back-end administrator view <%= name %> in <%= componentName %> component
*
* @package <%= _.slugify(componentName) %>
* @subpackage <%= viewFolderName %>
*
* @copyright Copyright (C) <%= currentDate %> <%= authorName %>. All rights reserved.
* @license <%= license %>
*/

// No direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
/**
* View to edit
*/
class <%= viewClassName %>View<%= _.classify(componentName) %> extends JViewLegacy {
protected $state;
protected $item;
protected $form;
/**
* Display the view
*/
public function display($tpl = null) {
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new Exception(implode("\n", $errors));
}
$this->addToolbar();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*/
protected function addToolbar() {
JFactory::getApplication()->input->set('hidemainmenu', true);
$user = JFactory::getUser();
$isNew = ($this->item->id == 0);
if (isset($this->item->checked_out)) {
$checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
} else {
$checkedOut = false;
}
$canDo = <%= viewClassName %>Helper::getActions();
JToolBarHelper::title(JText::_('COM_<%= _.underscored(componentName).toUpperCase() %>_TITLE_<%= viewFolderName.toUpperCase() %>'), '<%= viewFolderName %>.png');
// If not checked out, can save the item.
if (!$checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create')))) {
JToolBarHelper::apply('<%= viewFolderName %>.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('<%= viewFolderName %>.save', 'JTOOLBAR_SAVE');
}
if (!$checkedOut && ($canDo->get('core.create'))) {
JToolBarHelper::custom('<%= viewFolderName %>.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
}
// If an existing item, can save to a copy.
if (!$isNew && $canDo->get('core.create')) {
JToolBarHelper::custom('<%= viewFolderName %>.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
}
if (empty($this->item->id)) {
JToolBarHelper::cancel('<%= viewFolderName %>.cancel', 'JTOOLBAR_CANCEL');
} else {
JToolBarHelper::cancel('<%= viewFolderName %>.cancel', 'JTOOLBAR_CLOSE');
}
}
}
1 change: 1 addition & 0 deletions view/templates/_itemview/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
98 changes: 98 additions & 0 deletions view/templates/_itemview/tmpl/_edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* <%= viewFolderName %>/edit.php
*
* Default view for view <%= name %> in <%= componentName %> component
*
* @package <%= _.underscored(componentName) %>
* @subpackage <%= viewFolderName %>
*
* @copyright Copyright (C) <%= currentDate %> <%= authorName %>. All rights reserved.
* @license <%= license %>
*/
// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');

// Import CSS
$document = JFactory::getDocument();
$document->addStyleSheet('components/com_<%= _.underscored(componentName) %>/assets/css/<%= _.underscored(componentName) %>.css');
?>
<script type="text/javascript">
Joomla.submitbutton = function(task)
{
if (task == '<%= viewFolderName.slice(0,-1) %>.cancel') {
Joomla.submitform(task, document.getElementById('<%= viewFolderName.slice(0,-1) %>-form'));
}
else {

if (task != '<%= viewFolderName.slice(0,-1) %>.cancel' && document.formvalidator.isValid(document.id('<%= viewFolderName.slice(0,-1) %>-form'))) {

Joomla.submitform(task, document.getElementById('<%= viewFolderName.slice(0,-1) %>-form'));
}
else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
}
}
}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_<%= _.underscored(componentName) %>&layout=edit&id=' . (int) $this->item->id); ?>" method="post" enctype="multipart/form-data" name="adminForm" id="<%= viewFolderName.slice(0,-1) %>-form" class="form-validate">
<div class="control-group">
<div style="float: left;padding-right: 10px;"><?php echo $this->form->getLabel('title'); ?></div>
<?php echo $this->form->getInput('title'); ?>
</div>
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_<%= _.underscored(componentName).toUpperCase() %>_TITLE_GENERAL')); ?>
<div class="row-fluid">
<div class="span6 form-horizontal">
<fieldset class="adminform">
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('id'); ?></div>
<div class="controls"><?php echo $this->form->getInput('id'); ?></div>
</div>
<input type="hidden" name="jform[ordering]" value="<?php echo $this->item->ordering; ?>" />
<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
<input type="hidden" name="jform[checked_out]" value="<?php echo $this->item->checked_out; ?>" />
<input type="hidden" name="jform[checked_out_time]" value="<?php echo $this->item->checked_out_time; ?>" />
<?php if(empty($this->item->created_by)){ ?>
<input type="hidden" name="jform[created_by]" value="<?php echo JFactory::getUser()->id; ?>" />
<?php }
else{ ?>
<input type="hidden" name="jform[created_by]" value="<?php echo $this->item->created_by; ?>" />
<?php } ?>
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel(''); ?></div>
<div class="controls"><?php echo $this->form->getInput(''); ?></div>
</div>
</fieldset>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'information', JText::_('COM_<%= _.underscored(componentName).toUpperCase() %>_TITLE_INFORMATION')); ?>
<div class="span6 form-horizontal">
<fieldset class="adminform">
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel(''); ?></div>
<div class="controls"><?php echo $this->form->getInput(''); ?></div>
</div>
</fieldset>
</div>
<div class="span6 form-horizontal">
<fieldset class="adminform">
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel(''); ?></div>
<div class="controls"><?php echo $this->form->getInput(''); ?></div>
</div>
</fieldset>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
<script type="text/javascript"></script>
1 change: 1 addition & 0 deletions view/templates/_itemview/tmpl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
120 changes: 120 additions & 0 deletions view/templates/_listview/_listview.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* <%= viewFolderName %>/view.html.php
*
* View and display logic for back-end administrator view <%= name %> in <%= componentName %> component
*
* @package <%= _.slugify(componentName) %>
* @subpackage <%= viewFolderName %>
*
* @copyright Copyright (C) <%= currentDate %> <%= authorName %>. All rights reserved.
* @license <%= license %>
*/
defined('_JEXEC') or die;
/**
* Class <%= viewClassName %>
* @author <%= authorName %> <<%= authorEmail %>>
* TODO: Describe your view here
*/
class <%= viewClassName %>View<%= _.classify(componentName) %> extends JViewLegacy {
// TODO: place attributes here: ex. $protected $items;
protected $items;
protected $pagination;
protected $state;

/**
* Display logic for when view is displayed
*
* @author <%= authorName %> <<%= authorEmail %>>
*
* @param String $tpl template which is used to display the component page (view)
*
* @return bool whether items have been displayed
*/
public function display($tpl = null) {
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');

// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new Exception(implode("\n", $errors));
}

//<%= _.classify(componentName) %>Helper::addSubmenu("'".<%= viewClassName %>."'");

// TODO: constructor logic here
parent::display($tpl);
}

/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addToolbar() {
require_once JPATH_COMPONENT . '/helpers/<%= _.classify(componentName) %>.php';
$state = $this->get('State');
$canDo = Metro_<%= viewFolderName.slice(0,-1) %>Helper::getActions($state->get('filter.category_id'));
JToolBarHelper::title(JText::_('COM_<%= _.slugify(componentName).toUpperCase() %>_TITLE_<%= _.classify(viewClassName).toUpperCase() %>'), '<%= viewFolderName %>.png');
//Check if the form exists before showing the add/edit buttons
$formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/<%= viewFolderName.slice(0,-1) %>';
if (file_exists($formPath)) {
if ($canDo->get('core.create')) {
JToolBarHelper::addNew('<%= viewFolderName.slice(0,-1) %>.add', 'JTOOLBAR_NEW');
}
if ($canDo->get('core.edit') && isset($this->items[0])) {
JToolBarHelper::editList('<%= viewFolderName.slice(0,-1) %>.edit', 'JTOOLBAR_EDIT');
}
}
if ($canDo->get('core.edit.state')) {
if (isset($this->items[0]->state)) {
JToolBarHelper::divider();
JToolBarHelper::custom('<%= viewFolderName %>.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
JToolBarHelper::custom('<%= viewFolderName %>.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
} else if (isset($this->items[0])) {
//If this component does not use state then show a direct delete button as we can not trash
JToolBarHelper::deleteList('', '<%= viewFolderName %>.delete', 'JTOOLBAR_DELETE');
}
if (isset($this->items[0]->state)) {
JToolBarHelper::divider();
JToolBarHelper::archiveList('<%= viewFolderName %>.archive', 'JTOOLBAR_ARCHIVE');
}
if (isset($this->items[0]->checked_out)) {
JToolBarHelper::custom('<%= viewFolderName %>.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
}
}
//Show trash and delete for components that uses the state field
if (isset($this->items[0]->state)) {
if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
JToolBarHelper::deleteList('', '<%= viewFolderName %>.delete', 'JTOOLBAR_EMPTY_TRASH');
JToolBarHelper::divider();
} else if ($canDo->get('core.edit.state')) {
JToolBarHelper::trash('<%= viewFolderName %>.trash', 'JTOOLBAR_TRASH');
JToolBarHelper::divider();
}
}
if ($canDo->get('core.admin')) {
JToolBarHelper::preferences('com_<%= _.classify(componentName) %>');
}
//Set sidebar action - New in 3.0
JHtmlSidebar::setAction('index.php?option=com_<%= _.classify(componentName) %>&view=<%= viewFolderName %>');
$this->extra_sidebar = '';

JHtmlSidebar::addFilter(
JText::_('JOPTION_SELECT_PUBLISHED'),
'filter_published',
JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), "value", "text", $this->state->get('filter.state'), true)
);
}

protected function getSortFields()
{
return array(
'a.id' => JText::_('JGRID_HEADING_ID'),
'a.ordering' => JText::_('JGRID_HEADING_ORDERING'),
'a.state' => JText::_('JSTATUS'),
'a.title' => JText::_('COM_<%= _.slugify(componentName).toUpperCase() %>_<%= _.classify(viewClassName).toUpperCase() %>_TITLE'),
);
}
}
1 change: 1 addition & 0 deletions view/templates/_listview/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
Loading