/   /   /  OroCRM : Create custom grid action (technique and secret)

Note:

For more extensions and themes visit our store

OroCRM : Create custom grid action (technique and secret)


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

  1. <?php
  2. namespace Ibnab\Bundle\PmanagerBundle\Extension\Action\Actions;
  3. use Oro\Bundle\DataGridBundle\Extension\Action\ActionConfiguration;
  4. use Oro\Bundle\DataGridBundle\Extension\Action\Actions\AjaxAction;
  5. class GetpdfAction extends AjaxAction
  6. {
  7. /**
  8. * @var array
  9. */
  10. protected $requiredOptions = [  'entity_name', 'data_identifier'];
  11. public function getOptions()
  12. {
  13. $options = parent::getOptions();
  14. $options['frontend_type'] = 'getpdf';
  15. if (empty($options['frontend_handle'])) {
  16. $options['frontend_handle'] = 'getpdf';
  17. }
  18. return $options;
  19. }
  20. }
  21.  

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 :
 
  1.  
  2. config:
  3.     paths:
  4.         'oro/datagrid/action/getpdf-action': 'bundles/ibnabpmanager/js/datagrid/action/getpdf-action.js'
  5.   

And create file  getpdf-action.js inside  your custom bundle like:  Ibnab/Bundle/PmanagerBundle/Resources/public/js/datagrid/action/getpdf-action.js
put that :
 

  1.  
  2. /*global define*/
  3. 'oro/datagrid/action/model-action'
  4. ], function (ModelAction) {
  5. 'use strict';
  6.  
  7.     var GetpdfAction;
  8.  
  9.     /**
  10.     * Ajax action, triggers REST AJAX request
  11.     *
  12.     * @export  oro/datagrid/action/getpdf-action
  13.     * @class   oro.datagrid.action.GetpdfAction
  14.     * @extends oro.datagrid.action.ModelAction
  15.     */
  16.  
  17.     GetpdfAction = ModelAction.extend({
  18.         defaultMessages: {
  19.            confirm_title: 'Execution Confirmation',
  20.            confirm_content: 'Are you sure you want to do this?',
  21.            confirm_ok: 'Yes, do it',
  22.            confirm_cancel: 'Cancel',
  23.            success: 'Action performed.',
  24.            error: 'Action is not performed.',
  25.            empty_selection: 'Please, select item to perform action.'
  26.        }
  27.    });
  28.  
  29.     return GetpdfAction;
  30. });
  31.  

Third  now I want add my custom action to contact datagrid inside datagrid.yml of my custom option I will add :
 

  1.  
  2. datagrid:
  3.     contacts-grid:
  4.         properties:
  5.             getpdf_link:
  6.                 type:       url
  7.                 route:      pmanager_default_getpdf
  8.                 params:     [ id ]
  9.         actions:
  10.             getpdf:
  11.                 type: getpdf
  12.                 data_identifier: c.id
  13.                 frontend_handle: dialog
  14.                 frontend_options:
  15.                     title: 'Address Book'
  16.                 entity_name: %orocrm_contact.entity.class%
  17.                 acl_resource: pmanager_defaut_getpdf
  18.                 label: pmanager_defaut_getpdf
  19.                 icon: eye-open
  20.                 confirmation: true
  21.                 link: getpdf_link
  22.  

Fourthly oh don't forget creating service inside example action.yml with content :
 

  1.  
  2. parameters:
  3.     ibnab_pmanager.extension.action.type.getpdf.class:    Ibnab\Bundle\PmanagerBundle\Extension\Action\Actions\GetpdfAction
  4.  
  5. services:
  6.     ibnab_pmanager.extension.action.type.getpdf:
  7.         class: %ibnab_pmanager.extension.action.type.getpdf.class%
  8.         scope: prototype
  9.         tags:
  10.             - { name: oro_datagrid.extension.action.type, type: getpdf }
  11.  


inside IbnabPmanagerExtension.php add :
 

  1.  
  2.  $loader->load('actions.yml');
  3.   

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 :
 
  1.  
  2. /*global define*/
  3. define(function () {
  4.     'use strict';
  5.      var moduleNameTemplate = 'oro/datagrid/action/{{type}}-action';
  6.      return function (type) {
  7.          alert(moduleNameTemplate.replace('{{type}}', type));
  8.          return moduleNameTemplate.replace('{{type}}', type);
  9.      };
  10. });
  11.   

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

Related Posts

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.