Reordering header buttons

為{幸葍}努か 提交于 2019-12-11 16:44:33

问题


I have added a custom save button in Sales Order screen in place of my current one. How do I reorder the main toolbar so that new save button is in place of the old one? You can do this easily for grid buttons, but for header ones it is not so obvious.


回答1:


The order of the buttons is based on the order of the PXActions in the graph.

(1) In this example my save button is first, then cancel button second.

public class MyGraph : PXGraph<MyGraph>
{
    public PXSave<MyPrimaryDac> Save;
    public PXCancel<MyPrimaryDac> Cancel;
}

(2) In this example my cancel button is first, then save button second.

public class MyGraph : PXGraph<MyGraph>
{
    public PXCancel<MyPrimaryDac> Cancel;
    public PXSave<MyPrimaryDac> Save;
}

Note that PXSave and PXCancel are PXActions.

Edit: from comments and question edits if you are extending another graph you should be able to use a new class inherited from PXSave and set the property name the same ("Save" in the example of sales order). Here is something that should work for an override to the save button and asking the user a question and keeps the save button in the same button location...

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public SalesPXSave<SOOrder> Save;

    public class SalesPXSave<TNode> : PXSave<TNode> where TNode : class, IBqlTable, new()
    {
        public SalesPXSave(PXGraph graph, string name) : base(graph, name)
        {
        }

        public SalesPXSave(PXGraph graph, Delegate handler) : base(graph, handler)
        {
        }

        [PXSaveButton]
        [PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        protected override IEnumerable Handler(PXAdapter adapter)
        {
            bool someCondition = true;
            if (someCondition)
            {
                if (adapter.View.Ask(adapter.View.Graph.Caches[typeof(TNode)].Current, "Hi User",
                    MessageButtons.YesNo) != WebDialogResult.Yes)
                {
                    return adapter.Get();
                }
            }

            return base.Handler(adapter);
        }
    }
}

Edit: For reference here are some quick untested examples of extending RowPersisting or the Persist in an extension if this is preferred vs extending the buttons...

[PXOverride]
public virtual void Persist(Action del)
{
    if (Base.Document.Ask(Base.Document.Current, "Question", "Continue?",
            MessageButtons.YesNo) != WebDialogResult.Yes)
    {
        return;
    }

    del?.Invoke();
}


protected virtual void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting del)
{
    var row = (SOOrder)e.Row;
    if (row == null)
    {
        return;
    }

    if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update || e.Operation == PXDBOperation.Delete) &&
        Base.Document.Ask(row, "Question", "Continue ?", MessageButtons.YesNo, true) != WebDialogResult.Yes)
    {
        e.Cancel = true;
        return;
    }

    del?.Invoke(cache, e);
}


来源:https://stackoverflow.com/questions/48672689/reordering-header-buttons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!