This topic contains 22 replies, has 3 voices, and was last updated by Mike Kudelya 7 years, 1 month ago.
- Topic
Hi,
I work on a project that aim to monitor website.
So I have an entity, named Alerte, which is create or update automatically. I don’t need ( and I don’t want) a form associated, no one have to manage this entity ( create or delete) but in some case i need that a user can update just one field which contain a DateTime. So I want a button, when i click on it, it update this entity field with new DateTime but i never need a update page with form.
I found a lot of information but none really is that i want.
I follow this tuto : http://www.ibnab.com/en/blog/orocrm/orocrm-create-custom-grid-action-technique-and-secret
But i found these informations too :
– https://github.com/orocrm/platform/blob/11114aa77cb972f82038592bb743c96cf7fb1c2f/src/Oro/Bundle/ActionBundle/Resources/doc/configuration-reference.md#substitution-of-action
– https://github.com/orocrm/platform/blob/master/src/Oro/Component/Action/Resources/doc/actions.mdI think that I can do what i want with just configuring an action.
I really need to undestand how it works.
My code :
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667<?phpnamespace Sinabs\MonitoringBundle\Controller;use Symfony\Component\HttpFoundation\Request;use Symfony\Bundle\FrameworkBundle\Controller\Controller;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;use Oro\Bundle\SecurityBundle\Annotation\Acl;use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;use Sinabs\MonitoringBundle\Entity\Alerte;/*** Alerte controller.** @Route("/alerte")*/class AlerteController extends Controller {/*** Lists all Alerte entities.** @Route("/", name="monitoring.alerte_index")* @Template()* @Acl(* id="monitoring.alerte_view",* type="entity",* class="SinabsMonitoringBundle:Alerte",* permission="VIEW"* )**/public function indexAction() {return array('gridName' => 'alertes-grid');}/*** Finds and displays a Alerte entity.** @Route("/{id}", name="monitoring.alerte_view", requirements={"id"="\d+"})* @Template()* @AclAncestor("monitoring.alerte_view")**/public function viewAction(Alerte $alerte) {return array('entity' => $alerte);}/*** mark alerte as ended set the end_time.** @Route("/{id}", name="monitoring.alerte_end", requirements={"id"="\d+"})* @AclAncestor("monitoring.alerte_view")**/public function endAction(Alerte $alerte) {$alerte->setEnd(new \DateTime());$entityManager = $this->getDoctrine()->getManager();$entityManager->persist($alerte);$entityManager->flush();return $this->redirect($this->generateUrl('monitoring.alerte_index'));}}123456789101112131415161718192021222324<?phpnamespace Sinabs\MonitoringBundle\Extension\Action\Actions;use Oro\Bundle\DataGridBundle\Extension\Action\ActionConfiguration;use Oro\Bundle\DataGridBundle\Extension\Action\Actions\AjaxAction;class EndAlerteAction extends AjaxAction {/*** @var array*/protected $requiredOptions = [ 'entity_name', 'data_identifier'];public function getOptions() {$options = parent::getOptions();$options['frontend_type'] = 'end_alerte';if (empty($options['frontend_handle'])) {$options['frontend_handle'] = 'end_alerte';}return $options;}}123456789101112131415161718192021222324252627282930/*global define*/define(['./model-action'], function (ModelAction) {'use strict';var EndAlerteAction;/*** Ajax action, triggers REST AJAX request** @export oro/datagrid/action/end_alerte-action* @class oro.datagrid.action.EndAlerteAction* @extends oro.datagrid.action.ModelAction*/EndAlerteAction = ModelAction.extend({defaultMessages: {confirm_title: 'Execution Confirmation',confirm_content: 'Are you sure you want to do this?',confirm_ok: 'Yes, do it',confirm_cancel: 'Cancel',success: 'Action performed.',error: 'Action is not performed.',empty_selection: 'Please, select item to perform action.'}});return EndAlerteAction;});123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990alertes-grid:source:acl_resource: monitoring.alerte_viewtype: ormquery:select:- a.id- a.start- a.end- a.level- a.description- a.nb_notified- w.name- m.id as monitor_idfrom:- { table: SinabsMonitoringBundle:Alerte , alias a }join:left:- { join: a.monitor, alias m }- { join: m.webSite, alias w }columns:id:label: Idstart:label: Problem start atfrontend_type: datetimeend:label: Problem end atfrontend_type: datetimelevel:label: Leveldescription:label: Descriptionnb_notified:label: Nb persons notifiedname:label: Related WebSitemonitor_id:label: Related Monitorproperties:id: ~view_link:type: urlroute: monitoring.alerte_viewparams:- idend_alerte_link:type: urlroute: monitoring.alerte_endparams: [ id ]sorters:columns:start:data_name: a.startdefault:start: ASCfilters:columns:level:type: stringdata_name: a.leveldescription:type: stringdata_name: a.descriptionnb_notified:type: stringdata_name: a.nb_notifiedname:type: stringdata_name: w.nameactions:view:type: navigatelabel: Viewlink: view_linkicon: eye-openacl_resource: monitoring.alerte_viewrowAction: trueend_alerte:type: end_alertedata_identifier: a.idfrontend_handle: dialogfrontend_options:title: 'End Alerte'entity_name: %sinabs_monitoring.alerte.entity.class%acl_resource: monitoring.alerte_viewlabel: end_alerteicon: editconfirmation: truelink: end_alerte_link12345678910//actions.ymlparameters:sinabs_monitoring.extension.action.type.end_alerte.class: Sinabs\MonitoringBundle\Extension\Action\Actions\EndAlerteActionservices:sinabs_monitoring.extension.action.type.end_alerte:class: %sinabs_monitoring.extension.action.type.end_alerte.class%scope: prototypetags:- { name: oro_datagrid.extension.action.type, type: end_alerte }But maybe something like this can be done :
12345678910111213actions:monitoring_alerte_end_action:label: End Alerteenabled: falseentities:- Sinabs\MonitoringBundle\Entity\Alerteorder: 0acl_resource: monitoring.alerte_viewpre_conditions:@empty: [$end]functions:- @create_datetime:attribute: $endBut i dont understand how it works.
Thanks for replies.
Adrien
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.