AnsweredAssumed Answered

Lock edit record depend on status

Question asked by Luca Bartolini on Jun 15, 2015
Latest reply on Jun 15, 2015 by Francesca Shiekh
My english is bad but i'll try to explain the problem....
I want to prevent the edit record.

I made a class with a static function that it returns true if the edit is allowed or it returns SugarException( custom message ) if the status=Clompleted

I extended module api(/custom/modules/Cases/clients/base/api/) ......it calls my static function

if (! defined ( 'sugarEntry' ) || ! sugarEntry) die ( 'Not A Valid Entry Point' );

require_once 'clients/base/api/ModuleApi.php';
require_once 'data/BeanFactory.php';
require_once 'custom/modules/Cases/WorkFlow.php';   //<---my class with static function


class CheckStatusCasesApi extends ModuleApi {

public function registerApiRest() {

return array (
'checkStatusCases' => array (
'reqType' => 'GET',
'path' => array('Cases','?', 'check_status_cases'),
'pathVars' => array('module', 'id','status'),
'method' => 'checkStatusCases',
'shortHelp' => 'Formal verification transitional status.',
'longHelp' => 'custom/modules/Cases/clients/base/api/help/Cases_CheckStatusCasesApi_help.html',
'exceptions' => array(
'SugarApiExceptionError',
'SugarApiExceptionNotAuthorized'
),

);
}

/**
* This method check if the cases status isnt Closed

* @param ServiceBase $api
* @param array $args
* @throws SugarApiExceptionError
* @return boolean
*/
   public function checkStatusCases(ServiceBase $api, array $args) {
          $id = $args['id'];
          $status = $args['status'];
       
           $rtnVal = WorkFlowCases::checkStatusChanged( $id, $status );
      
           if ($rtnVal)
          {
             
                return $rtnVal;
           
           }

            return false;
   
      }
}


It's OK...i suppose.

In record.js (/custom/modules/Cases/clients/base/fields/rowaction/) i wrote


({    extendsFrom: 'ButtonField',

    initialize: function(options) {
        this.options.def.events = _.extend({}, this.options.def.events, {
            'click .rowaction': 'rowActionSelect'
        });
        this._super("initialize", [options]);
     
    },

    /**
     * Triggers event provided at this.def.event on the view's context object by default.
     * Can be configured to trigger events on 'view' itself or the view's 'layout'.
     * @param evt
     */



    rowActionSelect: function(evt) {
        if(this.isDisabled()){
            return;
        }

        //TODO Add your custom logic



           var caseID =  this.model.get('id');
            var status = this.model.get('status');
         

            var self = this;

            app.api.call('GET', app.api.buildURL('Cases/' + caseID + '/check_status_cases'), null, {

                success: function(data) {

                              //EDITING IS ALLOWED
                },

                error: function(error) {

                     //EDITING IS NOT ALLOWED

                            //self.$('.record-edit-link-wrapper').remove();
                           //self.editableFields=[];

                           app.alert.show("workflow-status-message", {
                                    level: 'warning',
                                    messages: app.lang.get(error.message , 'Cases'),
                                    autoClose: false
                            });



                    }

                });
       

        // make sure that we are not disabled first
        if(this.preventClick(evt) !== false) {
            var target = this.view.context;  // view's 'context' is target by default
            if (this.def.target === 'view') {
                target = this.view;
            } else if (this.def.target === 'layout') {
                target = this.view.layout;
            }
            if ($(evt.currentTarget).data('event')) {
                target.trigger($(evt.currentTarget).data('event'), this.model, this);
            }
        }
    }

})


But it doesn't work....how can i do it?

Outcomes