/// <summary>
        /// Binds the pipeline actions section for a specific Sms Pipeline.
        /// </summary>
        /// <param name="smsPipeline">The SMS pipeline.</param>
        private void BindActions(SmsPipeline smsPipeline)
        {
            if (smsPipeline == null)
            {
                divSmsActionsPanel.Visible = false;
                return;
            }

            var actions = smsPipeline.SmsActions
                          .OrderBy(a => a.Order)
                          .ThenBy(a => a.Id)
                          .ToList()
                          .Select(a => new
            {
                a.Id,
                a.Name,
                a.SmsActionComponentEntityTypeId,
                a.IsActive,
                a.ContinueAfterProcessing,
                Component = SmsActionContainer.GetComponent(EntityTypeCache.Get(a.SmsActionComponentEntityTypeId).Name)
            })
                          .ToList();

            if (actions.Any())
            {
                olActions.RemoveCssClass("drag-container-empty");
            }
            else
            {
                olActions.AddCssClass("drag-container-empty");
            }

            rptrActions.DataSource = actions;
            rptrActions.DataBind();
        }
예제 #2
0
        /// <summary>
        /// Binds the actions repeater.
        /// </summary>
        private void BindActions()
        {
            var rockContext      = new RockContext();
            var smsActionService = new SmsActionService(rockContext);

            var actions = smsActionService.Queryable()
                          .OrderBy(a => a.Order)
                          .ThenBy(a => a.Id)
                          .ToList()
                          .Select(a => new
            {
                a.Id,
                a.Name,
                a.SmsActionComponentEntityTypeId,
                a.IsActive,
                a.ContinueAfterProcessing,
                Component = SmsActionContainer.GetComponent(EntityTypeCache.Get(a.SmsActionComponentEntityTypeId).Name)
            })
                          .ToList();

            if (actions.Any())
            {
                olActions.RemoveCssClass("drag-container-empty");
            }
            else
            {
                olActions.AddCssClass("drag-container-empty");
            }

            rptrActions.DataSource = actions;
            rptrActions.DataBind();
        }
예제 #3
0
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments = argument.SplitDelimitedValues();

            //
            // Check for the event to add a new action.
            //
            if (segments.Length == 3 && segments[0] == "add-action")
            {
                var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                var order           = segments[2].AsInteger();

                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var action = new SmsAction
                {
                    SmsPipelineId = GetSmsPipelineId().Value,
                    Name          = actionComponent.Title,
                    IsActive      = true,
                    Order         = order,
                    SmsActionComponentEntityTypeId = actionComponent.TypeId
                };

                smsActionService.Queryable()
                .Where(a => a.Order >= order)
                .ToList()
                .ForEach(a => a.Order += 1);

                smsActionService.Add(action);

                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }

            //
            // Check for the event to drag-reorder actions.
            //
            else if (segments.Length == 3 && segments[0] == "reorder-action")
            {
                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService.Queryable()
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }
        }
예제 #4
0
        /// <summary>
        /// Handles the ItemCommand event of the rptrActions control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rptrActions_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var smsActionService = new SmsActionService(new RockContext());
            var action           = smsActionService.Get(e.CommandArgument.ToString().AsInteger());

            if (e.CommandName == "EditAction")
            {
                var component = SmsActionContainer.GetComponent(EntityTypeCache.Get(action.SmsActionComponentEntityTypeId).Name);

                hfEditActionId.Value = action.Id.ToString();
                lActionType.Text     = component.Title;
                tbName.Text          = action.Name;
                cbActive.Checked     = action.IsActive;
                cbContinue.Checked   = action.ContinueAfterProcessing;

                avcFilters.AddEditControls(action);
                avcAttributes.AddEditControls(action);

                pnlEditAction.Visible = true;

                BindActions();
            }
        }
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument      = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments      = argument.SplitDelimitedValues();
            var    smsPipelineId = GetSmsPipelineId();

            if (smsPipelineId == null || segments.Length != 3)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService
                              .Queryable()
                              .Where(a => a.SmsPipelineId == smsPipelineId)
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                // Reset order actions to eliminate gaps.
                for (var i = 0; i < actions.Count; i++)
                {
                    actions[i].Order = i;
                }

                // Check for the event to add a new action.
                if (segments[0] == "add-action")
                {
                    var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                    var order           = segments[2].AsInteger();

                    var action = new SmsAction
                    {
                        SmsPipelineId = smsPipelineId.Value,
                        Name          = actionComponent.Title,
                        IsActive      = true,
                        Order         = order,
                        SmsActionComponentEntityTypeId = actionComponent.TypeId
                    };

                    actions
                    .Where(a => a.Order >= order)
                    .ToList()
                    .ForEach(a => a.Order += 1);

                    smsActionService.Add(action);
                }
                else if (segments[0] == "reorder-action")
                {
                    // Check for the event to drag-reorder actions.
                    smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                }

                rockContext.SaveChanges();
                BindActions();
                SmsActionCache.Clear();
            }
        }