mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 15:52:24 +02:00
N°633 - Portal: CreateBrick now accepts abstract classes. This is a refactoring from an extension (CreateBrickExtended) that has been merge into the core.
SVN:trunk[4553]
This commit is contained in:
@@ -118,4 +118,5 @@ Dict::Add('CS CZ', 'Czech', 'Čeština', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('CS CZ', 'Czech', 'Čeština', array(
|
Dict::Add('CS CZ', 'Czech', 'Čeština', array(
|
||||||
'Brick:Portal:Create:Name' => 'Rychlé vytvoření',
|
'Brick:Portal:Create:Name' => 'Rychlé vytvoření',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Please, choose a type~~',
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -113,5 +113,5 @@ Dict::Add('DE DE', 'German', 'Deutsch', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('DE DE', 'German', 'Deutsch', array(
|
Dict::Add('DE DE', 'German', 'Deutsch', array(
|
||||||
'Brick:Portal:Create:Name' => 'Schnelles Erstellen',
|
'Brick:Portal:Create:Name' => 'Schnelles Erstellen',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Please, choose a type~~',
|
||||||
));
|
));
|
||||||
?>
|
|
||||||
|
|||||||
@@ -114,5 +114,5 @@ Dict::Add('EN US', 'English', 'English', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('EN US', 'English', 'English', array(
|
Dict::Add('EN US', 'English', 'English', array(
|
||||||
'Brick:Portal:Create:Name' => 'Quick creation',
|
'Brick:Portal:Create:Name' => 'Quick creation',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Please, choose a type',
|
||||||
));
|
));
|
||||||
?>
|
|
||||||
|
|||||||
@@ -114,5 +114,5 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array(
|
Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array(
|
||||||
'Brick:Portal:Create:Name' => 'Creación rápida',
|
'Brick:Portal:Create:Name' => 'Creación rápida',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Please, choose a type~~',
|
||||||
));
|
));
|
||||||
?>
|
|
||||||
|
|||||||
@@ -114,5 +114,6 @@ Dict::Add('FR FR', 'French', 'Français', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('FR FR', 'French', 'Français', array(
|
Dict::Add('FR FR', 'French', 'Français', array(
|
||||||
'Brick:Portal:Create:Name' => 'Création rapide',
|
'Brick:Portal:Create:Name' => 'Création rapide',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Veuillez choisir le type',
|
||||||
));
|
));
|
||||||
?>
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ namespace Combodo\iTop\Portal\Controller;
|
|||||||
use \Silex\Application;
|
use \Silex\Application;
|
||||||
use \Symfony\Component\HttpFoundation\Request;
|
use \Symfony\Component\HttpFoundation\Request;
|
||||||
use \Symfony\Component\HttpKernel\HttpKernelInterface;
|
use \Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use \MetaModel;
|
||||||
use \Combodo\iTop\Portal\Helper\ApplicationHelper;
|
use \Combodo\iTop\Portal\Helper\ApplicationHelper;
|
||||||
use \Combodo\iTop\Portal\Helper\ContextManipulatorHelper;
|
use \Combodo\iTop\Portal\Helper\ContextManipulatorHelper;
|
||||||
|
use \Combodo\iTop\Portal\Helper\SecurityHelper;
|
||||||
|
|
||||||
class CreateBrickController extends BrickController
|
class CreateBrickController extends BrickController
|
||||||
{
|
{
|
||||||
@@ -31,28 +33,62 @@ class CreateBrickController extends BrickController
|
|||||||
public function DisplayAction(Request $oRequest, Application $oApp, $sBrickId)
|
public function DisplayAction(Request $oRequest, Application $oApp, $sBrickId)
|
||||||
{
|
{
|
||||||
$oBrick = ApplicationHelper::GetLoadedBrickFromId($oApp, $sBrickId);
|
$oBrick = ApplicationHelper::GetLoadedBrickFromId($oApp, $sBrickId);
|
||||||
|
$sObjectClass = $oBrick->GetClass();
|
||||||
|
|
||||||
$aRouteParams = array(
|
$aRouteParams = array(
|
||||||
'sObjectClass' => $oBrick->GetClass()
|
'sObjectClass' => $oBrick->GetClass()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Preparing redirection route
|
// Checking for actions rules
|
||||||
// - Checking for action rules
|
$aRules = $oBrick->GetRules();
|
||||||
$aRules = $oBrick->GetRules();
|
if (!empty($aRules))
|
||||||
if (!empty($aRules))
|
{
|
||||||
{
|
$aRouteParams['ar_token'] = ContextManipulatorHelper::EncodeRulesToken($aRules);
|
||||||
$aRouteParams['ar_token'] = ContextManipulatorHelper::EncodeRulesToken($aRules);
|
}
|
||||||
}
|
|
||||||
// - Adding brick id to the params
|
// Checking if the target object class is asbtract or not
|
||||||
$aRouteParams['sBrickId'] = $sBrickId;
|
// - If is not abstract, we redirect to object creation form
|
||||||
// - Generating route
|
if (!MetaModel::IsAbstract($sObjectClass))
|
||||||
$sRedirectRoute = $oApp['url_generator']->generate('p_object_create', $aRouteParams);
|
{
|
||||||
// - Request
|
// Preparing redirection route
|
||||||
$oSubRequest = Request::create($sRedirectRoute, 'GET', $oRequest->query->all(), $oRequest->cookies->all(), array(), $oRequest->server->all());
|
// - Adding brick id to the params
|
||||||
|
$aRouteParams['sBrickId'] = $sBrickId;
|
||||||
return $oApp->handle($oSubRequest, HttpKernelInterface::SUB_REQUEST, true);
|
// - Generating route
|
||||||
|
$sRedirectRoute = $oApp['url_generator']->generate('p_object_create', $aRouteParams);
|
||||||
|
// - Request
|
||||||
|
$oSubRequest = Request::create($sRedirectRoute, 'GET', $oRequest->query->all(), $oRequest->cookies->all(), array(), $oRequest->server->all());
|
||||||
|
|
||||||
|
$oResponse = $oApp->handle($oSubRequest, HttpKernelInterface::SUB_REQUEST, true);
|
||||||
|
}
|
||||||
|
// - Else, we list the leaf classes as an intermediate step
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aData = array(
|
||||||
|
'oBrick' => $oBrick,
|
||||||
|
'sBrickId' => $sBrickId,
|
||||||
|
'aLeafClasses' => array(),
|
||||||
|
'ar_token' => $aRouteParams['ar_token']
|
||||||
|
);
|
||||||
|
|
||||||
|
$aLeafClasses = array();
|
||||||
|
$aChildClasses = MetaModel::EnumChildClasses($sObjectClass);
|
||||||
|
foreach ($aChildClasses as $sChildClass)
|
||||||
|
{
|
||||||
|
if (!MetaModel::IsAbstract($sChildClass) && SecurityHelper::IsActionAllowed($oApp, UR_ACTION_CREATE, $sChildClass))
|
||||||
|
{
|
||||||
|
$aLeafClasses[] = array(
|
||||||
|
'id' => $sChildClass,
|
||||||
|
'name' => MetaModel::GetName($sChildClass)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aData['aLeafClasses'] = $aLeafClasses;
|
||||||
|
|
||||||
|
$oResponse = $oApp['twig']->render($oBrick->GetPageTemplatePath(), $aData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $oResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -32,6 +32,7 @@ class CreateBrick extends PortalBrick
|
|||||||
{
|
{
|
||||||
const DEFAULT_HOME_ICON_CLASS = 'fa fa-plus';
|
const DEFAULT_HOME_ICON_CLASS = 'fa fa-plus';
|
||||||
const DEFAULT_NAVIGATION_MENU_ICON_CLASS = 'fa fa-plus fa-2x';
|
const DEFAULT_NAVIGATION_MENU_ICON_CLASS = 'fa fa-plus fa-2x';
|
||||||
|
const DEFAULT_PAGE_TEMPLATE_PATH = 'itop-portal-base/portal/src/views/bricks/create/modal.html.twig';
|
||||||
const DEFAULT_CLASS = '';
|
const DEFAULT_CLASS = '';
|
||||||
|
|
||||||
static $sRouteName = 'p_create_brick';
|
static $sRouteName = 'p_create_brick';
|
||||||
@@ -131,5 +132,3 @@ class CreateBrick extends PortalBrick
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -30,5 +30,3 @@ class CreateBrickRouter extends AbstractRouter
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
{# itop-portal-base/portal/src/views/bricks/create/layout.html.twig #}
|
||||||
|
{# Create brick base layout #}
|
||||||
|
{% extends 'itop-portal-base/portal/src/views/modal/layout.html.twig' %}
|
||||||
|
|
||||||
|
{% block pModalTitle %}
|
||||||
|
{{ oBrick.GetTitle()|dict_s }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block pModalBody %}
|
||||||
|
<p>{{ 'Brick:Portal:Create:ChooseType'|dict_s }}</p>
|
||||||
|
<ul id="{{ sBrickId }}_leaf_classes">
|
||||||
|
{% for aLeafClass in aLeafClasses %}
|
||||||
|
<li><a href="#" data-target-class="{{ aLeafClass.id }}">{{ aLeafClass.name }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('#{{ sBrickId }}_leaf_classes a').off('click').on('click', function(oEvent){
|
||||||
|
oEvent.preventDefault();
|
||||||
|
|
||||||
|
var sUrl = '{{ app['url_generator'].generate('p_object_create', {sObjectClass : '-sObjectClass-'})|raw }}';
|
||||||
|
var oModalElem = $(this).closest('.modal');
|
||||||
|
// Showing loader
|
||||||
|
oModalElem.find('.modal-content').html($('#page_overlay .overlay_content').html());
|
||||||
|
// Preparing target class url
|
||||||
|
sUrl = sUrl.replace(/-sObjectClass-/, $(this).attr('data-target-class') );
|
||||||
|
sUrl = AddParameterToUrl(sUrl, 'ar_token', '{{ ar_token }}');
|
||||||
|
// Loading form
|
||||||
|
oModalElem.find('.modal-content').load(sUrl, function(oData, sStatus, oXHR){
|
||||||
|
var oResponse = (oXHR.responseJSON !== undefined) ? oXHR.responseJSON : JSON.parse(oXHR.responseText);
|
||||||
|
|
||||||
|
// Note : This could be refactored for a global use
|
||||||
|
oModalElem.html( $('#modal-for-alert').html() );
|
||||||
|
oModalElem.find('.modal-title').html(oResponse.error_title);
|
||||||
|
oModalElem.find('.modal-body .alert').html(oResponse.error_message)
|
||||||
|
.removeClass('alert-success alert-info alert-warning alert-danger')
|
||||||
|
.addClass('alert-danger');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block pModalFooter %}
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'Portal:Button:Cancel'|dict_s }}</button>
|
||||||
|
{% endblock %}
|
||||||
@@ -96,4 +96,5 @@ Dict::Add('RU RU', 'Russian', 'Русский', array(
|
|||||||
// CreateBrick brick
|
// CreateBrick brick
|
||||||
Dict::Add('RU RU', 'Russian', 'Русский', array(
|
Dict::Add('RU RU', 'Russian', 'Русский', array(
|
||||||
'Brick:Portal:Create:Name' => 'Быстрое создание',
|
'Brick:Portal:Create:Name' => 'Быстрое создание',
|
||||||
|
'Brick:Portal:Create:ChooseType' => 'Please, choose a type~~',
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user