Exemplo n.º 1
0
        public bool triggerOnButtonClick(NbtButtonData ButtonData)
        {
            bool Ret = false;

            //1: We have Button Data
            if (null != ButtonData)
            {
                //2: Before the Button Click, Save the Node if any tabs and properties have been provided
                Collection <Int32> TabIds = new Collection <int>();
                if (null != ButtonData.TabIds)
                {
                    TabIds = ButtonData.TabIds.ToIntCollection(ExcludeMinVal: true, ExcludeDuplicates: true);
                }

                if (TabIds.Count > 0)
                {
                    foreach (Int32 TabId in TabIds)
                    {
                        _onBeforeButtonClickSaveProps(CswConvert.ToString(TabId), ButtonData);
                    }
                }
                else
                {
                    if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add)
                    {
                        //Client-side, we are defining a tabid as EditMode + '_tab'. This isn't great, but it's what we've got right now.
                        _onBeforeButtonClickSaveProps(CswEnumNbtNodeEditMode.Add + "_tab", ButtonData);
                    }
                }

                //3: If we're adding, we're always refreshing on add as the default option
                if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add)
                {
                    ButtonData.Action = CswEnumNbtButtonAction.refreshonadd;
                }

                //4: If this is the Save property, we're done; else execute the click event
                if (null != ButtonData.NodeTypeProp && ButtonData.NodeTypeProp.IsSaveProp)
                {
                    Ret = true;
                }
                else
                {
                    Ret = onButtonClick(ButtonData);
                }

                //5: If we had tabs or props coming in, we should get the current values to send back (they probably changed after the button click)
                if (TabIds.Count > 0)
                {
                    foreach (Int32 TabId in TabIds)
                    {
                        _onAfterButtonClickSaveProps(CswConvert.ToString(TabId), ButtonData);
                    }
                    if (ButtonData.NodeIds.Count > 1)
                    {
                        Collection <CswPrimaryKey> MultiNodePks = new Collection <CswPrimaryKey>();
                        foreach (string CopyToNodeId in ButtonData.NodeIds)
                        {
                            CswPrimaryKey MultiNodePk = CswConvert.ToPrimaryKey(CopyToNodeId);
                            if (null != MultiNodePk && MultiNodePk != NodeId)
                            {
                                MultiNodePks.Add(MultiNodePk);
                            }
                        }
                        if (ButtonData.NodeIds.Count >= CswNbtBatchManager.getBatchThreshold(_CswNbtResources))
                        {
                            if (ButtonData.PropIds.Count > 0)
                            {
                                Collection <Int32> NodeTypePropIds = new Collection <Int32>();
                                foreach (string PropIdAttrStr in ButtonData.PropIds)
                                {
                                    CswPropIdAttr PropIdAttr = new CswPropIdAttr(PropIdAttrStr);
                                    NodeTypePropIds.Add(PropIdAttr.NodeTypePropId);
                                }
                                CswNbtBatchOpMultiEdit op    = new CswNbtBatchOpMultiEdit(_CswNbtResources);
                                CswNbtObjClassBatchOp  Batch = op.makeBatchOp(Node, MultiNodePks, NodeTypePropIds);
                                ButtonData.Action        = CswEnumNbtButtonAction.batchop;
                                ButtonData.Data["batch"] = Batch.Node.NodeLink;
                            }
                            if (ButtonData.MultiClick && null != ButtonData.NodeTypeProp)
                            {
                                CswNbtBatchOpMultiButtonClick op    = new CswNbtBatchOpMultiButtonClick(_CswNbtResources);
                                CswNbtObjClassBatchOp         Batch = op.makeBatchOp(MultiNodePks, ButtonData.NodeTypeProp.PropId);
                                ButtonData.Action        = CswEnumNbtButtonAction.batchop;
                                ButtonData.Data["batch"] = Batch.Node.NodeLink;
                            }
                        }
                        else
                        {
                            if (ButtonData.PropIds.Count > 0)
                            {
                                CswNbtSdTabsAndProps Sd = new CswNbtSdTabsAndProps(_CswNbtResources);
                                Sd.copyPropValues(Node, ButtonData.NodeIds, ButtonData.PropIds);
                            }
                            if (ButtonData.MultiClick)
                            {
                                foreach (CswPrimaryKey MultiNodeId in MultiNodePks)
                                {
                                    CswNbtNode MultiNode = _CswNbtResources.Nodes[MultiNodeId];
                                    if (null != MultiNode)
                                    {
                                        MultiNode.ObjClass.onButtonClick(ButtonData);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add)
                    {
                        _onAfterButtonClickSaveProps(CswEnumNbtNodeEditMode.Add + "_tab", ButtonData);
                    }
                }
            }
            return(Ret);
        }