how to prevent module editing depending on status 'Completed'

I am a beginner on Sugar...

My target is prevent module editing.

I wrote down ......this.$('.record-edit-link-wrapper').remove(); 
 and it works....
but i want to disabled icon-pencil (it is my biggest problem) on each field ....In order to prevent editing if status is Completed...
How can do it?
Sugar 7.5.1 pro
Parents
  • Ciao Luca,

    SugarCRM has a number of “views” that are used to build the page. Record View is the one sugar uses to display all the details of the case. It has a full edit (using the button) and an inline edit (field by field within the display of the details - the pencils you see when you hover on a field indicate which fields are editable inline).

    There may also be other views you need to take care of, mobile views, inline edit in subpanels etc which may become workarounds to editing.

    But let's start with record view, based on Mike Solomon's work (the link I gave you above) to prevent editing you need to work on preventing inline editing and disabling the Edit button in record view: 

       custom/modules/Cases/clients/base/view/record/record.js

    You don’t need an API to check if the Case is closed. You can retrieve field values from within your javascript, inside record.js as long as the page has been rendered.

    this.model.get(‘status') 

    will return the contents of the ‘status’ field for that record.


    So to disable inline editing you will create

    custom/modules/Cases/clients/base/view/record/record.js

    on render, you will disable the inline editing if the status is Completed (the custom checkReadonly function), and when the user clicks "Edit" you will pop up a message that "Edit is not allowed for completed Cases" (in the editClicked function).

    (NOTE this code is NOT tested, so there may be errors, always check your console log :) ).

    ({
      extendsFrom: 'RecordView',
      initialize: function(options){
          this._super('initialize', [options]);
          this.on('render',this.checkReadonly,this);
      },
      checkReadonly: function(){
         var status = this.model.get(‘status');
          if (status == ‘Completed'){ 
                //do not allow inline edit on any fields
                this.editableFields = [];
          }
      },
      editClicked: function(){
        //this overrides an existing event handler when "Edit" is clicked
        //see original at <sugar_root>/jssource/src_files/clients/base/views/record/record.js
        var status = this.model.get(‘status'); //get the status for this record
          if (status == ‘Completed'){ 
              //stop the edit button from being used
              var msg = 'Edit not allowed for Completed Cases';
              app.alert.show(‘case-completed', {
                 level: 'warning',
                 messages: msg,
                 autoClose: true
             });       
             return; //goes back to the view without changing to Edit layout
          }else{
            //allow the edit 
            this.setButtonStates(this.STATE.EDIT);
            this.toggleEdit(true);
         }
      },
    })
    Hope this helps,
    in bocca al lupo,
    FrancescaS
Reply
  • Ciao Luca,

    SugarCRM has a number of “views” that are used to build the page. Record View is the one sugar uses to display all the details of the case. It has a full edit (using the button) and an inline edit (field by field within the display of the details - the pencils you see when you hover on a field indicate which fields are editable inline).

    There may also be other views you need to take care of, mobile views, inline edit in subpanels etc which may become workarounds to editing.

    But let's start with record view, based on Mike Solomon's work (the link I gave you above) to prevent editing you need to work on preventing inline editing and disabling the Edit button in record view: 

       custom/modules/Cases/clients/base/view/record/record.js

    You don’t need an API to check if the Case is closed. You can retrieve field values from within your javascript, inside record.js as long as the page has been rendered.

    this.model.get(‘status') 

    will return the contents of the ‘status’ field for that record.


    So to disable inline editing you will create

    custom/modules/Cases/clients/base/view/record/record.js

    on render, you will disable the inline editing if the status is Completed (the custom checkReadonly function), and when the user clicks "Edit" you will pop up a message that "Edit is not allowed for completed Cases" (in the editClicked function).

    (NOTE this code is NOT tested, so there may be errors, always check your console log :) ).

    ({
      extendsFrom: 'RecordView',
      initialize: function(options){
          this._super('initialize', [options]);
          this.on('render',this.checkReadonly,this);
      },
      checkReadonly: function(){
         var status = this.model.get(‘status');
          if (status == ‘Completed'){ 
                //do not allow inline edit on any fields
                this.editableFields = [];
          }
      },
      editClicked: function(){
        //this overrides an existing event handler when "Edit" is clicked
        //see original at <sugar_root>/jssource/src_files/clients/base/views/record/record.js
        var status = this.model.get(‘status'); //get the status for this record
          if (status == ‘Completed'){ 
              //stop the edit button from being used
              var msg = 'Edit not allowed for Completed Cases';
              app.alert.show(‘case-completed', {
                 level: 'warning',
                 messages: msg,
                 autoClose: true
             });       
             return; //goes back to the view without changing to Edit layout
          }else{
            //allow the edit 
            this.setButtonStates(this.STATE.EDIT);
            this.toggleEdit(true);
         }
      },
    })
    Hope this helps,
    in bocca al lupo,
    FrancescaS
Children
No Data