Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var record = listFieldService.GetById(id);
            var list   = record.List ?? listService.GetById(record.ListId);

            WorkContext.Breadcrumbs.Add(T("Manage Lists"), Url.Action("Index", "List", new { area = Constants.Areas.Lists }));
            WorkContext.Breadcrumbs.Add(list.Name);
            WorkContext.Breadcrumbs.Add(T("Fields"), Url.Action("Index", new { area = Constants.Areas.Lists }));
            WorkContext.Breadcrumbs.Add(record.Name);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var settings = new SharpSerializerXmlSettings
            {
                IncludeAssemblyVersionInTypeName = false,
                IncludeCultureInTypeName         = false,
                IncludePublicKeyTokenInTypeName  = false
            };

            var sharpSerializer = new SharpSerializer(settings);

            var field = (IListField)sharpSerializer.DeserializeFromString(record.FieldProperties);

            if (field.Id == 0)
            {
                field.Id = id;
            }

            var result = new ControlFormResult <IListField>(field, field.GetType())
            {
                Title                = T("Edit Field").Text,
                UpdateActionName     = "Update",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.ExcludeProperty(x => x.Name);

            result.AddHiddenValue("Name", record.Name);
            result.AddHiddenValue("FieldType", GetFullTypeName(field.GetType()));

            return(result);
        }
Esempio n. 2
0
        protected override void OnCreating(ControlFormResult <UserModel> controlForm)
        {
            controlForm.AddProperty("Password", new ControlTextAttribute
            {
                Type              = ControlText.Password,
                MaxLength         = 128,
                Required          = true,
                LabelText         = "Password",
                ContainerCssClass = "col-xs-6 col-md-6",
                ContainerRowIndex = 1
            });
            controlForm.AddProperty("ConfirmPassword", new ControlTextAttribute
            {
                Type              = ControlText.Password,
                MaxLength         = 128,
                Required          = true,
                EqualTo           = "Password",
                LabelText         = "Confirm Password",
                ContainerCssClass = "col-xs-6 col-md-6",
                ContainerRowIndex = 1
            });

            var callbackUrl = Request.QueryString["callbackUrl"];

            if (!string.IsNullOrEmpty(callbackUrl))
            {
                controlForm.AddHiddenValue("CallbackUrl", callbackUrl);
            }

            controlForm.ShowBoxHeader        = false;
            controlForm.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml;
            controlForm.FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml;
        }
Esempio n. 3
0
        public ActionResult ViewHistoricPage(int id)
        {
            if (!CheckPermission(PagesPermissions.ManagePages))
            {
                return(new HttpUnauthorizedResult());
            }

            HistoricPageModel model = historicPageService.GetById(id);

            WorkContext.Breadcrumbs.Add(T("Pages"), Url.Action("Index", new { area = Constants.Areas.Pages }));
            WorkContext.Breadcrumbs.Add(model.Title);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var menuItem = menuItemService.GetMenuItemByRefId(id);

            if (menuItem != null)
            {
                model.ShowOnMenuId = menuItem.MenuId;
            }

            var result = new ControlFormResult <HistoricPageModel>(model)
            {
                Title                = T("Edit Page").Text,
                UpdateActionName     = "Update",
                CssClass             = "form-edit-page",
                ReadOnly             = true,
                CancelButtonText     = T("Close"),
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.AddAction(true)
            .HasText(T("Restore Version"))
            .HasName("RestoreVersion")
            .HasButtonStyle(ButtonStyle.Warning)
            .HasConfirmMessage(T("Are you sure you want to restore this version of the page?").Text);

            var themes = extensionManager.AvailableExtensions().Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType) && descriptor.Features.Any(f => f.Name == x.Id)).ToDictionary(k => k.Id, v => v.Name);

            result.RegisterExternalDataSource(x => x.Theme, themes);
            result.RegisterExternalDataSource(x => x.ShowOnMenuId, menuService.GetRecords().ToDictionary(k => k.Id, v => v.Name));

            // Page tags
            var tags = pageTagService.GetRecords();

            if (tags.Count > 0)
            {
                result.AddHiddenValue("RichtextCustomTags", JsonConvert.SerializeObject(tags.Select(x => new[] { x.Name, "[%" + x.Name + "%]" })));
            }

            return(result);
        }
Esempio n. 4
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(StandardPermissions.FullAccess))
            {
                return(new HttpUnauthorizedResult());
            }

            LanguageModel model = languageService.GetById(id);

            model.CultureCode2 = model.CultureCode;

            var result = new ControlFormResult <LanguageModel>(model)
            {
                Title                = T("Edit Language"),
                UpdateActionName     = "Update",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            if (model.CultureCode == siteSettings.DefaultLanguage)
            {
                result.ExcludeProperty(x => x.Active);
                result.AddHiddenValue("Active", "true");
            }

            result.RegisterFileUploadOptions("ImageFlag.FileName", new ControlFileUploadOptions
            {
                AllowedExtensions = "jpg,jpeg,png,gif"
            });

            var themeManager = WorkContext.Resolve <IThemeManager>();

            result.RegisterExternalDataSource(x => x.Theme, themeManager.GetInstalledThemes());

            result.ExcludeProperty(x => x.CultureCode);
            result.AddHiddenValue("CultureCode", model.CultureCode);

            return(result);
        }
        public ActionResult Edit(string id, string returnUrl)
        {
            if (!CheckPermission(Permissions.ManageSiteSettings))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = settings.Value.FirstOrDefault(x => x.GetType().FullName == id);

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

            WorkContext.Breadcrumbs.Add(T("Settings"), Url.Action("Index", new { area = Constants.Areas.Core }));
            WorkContext.Breadcrumbs.Add(model.Name);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var value = service.GetSettings(model.GetType());

            var controlForm = new ControlFormResult <ISettings>(value, model.GetType())
            {
                Title                = model.Name,
                UpdateActionName     = "Save",
                CancelButtonUrl      = string.IsNullOrEmpty(returnUrl) ? Url.Action("Index") : returnUrl,
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            controlForm.AddHiddenValue("Id", id);
            controlForm.AddHiddenValue("_ReturnUrl", returnUrl);

            model.OnEditing(controlForm, WorkContext);

            return(controlForm);
        }
Esempio n. 6
0
        public ActionResult Create()
        {
            if (!CheckPermission(PagesPermissions.ManagePages))
            {
                return(new HttpUnauthorizedResult());
            }

            WorkContext.Breadcrumbs.Add(T("Pages"), Url.Action("Index", new { area = Constants.Areas.Pages }));
            WorkContext.Breadcrumbs.Add(T("Create"));

            var model = new PageModel {
                IsEnabled = true, Title = ""
            };

            var result = new ControlFormResult <PageModel>(model)
            {
                Title                = T("Create Page").Text,
                UpdateActionName     = "Update",
                CssClass             = "form-edit-page",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            //result.AddAction(true, false, false).HasText(T("Preview")).HasUrl(Url.Action("Preview")).HasButtonStyle(ButtonStyle.Default);

            var themes = extensionManager.AvailableExtensions().Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType) && descriptor.Features.Any(f => f.Name == x.Id)).ToDictionary(k => k.Id, v => v.Name);

            result.RegisterExternalDataSource(x => x.Theme, themes);
            result.RegisterExternalDataSource(x => x.ShowOnMenuId, menuService.GetRecords().ToDictionary(k => k.Id, v => v.Name));

            // Page tags
            var tags = pageTagService.GetRecords();

            if (tags.Count > 0)
            {
                result.AddHiddenValue("RichtextCustomTags", JsonConvert.SerializeObject(tags.Select(x => new[] { x.Name, "[%" + x.Name + "%]" })));
            }

            return(result);
        }
        private ActionResult UserProfile(int userId, bool editMode = false)
        {
            var result = new ControlFormResult
            {
                UpdateActionName = "UpdateProfile",
                SubmitButtonText = T("Save").Text,
                ReadOnly         = !editMode
            };

            string title;
            bool   onlyPublicProperties = false;

            if (editMode)
            {
                if (userId == WorkContext.CurrentUser.Id)
                {
                    title = T("Edit My Profile");
                }
                else if (WorkContext.CurrentUser.SuperUser || CheckPermission(StandardPermissions.FullAccess))
                {
                    title = T("Edit Profile");
                }
                else
                {
                    return(new HttpUnauthorizedResult());
                }
            }
            else
            {
                if (userId == WorkContext.CurrentUser.Id)
                {
                    title = T("My Profile");

                    result.AddAction(addToTop: false)
                    .HasText(T("Edit"))
                    .HasUrl(Url.Action("EditMyProfile"))
                    .HasButtonStyle(ButtonStyle.Primary);
                }
                else if (WorkContext.CurrentUser.SuperUser || CheckPermission(StandardPermissions.FullAccess))
                {
                    var user = service.GetUser(userId);
                    title = string.Format(T("Profile for '{0}'", user.UserName));

                    result.AddAction(addToTop: false)
                    .HasText(T("Edit"))
                    .HasUrl(Url.Action("EditProfile", RouteData.Values.Merge(new { userId })))
                    .HasButtonStyle(ButtonStyle.Primary);
                }
                else
                {
                    var user = service.GetUser(userId);
                    title = string.Format(T("Profile for '{0}'", user.UserName));
                    onlyPublicProperties = true;
                }

                result.CancelButtonText = T("Close");
            }

            result.Title = title;

            result.AddHiddenValue("UserId", userId.ToString());

            bool hasProperties = false;

            foreach (var provider in userProfileProviders.Value)
            {
                var newGroup = result.AddGroupedLayout(provider.Category);

                foreach (var field in provider.GetFields(WorkContext, userId, onlyPublicProperties))
                {
                    hasProperties = true;

                    result.AddProperty(field.Name, field, field.Value);
                    newGroup.Add(field.Name);
                }
            }

            if (!hasProperties)
            {
                return(new ContentViewResult
                {
                    Title = title,
                    BodyContent = T("There is no profile available to view.")
                });
            }

            return(result);
        }
Esempio n. 8
0
        public ActionResult Translate(int id, string cultureCode)
        {
            if (!CheckPermission(PagesPermissions.ManagePages))
            {
                return(new HttpUnauthorizedResult());
            }

            PageModel model = pageService.GetPageByLanguage(id, cultureCode);

            WorkContext.Breadcrumbs.Add(T("Pages"), Url.Action("Index", new { area = Constants.Areas.Pages }));
            if (model != null)
            {
                WorkContext.Breadcrumbs.Add(model.Title);
            }

            WorkContext.Breadcrumbs.Add(T("Translate"));
            WorkContext.Breadcrumbs.Add(cultureCode);

            var showSaveAndContinue = false;

            if (model == null)
            {
                model                     = pageService.GetById(id);
                model.Id                  = 0;
                model.CultureCode         = cultureCode;
                model.RefId               = id;
                ViewData.ModelState["Id"] = new ModelState {
                    Value = new ValueProviderResult(Guid.Empty, Guid.Empty.ToString(), null)
                };
            }
            else
            {
                ViewData.ModelState["Id"] = new ModelState {
                    Value = new ValueProviderResult(model.Id, model.Id.ToString(), null)
                };
                showSaveAndContinue = true;
            }

            var result = new ControlFormResult <PageModel>(model)
            {
                Title                = T("Translate Page").Text,
                UpdateActionName     = "Update",
                CssClass             = "form-edit-page",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.AssignGridLayout(x => x.Id, 0, 0);
            result.AssignGridLayout(x => x.CultureCode, 0, 0);
            result.AssignGridLayout(x => x.RefId, 0, 0);
            result.AssignGridLayout(x => x.Title, 0, 0);
            result.AssignGridLayout(x => x.MetaKeywords, 1, 0);
            result.AssignGridLayout(x => x.IsEnabled, 0, 1);
            result.AssignGridLayout(x => x.MetaDescription, 1, 1);
            result.AssignGridLayout(x => x.BodyContent, 0, 2, 2);

            result.ExcludeProperty(x => x.Slug);
            result.AddHiddenValue("Slug", model.Slug);

            result.ExcludeProperty(x => x.Theme);
            result.AddHiddenValue("Theme", model.Theme);

            result.ExcludeProperty(x => x.CssClass);
            result.AddHiddenValue("CssClass", model.CssClass);

            result.ExcludeProperty(x => x.ShowOnMenuId);
            if (model.ShowOnMenuId.HasValue)
            {
                result.AddHiddenValue("ShowOnMenuId", model.ShowOnMenuId.Value.ToString());
            }

            if (showSaveAndContinue)
            {
                result.AddAction(true, true, false).HasText(T("Save & Continue")).HasName("SaveAndContinue").HasButtonStyle(ButtonStyle.Info);
            }

            // Page tags
            var tags = pageTagService.GetRecords();

            if (tags.Count > 0)
            {
                result.AddHiddenValue("RichtextCustomTags", JsonConvert.SerializeObject(tags.Select(x => new[] { x.Name, "[%" + x.Name + "%]" })));
            }

            return(result);
        }
Esempio n. 9
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(PagesPermissions.ManagePages))
            {
                return(new HttpUnauthorizedResult());
            }

            PageModel model = pageService.GetById(id);

            WorkContext.Breadcrumbs.Add(T("Pages"), Url.Action("Index", new { area = Constants.Areas.Pages }));
            WorkContext.Breadcrumbs.Add(model.Title);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var menuItem = menuItemService.GetMenuItemByRefId(id);

            if (menuItem != null)
            {
                model.ShowOnMenuId = menuItem.MenuId;
            }

            var result = new ControlFormResult <PageModel>(model)
            {
                Title                = T("Edit Page").Text,
                UpdateActionName     = "Update",
                CssClass             = "form-edit-page",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.AddAction(true, true, false).HasText(T("Save & Continue")).HasName("SaveAndContinue").HasButtonStyle(ButtonStyle.Info);

            result.AddAction(addToTop: false)
            .HasText(T("Preview"))
            .HasClientId("btnPreview")
            .HasButtonStyle(ButtonStyle.Info);

            var themes = extensionManager.AvailableExtensions().Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType) && descriptor.Features.Any(f => f.Name == x.Id)).ToDictionary(k => k.Id, v => v.Name);

            result.RegisterExternalDataSource(x => x.Theme, themes);
            result.RegisterExternalDataSource(x => x.ShowOnMenuId, menuService.GetRecords().ToDictionary(k => k.Id, v => v.Name));

            // Page tags
            var tags = pageTagService.GetRecords();

            if (tags.Count > 0)
            {
                result.AddHiddenValue("RichtextCustomTags", JsonConvert.SerializeObject(tags.Select(x => new[] { x.Name, "[%" + x.Name + "%]" })));
            }

            var scriptRegister = new ScriptRegister(WorkContext);

            scriptRegister.IncludeInline(Constants.Scripts.JQueryFormExtension);
            scriptRegister.IncludeInline(Constants.Scripts.JQueryFormParams);

            var sbScript = new StringBuilder(256);

            sbScript.Append("$(document).ready(function(){");
            sbScript.Append("$('#btnPreview').click(function(e){");
            sbScript.Append("var data = $('form').formParams();");
            sbScript.Append("var bodyContent = $('#idContentoEdit0').contents().find('body').html();");
            sbScript.Append("data.BodyContent = bodyContent;");
            sbScript.AppendFormat("$.form('{0}',", Url.Action("Preview"));
            sbScript.Append("data");
            sbScript.Append(").attr('target', '_blank').submit().remove(); return false;");
            sbScript.Append("});})");

            scriptRegister.IncludeInline(sbScript.ToString());

            return(result);
        }
Esempio n. 10
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(WidgetPermissions.ManageWidgets))
            {
                return(new HttpUnauthorizedResult());
            }

            var widgetService = WorkContext.Resolve <IWidgetService>();
            var records       = widgetService.GetRecords(x => x.Id == id || x.RefId == id);
            var widgets       = widgetService.GetWidgets(records);
            var widget        = widgets.First(x => x.Id == id);
            var widgetType    = widget.GetType();

            WorkContext.Breadcrumbs.Add(T("Widgets"), Url.Action("Index"));
            WorkContext.Breadcrumbs.Add(widget.Title);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var result = new ControlFormResult <IWidget>(widget, widgetType)
            {
                Title                = T("Edit Widget").Text,
                UpdateActionName     = "Update",
                Layout               = ControlFormLayout.Tab,
                ShowCloseButton      = true,
                IsAjaxSupported      = false,
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.AddHiddenValue("WidgetType", GetFullTypeName(widget.GetType()));
            if (widget.PageId.HasValue)
            {
                result.AddHiddenValue("PageId", widget.PageId.Value.ToString());
            }

            var mainTab           = result.AddTabbedLayout("Widget Settings");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = widgetType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            result.ExcludeProperty(x => x.Localized);
            if (!widget.HasTitle)
            {
                result.ExcludeProperty(x => x.ShowTitleOnPage);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);

            if (languages.Count > 1)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = widgets.FirstOrDefault(x => x.CultureCode == language.CultureCode) ??
                                            widget.ShallowCopy();

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (controlAttribute.Key == "Id")
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }

                    if (!widget.HasTitle)
                    {
                        result.ExcludeProperty("Title." + language.CultureCode);
                        result.ExcludeProperty("ShowTitleOnPage." + language.CultureCode);
                    }
                }
            }

            var zoneService = WorkContext.Resolve <IZoneService>();
            var zones       = zoneService.GetRecords().ToDictionary(x => x.Id, x => x.Name);

            result.RegisterExternalDataSource(x => x.ZoneId, zones);

            return(widget.BuildEditor(this, WorkContext, result));
        }
Esempio n. 11
0
 public ControlForm <TModel> AddHiddenValue(string name, string value)
 {
     model.AddHiddenValue(name, value);
     return(this);
 }