1 – Now if you want create custom action oro platform have perfect technique for handling the datagrid and put your custom action link in any grid .
First create folder extension inside your bundle Extension/Action/Actions/GetpdfAction.php
I want extend ajax action behavior for that I will extends :
Oro\Bundle\DataGridBundle\Extension\Action\Actions\AjaxAction;
the content of the class
<?php namespace Ibnab\Bundle\PmanagerBundle\Extension\Action\Actions; use Oro\Bundle\DataGridBundle\Extension\Action\ActionConfiguration; use Oro\Bundle\DataGridBundle\Extension\Action\Actions\AjaxAction; class GetpdfAction extends AjaxAction { /** * @var array */ protected $requiredOptions = [ 'entity_name', 'data_identifier']; public function getOptions() { $options = parent::getOptions(); $options['frontend_type'] = 'getpdf'; $options['frontend_handle'] = 'getpdf'; } return $options; } }
see the frontend type is very important part is the link between your action and custom js in second section 'getpdf-action.js'
getpdf-action.js
Second now you need create requirejs.yml for declaring your custom js yes is for customize options , change message route or other for more info about all options go to :
/vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/action/abstract-action.js
ok inside requirejs.yml put :
config: paths: 'oro/datagrid/action/getpdf-action': 'bundles/ibnabpmanager/js/datagrid/action/getpdf-action.js'
And create file getpdf-action.js inside your custom bundle like: Ibnab/Bundle/PmanagerBundle/Resources/public/js/datagrid/action/getpdf-action.js
put that :
/*global define*/ 'oro/datagrid/action/model-action' ], function (ModelAction) { 'use strict'; var GetpdfAction; /** * Ajax action, triggers REST AJAX request * * @export oro/datagrid/action/getpdf-action * @class oro.datagrid.action.GetpdfAction * @extends oro.datagrid.action.ModelAction */ GetpdfAction = 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 GetpdfAction; });
Third now I want add my custom action to contact datagrid inside datagrid.yml of my custom option I will add :
datagrid: contacts-grid: properties: getpdf_link: type: url route: pmanager_default_getpdf params: [ id ] actions: getpdf: type: getpdf data_identifier: c.id frontend_handle: dialog frontend_options: title: 'Address Book' entity_name: %orocrm_contact.entity.class% acl_resource: pmanager_defaut_getpdf label: pmanager_defaut_getpdf icon: eye-open confirmation: true link: getpdf_link
Fourthly oh don't forget creating service inside example action.yml with content :
parameters: ibnab_pmanager.extension.action.type.getpdf.class: Ibnab\Bundle\PmanagerBundle\Extension\Action\Actions\GetpdfAction services: ibnab_pmanager.extension.action.type.getpdf: class: %ibnab_pmanager.extension.action.type.getpdf.class% scope: prototype tags: - { name: oro_datagrid.extension.action.type, type: getpdf }
inside IbnabPmanagerExtension.php add :
$loader->load('actions.yml');
to function load
You can play now with it enter to contact grid page :
and refresh customize your getpdf-action.js and see if have action if not is note loaded
I find small truck for see if is loaded with my frontend-type I go to :
/opt/lampp/htdocs/alloro/oc2/vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/map-action-module-name.js
and I change the code to :
/*global define*/ 'use strict'; var moduleNameTemplate = 'oro/datagrid/action/{{type}}-action'; return function (type) { alert(moduleNameTemplate.replace('{{type}}', type)); return moduleNameTemplate.replace('{{type}}', type); }; });
this js maped every action with it js based on frontend-type
and shift + ctrl + f5 = it will be show all loaded action by frontend-type and the js related to this action
More resources on the same project see all folder :
/opt/lampp/htdocs/alloro/oc2/vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/action/
And folder :
/opt/lampp/htdocs/alloro/oc2/vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Extension/Action/Actions
See DatagridBunlde genraly in oro platform
For testing with changing js don't forget :
rm -rf web/bundles/*
php app/console assets:install
Five more on-line resource
http://www.orocrm.com/forums/topic/%D1%81ustom-javascript-action
http://www.orocrm.com/forums/topic/custom-mass-actions
http://www.orocrm.com/forums/topic/how-to-get-the-data-from-datagrid-action
http://www.orocrm.com/forums/topic/hdi-open-dialog-from-datagrid
https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/datagrid.md
https://www.youtube.com/watch?v=WJZ98akh8tM
Comments