Can I use a dependency to set entire record to read only?

I know how to use a dependency to set one or more fields to ReadOnly but is there a simple way to set EVERY field in a record to read only without having to do it for each field?

I would like to avoid using the controllers to get it done for each view (record/list).

thank you,
FrancescaS

Parents
  • We have done it recently.

    Basically you need to create a custom rowaction field which automatically set itself as disabled given a trigger.

    Find examples:

    custom/clients/base/fields/unlink-action-deactivable/unlink-action-deactivable.js

    ({
    extendsFrom: 'UnlinkActionField',

    initialize: function(options) {
    this._super("initialize", [options]);
    },

    bindDataChange: function() {
    _.each(this.def.deactivable.triggerFields, function(field) {
    this.context.parent.get('model').on('change:' + field, this.deactivate, this);
    }, this);
    },

    deactivate: function() {
    if(this.context != null) {
    var context = new SUGAR.expressions.SidecarExpressionContext(this.parent, this.context.parent.get('model'), false);
    var value = SUGAR.expressions.ExpressionParser.prototype.evaluate(this.def.deactivable.trigger, context).evaluate();

    if(value == 'true') {
    if(!this.getFieldElement().hasClass('disabled')) this.getFieldElement().addClass('disabled');
    } else {
    if(this.getFieldElement().hasClass('disabled')) this.getFieldElement().removeClass('disabled');
    }
    }
    }
    })

    subpanel-list for a given module

    'rowactions' => array(
    'actions' => array(
    array(
    'type' => 'rowaction',
    'css_class' => 'btn',
    'tooltip' => 'LBL_PREVIEW',
    'event' => 'list:preview:fire',
    'icon' => 'fa-eye',
    'acl_action' => 'view',
    ),
    array(
    'type' => 'unlink-action-deactivable',
    'icon' => 'fa-chain-broken',
    'label' => 'LBL_UNLINK_BUTTON',
    'deactivable' => array(
    'triggerFields' => array('status'),
    'trigger' => 'or(isInList($status, createList("Closed", "Cancelado", "Pedido nao Postado")), not(isUserInList(createList("SIMM_GER", "SIMM_SUP"))))',
    )
    ),
    ),
    ),

    This solution, with minor adjustments, works oover any button (Edit, Save, Unlink, Add etc).

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Reply
  • We have done it recently.

    Basically you need to create a custom rowaction field which automatically set itself as disabled given a trigger.

    Find examples:

    custom/clients/base/fields/unlink-action-deactivable/unlink-action-deactivable.js

    ({
    extendsFrom: 'UnlinkActionField',

    initialize: function(options) {
    this._super("initialize", [options]);
    },

    bindDataChange: function() {
    _.each(this.def.deactivable.triggerFields, function(field) {
    this.context.parent.get('model').on('change:' + field, this.deactivate, this);
    }, this);
    },

    deactivate: function() {
    if(this.context != null) {
    var context = new SUGAR.expressions.SidecarExpressionContext(this.parent, this.context.parent.get('model'), false);
    var value = SUGAR.expressions.ExpressionParser.prototype.evaluate(this.def.deactivable.trigger, context).evaluate();

    if(value == 'true') {
    if(!this.getFieldElement().hasClass('disabled')) this.getFieldElement().addClass('disabled');
    } else {
    if(this.getFieldElement().hasClass('disabled')) this.getFieldElement().removeClass('disabled');
    }
    }
    }
    })

    subpanel-list for a given module

    'rowactions' => array(
    'actions' => array(
    array(
    'type' => 'rowaction',
    'css_class' => 'btn',
    'tooltip' => 'LBL_PREVIEW',
    'event' => 'list:preview:fire',
    'icon' => 'fa-eye',
    'acl_action' => 'view',
    ),
    array(
    'type' => 'unlink-action-deactivable',
    'icon' => 'fa-chain-broken',
    'label' => 'LBL_UNLINK_BUTTON',
    'deactivable' => array(
    'triggerFields' => array('status'),
    'trigger' => 'or(isInList($status, createList("Closed", "Cancelado", "Pedido nao Postado")), not(isUserInList(createList("SIMM_GER", "SIMM_SUP"))))',
    )
    ),
    ),
    ),

    This solution, with minor adjustments, works oover any button (Edit, Save, Unlink, Add etc).

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Children
No Data