Exemplo n.º 1
0
        public static void SetupStyle(
            List <MarkupCss> markupCss,
            ModuleConfiguration config,
            SuperFlexiDisplaySettings displaySettings,
            string clientID,
            int moduleID,
            int pageID,
            Page page,
            Control control)
        {
            string styleLinkFormat = "\n<link rel=\"stylesheet\" href=\"{0}\" media=\"{2}\" data-name=\"{1}\">";
            string rawCSSFormat    = "\n<style type=\"text/css\" data-name=\"{1}\" media=\"{2}\">\n{0}\n</style>";

            foreach (MarkupCss style in markupCss)
            {
                StringBuilder sbStyleText = new StringBuilder();
                StringBuilder sbStyleName = new StringBuilder();

                sbStyleName.Append(String.IsNullOrWhiteSpace(style.Name) ? clientID + "flexiStyle_" + markupCss.IndexOf(style) : "flexiStyle_" + style.Name);
                SuperFlexiHelpers.ReplaceStaticTokens(sbStyleName, config, false, displaySettings, moduleID, pageID, out sbStyleName);
                string scriptName = sbStyleName.ToString();
                if (!String.IsNullOrWhiteSpace(style.Url))
                {
                    sbStyleText.Append(string.Format(styleLinkFormat,
                                                     style.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/"),
                                                     scriptName, style.Media));
                }
                else if (!String.IsNullOrWhiteSpace(style.CSS))
                {
                    sbStyleText.Append(string.Format(rawCSSFormat, style.CSS, scriptName, style.Media));
                }

                SuperFlexiHelpers.ReplaceStaticTokens(sbStyleText, config, false, displaySettings, moduleID, pageID, out sbStyleText);

                LiteralControl theLiteral = new LiteralControl();
                theLiteral.Text = sbStyleText.ToString();

                StyleSheetCombiner ssc = (StyleSheetCombiner)page.Header.FindControl("StyleSheetCombiner");

                if (ssc != null)
                {
                    int sscIndex = page.Header.Controls.IndexOf(ssc);
                    if (style.RenderAboveSSC)
                    {
                        page.Header.Controls.AddAt(sscIndex, theLiteral);
                    }
                    else
                    {
                        page.Header.Controls.AddAt(sscIndex + 1, theLiteral);
                    }
                }
                else
                {
                    page.Header.Controls.AddAt(0, theLiteral);
                }
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //LoadSettings();
            //SetupScripts();

            module      = new Module(moduleId);
            moduleTitle = module.ModuleTitle;

            siteSettings = CacheHelper.GetCurrentSiteSettings();
            pageSettings = new PageSettings(siteSettings.SiteId, pageId);
            if (config.MarkupDefinition != null)
            {
                displaySettings = config.MarkupDefinition;
            }

            if (config.ProcessItems)
            {
                fields = Field.GetAllForDefinition(config.FieldDefinitionGuid);

                if (config.IsGlobalView)
                {
                    items       = Item.GetAllForDefinition(config.FieldDefinitionGuid, config.DescendingSort);
                    fieldValues = ItemFieldValue.GetItemValuesByDefinition(config.FieldDefinitionGuid);
                }
                else
                {
                    items       = Item.GetModuleItems(moduleId, config.DescendingSort);
                    fieldValues = ItemFieldValue.GetItemValuesByModule(module.ModuleGuid);
                }
            }

            if (SiteUtils.IsMobileDevice() && config.MobileMarkupDefinition != null)
            {
                displaySettings = config.MobileMarkupDefinition;
            }

            if (config.MarkupScripts.Count > 0 || (SiteUtils.IsMobileDevice() && config.MobileMarkupScripts.Count > 0))
            {
                if (SiteUtils.IsMobileDevice() && config.MobileMarkupScripts.Count > 0)
                {
                    SuperFlexiHelpers.SetupScripts(config.MobileMarkupScripts, config, displaySettings, IsEditable, IsPostBack, ClientID, ModuleId, PageId, Page, this);
                }
                else
                {
                    SuperFlexiHelpers.SetupScripts(config.MarkupScripts, config, displaySettings, IsEditable, IsPostBack, ClientID, ModuleId, PageId, Page, this);
                }
            }

            if (config.MarkupCSS.Count > 0)
            {
                SuperFlexiHelpers.SetupStyle(config.MarkupCSS, config, displaySettings, ClientID, ModuleId, PageId, Page, this);
            }

            //if (Page.IsPostBack) { return; }

            PopulateControls();
        }
Exemplo n.º 3
0
        protected virtual void LoadSettings()
        {
            module      = new Module(ModuleId);
            moduleTitle = module.ModuleTitle;

            siteSettings = CacheHelper.GetCurrentSiteSettings();
            if (CurrentPage == null)
            {
                CurrentPage = CacheHelper.GetCurrentPage();
                if (CurrentPage == null)
                {
                    log.Info("Can't use CacheHelper.GetCurrentPage() here.");
                    CurrentPage = new PageSettings(siteSettings.SiteId, PageId);
                }
            }
            if (config.MarkupDefinition != null)
            {
                displaySettings = config.MarkupDefinition;
            }

            fields = Field.GetAllForDefinition(config.FieldDefinitionGuid);

            if (config.IsGlobalView)
            {
                items = Item.GetForDefinition(config.FieldDefinitionGuid, siteSettings.SiteGuid, config.DescendingSort);
            }
            else
            {
                items = Item.GetForModule(ModuleId, config.DescendingSort);
            }


            if (SiteUtils.IsMobileDevice() && config.MobileMarkupDefinition != null)
            {
                displaySettings = config.MobileMarkupDefinition;
            }

            if (config.MarkupScripts.Count > 0 || (SiteUtils.IsMobileDevice() && config.MobileMarkupScripts.Count > 0))
            {
                if (SiteUtils.IsMobileDevice() && config.MobileMarkupScripts.Count > 0)
                {
                    SuperFlexiHelpers.SetupScripts(config.MobileMarkupScripts, config, displaySettings, IsEditable, Page.IsPostBack, ClientID, siteSettings, module, CurrentPage, Page, this);
                }
                else
                {
                    SuperFlexiHelpers.SetupScripts(config.MarkupScripts, config, displaySettings, IsEditable, Page.IsPostBack, ClientID, siteSettings, module, CurrentPage, Page, this);
                }
            }

            if (config.MarkupCSS.Count > 0)
            {
                SuperFlexiHelpers.SetupStyle(config.MarkupCSS, config, displaySettings, IsEditable, ClientID, siteSettings, module, CurrentPage, Page, this);
            }
        }
Exemplo n.º 4
0
        private void LoadSettings()
        {
            int moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);
            //moduleSettings = ModuleSettings.GetModuleSettings(moduleId);
            Module module = new Module(moduleId);

            config = new ModuleConfiguration(module);

            if (!String.IsNullOrWhiteSpace(controlField.Attributes))
            {
                attributes = SuperFlexiHelpers.GetDictionaryFromString(controlField.Attributes);
            }
        }
Exemplo n.º 5
0
        private void LoadSettings()
        {
            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);

            //we want to get the module using this method because it will let the module be editable when placed on the page with a ModuleWrapper
            module = SuperFlexiHelpers.GetSuperFlexiModule(moduleId);
            if (module == null)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }
            config = new ModuleConfiguration(module);

            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();

            AddClassToBody("flexi-export " + config.EditPageCssClass);
        }
Exemplo n.º 6
0
        private void LoadSettings()
        {
            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);

            //we want to get the module using this method because it will let the module be editable when placed on the page with a ModuleWrapper
            module = SuperFlexiHelpers.GetSuperFlexiModule(moduleId);
            if (module == null)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }
            config = new ModuleConfiguration(module);


            //edContent.Height = Unit.Pixel(400);
            edContent.WebEditor.ToolBar = ToolBar.FullWithTemplates;

            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();
            AddClassToBody(isFooter ? "flexi-editfooter" : "flexi-editheader");
            AddClassToBody(config.EditPageCssClass);
        }
Exemplo n.º 7
0
        public static void ReplaceStaticTokens(
            StringBuilder stringBuilder,
            ModuleConfiguration config,
            bool isEditable,
            SuperFlexiDisplaySettings displaySettings,
            int moduleId,
            PageSettings pageSettings,
            SiteSettings siteSettings,
            out StringBuilder sb)
        {
            sb = stringBuilder;
            string featuredImageUrl       = String.IsNullOrWhiteSpace(config.InstanceFeaturedImage) ? string.Empty : WebUtils.GetApplicationRoot() + config.InstanceFeaturedImage;
            string jsonObjName            = "sflexi" + moduleId.ToString() + (config.IsGlobalView ? "Modules" : "Items");
            string currentSkin            = string.Empty;
            string siteRoot               = SiteUtils.GetNavigationSiteRoot();
            bool   publishedOnCurrentPage = true;

            if (HttpContext.Current != null && HttpContext.Current.Request.Params.Get("skin") != null)
            {
                currentSkin = SiteUtils.SanitizeSkinParam(HttpContext.Current.Request.Params.Get("skin")) + "/";
            }

            if (isEditable)
            {
                var pageModules = PageModule.GetPageModulesByModule(moduleId);
                if (pageModules.Where(pm => pm.PageId == pageSettings.PageId).ToList().Count() == 0)
                {
                    publishedOnCurrentPage = false;
                }
            }

            Module module = new Module(moduleId);

            if (module != null)
            {
                sb.Replace("$_ModuleTitle_$", module.ShowTitle ? String.Format(displaySettings.ModuleTitleFormat, module.ModuleTitle) : string.Empty);
                sb.Replace("$_RawModuleTitle_$", module.ModuleTitle);
                sb.Replace("$_ModuleGuid_$", module.ModuleGuid.ToString());
                if (String.IsNullOrWhiteSpace(config.ModuleFriendlyName))
                {
                    sb.Replace("$_FriendlyName_$", module.ModuleTitle);
                }

                siteSettings = new SiteSettings(module.SiteGuid);
            }
            if (!String.IsNullOrWhiteSpace(config.ModuleFriendlyName))
            {
                sb.Replace("$_FriendlyName_$", config.ModuleFriendlyName);
            }
            sb.Replace("$_FeaturedImageUrl_$", featuredImageUrl);
            sb.Replace("$_ModuleID_$", moduleId.ToString());
            sb.Replace("$_PageID_$", pageSettings.PageId.ToString());
            sb.Replace("$_PageUrl_$", siteRoot + pageSettings.Url.Replace("~/", ""));
            sb.Replace("$_PageName_$", siteRoot + pageSettings.PageName);
            //sb.Replace("$_ModuleLinks_$", isEditable ? SuperFlexiHelpers.GetModuleLinks(config, displaySettings, moduleId, pageSettings.PageId) : string.Empty);
            sb.Replace("$_ModuleLinks_$", isEditable ? SuperFlexiHelpers.GetModuleLinks(config, displaySettings, moduleId, publishedOnCurrentPage ? pageSettings.PageId : -1) : string.Empty);
            sb.Replace("$_JSONNAME_$", jsonObjName);
            sb.Replace("$_ModuleClass_$", SiteUtils.IsMobileDevice() && !String.IsNullOrWhiteSpace(config.MobileInstanceCssClass) ? config.MobileInstanceCssClass : config.InstanceCssClass);
            sb.Replace("$_ModuleTitleElement_$", module.HeadElement);
            sb.Replace("$_SiteID_$", siteSettings.SiteId.ToString());
            sb.Replace("$_SiteRoot_$", String.IsNullOrWhiteSpace(siteRoot) ? "/" : siteRoot);
            sb.Replace("$_SitePath_$", String.IsNullOrWhiteSpace(siteRoot) ? "/" : WebUtils.GetApplicationRoot() + "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToInvariantString());
            sb.Replace("$_SkinPath_$", SiteUtils.DetermineSkinBaseUrl(currentSkin));
            sb.Replace("$_CustomSettings_$", config.CustomizableSettings); //this needs to be enhanced, a lot, right now we just dump the 'settings' where ever this token exists.
            sb.Replace("$_EditorType_$", siteSettings.EditorProviderName);
            sb.Replace("$_EditorSkin_$", siteSettings.EditorSkin.ToString());
            sb.Replace("$_EditorBasePath_$", WebUtils.ResolveUrl(ConfigurationManager.AppSettings["CKEditor:BasePath"]));
            sb.Replace("$_EditorConfigPath_$", WebUtils.ResolveUrl(ConfigurationManager.AppSettings["CKEditor:ConfigPath"]));
            sb.Replace("$_EditorToolbarSet_$", mojoPortal.Web.Editor.ToolBar.FullWithTemplates.ToString());
            sb.Replace("$_EditorTemplatesUrl_$", siteRoot + "/Services/CKeditorTemplates.ashx?cb=" + Guid.NewGuid().ToString());
            sb.Replace("$_EditorStylesUrl_$", siteRoot + "/Services/CKeditorStyles.ashx?cb=" + Guid.NewGuid().ToString().Replace("-", string.Empty));
            sb.Replace("$_DropFileUploadUrl_$", siteRoot + "/Services/FileService.ashx?cmd=uploadfromeditor&rz=true&ko=" + WebConfigSettings.KeepFullSizeImagesDroppedInEditor.ToString().ToLower()
                       + "&t=" + Global.FileSystemToken.ToString());
            sb.Replace("$_FileBrowserUrl_$", siteRoot + WebConfigSettings.FileDialogRelativeUrl);
            sb.Replace("$_HeaderContent_$", config.HeaderContent);
            sb.Replace("$_FooterContent_$", config.FooterContent);
            sb.Replace("$_SkinVersionGuid_$", siteSettings.SkinVersion.ToString());
        }
Exemplo n.º 8
0
        private void MapDefinedMarkup(XmlNode node, bool isMobile = false)
        {
            if (node != null)
            {
                //bool desktopOnly = false;
                XmlAttributeCollection attrCollection = node.Attributes;

                if (attrCollection["name"] != null)
                {
                    markupDefinitionName = attrCollection["name"].Value;
                }

                if (attrCollection["moduleClass"] != null)
                {
                    if (isMobile)
                    {
                        mobileInstanceCssClass += " " + attrCollection["moduleClass"].Value;
                    }
                    else
                    {
                        instanceCssClass += " " + attrCollection["moduleClass"].Value;
                    }
                }
                useStandardMarkupOnDesktopOnly = XmlUtils.ParseBoolFromAttribute(attrCollection, "desktopOnly", useStandardMarkupOnDesktopOnly);
                useHeader   = XmlUtils.ParseBoolFromAttribute(attrCollection, "useHeader", useHeader);
                useFooter   = XmlUtils.ParseBoolFromAttribute(attrCollection, "useFooter", useFooter);
                allowImport = XmlUtils.ParseBoolFromAttribute(attrCollection, "allowImport", allowImport);
                allowExport = XmlUtils.ParseBoolFromAttribute(attrCollection, "allowExport", allowExport);
                //renderModuleLinksWithModuleTitle = XmlUtils.ParseBoolFromAttribute(attrCollection, "renderModuleLinksWithModuleTitle", renderModuleLinksWithModuleTitle);

                if (attrCollection["editPageClass"] != null)
                {
                    editPageCssClass += " " + attrCollection["editPageClass"].Value;
                }
                if (attrCollection["editPageTitle"] != null)
                {
                    editPageTitle = attrCollection["editPageTitle"].Value;
                }
                if (attrCollection["editPageUpdateButtonText"] != null)
                {
                    editPageUpdateButtonText = attrCollection["editPageUpdateButtonText"].Value;
                }
                if (attrCollection["editPageSaveButtonText"] != null)
                {
                    editPageSaveButtonText = attrCollection["editPageSaveButtonText"].Value;
                }
                if (attrCollection["editPageDeleteButtonText"] != null)
                {
                    editPageDeleteButtonText = attrCollection["editPageDeleteButtonText"].Value;
                }
                if (attrCollection["editPageCancelLinkText"] != null)
                {
                    editPageCancelLinkText = attrCollection["editPageCancelLinkText"].Value;
                }
                if (attrCollection["editPageDeleteWarning"] != null)
                {
                    editPageDeleteWarning = attrCollection["editPageDeleteWarning"].Value;
                }
                if (attrCollection["importPageTitle"] != null)
                {
                    importPageTitle = attrCollection["importPageTitle"].Value;
                }
                if (attrCollection["exportPageTitle"] != null)
                {
                    exportPageTitle = attrCollection["exportPageTitle"].Value;
                }
                if (attrCollection["importPageCancelLinkText"] != null)
                {
                    importPageCancelLinkText = attrCollection["importPageCancelLinkText"].Value;
                }
                if (attrCollection["fieldDefinitionSrc"] != null)
                {
                    fieldDefinitionSrc = attrCollection["fieldDefinitionSrc"].Value.Replace("$_SitePath_$", "/Data/Sites/" + siteId.ToInvariantString());
                }
                if (attrCollection["fieldDefinitionGuid"] != null)
                {
                    fieldDefinitionGuid = Guid.Parse(attrCollection["fieldDefinitionGuid"].Value);
                }
                if (attrCollection["jsonRenderLocation"] != null)
                {
                    jsonRenderLocation = attrCollection["jsonRenderLocation"].Value;
                }
                if (attrCollection["jsonLabelObjects"] != null)
                {
                    jsonLabelObjects = Convert.ToBoolean(attrCollection["jsonLabelObjects"].Value);
                }
                if (attrCollection["headerLocation"] != null)
                {
                    headerLocation = attrCollection["headerLocation"].Value;
                }
                if (attrCollection["footerLocation"] != null)
                {
                    footerLocation = attrCollection["footerLocation"].Value;
                }
                if (attrCollection["hideOuterWrapperPanel"] != null)
                {
                    hideOuterWrapperPanel = Convert.ToBoolean(attrCollection["hideOuterWrapperPanel"].Value);
                }
                if (attrCollection["hideInnerWrapperPanel"] != null)
                {
                    hideInnerWrapperPanel = Convert.ToBoolean(attrCollection["hideInnerWrapperPanel"].Value);
                }
                if (attrCollection["hideOuterBodyPanel"] != null)
                {
                    hideOuterBodyPanel = Convert.ToBoolean(attrCollection["hideOuterBodyPanel"].Value);
                }
                if (attrCollection["hideInnerBodyPanel"] != null)
                {
                    hideInnerBodyPanel = Convert.ToBoolean(attrCollection["hideInnerBodyPanel"].Value);
                }
                if (attrCollection["showSaveAsNewButton"] != null)
                {
                    showSaveAsNew = Convert.ToBoolean(attrCollection["showSaveAsNewButton"].Value);
                }
                if (attrCollection["maxItems"] != null)
                {
                    maxItems = Convert.ToInt32(attrCollection["maxItems"].Value);
                }
                if (attrCollection["processItems"] != null)
                {
                    processItems = Convert.ToBoolean(attrCollection["processItems"].Value);
                }

                MarkupDefinition workingMarkupDefinition = new MarkupDefinition();
                if (isMobile && !useStandardMarkupOnDesktopOnly)
                {
                    // do this so mobile settings are added to desktop
                    workingMarkupDefinition = (MarkupDefinition)markupDefinition.Clone();
                }

                foreach (XmlNode childNode in node)
                {
                    if (!String.IsNullOrWhiteSpace(childNode.InnerText) || !String.IsNullOrWhiteSpace(childNode.InnerXml))
                    {
                        switch (childNode.Name)
                        {
                        case "ModuleTitleMarkup":
                            workingMarkupDefinition.ModuleTitleMarkup = childNode.InnerText.Trim();
                            break;

                        case "ModuleTitleFormat":
                            workingMarkupDefinition.ModuleTitleFormat = childNode.InnerText.Trim();
                            break;

                        case "ModuleLinksFormat":
                            workingMarkupDefinition.ModuleLinksFormat = childNode.InnerText.Trim();
                            break;

                        case "ModuleInstanceMarkupTop":
                            workingMarkupDefinition.ModuleInstanceMarkupTop = childNode.InnerText.Trim();
                            break;

                        case "ModuleInstanceMarkupBottom":
                            workingMarkupDefinition.ModuleInstanceMarkupBottom = childNode.InnerText.Trim();
                            break;

                        case "InstanceFeaturedImageFormat":
                            workingMarkupDefinition.InstanceFeaturedImageFormat = childNode.InnerText.Trim();
                            break;

                        case "HeaderContentFormat":
                            workingMarkupDefinition.HeaderContentFormat = childNode.InnerText.Trim();
                            break;

                        case "FooterContentFormat":
                            workingMarkupDefinition.FooterContentFormat = childNode.InnerText.Trim();
                            break;

                        case "ItemMarkup":
                            workingMarkupDefinition.ItemMarkup = childNode.InnerText.Trim();
                            break;

                        case "ItemsRepeaterMarkup":
                            workingMarkupDefinition.ItemsRepeaterMarkup = childNode.InnerText.Trim();
                            XmlAttributeCollection repeaterAttribs = childNode.Attributes;
                            if (repeaterAttribs["itemsPerGroup"] != null)
                            {
                                workingMarkupDefinition.ItemsPerGroup = XmlUtils.ParseInt32FromAttribute(repeaterAttribs, "itemsPerGroup", workingMarkupDefinition.ItemsPerGroup);
                            }
                            break;

                        case "ItemsWrapperFormat":
                            workingMarkupDefinition.ItemsWrapperFormat = childNode.InnerText.Trim();
                            break;

                        case "ModuleSettingsLinkFormat":
                            workingMarkupDefinition.ModuleSettingsLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "AddItemLinkFormat":
                            workingMarkupDefinition.AddItemLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "EditHeaderLinkFormat":
                            workingMarkupDefinition.EditHeaderLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "EditFooterLinkFormat":
                            workingMarkupDefinition.EditFooterLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "ItemEditLinkFormat":
                            workingMarkupDefinition.ItemEditLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "ImportInstructions":
                            importInstructions = childNode.InnerText.Trim();
                            break;

                        case "ExportInstructions":
                            exportInstructions = childNode.InnerText.Trim();
                            break;

                        case "ImportLinkFormat":
                            workingMarkupDefinition.ImportLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "ExportLinkFormat":
                            workingMarkupDefinition.ExportLinkFormat = childNode.InnerText.Trim();
                            break;

                        case "GlobalViewMarkup":
                            workingMarkupDefinition.GlobalViewMarkup = childNode.InnerText.Trim();
                            break;

                        case "GlobalViewItemMarkup":
                            workingMarkupDefinition.GlobalViewItemMarkup = childNode.InnerText.Trim();
                            break;

                        case "CheckBoxListMarkup":
                        case "RadioButtonListMarkup":
                            CheckBoxListMarkup cblm = new CheckBoxListMarkup();

                            XmlAttributeCollection cblmAttribs = childNode.Attributes;
                            if (cblmAttribs["field"] != null)
                            {
                                cblm.Field = cblmAttribs["field"].Value;
                            }
                            if (cblmAttribs["token"] != null)
                            {
                                cblm.Token = cblmAttribs["token"].Value;
                            }

                            foreach (XmlNode cblmNode in childNode)
                            {
                                switch (cblmNode.Name)
                                {
                                case "Separator":
                                    cblm.Separator = cblmNode.InnerText.Trim();
                                    break;

                                case "Content":
                                    cblm.Markup = cblmNode.InnerText.Trim();
                                    break;
                                }
                            }
                            checkBoxListMarkups.Add(cblm);
                            break;

                        case "Scripts":
                            if (isMobile)
                            {
                                mobileMarkupScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode);
                            }
                            else
                            {
                                markupScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode);
                            }
                            //SetupDefinedScripts(childNode, isMobile);
                            //rawScript = childNode.InnerText;
                            break;

                        case "Styles":
                            markupCSS = SuperFlexiHelpers.ParseCssFromXmlNode(childNode);
                            break;
                        }
                    }
                }

                if (isMobile)
                {
                    mobileMarkupDefinition = workingMarkupDefinition;
                }
                else
                {
                    markupDefinition = workingMarkupDefinition;
                }
            }
        }
        private IndexItem GetIndexItem(PageSettings pageSettings, int moduleID, Item item)
        {
            Module module = new Module(moduleID);

            log.Debug($"moduleid: {moduleID} for module {module.ModuleTitle}");

            ModuleConfiguration config = new ModuleConfiguration(module);

            if (!config.IncludeInSearch)
            {
                return(null);
            }
            SuperFlexiDisplaySettings displaySettings = new SuperFlexiDisplaySettings();
            ModuleDefinition          flexiFeature    = new ModuleDefinition(config.FeatureGuid);
            IndexItem indexItem = new IndexItem();

            indexItem.SiteId              = pageSettings.SiteId;
            indexItem.PageId              = pageSettings.PageId;
            indexItem.PageName            = pageSettings.PageName;
            indexItem.ViewRoles           = pageSettings.AuthorizedRoles;
            indexItem.FeatureId           = flexiFeature.FeatureGuid.ToString();
            indexItem.FeatureName         = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName;
            indexItem.FeatureResourceFile = flexiFeature.ResourceFile;
            indexItem.ItemId              = item.ItemID;
            indexItem.CreatedUtc          = item.CreatedUtc;
            indexItem.LastModUtc          = item.LastModUtc;
            if (pageSettings.UseUrl)
            {
                if (pageSettings.UrlHasBeenAdjustedForFolderSites)
                {
                    indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty);
                }
                else
                {
                    indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty);
                }
                indexItem.UseQueryStringParams = false;
            }

            SearchDef searchDef = SearchDef.GetByFieldDefinition(item.DefinitionGuid);

            bool hasSearchDef = true;

            if (searchDef == null)
            {
                searchDef    = new SearchDef();
                hasSearchDef = false;
            }
            System.Text.StringBuilder sbTitle             = new System.Text.StringBuilder(searchDef.Title);
            System.Text.StringBuilder sbKeywords          = new System.Text.StringBuilder(searchDef.Keywords);
            System.Text.StringBuilder sbDescription       = new System.Text.StringBuilder(searchDef.Description);
            System.Text.StringBuilder sbLink              = new System.Text.StringBuilder(searchDef.Link);
            System.Text.StringBuilder sbLinkQueryAddendum = new System.Text.StringBuilder(searchDef.LinkQueryAddendum);
            SiteSettings siteSettings = new SiteSettings(pageSettings.SiteGuid);

            SuperFlexiHelpers.ReplaceStaticTokens(sbTitle, config, false, displaySettings, module, pageSettings, siteSettings, out sbTitle);
            SuperFlexiHelpers.ReplaceStaticTokens(sbKeywords, config, false, displaySettings, module, pageSettings, siteSettings, out sbKeywords);
            SuperFlexiHelpers.ReplaceStaticTokens(sbDescription, config, false, displaySettings, module, pageSettings, siteSettings, out sbDescription);
            SuperFlexiHelpers.ReplaceStaticTokens(sbLink, config, false, displaySettings, module, pageSettings, siteSettings, out sbLink);
            SuperFlexiHelpers.ReplaceStaticTokens(sbLinkQueryAddendum, config, false, displaySettings, module, pageSettings, siteSettings, out sbLinkQueryAddendum);

            var fieldValues = ItemFieldValue.GetItemValues(item.ItemGuid);

            log.Debug($"SuperFlexi Index: total field value count for ItemGuid ({item.ItemGuid}) is {fieldValues.Count}");
            foreach (ItemFieldValue fieldValue in fieldValues)
            {
                Field field = new Field(fieldValue.FieldGuid);
                if (field == null || !field.Searchable)
                {
                    continue;
                }

                if (hasSearchDef)
                {
                    sbTitle.Replace(field.Token, fieldValue.FieldValue);
                    sbKeywords.Replace(field.Token, fieldValue.FieldValue);
                    sbDescription.Replace(field.Token, fieldValue.FieldValue);
                    sbLink.Replace(field.Token, fieldValue.FieldValue);
                    sbLinkQueryAddendum.Replace(field.Token, fieldValue.FieldValue);
                }
                else
                {
                    sbKeywords.Append(fieldValue.FieldValue);
                }

                if (debugLog)
                {
                    log.DebugFormat("RebuildIndex indexing item [{0} = {1}]", field.Name, fieldValue.FieldValue);
                }
            }

            if (hasSearchDef)
            {
                sbTitle.Replace("$_ItemID_$", item.ItemID.ToString());
                sbKeywords.Replace("$_ItemID_$", item.ItemID.ToString());
                sbDescription.Replace("$_ItemID_$", item.ItemID.ToString());
                sbLink.Replace("$_ItemID_$", item.ItemID.ToString());
                sbLinkQueryAddendum.Replace("$_ItemID_$", item.ItemID.ToString());

                indexItem.Content = sbDescription.ToString();
                indexItem.Title   = sbTitle.ToString();

                if (sbLink.Length > 0)
                {
                    indexItem.ViewPage = sbLink.ToString();
                }

                if (sbLinkQueryAddendum.Length > 0)
                {
                    indexItem.QueryStringAddendum  = sbLinkQueryAddendum.ToString();
                    indexItem.UseQueryStringParams = false;
                }
            }
            else
            {
                indexItem.ModuleTitle = pageSettings.PageName;
                indexItem.Title       = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName;
            }

            indexItem.PageMetaKeywords = sbKeywords.ToString();
            indexItem.Categories       = sbKeywords.ToString();

            return(indexItem);
        }
Exemplo n.º 10
0
        private void PopulateControls()
        {
            string featuredImageUrl = string.Empty;
            string markupTop        = string.Empty;
            string markupBottom     = string.Empty;

            featuredImageUrl = String.IsNullOrWhiteSpace(config.InstanceFeaturedImage) ? featuredImageUrl : WebUtils.GetRelativeSiteRoot() + config.InstanceFeaturedImage;
            markupTop        = displaySettings.ModuleInstanceMarkupTop;
            markupBottom     = displaySettings.ModuleInstanceMarkupBottom;

            strOutput.Append(markupTop);

            if (config.UseHeader && config.HeaderLocation == "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.HeaderContent) && !String.Equals(config.HeaderContent, "<p>&nbsp;</p>"))
            {
                try
                {
                    strOutput.Append(string.Format(displaySettings.HeaderContentFormat, config.HeaderContent));
                }
                catch (FormatException ex)
                {
                    log.ErrorFormat(markupErrorFormat, "HeaderContentFormat", moduleTitle, ex);
                }
            }
            StringBuilder  jsonString   = new StringBuilder();
            StringWriter   stringWriter = new StringWriter(jsonString);
            JsonTextWriter jsonWriter   = new JsonTextWriter(stringWriter);

            // http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DateTimeZoneHandling.htm
            jsonWriter.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            // http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DateFormatHandling.htm
            jsonWriter.DateFormatHandling = DateFormatHandling.IsoDateFormat;

            string jsonObjName = "sflexi" + module.ModuleId.ToString() + (config.IsGlobalView ? "Modules" : "Items");

            if (config.RenderJSONOfData)
            {
                jsonWriter.WriteRaw("var " + jsonObjName + " = ");
                if (config.JsonLabelObjects || config.IsGlobalView)
                {
                    jsonWriter.WriteStartObject();
                }
                else
                {
                    jsonWriter.WriteStartArray();
                }
            }

            List <IndexedStringBuilder> itemsMarkup = new List <IndexedStringBuilder>();
            //List<Item> categorizedItems = new List<Item>();
            bool usingGlobalViewMarkup = !String.IsNullOrWhiteSpace(displaySettings.GlobalViewMarkup);
            int  currentModuleID       = -1;

            foreach (Item item in items)
            {
                bool itemIsEditable = isEditable || WebUser.IsInRoles(item.EditRoles);
                bool itemIsViewable = WebUser.IsInRoles(item.ViewRoles) || itemIsEditable;
                if (!itemIsViewable)
                {
                    continue;
                }

                //int itemCount = 0;
                //StringBuilder content = new StringBuilder();
                IndexedStringBuilder content = new IndexedStringBuilder();

                ModuleConfiguration itemModuleConfig = new ModuleConfiguration(module);
                item.ModuleFriendlyName = itemModuleConfig.ModuleFriendlyName;
                if (String.IsNullOrWhiteSpace(itemModuleConfig.ModuleFriendlyName))
                {
                    Module itemModule = new Module(item.ModuleGuid);
                    if (itemModule != null)
                    {
                        item.ModuleFriendlyName = itemModule.ModuleTitle;
                    }
                }

                if (config.IsGlobalView)
                {
                    content.SortOrder1 = itemModuleConfig.GlobalViewSortOrder;
                    content.SortOrder2 = item.SortOrder;
                }
                else
                {
                    content.SortOrder1 = item.SortOrder;
                }


                List <ItemFieldValue> fieldValues = ItemFieldValue.GetItemValues(item.ItemGuid);

                //using item.ModuleID here because if we are using a 'global view' we need to be sure the item edit link uses the correct module id.
                string itemEditUrl  = WebUtils.GetSiteRoot() + "/SuperFlexi/Edit.aspx?pageid=" + pageId + "&mid=" + item.ModuleID + "&itemid=" + item.ItemID;
                string itemEditLink = itemIsEditable ? String.Format(displaySettings.ItemEditLinkFormat, itemEditUrl) : string.Empty;

                if (config.RenderJSONOfData)
                {
                    if (config.IsGlobalView)
                    {
                        if (currentModuleID != item.ModuleID)
                        {
                            if (currentModuleID != -1)
                            {
                                jsonWriter.WriteEndObject();
                                jsonWriter.WriteEndObject();
                            }

                            currentModuleID = item.ModuleID;

                            //always label objects in globalview
                            jsonWriter.WritePropertyName("m" + currentModuleID.ToString());
                            jsonWriter.WriteStartObject();
                            jsonWriter.WritePropertyName("Module");
                            jsonWriter.WriteValue(item.ModuleFriendlyName);
                            jsonWriter.WritePropertyName("Items");
                            jsonWriter.WriteStartObject();
                        }
                    }
                    if (config.JsonLabelObjects || config.IsGlobalView)
                    {
                        jsonWriter.WritePropertyName("i" + item.ItemID.ToString());
                    }
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName("ItemId");
                    jsonWriter.WriteValue(item.ItemID.ToString());
                    jsonWriter.WritePropertyName("SortOrder");
                    jsonWriter.WriteValue(item.SortOrder.ToString());
                    if (IsEditable)
                    {
                        jsonWriter.WritePropertyName("EditUrl");
                        jsonWriter.WriteValue(itemEditUrl);
                    }
                }
                content.Append(displaySettings.ItemMarkup);

                foreach (Field field in fields)
                {
                    if (String.IsNullOrWhiteSpace(field.Token))
                    {
                        field.Token = "$_NONE_$";                                         //just in case someone has loaded the database with fields without using a source file.
                    }
                    bool fieldValueFound = false;

                    foreach (ItemFieldValue fieldValue in fieldValues)
                    {
                        if (field.FieldGuid == fieldValue.FieldGuid)
                        {
                            fieldValueFound = true;

                            if (String.IsNullOrWhiteSpace(fieldValue.FieldValue) ||
                                fieldValue.FieldValue.StartsWith("&deleted&") ||
                                fieldValue.FieldValue.StartsWith("&amp;deleted&amp;") ||
                                fieldValue.FieldValue.StartsWith("<p>&deleted&</p>") ||
                                fieldValue.FieldValue.StartsWith("<p>&amp;deleted&amp;</p>"))
                            {
                                content.Replace("^" + field.Token + "^", string.Empty);
                                content.Replace("^" + field.Token, string.Empty);
                                content.Replace(field.Token + "^", string.Empty);
                                content.Replace(field.Token, string.Empty);
                            }
                            else
                            {
                                if (IsDateField(field))
                                {
                                    DateTime dateTime = new DateTime();
                                    if (DateTime.TryParse(fieldValue.FieldValue, out dateTime))
                                    {
                                        /// ^field.Token is used when we don't want the preTokenString and postTokenString to be used
                                        content.Replace("^" + field.Token + "^", dateTime.ToString(field.DateFormat));
                                        content.Replace("^" + field.Token, dateTime.ToString(field.DateFormat) + field.PostTokenString);
                                        content.Replace(field.Token + "^", field.PreTokenString + dateTime.ToString(field.DateFormat));
                                        content.Replace(field.Token, field.PreTokenString + dateTime.ToString(field.DateFormat) + field.PostTokenString);
                                    }
                                }

                                if (IsCheckBoxListField(field) || IsRadioButtonListField(field))
                                {
                                    foreach (CheckBoxListMarkup cblm in config.CheckBoxListMarkups)
                                    {
                                        if (cblm.Field == field.Name)
                                        {
                                            StringBuilder cblmContent = new StringBuilder();

                                            List <string> values = fieldValue.FieldValue.SplitOnCharAndTrim(';');
                                            if (values.Count > 0)
                                            {
                                                foreach (string value in values)
                                                {
                                                    //why did we use _ValueItemID_ here instead of _ItemID_?
                                                    cblmContent.Append(cblm.Markup.Replace(field.Token, value).Replace("$_ValueItemID_$", item.ItemID.ToString()) + cblm.Separator);
                                                    cblm.SelectedValues.Add(new CheckBoxListMarkup.SelectedValue {
                                                        Value = value, ItemID = item.ItemID
                                                    });
                                                    //cblm.SelectedValues.Add(fieldValue);
                                                }
                                            }
                                            cblmContent.Length -= cblm.Separator.Length;
                                            content.Replace(cblm.Token, cblmContent.ToString());
                                        }
                                    }
                                }
                                //else
                                //{
                                /// ^field.Token is used when we don't want the preTokenString and postTokenString to be used


                                content.Replace("^" + field.Token + "^", fieldValue.FieldValue);
                                content.Replace("^" + field.Token, fieldValue.FieldValue + field.PostTokenString);
                                content.Replace(field.Token + "^", field.PreTokenString + fieldValue.FieldValue);
                                content.Replace(field.Token, field.PreTokenString + fieldValue.FieldValue + field.PostTokenString);
                                //}
                            }
                            //if (!String.IsNullOrWhiteSpace(field.LinkedField))
                            //{
                            //    Field linkedField = fields.Find(delegate(Field f) { return f.Name == field.LinkedField; });
                            //    if (linkedField != null)
                            //    {
                            //        ItemFieldValue linkedValue = fieldValues.Find(delegate(ItemFieldValue fv) { return fv.FieldGuid == linkedField.FieldGuid; });
                            //        content.Replace(linkedField.Token, linkedValue.FieldValue);
                            //    }
                            //}

                            if (config.RenderJSONOfData)
                            {
                                jsonWriter.WritePropertyName(field.Name);
                                //if (IsDateField(field))
                                //{
                                //    DateTime dateTime = new DateTime();
                                //    if (DateTime.TryParse(fieldValue.FieldValue, out dateTime))
                                //    {
                                //        jsonWriter.WriteValue(dateTime);
                                //    }

                                //}
                                //else
                                //{
                                jsonWriter.WriteValue(fieldValue.FieldValue);
                                //}
                            }
                        }
                    }

                    if (!fieldValueFound)
                    {
                        content.Replace(field.Token, field.DefaultValue);
                    }
                }

                if (config.RenderJSONOfData)
                {
                    //if (config.IsGlobalView)
                    //{
                    //    jsonWriter.WriteEndObject();
                    //}
                    jsonWriter.WriteEndObject();
                }

                content.Replace("$_EditLink_$", itemEditLink);
                content.Replace("$_ItemID_$", item.ItemID.ToString());
                content.Replace("$_SortOrder_$", item.SortOrder.ToString());

                if (!String.IsNullOrWhiteSpace(content))
                {
                    itemsMarkup.Add(content);
                }
            }
            if (config.DescendingSort)
            {
                itemsMarkup.Sort(delegate(IndexedStringBuilder a, IndexedStringBuilder b)
                {
                    int xdiff = b.SortOrder1.CompareTo(a.SortOrder1);
                    if (xdiff != 0)
                    {
                        return(xdiff);
                    }
                    else
                    {
                        return(b.SortOrder2.CompareTo(a.SortOrder2));
                    }
                });
            }
            else
            {
                itemsMarkup.Sort(delegate(IndexedStringBuilder a, IndexedStringBuilder b)
                {
                    int xdiff = a.SortOrder1.CompareTo(b.SortOrder1);
                    if (xdiff != 0)
                    {
                        return(xdiff);
                    }
                    else
                    {
                        return(a.SortOrder2.CompareTo(b.SortOrder2));
                    }
                });
            }
            StringBuilder allItems = new StringBuilder();

            if (displaySettings.ItemsPerGroup == -1)
            {
                foreach (IndexedStringBuilder sb in itemsMarkup)
                {
                    //allItems.Append(displaySettings.GlobalViewModuleGroupMarkup.Replace("$_ModuleGroupName_$", sb.GroupName));
                    allItems.Append(sb.ToString());
                }
                if (usingGlobalViewMarkup)
                {
                    strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, displaySettings.GlobalViewMarkup.Replace("$_ModuleGroups_$", allItems.ToString()));
                }
                else
                {
                    strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, allItems.ToString());
                }
            }
            else
            {
                int itemIndex = 0;

                decimal totalGroupCount = Math.Ceiling(itemsMarkup.Count / Convert.ToDecimal(displaySettings.ItemsPerGroup));

                if (totalGroupCount < 1 && itemsMarkup.Count > 0)
                {
                    totalGroupCount = 1;
                }

                int currentGroup            = 1;
                List <StringBuilder> groups = new List <StringBuilder>();
                while (currentGroup <= totalGroupCount && itemIndex < itemsMarkup.Count)
                {
                    StringBuilder group = new StringBuilder();
                    group.Append(displaySettings.ItemsRepeaterMarkup);
                    //group.SortOrder1 = itemsMarkup[itemIndex].SortOrder1;
                    //group.SortOrder2 = itemsMarkup[itemIndex].SortOrder2;
                    //group.GroupName = itemsMarkup[itemIndex].GroupName;
                    for (int i = 0; i < displaySettings.ItemsPerGroup; i++)
                    {
                        if (itemIndex < itemsMarkup.Count)
                        {
                            group.Replace("$_Items[" + i.ToString() + "]_$", itemsMarkup[itemIndex].ToString());
                            itemIndex++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    groups.Add(group);
                    currentGroup++;
                }

                //groups.Sort(delegate (IndexedStringBuilder a, IndexedStringBuilder b) {
                //    int xdiff = a.SortOrder1.CompareTo(b.SortOrder1);
                //    if (xdiff != 0) return xdiff;
                //    else return a.SortOrder2.CompareTo(b.SortOrder2);
                //});

                foreach (StringBuilder group in groups)
                {
                    allItems.Append(group.ToString());
                }

                strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, Regex.Replace(allItems.ToString(), @"(\$_Items\[[0-9]+\]_\$)", string.Empty, RegexOptions.Multiline));
            }



            //strOutput.Append(displaySettings.ItemListMarkupBottom);
            if (config.RenderJSONOfData)
            {
                if (config.JsonLabelObjects || config.IsGlobalView)
                {
                    jsonWriter.WriteEndObject();

                    if (config.IsGlobalView)
                    {
                        jsonWriter.WriteEndObject();
                        jsonWriter.WriteEnd();
                    }
                }
                else
                {
                    jsonWriter.WriteEndArray();
                }

                MarkupScript jsonScript = new MarkupScript();

                jsonWriter.Close();
                stringWriter.Close();

                jsonScript.RawScript  = stringWriter.ToString();
                jsonScript.Position   = config.JsonRenderLocation;
                jsonScript.ScriptName = "sflexi" + module.ModuleId.ToString() + config.MarkupDefinitionName.ToCleanFileName() + "-JSON";

                List <MarkupScript> scripts = new List <MarkupScript>();
                scripts.Add(jsonScript);

                SuperFlexiHelpers.SetupScripts(scripts, config, displaySettings, IsEditable, IsPostBack, ClientID, ModuleId, PageId, Page, this);
            }

            if (config.UseFooter && config.FooterLocation == "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.FooterContent) && !String.Equals(config.FooterContent, "<p>&nbsp;</p>"))
            {
                try
                {
                    strOutput.AppendFormat(displaySettings.FooterContentFormat, config.FooterContent);
                }
                catch (System.FormatException ex)
                {
                    log.ErrorFormat(markupErrorFormat, "FooterContentFormat", moduleTitle, ex);
                }
            }

            strOutput.Append(markupBottom);

            SuperFlexiHelpers.ReplaceStaticTokens(strOutput, config, isEditable, displaySettings, module.ModuleId, pageSettings, siteSettings, out strOutput);

            //this is for displaying all of the selected values from the items outside of the items themselves
            foreach (CheckBoxListMarkup cblm in config.CheckBoxListMarkups)
            {
                StringBuilder cblmContent = new StringBuilder();

                if (fields.Count > 0 && cblm.SelectedValues.Count > 0)
                {
                    Field theField = fields.Where(field => field.Name == cblm.Field).Single();
                    if (theField != null)
                    {
                        List <CheckBoxListMarkup.SelectedValue> distinctSelectedValues = new List <CheckBoxListMarkup.SelectedValue>();
                        foreach (CheckBoxListMarkup.SelectedValue selectedValue in cblm.SelectedValues)
                        {
                            CheckBoxListMarkup.SelectedValue match = distinctSelectedValues.Find(i => i.Value == selectedValue.Value);
                            if (match == null)
                            {
                                distinctSelectedValues.Add(selectedValue);
                            }
                            else
                            {
                                match.Count++;
                            }
                        }
                        //var selectedValues = cblm.SelectedValues.GroupBy(selectedValue => selectedValue.Value)
                        //    .Select(distinctSelectedValue => new { Value = distinctSelectedValue.Key, Count = distinctSelectedValue.Count(), ItemID = distinctSelectedValue.ItemID })
                        //    .OrderBy(x => x.Value);
                        foreach (CheckBoxListMarkup.SelectedValue value in distinctSelectedValues)
                        {
                            cblmContent.Append(cblm.Markup.Replace(theField.Token, value.Value).Replace("$_ValueItemID_$", value.ItemID.ToString()) + cblm.Separator);
                            cblmContent.Replace("$_CBLValueCount_$", value.Count.ToString());
                        }
                    }

                    if (cblmContent.Length >= cblm.Separator.Length)
                    {
                        cblmContent.Length -= cblm.Separator.Length;
                    }

                    strOutput.Replace(cblm.Token, cblmContent.ToString());
                }

                strOutput.Replace(cblm.Token, string.Empty);
            }
            theLit.Text = strOutput.ToString();
        }
Exemplo n.º 11
0
        private void LoadSettings()
        {
            Module module = new Module(ModuleGuid);

            config = new ModuleConfiguration(module);
            //PageSettings currentPage = CacheHelper.GetCurrentPage();

            if (config.MarkupDefinition != null)
            {
                displaySettings = config.MarkupDefinition;
            }

            if (ModuleConfiguration != null)
            {
                Title       = ModuleConfiguration.ModuleTitle;
                Description = ModuleConfiguration.FeatureName;
            }
            StringBuilder moduleTitle = new StringBuilder();

            moduleTitle.Append(displaySettings.ModuleTitleMarkup);
            SuperFlexiHelpers.ReplaceStaticTokens(moduleTitle, config, IsEditable, displaySettings, module, currentPage, siteSettings, out moduleTitle);
            litModuleTitle.Text = moduleTitle.ToString();

            if (config.InstanceCssClass.Length > 0 && !config.HideOuterWrapperPanel)
            {
                pnlOuterWrap.SetOrAppendCss(config.InstanceCssClass.Replace("$_ModuleID_$", ModuleId.ToString()));
            }

            if (SiteUtils.IsMobileDevice() && config.MobileInstanceCssClass.Length > 0 && !config.HideOuterWrapperPanel)
            {
                pnlOuterWrap.SetOrAppendCss(config.MobileInstanceCssClass.Replace("$_ModuleID_$", ModuleId.ToString()));
            }

            theWidget.Config = config;
            if (currentPage != null)
            {
                theWidget.PageId      = currentPage.PageId;
                theWidget.CurrentPage = currentPage;
            }
            theWidget.ModuleId      = ModuleId;
            theWidget.IsEditable    = IsEditable;
            theWidget.SiteRoot      = SiteRoot;
            theWidget.ImageSiteRoot = ImageSiteRoot;

            //theWidgetRazor.Config = config;
            //theWidgetRazor.PageId = PageId;
            //theWidgetRazor.ModuleId = ModuleId;
            //theWidgetRazor.IsEditable = IsEditable;
            //theWidgetRazor.SiteRoot = SiteRoot;
            //theWidgetRazor.ImageSiteRoot = ImageSiteRoot;

            theWidget.Visible = true;
            //theWidgetRazor.Visible = config.UseRazor;

            if (config.UseHeader && config.HeaderLocation != "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.HeaderContent) && !String.Equals(config.HeaderContent, "<p>&nbsp;</p>"))
            {
                StringBuilder headerContent = new StringBuilder();
                headerContent.AppendFormat(displaySettings.HeaderContentFormat, config.HeaderContent);
                SuperFlexiHelpers.ReplaceStaticTokens(headerContent, config, IsEditable, displaySettings, module, currentPage, siteSettings, out headerContent);
                LiteralControl litHeaderContent = new LiteralControl(headerContent.ToString());
                //if HeaderLocation is set to a hidden panel the header will be added to the Outside.
                switch (config.HeaderLocation)
                {
                default:
                    break;

                case "OuterBodyPanel":
                    if (config.HideOuterBodyPanel)
                    {
                        goto case "Outside";
                    }
                    pnlOuterBody.Controls.AddAt(0, litHeaderContent);
                    break;

                case "InnerWrapperPanel":
                    if (config.HideInnerWrapperPanel)
                    {
                        goto case "Outside";
                    }
                    pnlInnerWrap.Controls.AddAt(0, litHeaderContent);
                    break;

                case "OuterWrapperPanel":
                    if (config.HideOuterWrapperPanel)
                    {
                        goto case "Outside";
                    }
                    pnlOuterWrap.Controls.AddAt(0, litHeaderContent);
                    break;

                case "Outside":
                    litHead.Text = headerContent.ToString();
                    break;
                }
            }

            if (config.UseFooter && config.FooterLocation != "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.FooterContent) && !String.Equals(config.FooterContent, "<p>&nbsp;</p>"))
            {
                StringBuilder footerContent = new StringBuilder();
                footerContent.AppendFormat(displaySettings.FooterContentFormat, config.FooterContent);
                SuperFlexiHelpers.ReplaceStaticTokens(footerContent, config, IsEditable, displaySettings, module, currentPage, siteSettings, out footerContent);
                LiteralControl litFooterContent = new LiteralControl(footerContent.ToString());
                //if FooterLocation is set to a hidden panel the footer will be added to the Outside.
                switch (config.FooterLocation)
                {
                default:
                    break;

                case "OuterBodyPanel":
                    if (config.HideOuterBodyPanel)
                    {
                        goto case "Outside";
                    }
                    pnlOuterBody.Controls.Add(litFooterContent);
                    break;

                case "InnerWrapperPanel":
                    if (config.HideInnerWrapperPanel)
                    {
                        goto case "Outside";
                    }
                    pnlInnerWrap.Controls.Add(litFooterContent);
                    break;

                case "OuterWrapperPanel":
                    if (config.HideOuterWrapperPanel)
                    {
                        goto case "Outside";
                    }
                    pnlOuterWrap.Controls.Add(litFooterContent);
                    break;

                case "Outside":
                    litFoot.Text = footerContent.ToString();
                    break;
                }
            }

            pnlOuterWrap.RenderContentsOnly = config.HideOuterWrapperPanel;
            pnlInnerWrap.RenderContentsOnly = config.HideInnerWrapperPanel;
            pnlOuterBody.RenderContentsOnly = config.HideOuterBodyPanel;
            pnlInnerBody.RenderContentsOnly = config.HideInnerBodyPanel;
        }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //LoadSettings();
            //SetupScripts();

            module      = new Module(ModuleId);
            moduleTitle = module.ModuleTitle;

            siteSettings = CacheHelper.GetCurrentSiteSettings();

            if (CurrentPage == null)
            {
                CurrentPage = CacheHelper.GetCurrentPage();
                //if (CurrentPage == null)
                //{
                //	log.Info("Can't use CacheHelper.GetCurrentPage() here.");
                //	CurrentPage = new PageSettings(siteSettings.SiteId, PageId);
                //}
            }
            if (Config.MarkupDefinition != null)
            {
                displaySettings = Config.MarkupDefinition;
            }

            if (Config.ProcessItems)
            {
                fields = Field.GetAllForDefinition(Config.FieldDefinitionGuid);

                if (Config.IsGlobalView)
                {
                    //items = Item.GetAllForDefinition(Config.FieldDefinitionGuid, siteSettings.SiteGuid, Config.DescendingSort);
                    //fieldValues = ItemFieldValue.GetItemValuesByDefinition(Config.FieldDefinitionGuid);
                    itemsWithValues = Item.GetForDefinitionWithValues(Config.FieldDefinitionGuid, siteSettings.SiteGuid, Config.DescendingSort);
                }
                else
                {
                    //items = Item.GetForModule(ModuleId, Config.DescendingSort);
                    //fieldValues = ItemFieldValue.GetItemValuesByModule(module.ModuleGuid);
                    itemsWithValues = Item.GetForModuleWithValues(ModuleId, Config.DescendingSort);
                }
            }

            if (SiteUtils.IsMobileDevice() && Config.MobileMarkupDefinition != null)
            {
                displaySettings = Config.MobileMarkupDefinition;
            }

            if (Config.MarkupScripts.Count > 0 || (SiteUtils.IsMobileDevice() && Config.MobileMarkupScripts.Count > 0))
            {
                if (SiteUtils.IsMobileDevice() && Config.MobileMarkupScripts.Count > 0)
                {
                    SuperFlexiHelpers.SetupScripts(Config.MobileMarkupScripts, Config, displaySettings, IsEditable, IsPostBack, ClientID, siteSettings, module, CurrentPage, Page, this);
                }
                else
                {
                    SuperFlexiHelpers.SetupScripts(Config.MarkupScripts, Config, displaySettings, IsEditable, IsPostBack, ClientID, siteSettings, module, CurrentPage, Page, this);
                }
            }

            if (Config.MarkupCSS.Count > 0)
            {
                SuperFlexiHelpers.SetupStyle(Config.MarkupCSS, Config, displaySettings, IsEditable, ClientID, siteSettings, module, CurrentPage, Page, this);
            }

            //if (Page.IsPostBack) { return; }

            PopulateControls();
        }
Exemplo n.º 13
0
        public static void SetupScripts(
            List <MarkupScript> markupScripts,
            ModuleConfiguration config,
            SuperFlexiDisplaySettings displaySettings,
            bool forceHttps,
            bool isEditable,
            bool isPostBack,
            string clientID,
            int moduleID,
            int pageID,
            Page page,
            Control control)
        {
            string scriptRefFormat = "\n<script type=\"text/javascript\" src=\"{0}\" data-name=\"{1}\"></script>";
            string rawScriptFormat = "\n<script type=\"text/javascript\" data-name=\"{1}\">\n{0}\n</script>";

            foreach (MarkupScript script in markupScripts)
            {
                StringBuilder sbScriptText = new StringBuilder();
                StringBuilder sbScriptName = new StringBuilder();

                sbScriptName.Append(String.IsNullOrWhiteSpace(script.ScriptName) ? clientID + "flexiScript_" + markupScripts.IndexOf(script) : "flexiScript_" + script.ScriptName);
                SuperFlexiHelpers.ReplaceStaticTokens(sbScriptName, config, isEditable, displaySettings, moduleID, pageID, out sbScriptName);
                string scriptName = sbScriptName.ToString();
                if (!String.IsNullOrWhiteSpace(script.Url))
                {
                    string scriptUrl = GetPathToFile(config, script.Url, forceHttps);
                    sbScriptText.Append(string.Format(scriptRefFormat, scriptUrl, scriptName));
                }
                else if (!String.IsNullOrWhiteSpace(script.RawScript))
                {
                    sbScriptText.Append(string.Format(rawScriptFormat, script.RawScript, scriptName));
                }

                SuperFlexiHelpers.ReplaceStaticTokens(sbScriptText, config, isEditable, displaySettings, moduleID, pageID, out sbScriptText);

                // script position options
                // inHead
                // inBody (register script) (default)
                // aboveMarkupDefinition
                // belowMarkupDefinition
                // bottomStartup (register startup script)
                switch (script.Position)
                {
                case "inHead":
                    if (!isPostBack && !page.IsCallback)
                    {
                        if (page.Header.FindControl(scriptName) == null)
                        {
                            LiteralControl headLit = new LiteralControl();
                            headLit.ID              = scriptName;
                            headLit.Text            = sbScriptText.ToString();
                            headLit.ClientIDMode    = System.Web.UI.ClientIDMode.Static;
                            headLit.EnableViewState = false;
                            page.Header.Controls.Add(headLit);
                        }
                    }
                    break;

                case "aboveMarkupDefinition":
                    if (control == null)
                    {
                        goto case "bottomStartup";
                    }
                    if (control.FindControlRecursive(scriptName) == null)
                    {
                        Control aboveMarkupDefinitionScripts = control.FindControlRecursive("aboveMarkupDefinitionScripts");
                        if (aboveMarkupDefinitionScripts != null)
                        {
                            LiteralControl aboveLit = new LiteralControl();
                            aboveLit.ID   = scriptName;
                            aboveLit.Text = sbScriptText.ToString();
                            aboveMarkupDefinitionScripts.Controls.Add(aboveLit);
                        }
                        else
                        {
                            goto case "bottomStartup";
                        }
                    }
                    break;

                case "belowMarkupDefinition":
                    if (control == null)
                    {
                        goto case "bottomStartup";
                    }
                    if (control.FindControlRecursive(scriptName) == null)
                    {
                        Control belowMarkupDefinitionScripts = control.FindControlRecursive("belowMarkupDefinitionScripts");
                        if (belowMarkupDefinitionScripts != null)
                        {
                            LiteralControl belowLit = new LiteralControl();
                            belowLit.ID   = scriptName;
                            belowLit.Text = sbScriptText.ToString();
                            belowMarkupDefinitionScripts.Controls.Add(belowLit);
                        }
                        else
                        {
                            goto case "bottomStartup";
                        }
                    }
                    //strBelowMarkupScripts.AppendLine(scriptText);
                    break;

                case "bottomStartup":
                    if (!page.ClientScript.IsStartupScriptRegistered(scriptName))
                    {
                        ScriptManager.RegisterStartupScript(
                            page,
                            typeof(Page),
                            scriptName,
                            sbScriptText.ToString(),
                            false);
                    }
                    break;

                case "inBody":
                default:
                    if (!page.ClientScript.IsClientScriptBlockRegistered(scriptName))
                    {
                        ScriptManager.RegisterClientScriptBlock(
                            page,
                            typeof(Page),
                            scriptName,
                            sbScriptText.ToString(),
                            false);
                    }
                    break;
                }
            }
        }
Exemplo n.º 14
0
        public static void SetupScripts(
            List <MarkupScript> markupScripts,
            ModuleConfiguration config,
            SuperFlexiDisplaySettings displaySettings,
            bool isEditable,
            bool isPostBack,
            string clientID,
            int moduleID,
            int pageID,
            Page page,
            Control control)
        {
            string scriptRefFormat = "\n<script type=\"text/javascript\" src=\"{0}\" data-name=\"{1}\"></script>";
            string rawScriptFormat = "\n<script type=\"text/javascript\" data-name=\"{1}\">\n{0}\n</script>";

            foreach (MarkupScript script in markupScripts)
            {
                StringBuilder sbScriptText = new StringBuilder();
                StringBuilder sbScriptName = new StringBuilder();

                sbScriptName.Append(String.IsNullOrWhiteSpace(script.ScriptName) ? clientID + "flexiScript_" + markupScripts.IndexOf(script) : "flexiScript_" + script.ScriptName);
                SuperFlexiHelpers.ReplaceStaticTokens(sbScriptName, config, isEditable, displaySettings, moduleID, pageID, out sbScriptName);
                string scriptName = sbScriptName.ToString();
                if (!String.IsNullOrWhiteSpace(script.Url))
                {
                    //string scriptUrl = string.Empty;
                    //if (script.Url.StartsWith("/") ||
                    //	script.Url.StartsWith("http://") ||
                    //	script.Url.StartsWith("https://"))
                    //{
                    //	scriptUrl = script.Url;
                    //}
                    //else if (script.Url.StartsWith("~/"))
                    //{
                    //	scriptUrl = WebUtils.ResolveServerUrl(script.Url);
                    //}
                    //else if (script.Url.StartsWith("$_SitePath_$"))
                    //{
                    //	scriptUrl = script.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/");
                    //}
                    //else
                    //{
                    //	scriptUrl = new Uri(config.SolutionLocationUrl, script.Url).ToString();
                    //}
                    //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)))
                    //{
                    //	FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile));
                    //	scriptUrl = WebUtils.ResolveServerUrl(Path.Combine(fileInfo.DirectoryName.Replace(System.Web.Hosting.HostingEnvironment.MapPath("~"), "~/"), script.Url));
                    //}
                    string scriptUrl = GetPathToFile(config, script.Url);
                    sbScriptText.Append(string.Format(scriptRefFormat, scriptUrl, scriptName));
                }
                else if (!String.IsNullOrWhiteSpace(script.RawScript))
                {
                    sbScriptText.Append(string.Format(rawScriptFormat, script.RawScript, scriptName));
                }

                SuperFlexiHelpers.ReplaceStaticTokens(sbScriptText, config, isEditable, displaySettings, moduleID, pageID, out sbScriptText);

                // script position options
                // inHead
                // inBody (register script) (default)
                // aboveMarkupDefinition
                // belowMarkupDefinition
                // bottomStartup (register startup script)
                switch (script.Position)
                {
                case "inHead":
                    if (!isPostBack && !page.IsCallback)
                    {
                        if (page.Header.FindControl(scriptName) == null)
                        {
                            LiteralControl headLit = new LiteralControl();
                            headLit.ID              = scriptName;
                            headLit.Text            = sbScriptText.ToString();
                            headLit.ClientIDMode    = System.Web.UI.ClientIDMode.Static;
                            headLit.EnableViewState = false;
                            page.Header.Controls.Add(headLit);
                        }
                    }
                    break;

                case "aboveMarkupDefinition":
                    if (control == null)
                    {
                        goto case "bottomStartup";
                    }
                    if (control.FindControlRecursive(scriptName) == null)
                    {
                        Control aboveMarkupDefinitionScripts = control.FindControlRecursive("aboveMarkupDefinitionScripts");
                        if (aboveMarkupDefinitionScripts != null)
                        {
                            LiteralControl aboveLit = new LiteralControl();
                            aboveLit.ID   = scriptName;
                            aboveLit.Text = sbScriptText.ToString();
                            aboveMarkupDefinitionScripts.Controls.Add(aboveLit);
                        }
                        else
                        {
                            goto case "bottomStartup";
                        }
                    }
                    break;

                case "belowMarkupDefinition":
                    if (control == null)
                    {
                        goto case "bottomStartup";
                    }
                    if (control.FindControlRecursive(scriptName) == null)
                    {
                        Control belowMarkupDefinitionScripts = control.FindControlRecursive("belowMarkupDefinitionScripts");
                        if (belowMarkupDefinitionScripts != null)
                        {
                            LiteralControl belowLit = new LiteralControl();
                            belowLit.ID   = scriptName;
                            belowLit.Text = sbScriptText.ToString();
                            belowMarkupDefinitionScripts.Controls.Add(belowLit);
                        }
                        else
                        {
                            goto case "bottomStartup";
                        }
                    }
                    //strBelowMarkupScripts.AppendLine(scriptText);
                    break;

                case "bottomStartup":
                    if (!page.ClientScript.IsStartupScriptRegistered(scriptName))
                    {
                        ScriptManager.RegisterStartupScript(
                            page,
                            typeof(Page),
                            scriptName,
                            sbScriptText.ToString(),
                            false);
                    }
                    break;

                case "inBody":
                default:
                    if (!page.ClientScript.IsClientScriptBlockRegistered(scriptName))
                    {
                        ScriptManager.RegisterClientScriptBlock(
                            page,
                            typeof(Page),
                            scriptName,
                            sbScriptText.ToString(),
                            false);
                    }
                    break;
                }
            }
        }
Exemplo n.º 15
0
        //public static List<MarkupScript> ParseScriptsFromXml(ModuleConfiguration config)
        //{
        //    List<MarkupScript> scripts = new List<MarkupScript>();
        //    string fullPath = string.Empty;
        //    XmlDocument doc = new XmlDocument();
        //    if (DefinitionExists(config.FieldDefinitionSrc, out doc))
        //    {
        //        XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields/Scripts");

        //        if (node == null) return scripts;

        //        try
        //        {
        //            scripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(node);
        //        }
        //        catch (System.Xml.XmlException ex)
        //        {
        //            log.Error(ex);
        //        }
        //    }
        //    return scripts;
        //}



        /// <summary>
        /// Creates a list of Field from field definition xml file.
        /// </summary>
        /// <param name="fieldDefinitionSrc"></param>
        /// <returns>IList</returns>
        public static List <Field> ParseFieldDefinitionXml(ModuleConfiguration config, Guid siteGuid)
        {
            List <Field> fields   = new List <Field>();
            string       fullPath = string.Empty;
            XmlDocument  doc      = new XmlDocument();

            if (DefinitionExists(config.FieldDefinitionSrc, out doc))
            {
                XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields");
                if (node != null)
                {
                    XmlAttributeCollection attribs = node.Attributes;

                    string definitionName = string.Empty;
                    Guid   definitionGuid = Guid.NewGuid();
                    if (attribs["definitionName"] != null)
                    {
                        definitionName = attribs["definitionName"].Value;
                    }
                    if (attribs["definitionGuid"] != null)
                    {
                        definitionGuid = Guid.Parse(attribs["definitionGuid"].Value);
                    }

                    foreach (XmlNode childNode in node)
                    {
                        if (childNode.Name == "Field")
                        {
                            try
                            {
                                Field field = new Field();
                                XmlAttributeCollection itemDefAttribs = childNode.Attributes;

                                field.DefinitionName = definitionName;
                                field.DefinitionGuid = definitionGuid;
                                if (itemDefAttribs["name"] != null)
                                {
                                    field.Name = itemDefAttribs["name"].Value;
                                }
                                if (itemDefAttribs["label"] != null)
                                {
                                    field.Label = itemDefAttribs["label"].Value;
                                }
                                if (itemDefAttribs["defaultValue"] != null)
                                {
                                    field.DefaultValue = itemDefAttribs["defaultValue"].Value;
                                }
                                if (itemDefAttribs["controlType"] != null)
                                {
                                    field.ControlType = itemDefAttribs["controlType"].Value;
                                }
                                if (itemDefAttribs["controlSrc"] != null)
                                {
                                    field.ControlSrc = itemDefAttribs["controlSrc"].Value;
                                }
                                field.SortOrder = XmlUtils.ParseInt32FromAttribute(itemDefAttribs, "sortOrder", field.SortOrder);
                                if (itemDefAttribs["helpKey"] != null)
                                {
                                    field.HelpKey = itemDefAttribs["helpKey"].Value;
                                }
                                field.Required = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "required", field.Required);
                                if (itemDefAttribs["requiredMessageFormat"] != null)
                                {
                                    field.RequiredMessageFormat = itemDefAttribs["requiredMessageFormat"].Value;
                                }
                                if (itemDefAttribs["regex"] != null)
                                {
                                    field.Regex = itemDefAttribs["regex"].Value;
                                }
                                if (itemDefAttribs["regexMessageFormat"] != null)
                                {
                                    field.RegexMessageFormat = itemDefAttribs["regexMessageFormat"].Value;
                                }
                                if (itemDefAttribs["token"] != null && !String.IsNullOrWhiteSpace(itemDefAttribs["token"].Value))
                                {
                                    field.Token = itemDefAttribs["token"].Value;
                                }

                                field.Searchable = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isSearchable", field.Searchable);
                                if (itemDefAttribs["editPageControlWrapperCssClass"] != null)
                                {
                                    field.EditPageControlWrapperCssClass = itemDefAttribs["editPageControlWrapperCssClass"].Value;
                                }
                                if (itemDefAttribs["editPageLabelCssClass"] != null)
                                {
                                    field.EditPageLabelCssClass = itemDefAttribs["editPageLabelCssClass"].Value;
                                }
                                if (itemDefAttribs["editPageControlCssClass"] != null)
                                {
                                    field.EditPageControlCssClass = itemDefAttribs["editPageControlCssClass"].Value;
                                }
                                field.DatePickerIncludeTimeForDate = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerIncludeTimeForDate", field.DatePickerIncludeTimeForDate);
                                field.DatePickerShowMonthList      = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowMonthList", field.DatePickerShowMonthList);
                                field.DatePickerShowYearList       = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowYearList", field.DatePickerShowYearList);
                                if (itemDefAttribs["datePickerYearRange"] != null)
                                {
                                    field.DatePickerYearRange = itemDefAttribs["datePickerYearRange"].Value;
                                }
                                if (itemDefAttribs["imageBrowserEmptyUrl"] != null)
                                {
                                    field.ImageBrowserEmptyUrl = itemDefAttribs["imageBrowserEmptyUrl"].Value;
                                }
                                field.CheckBoxReturnBool = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "checkBoxReturnBool", field.CheckBoxReturnBool);
                                if (itemDefAttribs["checkBoxReturnValueWhenTrue"] != null)
                                {
                                    field.CheckBoxReturnValueWhenTrue = itemDefAttribs["checkBoxReturnValueWhenTrue"].Value;
                                }
                                if (itemDefAttribs["checkBoxReturnValueWhenFalse"] != null)
                                {
                                    field.CheckBoxReturnValueWhenFalse = itemDefAttribs["checkBoxReturnValueWhenFalse"].Value;
                                }
                                if (itemDefAttribs["dateFormat"] != null)
                                {
                                    field.DateFormat = itemDefAttribs["dateFormat"].Value;
                                }
                                if (itemDefAttribs["textBoxMode"] != null)
                                {
                                    field.TextBoxMode = itemDefAttribs["textBoxMode"].Value;
                                }
                                field.IsDeleted = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isDeleted", field.IsDeleted);
                                field.IsGlobal  = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isGlobal", field.IsGlobal);

                                StringBuilder options    = new StringBuilder();
                                StringBuilder attributes = new StringBuilder();
                                foreach (XmlNode subNode in childNode)
                                {
                                    switch (subNode.Name)
                                    {
                                    case "Options":
                                        GetKeyValuePairs(subNode.ChildNodes, out options);
                                        break;

                                    case "Attributes":
                                        GetKeyValuePairs(subNode.ChildNodes, out attributes);
                                        break;

                                    case "PreTokenString":
                                        field.PreTokenString = subNode.InnerText.Trim();
                                        break;

                                    case "PostTokenString":
                                        field.PostTokenString = subNode.InnerText.Trim();
                                        break;
                                    }
                                }

                                if (options.Length > 0)
                                {
                                    field.Options = options.ToString();
                                }

                                if (attributes.Length > 0)
                                {
                                    field.Attributes = attributes.ToString();
                                }

                                fields.Add(field);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "Scripts")
                        {
                            try
                            {
                                config.EditPageScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "Styles")
                        {
                            try
                            {
                                config.EditPageCSS = SuperFlexiHelpers.ParseCssFromXmlNode(childNode);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "SearchDefinition")
                        {
                            try
                            {
                                SuperFlexiHelpers.ParseSearchDefinition(childNode, definitionGuid, siteGuid);
                            }
                            catch (XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                    }
                }
            }

            fields.Sort();
            return(fields);
        }
Exemplo n.º 16
0
        private void ExportBtn_Click(Object sender, EventArgs e)
        {
            dynamic expando = SuperFlexiHelpers.GetExpandoForModuleItems(module, config, false);

            ExportHelper.ExportDynamicListToCSV(HttpContext.Current, expando.Items, $"export-{txtExportName.Text}.csv");
        }
Exemplo n.º 17
0
        private void ExportBtn_Click(Object sender, EventArgs e)
        {
            dynamic expando = SuperFlexiHelpers.GetExpandoForModuleItems(module, config, false);

            ExportHelper.ExportDynamicListToCSV(HttpContext.Current, expando.Items, String.Format("export-{0}.csv", config.MarkupDefinitionName));
        }
Exemplo n.º 18
0
        public static void SetupStyle(
            List <MarkupCss> markupCss,
            ModuleConfiguration config,
            SuperFlexiDisplaySettings displaySettings,
            string clientID,
            int moduleID,
            int pageID,
            Page page,
            Control control)
        {
            string styleLinkFormat = "\n<link rel=\"stylesheet\" href=\"{0}\" media=\"{2}\" data-name=\"{1}\">";
            string rawCSSFormat    = "\n<style type=\"text/css\" data-name=\"{1}\" media=\"{2}\">\n{0}\n</style>";

            foreach (MarkupCss style in markupCss)
            {
                StringBuilder sbStyleText = new StringBuilder();
                StringBuilder sbStyleName = new StringBuilder();

                sbStyleName.Append(String.IsNullOrWhiteSpace(style.Name) ? clientID + "flexiStyle_" + markupCss.IndexOf(style) : "flexiStyle_" + style.Name);
                SuperFlexiHelpers.ReplaceStaticTokens(sbStyleName, config, false, displaySettings, moduleID, pageID, out sbStyleName);
                string styleName = sbStyleName.ToString();
                if (!String.IsNullOrWhiteSpace(style.Url))
                {
                    string styleUrl = string.Empty;

                    if (style.Url.StartsWith("/") ||
                        style.Url.StartsWith("http://") ||
                        style.Url.StartsWith("https://"))
                    {
                        styleUrl = style.Url;
                    }
                    else if (style.Url.StartsWith("~/"))
                    {
                        styleUrl = WebUtils.ResolveServerUrl(style.Url);
                    }
                    else if (style.Url.StartsWith("$_SitePath_$"))
                    {
                        styleUrl = style.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/");
                    }
                    else
                    {
                        styleUrl = new Uri(config.SolutionLocationUrl, style.Url).ToString();
                    }
                    //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)))
                    //{
                    //	FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile));
                    //	styleUrl = WebUtils.ResolveServerUrl(Path.Combine(fileInfo.DirectoryName.Replace(System.Web.Hosting.HostingEnvironment.MapPath("~"), "~/"), style.Url));
                    //}

                    sbStyleText.Append(string.Format(styleLinkFormat, styleUrl, styleName, style.Media));
                }
                else if (!String.IsNullOrWhiteSpace(style.CSS))
                {
                    sbStyleText.Append(string.Format(rawCSSFormat, style.CSS, styleName, style.Media));
                }

                SuperFlexiHelpers.ReplaceStaticTokens(sbStyleText, config, false, displaySettings, moduleID, pageID, out sbStyleText);

                LiteralControl theLiteral = new LiteralControl();
                theLiteral.Text = sbStyleText.ToString();

                StyleSheetCombiner ssc = (StyleSheetCombiner)page.Header.FindControl("StyleSheetCombiner");

                if (ssc != null)
                {
                    int sscIndex = page.Header.Controls.IndexOf(ssc);
                    if (style.RenderAboveSSC)
                    {
                        page.Header.Controls.AddAt(sscIndex, theLiteral);
                    }
                    else
                    {
                        page.Header.Controls.AddAt(sscIndex + 1, theLiteral);
                    }
                }
                else
                {
                    page.Header.Controls.AddAt(0, theLiteral);
                }
            }
        }
Exemplo n.º 19
0
        //public static List<MarkupScript> ParseScriptsFromXml(ModuleConfiguration config)
        //{
        //    List<MarkupScript> scripts = new List<MarkupScript>();
        //    string fullPath = string.Empty;
        //    XmlDocument doc = new XmlDocument();
        //    if (DefinitionExists(config.FieldDefinitionSrc, out doc))
        //    {
        //        XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields/Scripts");

        //        if (node == null) return scripts;

        //        try
        //        {
        //            scripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(node);
        //        }
        //        catch (System.Xml.XmlException ex)
        //        {
        //            log.Error(ex);
        //        }
        //    }
        //    return scripts;
        //}



        /// <summary>
        /// Creates a list of Field from field definition xml file.
        /// </summary>
        /// <param name="fieldDefinitionSrc"></param>
        /// <returns>IList</returns>
        public static List <Field> ParseFieldDefinitionXml(ModuleConfiguration config, Guid siteGuid)
        {
            List <Field> fields   = new List <Field>();
            string       fullPath = string.Empty;
            XmlDocument  doc      = new XmlDocument();

            FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider];

            if (p == null)
            {
                log.Error("File System Provider Could Not Be Loaded.");
                return(fields);
            }
            IFileSystem fileSystem = p.GetFileSystem();

            if (fileSystem == null)
            {
                log.Error("File System Could Not Be Loaded.");
                return(fields);
            }



            //implemented "solutions" on 9/13/2017 (mojoPortal 2.6.0.0) which allows for markup definitions and field definitions to be wrapped up in a single folder
            //b/c of this, we added the ability to pull the field definition file from the location of the markup definition (.sfmarkup) file w/o needing to use the full path in the fieldDefinitionSrc property

            string solutionFieldDefSrc = string.Empty;

            if (config.FieldDefinitionSrc.StartsWith("~/"))
            {
                solutionFieldDefSrc = config.FieldDefinitionSrc;
            }
            else if (config.FieldDefinitionSrc.StartsWith("/"))
            {
                solutionFieldDefSrc = "~" + config.FieldDefinitionSrc;
            }
            //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)))
            else
            {
                var    sfMarkupFile = fileSystem.RetrieveFile(config.MarkupDefinitionFile);
                string sfFieldPath  = fileSystem.CombinePath(sfMarkupFile.FolderVirtualPath, config.FieldDefinitionSrc);
                var    sfFieldFile  = fileSystem.RetrieveFile(sfFieldPath);

                //FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile));

                //solutionFieldDefSrc = fileInfo.DirectoryName + "/" + config.FieldDefinitionSrc;

                solutionFieldDefSrc = sfFieldFile.VirtualPath;
            }



            if (DefinitionExists(solutionFieldDefSrc, out doc))
            {
                XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields");
                if (node != null)
                {
                    XmlAttributeCollection attribs = node.Attributes;

                    string definitionName = string.Empty;
                    Guid   definitionGuid = Guid.NewGuid();
                    if (attribs["definitionName"] != null)
                    {
                        definitionName = attribs["definitionName"].Value;
                    }
                    if (attribs["definitionGuid"] != null)
                    {
                        definitionGuid = Guid.Parse(attribs["definitionGuid"].Value);
                    }

                    if (definitionGuid != config.FieldDefinitionGuid)
                    {
                        log.ErrorFormat(@"
							SuperFlexi Solution [{0}] located at [{1}] uses fieldDefinitionGuid = [{2}]
							but the field definition at [{3}] uses definitionGuid = [{4}]. Items will not display properly and may end up corrupted.
							"                            ,
                                        config.MarkupDefinitionName, config.MarkupDefinitionFile, config.FieldDefinitionGuid.ToString(),
                                        solutionFieldDefSrc, definitionGuid);

                        return(null);
                    }

                    foreach (XmlNode childNode in node)
                    {
                        if (childNode.Name == "Field")
                        {
                            try
                            {
                                Field field = new Field();
                                XmlAttributeCollection itemDefAttribs = childNode.Attributes;

                                field.DefinitionName = definitionName;
                                field.DefinitionGuid = definitionGuid;
                                if (itemDefAttribs["name"] != null)
                                {
                                    field.Name = itemDefAttribs["name"].Value;
                                }
                                if (itemDefAttribs["label"] != null)
                                {
                                    field.Label = itemDefAttribs["label"].Value;
                                }
                                if (itemDefAttribs["defaultValue"] != null)
                                {
                                    field.DefaultValue = itemDefAttribs["defaultValue"].Value;
                                }
                                if (itemDefAttribs["controlType"] != null)
                                {
                                    field.ControlType = itemDefAttribs["controlType"].Value;
                                }
                                if (itemDefAttribs["controlSrc"] != null)
                                {
                                    field.ControlSrc = itemDefAttribs["controlSrc"].Value;
                                }
                                field.SortOrder = XmlUtils.ParseInt32FromAttribute(itemDefAttribs, "sortOrder", field.SortOrder);
                                if (itemDefAttribs["helpKey"] != null)
                                {
                                    field.HelpKey = itemDefAttribs["helpKey"].Value;
                                }
                                field.Required = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "required", field.Required);
                                if (itemDefAttribs["requiredMessageFormat"] != null)
                                {
                                    field.RequiredMessageFormat = itemDefAttribs["requiredMessageFormat"].Value;
                                }
                                if (itemDefAttribs["regex"] != null)
                                {
                                    field.Regex = itemDefAttribs["regex"].Value;
                                }
                                if (itemDefAttribs["regexMessageFormat"] != null)
                                {
                                    field.RegexMessageFormat = itemDefAttribs["regexMessageFormat"].Value;
                                }
                                if (itemDefAttribs["token"] != null && !String.IsNullOrWhiteSpace(itemDefAttribs["token"].Value))
                                {
                                    field.Token = itemDefAttribs["token"].Value;
                                }

                                field.Searchable = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isSearchable", field.Searchable);
                                if (itemDefAttribs["editPageControlWrapperCssClass"] != null)
                                {
                                    field.EditPageControlWrapperCssClass = itemDefAttribs["editPageControlWrapperCssClass"].Value;
                                }
                                if (itemDefAttribs["editPageLabelCssClass"] != null)
                                {
                                    field.EditPageLabelCssClass = itemDefAttribs["editPageLabelCssClass"].Value;
                                }
                                if (itemDefAttribs["editPageControlCssClass"] != null)
                                {
                                    field.EditPageControlCssClass = itemDefAttribs["editPageControlCssClass"].Value;
                                }
                                field.DatePickerIncludeTimeForDate = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerIncludeTimeForDate", field.DatePickerIncludeTimeForDate);
                                field.DatePickerShowMonthList      = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowMonthList", field.DatePickerShowMonthList);
                                field.DatePickerShowYearList       = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowYearList", field.DatePickerShowYearList);
                                if (itemDefAttribs["datePickerYearRange"] != null)
                                {
                                    field.DatePickerYearRange = itemDefAttribs["datePickerYearRange"].Value;
                                }
                                if (itemDefAttribs["imageBrowserEmptyUrl"] != null)
                                {
                                    field.ImageBrowserEmptyUrl = itemDefAttribs["imageBrowserEmptyUrl"].Value;
                                }
                                field.CheckBoxReturnBool = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "checkBoxReturnBool", field.CheckBoxReturnBool);
                                if (itemDefAttribs["checkBoxReturnValueWhenTrue"] != null)
                                {
                                    field.CheckBoxReturnValueWhenTrue = itemDefAttribs["checkBoxReturnValueWhenTrue"].Value;
                                }
                                if (itemDefAttribs["checkBoxReturnValueWhenFalse"] != null)
                                {
                                    field.CheckBoxReturnValueWhenFalse = itemDefAttribs["checkBoxReturnValueWhenFalse"].Value;
                                }
                                if (itemDefAttribs["dateFormat"] != null)
                                {
                                    field.DateFormat = itemDefAttribs["dateFormat"].Value;
                                }
                                if (itemDefAttribs["textBoxMode"] != null)
                                {
                                    field.TextBoxMode = itemDefAttribs["textBoxMode"].Value;
                                }
                                field.IsDeleted = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isDeleted", field.IsDeleted);
                                field.IsGlobal  = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isGlobal", field.IsGlobal);
                                if (itemDefAttribs["viewRoles"] != null)
                                {
                                    string viewRoles = itemDefAttribs["viewRoles"].Value;
                                    if (String.IsNullOrWhiteSpace(viewRoles))
                                    {
                                        viewRoles = "All Users;";
                                    }
                                    field.ViewRoles = viewRoles;
                                }
                                if (itemDefAttribs["editRoles"] != null)
                                {
                                    field.EditRoles = itemDefAttribs["editRoles"].Value;
                                }

                                StringBuilder options    = new StringBuilder();
                                StringBuilder attributes = new StringBuilder();
                                foreach (XmlNode subNode in childNode)
                                {
                                    switch (subNode.Name)
                                    {
                                    case "Options":
                                        options = XmlHelper.GetKeyValuePairsAsStringBuilder(subNode.ChildNodes);
                                        //GetKeyValuePairs(subNode.ChildNodes, out options);
                                        break;

                                    case "Attributes":
                                        attributes = XmlHelper.GetKeyValuePairsAsStringBuilder(subNode.ChildNodes);
                                        //GetKeyValuePairs(subNode.ChildNodes, out attributes);
                                        break;

                                    case "PreTokenString":
                                        field.PreTokenString = subNode.InnerText.Trim();
                                        break;

                                    case "PostTokenString":
                                        field.PostTokenString = subNode.InnerText.Trim();
                                        break;

                                    case "PreTokenStringWhenTrue":
                                        field.PreTokenStringWhenTrue = subNode.InnerText.Trim();
                                        break;

                                    case "PostTokenStringWhenTrue":
                                        field.PostTokenStringWhenTrue = subNode.InnerText.Trim();
                                        break;

                                    case "PreTokenStringWhenFalse":
                                        field.PreTokenStringWhenFalse = subNode.InnerText.Trim();
                                        break;

                                    case "PostTokenStringWhenFalse":
                                        field.PostTokenStringWhenFalse = subNode.InnerText.Trim();
                                        break;
                                    }
                                }

                                if (options.Length > 0)
                                {
                                    field.Options = options.ToString();
                                }

                                if (attributes.Length > 0)
                                {
                                    field.Attributes = attributes.ToString();
                                }

                                fields.Add(field);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "Scripts")
                        {
                            try
                            {
                                config.EditPageScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "Styles")
                        {
                            try
                            {
                                config.EditPageCSS = SuperFlexiHelpers.ParseCssFromXmlNode(childNode);
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                        else if (childNode.Name == "SearchDefinition")
                        {
                            try
                            {
                                SuperFlexiHelpers.ParseSearchDefinition(childNode, definitionGuid, siteGuid);
                            }
                            catch (XmlException ex)
                            {
                                log.Error(ex);
                            }
                        }
                    }
                }
            }

            fields.Sort();
            return(fields);
        }