Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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);
        }
        public ActionResult CreatePost(LayoutEditViewModel model, FormCollection formCollection)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            // validating form values
            model.Layout = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == model.Category && x.Type == model.Type);

            _formManager.Validate(new ValidatingContext {
                FormName = model.Layout.Form, ModelState = ModelState, ValueProvider = ValueProvider
            });

            var form = _formManager.Build(model.Layout.Form) ?? Services.New.EmptyForm();

            _formManager.Bind(form, formCollection);

            model.Form = form;

            if (ModelState.IsValid)
            {
                var layoutRecord = new LayoutRecord {
                    Category = model.Category, Type = model.Type
                };
                var query = _queryService.GetQuery(model.QueryId);
                query.Layouts.Add(layoutRecord);

                var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get);

                // save form parameters
                layoutRecord.State       = FormParametersHelper.ToString(dictionary);
                layoutRecord.Description = model.Description;
                layoutRecord.Display     = model.Display;
                layoutRecord.DisplayType = model.DisplayType;

                Services.ContentManager.Flush();

                Services.Notifier.Information(T("Layout Created"));

                return(RedirectToAction("Edit", new { id = layoutRecord.Id }));
            }

            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult EditActivityPost(int id, string localId, string name, string clientId, FormCollection formValues)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var activity = _activitiesManager.GetActivityByName(name);

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

            // validating form values
            _formManager.Validate(new ValidatingContext {
                FormName = activity.Form, ModelState = ModelState, ValueProvider = ValueProvider
            });

            // stay on the page if there are validation errors
            if (!ModelState.IsValid)
            {
                // build the form, and let external components alter it
                var form = activity.Form == null ? null : _formManager.Build(activity.Form);

                // bind form with existing values.
                _formManager.Bind(form, ValueProvider);

                var viewModel = New.ViewModel(Id: id, LocalId: localId, Form: form);

                return(View(viewModel));
            }

            var model = new UpdatedActivityModel {
                ClientId = clientId,
                Data     = formValues
            };

            TempData["UpdatedViewModel"] = model;

            return(RedirectToAction("Edit", new {
                id,
                localId
            }));
        }
Exemplo n.º 8
0
 public dynamic BindForm(dynamic form, IValueProvider valueProvider)
 {
     return(_formManager.Bind(form, valueProvider));
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }