-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An image edit view with action plugins, based on JForm (#122)
* Use JForm to render the action plugins * Only determine the with and height when it is a file * Updates * Add demo crop plugin * Introduce an event bus to activate and deactivate a plugin n the js side * Not needed * Valid HTML * Localizing the plugins * Move to plugin layouts * New lines * Add rotate plugin * Add rotate plugin * Remove not needed code
- Loading branch information
1 parent
0c8bda7
commit 9a16686
Showing
29 changed files
with
887 additions
and
99 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
administrator/components/com_media/libraries/media/plugin/mediaaction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
|
||
/** | ||
* Media Manager Base Plugin for the media actions | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class MediaActionPlugin extends JPlugin | ||
{ | ||
/** | ||
* Load the language file on instantiation. | ||
* | ||
* @var boolean | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $autoloadLanguage = true; | ||
|
||
/** | ||
* The form event. Load additional parameters when available into the field form. | ||
* Only when the type of the form is of interest. | ||
* | ||
* @param JForm $form The form | ||
* @param stdClass $data The data | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onContentPrepareForm(JForm $form, $data) | ||
{ | ||
// Check if it is the right form | ||
if ($form->getName() != 'com_media.file') | ||
{ | ||
return; | ||
} | ||
|
||
// Get the layout file to add the JS code | ||
$layout = JPluginHelper::getLayoutPath('media-action', $this->_name, $this->_name); | ||
|
||
// If there is a layout, include it | ||
if ($layout) | ||
{ | ||
include $layout; | ||
} | ||
|
||
// The file with the params for the edit view | ||
$paramsFile = JPATH_PLUGINS . '/media-action/' . $this->_name . '/form/' . $this->_name . '.xml'; | ||
|
||
// When the file exists, load it into the form | ||
if (file_exists($paramsFile)) | ||
{ | ||
$form->loadFile($paramsFile); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\Cms\Model\Form; | ||
|
||
/** | ||
* File Model | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class MediaModelFile extends Form | ||
{ | ||
/** | ||
* Method to get the record form. | ||
* | ||
* @param array $data Data for the form. | ||
* @param boolean $loadData True if the form is to load its own data (default case), false if not. | ||
* | ||
* @return JForm|boolean A JForm object on success, false on failure | ||
* | ||
* @since 1.6 | ||
*/ | ||
public function getForm($data = array(), $loadData = true) | ||
{ | ||
JPluginHelper::importPlugin('media-action'); | ||
|
||
// Get the form. | ||
$form = $this->loadForm('com_media.file', 'file', array('control' => 'jform', 'load_data' => $loadData)); | ||
|
||
if (empty($form)) | ||
{ | ||
return false; | ||
} | ||
|
||
return $form; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<form> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
administrator/components/com_media/views/file/tmpl/default.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
// Add javascripts | ||
JHtml::_('jquery.framework'); | ||
JHtml::_('behavior.formvalidator'); | ||
|
||
JHtml::_('script', 'media/com_media/js/EventBus.js', true, false); | ||
JHtml::_('script', 'media/com_media/js/edit.js'); | ||
|
||
/** | ||
* @var JForm $form | ||
*/ | ||
$form = $this->form; | ||
?> | ||
<form action="#" method="post" name="adminForm" id="media-form" class="form-validate"> | ||
<?php | ||
$fieldSets = $form->getFieldsets(); | ||
|
||
if ($fieldSets) | ||
{ | ||
echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'attrib-' . reset($fieldSets)->name)); | ||
|
||
echo JLayoutHelper::render('joomla.edit.params', $this); | ||
|
||
echo JHtml::_('bootstrap.endTabSet'); | ||
} | ||
?> | ||
</form> | ||
|
||
<span class="image-container"> | ||
<img id="media-edit-file" src="<?php echo $this->fullFilePath ?>"/> | ||
</span> |
72 changes: 72 additions & 0 deletions
72
administrator/components/com_media/views/file/view.html.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
jimport('joomla.filesystem.file'); | ||
|
||
/** | ||
* View to edit an file. | ||
* | ||
* @todo Prototype! | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class MediaViewFile extends JViewLegacy | ||
{ | ||
|
||
/** | ||
* Execute and display a template script. | ||
* | ||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths. | ||
* | ||
* @return mixed A string if successful, otherwise an Error object. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function display($tpl = null) | ||
{ | ||
$input = JFactory::getApplication()->input; | ||
|
||
$this->form = $this->get('Form'); | ||
|
||
// The component params | ||
$this->params = JComponentHelper::getParams('com_media'); | ||
|
||
$this->file = $input->getString('path', null); | ||
$this->fullFilePath = JUri::root() . $this->params->get('file_path', 'images') . '/' . $input->getString('path', null); | ||
|
||
if (!$this->file && JFile::exists($this->fullFilePath)) | ||
{ | ||
// @todo error handling controller redirect files | ||
throw new Exception('Image file does not exist'); | ||
} | ||
|
||
$this->addToolbar(); | ||
|
||
return parent::display($tpl); | ||
} | ||
|
||
/** | ||
* Add the toolbar buttons | ||
* | ||
* @return void | ||
* | ||
* @since _DEPLOY_VERSION | ||
*/ | ||
protected function addToolbar() | ||
{ | ||
JToolbarHelper::title(JText::_('COM_MEDIA_EDIT'), 'images mediamanager'); | ||
|
||
// @todo buttons | ||
JToolbarHelper::apply('file.apply'); | ||
JToolbarHelper::save('file.save'); | ||
JToolbarHelper::cancel('file.cancel'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
administrator/language/en-GB/en-GB.plg_media-action_crop.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_CROP="Media Action - Crop" | ||
PLG_MEDIA-ACTION_CROP_LABEL="Crop" | ||
PLG_MEDIA-ACTION_CROP_PARAM_X="X" | ||
PLG_MEDIA-ACTION_CROP_PARAM_Y="Y" | ||
PLG_MEDIA-ACTION_CROP_PARAM_WIDTH="Width" | ||
PLG_MEDIA-ACTION_CROP_PARAM_HEIGHT="Height" | ||
PLG_MEDIA-ACTION_CROP_XML_DESCRIPTION="Adds crop functionality for images." |
7 changes: 7 additions & 0 deletions
7
administrator/language/en-GB/en-GB.plg_media-action_crop.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_CROP="Media Action - Crop" | ||
PLG_MEDIA-ACTION_CROP_XML_DESCRIPTION="Crop functionality for images." |
10 changes: 10 additions & 0 deletions
10
administrator/language/en-GB/en-GB.plg_media-action_resize.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_RESIZE="Media Action - Resize" | ||
PLG_MEDIA-ACTION_RESIZE_LABEL="Resize" | ||
PLG_MEDIA-ACTION_RESIZE_PARAM_WIDTH="Width" | ||
PLG_MEDIA-ACTION_RESIZE_PARAM_HEIGHT="Height" | ||
PLG_MEDIA-ACTION_RESIZE_XML_DESCRIPTION="Resize functionality for images." |
7 changes: 7 additions & 0 deletions
7
administrator/language/en-GB/en-GB.plg_media-action_resize.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_RESIZE="Media Action - Resize" | ||
PLG_MEDIA-ACTION_RESIZE_XML_DESCRIPTION="Resize functionality for images." |
11 changes: 11 additions & 0 deletions
11
administrator/language/en-GB/en-GB.plg_media-action_rotate.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_ROTATE="Media Action - Rotate" | ||
PLG_MEDIA-ACTION_ROTATE_LABEL="Rotate" | ||
PLG_MEDIA-ACTION_ROTATE_PARAM_DIRECTION="Direction" | ||
PLG_MEDIA-ACTION_ROTATE_PARAM_DIRECTION_RIGHT="Right" | ||
PLG_MEDIA-ACTION_ROTATE_PARAM_DIRECTION_LEFT="Left" | ||
PLG_MEDIA-ACTION_ROTATE_XML_DESCRIPTION="Adds rotate functionality for images." |
7 changes: 7 additions & 0 deletions
7
administrator/language/en-GB/en-GB.plg_media-action_rotate.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_MEDIA-ACTION_ROTATE="Media Action - Rotate" | ||
PLG_MEDIA-ACTION_ROTATE_XML_DESCRIPTION="Adds rotate functionality for images." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.