Пример #1
0
        public ActionResult Create(int id, string category, string type)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var layout = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            if (layout == null)
            {
                return(HttpNotFound());
            }

            // build the form, and let external components alter it
            var form = _formManager.Build(layout.Form) ?? Services.New.EmptyForm();

            var viewModel = new LayoutEditViewModel {
                QueryId = id,
                Layout  = layout,
                Form    = form
            };

            return(View(viewModel));
        }
Пример #2
0
        public ActionResult Edit(int id, string category, string type, int filterId = -1)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage image profiles")))
                return new HttpUnauthorizedResult();

            var filter = _processingManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            if (filter == null) {
                return HttpNotFound();
            }

            // build the form, and let external components alter it
            var form = filter.Form == null ? null : _formManager.Build(filter.Form);

            string description = "";

            // bind form with existing values).
            if (filterId != -1) {
                var profile = _profileService.GetImageProfile(id);
                var filterRecord = profile.Filters.FirstOrDefault(f => f.Id == filterId);
                if (filterRecord != null) {
                    description = filterRecord.Description;
                    var parameters = FormParametersHelper.FromString(filterRecord.State);
                    _formManager.Bind(form, new DictionaryValueProvider<string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new FilterEditViewModel {Id = id, Description = description, Filter = filter, Form = form};
            return View(viewModel);
        }
Пример #3
0
        protected dynamic BuildForm(ElementEditorContext context, string formName, string position = null)
        {
            // TODO: Fix Forms API so that it works with prefixes. Right now only binding implements prefix, but building a form ignores the specified prefix.

            // If not a post-back, we need to bind the form with the element's data values. Otherwise, bind the form with the posted values.
            var valueProvider = context.Updater == null
                ? context.Element.Data.ToValueProvider(_cultureAccessor.CurrentCulture)
                : context.ValueProvider;

            var form = _formManager.Bind(_formManager.Build(formName), valueProvider);

            if (context.Updater != null)
            {
                // Update the element's data dictionary with the posted values.
                Action <object> process = s => UpdateElementProperty(s, context);
                FormNodesProcessor.ProcessForm(form, process);
            }

            if (!String.IsNullOrWhiteSpace(position))
            {
                form.Metadata.Position = position;
            }

            return(form);
        }
        public ActionResult Edit(int id, string category, string type, int filterId = -1)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var filter = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault();

            if (filter == null)
            {
                return(HttpNotFound());
            }

            // if there is no form to edit, save the filter and go back to the query
            if (filter.Form == null)
            {
                var group = _groupRepository.Get(id);

                if (filterId == -1)
                {
                    group.Filters.Add(
                        new FilterRecord {
                        Category = category,
                        Type     = type,
                        Position = group.Filters.Count
                    });
                }

                return(RedirectToAction("Edit", "Admin", new { id = group.QueryPartRecord.Id }));
            }

            // build the form, and let external components alter it
            var form = _formManager.Build(filter.Form);

            string description = "";

            // bind form with existing values).
            if (filterId != -1)
            {
                var group        = _groupRepository.Get(id);
                var filterRecord = group.Filters.Where(f => f.Id == filterId).FirstOrDefault();
                if (filterRecord != null)
                {
                    description = filterRecord.Description;
                    var parameters = FormParametersHelper.FromString(filterRecord.State);
                    _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new FilterEditViewModel {
                Id = id, Description = description, Filter = filter, Form = form
            };

            return(View(viewModel));
        }
Пример #5
0
        public ActionResult Edit(int id, string category, string type, int sortCriterionId = -1)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var sortCriterion = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            if (sortCriterion == null)
            {
                return(HttpNotFound());
            }

            // if there is no form to edit, save the sort criteria and go back to the query
            if (sortCriterion.Form == null)
            {
                if (sortCriterionId == -1)
                {
                    var query = _queryService.GetQuery(id);
                    query.SortCriteria.Add(new SortCriterionRecord {
                        Category = category,
                        Type     = type,
                        Position = query.SortCriteria.Count
                    });
                }

                return(RedirectToAction("Edit", "Admin", new { id }));
            }

            // build the form, and let external components alter it
            var form = _formManager.Build(sortCriterion.Form);

            var description = String.Empty;

            // bind form with existing values).
            if (sortCriterionId != -1)
            {
                var query = _queryService.GetQuery(id);
                var sortCriterionRecord = query.SortCriteria.FirstOrDefault(f => f.Id == sortCriterionId);
                if (sortCriterionRecord != null)
                {
                    description = sortCriterionRecord.Description;
                    var parameters = FormParametersHelper.FromString(sortCriterionRecord.State);
                    _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new SortCriterionEditViewModel {
                Id = id, Description = description, SortCriterion = sortCriterion, Form = form
            };

            return(View(viewModel));
        }
Пример #6
0
        protected dynamic BuildForm(ElementEditorContext context, string formName, string position = null)
        {
            // TODO: Fix Forms API so that it works with prefixes. Right now only binding implements prefix, but building a form ignores the specified prefix.
            var form = _formManager.Bind(_formManager.Build(formName), context.ValueProvider);

            if (!String.IsNullOrWhiteSpace(position))
            {
                form.Metadata.Position = position;
            }

            return(form);
        }
Пример #7
0
        public ActionResult EditActivity(string localId, string clientId, ActivityViewModel model)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var activity = _activitiesManager.GetActivityByName(model.Name);

            if (activity == null)
            {
                return(HttpNotFound());
            }

            // build the form, and let external components alter it
            var form = activity.Form == null ? null : _formManager.Build(activity.Form);

            // form is bound on client side
            var viewModel = New.ViewModel(LocalId: localId, ClientId: clientId, Form: form);

            return(View(viewModel));
        }
Пример #8
0
        protected override DriverResult Display(ListViewPart part, string displayType, dynamic shapeHelper)
        {
            var editors = _fieldTypeEditors
                          .Select(x => x.FormName)
                          .Distinct()
                          .Select(x => _formManager.Build(x));

            return(Combined(
                       ContentShape("Parts_ListView",
                                    () => shapeHelper.Parts_ListView(FilterEditors: editors)),
                       ContentShape("Parts_ListView_Buttons", buttons => buttons),
                       ContentShape("Parts_ListView_Filters", filters => filters),
                       ContentShape("Parts_ListView_FilterContent", filterContent => filterContent),
                       ContentShape("Parts_ListView_Views", views => views),
                       ContentShape("Parts_ListView_Search", search => search)
                       ));
        }
Пример #9
0
        public ActionResult Edit(int id, string category, string type, int propertyId = -1)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var property = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault();

            if (property == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PropertyEditViewModel {
                Id          = id,
                Description = String.Empty,
                Property    = property
            };

            dynamic form = null;

            // build the form, and let external components alter it
            if (property.Form != null)
            {
                form           = _formManager.Build(property.Form);
                viewModel.Form = form;
            }

            // bind form with existing values.
            if (propertyId != -1)
            {
                var propertyRecord = _repository.Get(propertyId);
                if (propertyRecord != null)
                {
                    viewModel.Description = propertyRecord.Description;
                    if (property.Form != null)
                    {
                        var parameters = FormParametersHelper.FromString(propertyRecord.State);
                        _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));
                    }

                    viewModel.CreateLabel        = propertyRecord.CreateLabel;
                    viewModel.ExcludeFromDisplay = propertyRecord.ExcludeFromDisplay;
                    viewModel.Label         = propertyRecord.Label;
                    viewModel.LinkToContent = propertyRecord.LinkToContent;

                    viewModel.CustomizeLabelHtml    = propertyRecord.CustomizeLabelHtml;
                    viewModel.CustomizePropertyHtml = propertyRecord.CustomizePropertyHtml;
                    viewModel.CustomizeWrapperHtml  = propertyRecord.CustomizeWrapperHtml;
                    viewModel.CustomLabelCss        = propertyRecord.CustomLabelCss;
                    viewModel.CustomLabelTag        = propertyRecord.CustomLabelTag;
                    viewModel.CustomPropertyCss     = propertyRecord.CustomPropertyCss;
                    viewModel.CustomPropertyTag     = propertyRecord.CustomPropertyTag;
                    viewModel.CustomWrapperCss      = propertyRecord.CustomWrapperCss;
                    viewModel.CustomWrapperTag      = propertyRecord.CustomWrapperTag;

                    viewModel.NoResultText = propertyRecord.NoResultText;
                    viewModel.ZeroIsEmpty  = propertyRecord.ZeroIsEmpty;
                    viewModel.HideEmpty    = propertyRecord.HideEmpty;

                    viewModel.RewriteOutput      = propertyRecord.RewriteOutput;
                    viewModel.RewriteText        = propertyRecord.RewriteText;
                    viewModel.StripHtmlTags      = propertyRecord.StripHtmlTags;
                    viewModel.TrimLength         = propertyRecord.TrimLength;
                    viewModel.AddEllipsis        = propertyRecord.AddEllipsis;
                    viewModel.MaxLength          = propertyRecord.MaxLength;
                    viewModel.TrimOnWordBoundary = propertyRecord.TrimOnWordBoundary;
                    viewModel.PreserveLines      = propertyRecord.PreserveLines;
                    viewModel.TrimWhiteSpace     = propertyRecord.TrimWhiteSpace;
                }
            }

            return(View(viewModel));
        }
Пример #10
0
        public ActionResult Edit(int id, string category, string type, int actionId = -1)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage rules")))
            {
                return(new HttpUnauthorizedResult());
            }

            var action = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            if (action == null)
            {
                return(HttpNotFound());
            }

            // if there is no form to edit, save the action and go back to the rule
            if (action.Form == null)
            {
                if (actionId == -1)
                {
                    var rule = _rulesServices.GetRule(id);
                    rule.Actions.Add(new ActionRecord {
                        Category = category, Type = type, Position = rule.Actions.Count + 1
                    });
                }

                return(RedirectToAction("Edit", "Admin", new { id }));
            }

            // build the form, and let external components alter it
            var form = _formManager.Build(action.Form);

            // generate an anti forgery token
            var viewContext = new ViewContext {
                HttpContext = HttpContext, Controller = this
            };
            var token = new HtmlHelper(viewContext, new ViewDataContainer()).AntiForgeryToken();

            // add a submit button to the form
            form
            ._Actions(Shape.Fieldset(
                          _RequestAntiForgeryToken: Shape.Markup(
                              Value: token.ToString()),
                          _Save: Shape.Submit(
                              Name: "op",
                              Value: T("Save"))
                          )
                      );

            // bind form with existing values).
            if (actionId != -1)
            {
                var rule         = _rulesServices.GetRule(id);
                var actionRecord = rule.Actions.FirstOrDefault(a => a.Id == actionId);
                if (actionRecord != null)
                {
                    var parameters = FormParametersHelper.FromString(actionRecord.Parameters);
                    _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new EditActionViewModel {
                Id = id, Action = action, Form = form
            };

            return(View(viewModel));
        }