NormalSettingsActions is the class to derive from to create a settings action that does not redirect the user to another page.

First steps

First you want to derive your new class from NormalSettingsActions as in the code example below.

CopyC#
public class ToggleCanCreateFolio : NormalSettingsAction
{

    public override string Label
    {
        get { throw new NotImplementedException(); }
    }

    public override SettingReturnAction Action
    {
        get { throw new NotImplementedException(); }
    }

    public override bool MultipleAction
    {
        get { throw new NotImplementedException(); }
    }

    public override List<string> HeadersToUpdate()
    {
        throw new NotImplementedException();
    }

    public override bool CanPerformAction(SettingsViewType viewType, string objectType, IFolio folio, ISiteManager sm)
    {
        throw new NotImplementedException();
    }

    public override bool DoAction(ICartellaObject obj, IFolio folio, ISiteManager siteManager, out string returnValue, out string errorMessage)
    {
        throw new NotImplementedException();
    }
}

These are the functions that must be defined for it to compile and be a fully functional Settings Action

API Reference

  • Label: This is the friendly name to be displayed to the user.

  • Action: This is the what the view must do to reflect that the action has occured. There are 3 different action that can be specified:

    1. SettingReturnAction.ChangeValue: This specifies that the view should be updated. This means that the selected items fields under the header returned by HeadersToUpdate will be changed to the returnValue paramether returned by DoAction.

    2. SettingReturnAction.Delete: This will remove the selected rows from the grid.

    3. SettingReturnAction.None: This does nothing to the view.

  • MultipleAction: This is if the action can be done to multiple items at once.

  • HeadersToUpdate: This returns a list of the items the property names of the headers that need to be updated to the return value of DoAction. Only really needs to be set if Action returns SettingReturnAction.ChangeValue

  • CanPerformAction: This returns whether the action can be used at the current location in the admin view.

  • DoAction: This returns whether the action succeded or not. If it succeds and Action returns SettingReturnAction.ChangeValue then returnValue must return the value that the row in the grid will be set to. If it returns false then an error message must be specified. This will be displayed to the user as a reason to why the action failed.

Example

This is a working example of a custom Normal Settings Action

CopyC#
public class ToggleCanCreateFolio : NormalSettingsAction
{
    //The friendly name displayed to the user
    public override string Label
    {
        get { return "Toggle Can Create Folio"; }
    }

    //What the view must do to update from the action
    public override SettingReturnAction Action
    {
        get { return SettingReturnAction.ChangeValue; }
    }

    //Whether this action can be done to multiple objects at once
    public override bool MultipleAction
    {
        get { return true; }
    }

    //The property name of the header values to update after the action is complete
    public override List<string> HeadersToUpdate()
    {
        return new List<string>()
        {
            (new CustomHeaderExample()).PropertyName
        };
    }

    //Whether this action can performed right now
    public override bool CanPerformAction(SettingsViewType viewType, string objectType, IFolio folio, ISiteManager sm)
    {
        if (viewType == SettingsViewType.deleted) return false;

        SettingsTypes st = SettingsUtility.GetSettingEnum(objectType);

        return st == SettingsTypes.User;
    }

    //Performs the action and returns whether it succeded 
    public override bool DoAction(ICartellaObject obj, IFolio folio, ISiteManager siteManager, out string returnValue, out string errorMessage)
    {
        returnValue = "";
        errorMessage = "No Error";
        IUser user = obj as IUser;

        if (user == null)
        {
            throw new ArgumentException("obj must be of type of IUser");
        }

        try
        {
            user.CanCreateFolio = !user.CanCreateFolio;
        }
        catch (Exception e)
        {
            errorMessage = e.Message;
            return false;
        }

        returnValue = (new CustomHeaderExample()).GetDisplayValue(obj, folio);

        return true;
    }
}