protected void ExtendModel(JObject model, bool onlyData, bool onlyMainData)
        {
            if (_portalSettings == null)
            {
                onlyData = true;
            }

            if (_templateFiles != null)
            {
                // include additional data in the Model
                if (_templateFiles.AdditionalDataInTemplate && _manifest.AdditionalDataDefined())
                {
                    model["AdditionalData"] = GetAdditionalData();
                }
                // include collections
                if (_templateFiles.Model != null)
                {
                    var additionalCollections = _templateFiles.Model.Where(c => c.Key != _collection);
                    if (additionalCollections.Any())
                    {
                        var collections  = model["Collections"] = new JObject();
                        var dsColContext = OpenContentUtils.CreateDataContext(_module);
                        foreach (var item in additionalCollections)
                        {
                            var colManifest = item.Value;
                            dsColContext.Collection = item.Key;
                            Select select = null;
                            if (item.Value.Query != null)
                            {
                                var          indexConfig  = OpenContentUtils.GetIndexConfig(_module.Settings.TemplateDir, item.Key);
                                QueryBuilder queryBuilder = new QueryBuilder(indexConfig);
                                var          u            = PortalSettings.Current.UserInfo;
                                queryBuilder.Build(item.Value.Query, true, u.UserID, DnnLanguageUtils.GetCurrentCultureCode(), u.Social.Roles);
                                select = queryBuilder.Select;
                            }
                            IDataItems dataItems   = _ds.GetAll(dsColContext, select);
                            var        colDataJson = new JArray();
                            foreach (var dataItem in dataItems.Items)
                            {
                                var json = dataItem.Data;
                                if (json is JObject)
                                {
                                    JObject context = new JObject();
                                    json["Context"] = context;
                                    context["Id"]   = dataItem.Id;
                                    EnhanceSelect2(json as JObject, onlyData);
                                    JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
                                }
                                colDataJson.Add(json);
                            }
                            collections[item.Key]          = new JObject();
                            collections[item.Key]["Items"] = colDataJson;
                        }
                    }
                }
            }
            // include settings in the Model
            if (!onlyMainData && _templateManifest.SettingsNeeded() && !string.IsNullOrEmpty(_settingsJson))
            {
                try
                {
                    var jsonSettings = JToken.Parse(_settingsJson);
                    JsonUtils.SimplifyJson(jsonSettings, GetCurrentCultureCode());
                    model["Settings"] = jsonSettings;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error parsing Json of Settings", ex);
                }
            }

            // include static localization in the Model
            if (!onlyMainData)
            {
                JToken localizationJson     = null;
                string localizationFilename = _physicalTemplateFolder + GetCurrentCultureCode() + ".json";
                if (File.Exists(localizationFilename))
                {
                    string fileContent = File.ReadAllText(localizationFilename);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        localizationJson = fileContent.ToJObject("Localization: " + localizationFilename);
                    }
                }
                if (localizationJson != null)
                {
                    model["Localization"] = localizationJson;
                }
            }
            if (!onlyData)
            {
                // include CONTEXT in the Model
                JObject context = new JObject();
                model["Context"]        = context;
                context["ModuleId"]     = _module.ViewModule.ModuleID;
                context["TabId"]        = _module.ViewModule.TabID;
                context["GoogleApiKey"] = OpenContentControllerFactory.Instance.OpenContentGlobalSettingsController(_portalId).GetGoogleApiKey();
                context["ModuleTitle"]  = _module.ViewModule.ModuleTitle;
                var editIsAllowed = !_manifest.DisableEdit && IsEditAllowed(-1);
                context["IsEditable"]    = editIsAllowed; //allowed to edit the item or list (meaning allow Add)
                context["IsEditMode"]    = IsEditMode;
                context["PortalId"]      = _portalId;
                context["MainUrl"]       = Globals.NavigateURL(_detailTabId, false, _portalSettings, "", GetCurrentCultureCode());
                context["HomeDirectory"] = _portalSettings.HomeDirectory;
                context["HTTPAlias"]     = _portalSettings.PortalAlias.HTTPAlias;
            }
        }
示例#2
0
        protected void ExtendModel(JObject model, bool onlyData, bool onlyMainData, string id = null)
        {
            if (_module.CanvasUnavailable)
            {
                onlyData = true;
            }

            if (_templateFiles != null)
            {
                // include additional data in the Model
                if (_templateFiles.AdditionalDataInTemplate && _manifest.AdditionalDataDefined())
                {
                    model["AdditionalData"] = GetAdditionalData(onlyData);
                }
                // include collections
                if (_templateFiles.Model != null)
                {
                    var additionalCollections = _templateFiles.Model.Where(c => c.Key != _collection);
                    if (additionalCollections.Any())
                    {
                        var collections  = model["Collections"] = new JObject();
                        var dsColContext = OpenContentUtils.CreateDataContext(_module);
                        foreach (var item in additionalCollections)
                        {
                            var colManifest = item.Value;
                            dsColContext.Collection = item.Key;
                            Select select = null;
                            if (item.Value.Query != null)
                            {
                                var                 indexConfig  = OpenContentUtils.GetIndexConfig(_module.Settings.TemplateDir, item.Key);
                                QueryBuilder        queryBuilder = new QueryBuilder(indexConfig);
                                var                 u            = PortalSettings.Current.UserInfo;
                                NameValueCollection queryString  = null;
                                if (item.Value.Query["RelatedField"] != null)
                                {
                                    queryString = new NameValueCollection();
                                    queryString.Add(item.Value.Query["RelatedField"].ToString(), id);
                                }
                                queryBuilder.Build(item.Value.Query, true, u.UserID, DnnLanguageUtils.GetCurrentCultureCode(), u.Social.Roles.FromDnnRoles(), queryString);
                                select = queryBuilder.Select;
                            }
                            IDataItems dataItems   = _ds.GetAll(dsColContext, select);
                            var        colDataJson = new JArray();
                            foreach (var dataItem in dataItems.Items)
                            {
                                var json = dataItem.Data;
                                if (json != null)
                                {
                                    JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
                                }
                                if (json is JObject)
                                {
                                    JObject context = new JObject();
                                    json["Context"] = context;
                                    context["Id"]   = dataItem.Id;
                                    EnhanceSelect2(json as JObject, onlyData);
                                    JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
                                }
                                colDataJson.Add(json);
                            }
                            collections[item.Key]          = new JObject();
                            collections[item.Key]["Items"] = colDataJson;
                        }
                    }
                }
            }
            // include settings in the Model
            if (!onlyMainData && _templateManifest != null && _templateManifest.SettingsNeeded() && !string.IsNullOrEmpty(_settingsJson))
            {
                try
                {
                    var jsonSettings = JToken.Parse(_settingsJson);
                    //if (DnnLanguageUtils.GetPortalLocales(_portalId).Count > 1)
                    //{
                    //    JsonUtils.SimplifyJson(jsonSettings, GetCurrentCultureCode());
                    //}
                    JsonUtils.SimplifyJson(jsonSettings, GetCurrentCultureCode());
                    model["Settings"] = jsonSettings;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error parsing Json of Settings", ex);
                }
            }

            // include static localization in the Model
            if (!onlyMainData)
            {
                var localizationJson = LocalizationUtils.LoadLocalizationJson(_module.Settings.TemplateDir, GetCurrentCultureCode());
                if (localizationJson != null)
                {
                    model["Localization"] = localizationJson;
                }
            }
            if (!onlyData)
            {
                // include CONTEXT in the Model
                JObject context = new JObject();
                model["Context"]        = context;
                context["TabId"]        = _module.ViewModule.TabId;
                context["ModuleId"]     = _module.ViewModule.ModuleId;
                context["GoogleApiKey"] = App.Services.CreateGlobalSettingsRepository(_portalId).GetGoogleApiKey();
                context["ModuleTitle"]  = _module.ViewModule.ModuleTitle;
                var editIsAllowed = !_manifest.DisableEdit && !_templateManifest.DisableEdit && IsEditAllowed(-1);
                context["IsEditable"]    = editIsAllowed; //allowed to edit the item or list (meaning allow Add)
                context["IsEditMode"]    = IsEditMode;
                context["PortalId"]      = _portalId;
                context["MainUrl"]       = _module.GetUrl(_detailTabId, GetCurrentCultureCode());
                context["HomeDirectory"] = _module.HomeDirectory;
                context["HTTPAlias"]     = _module.HostName;
                context["PortalName"]    = _module.PortalName;
                context["TemplatePath"]  = _module.Settings.TemplateDir.UrlFolder;
                context["TemplateName"]  = (String.IsNullOrEmpty(_manifest.Title) ? Path.GetFileName(_templateManifest.MainTemplateUri().FolderPath) : _manifest.Title) + " - " + (string.IsNullOrEmpty(_templateManifest.Title) ? _templateManifest.Key.ShortKey : _templateManifest.Title);
                //context["TemplateName"] = _templateManifest.MainTemplateUri().UrlFilePath ;
            }
        }
示例#3
0
        private void CompleteModel(JObject model, bool onlyData)
        {
            if (!onlyData && TemplateFiles != null && TemplateFiles.SchemaInTemplate)
            {
                // schema
                string schemaFilename = PhysicalTemplateFolder + "schema.json";
                model["Schema"] = JsonUtils.GetJsonFromFile(schemaFilename);
            }
            if (TemplateFiles != null && TemplateFiles.OptionsInTemplate)
            {
                // options
                JToken optionsJson = null;
                // default options
                string optionsFilename = PhysicalTemplateFolder + "options.json";
                if (File.Exists(optionsFilename))
                {
                    string fileContent = File.ReadAllText(optionsFilename);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        optionsJson = fileContent.ToJObject("Options");
                    }
                }
                // language options
                optionsFilename = PhysicalTemplateFolder + "options." + GetCurrentCultureCode() + ".json";
                if (File.Exists(optionsFilename))
                {
                    string fileContent = File.ReadAllText(optionsFilename);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var extraJson = fileContent.ToJObject("Options cultureSpecific");
                        if (optionsJson == null)
                        {
                            optionsJson = extraJson;
                        }
                        else
                        {
                            optionsJson = optionsJson.JsonMerge(extraJson);
                        }
                    }
                }
                if (optionsJson != null)
                {
                    model["Options"] = optionsJson;
                }
            }

            // additional data
            if (TemplateFiles != null && TemplateFiles.AdditionalDataInTemplate && Manifest.AdditionalDataExists())
            {
                var additionalData = model["AdditionalData"] = new JObject();
                foreach (var item in Manifest.AdditionalData)
                {
                    var dataManifest = item.Value;
                    var ds           = DataSourceManager.GetDataSource(Manifest.DataSource);
                    var dsContext    = new DataSourceContext()
                    {
                        PortalId    = PortalId,
                        TabId       = Module.TabID,
                        ModuleId    = MainModuleId,
                        TabModuleId = Module.TabModuleID,
                        Config      = Manifest.DataSourceConfig,
                    };
                    var    dsItem             = ds.GetData(dsContext, dataManifest.ScopeType, dataManifest.StorageKey ?? item.Key);
                    JToken additionalDataJson = new JObject();
                    if (dsItem != null && dsItem.Data != null)
                    {
                        if (LocaleController.Instance.GetLocales(PortalId).Count > 1)
                        {
                            JsonUtils.SimplifyJson(dsItem.Data, GetCurrentCultureCode());
                        }
                        additionalDataJson = dsItem.Data;
                    }
                    additionalData[(item.Value.ModelKey ?? item.Key).ToLowerInvariant()] = additionalDataJson;
                }
            }

            // settings
            if (!onlyData && TemplateManifest.SettingsNeeded() && !string.IsNullOrEmpty(settingsJson))
            {
                try
                {
                    dataJson = JToken.Parse(settingsJson);
                    if (LocaleController.Instance.GetLocales(PortalId).Count > 1)
                    {
                        JsonUtils.SimplifyJson(dataJson, GetCurrentCultureCode());
                    }
                    model["Settings"] = dataJson;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error parsing Json of Settings", ex);
                }
            }

            // static localization
            if (!onlyData)
            {
                JToken localizationJson     = null;
                string localizationFilename = PhysicalTemplateFolder + GetCurrentCultureCode() + ".json";
                if (File.Exists(localizationFilename))
                {
                    string fileContent = File.ReadAllText(localizationFilename);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        localizationJson = fileContent.ToJObject("Localization: " + localizationFilename);
                    }
                }
                if (localizationJson != null)
                {
                    model["Localization"] = localizationJson;
                }
            }

            if (!onlyData)
            {
                // context
                JObject context = new JObject();
                model["Context"]       = context;
                context["ModuleId"]    = Module.ModuleID;
                context["ModuleTitle"] = Module.ModuleTitle;
                context["AddUrl"]      = DnnUrlUtils.EditUrl(Module.ModuleID, PortalSettings);
                var editStatus = GetEditStatus(-1);
                context["IsEditable"] = editStatus;
                context["PortalId"]   = PortalId;
                context["MainUrl"]    = Globals.NavigateURL(MainTabId, false, PortalSettings, "", GetCurrentCultureCode());
                if (Data != null)
                {
                    string url = "";
                    if (Manifest != null && !string.IsNullOrEmpty(Manifest.DetailUrl))
                    {
                        HandlebarsEngine hbEngine  = new HandlebarsEngine();
                        dynamic          dynForHBS = JsonUtils.JsonToDynamic(model.ToString());
                        url = hbEngine.Execute(Manifest.DetailUrl, dynForHBS);
                        url = HttpUtility.HtmlDecode(url);
                    }
                    context["DetailUrl"] = Globals.NavigateURL(MainTabId, false, PortalSettings, "", GetCurrentCultureCode(), url.CleanupUrl(), "id=" + Data.Id);
                    context["Id"]        = Data.Id;
                    context["EditUrl"]   = editStatus ? DnnUrlUtils.EditUrl("id", Data.Id, Module.ModuleID, PortalSettings) : "";
                }
            }
        }
示例#4
0
        public List <MenuAction> GetMenuActions()
        {
            var actions = new List <MenuAction>();

            TemplateManifest template        = _settings.Template;
            bool             templateDefined = template != null;

            bool isListPageRequest   = _renderinfo.IsListPageRequest;
            bool isDetailPageRequest = _renderinfo.IsDetailPageRequest;

            //Add item / Edit Item
            if (templateDefined && template.DataNeeded() && !_settings.Manifest.DisableEdit)
            {
                string title = App.Services.Localizer.GetString(isListPageRequest ? "Add.Action" : "Edit.Action", ResourceFile);
                if (!string.IsNullOrEmpty(_settings.Manifest.Title))
                {
                    title = title + " " + _settings.Manifest.Title;
                }

                actions.Add(
                    new MenuAction(
                        title,
                        isListPageRequest ? "~/DesktopModules/OpenContent/images/addcontent2.png" : "~/DesktopModules/OpenContent/images/editcontent2.png",
                        isDetailPageRequest ? RenderContext.EditUrl("id", _renderinfo.DetailItemId) : RenderContext.EditUrl(),
                        ActionType.Add
                        )
                    );
            }

            //Add AdditionalData manage actions
            if (templateDefined && template.Manifest.AdditionalDataDefined() && !_settings.Manifest.DisableEdit)
            {
                foreach (var addData in template.Manifest.AdditionalDataDefinition)
                {
                    if (addData.Value.SourceRelatedDataSource == RelatedDataSourceType.AdditionalData)
                    {
                        actions.Add(
                            new MenuAction(
                                addData.Value.Title,
                                "~/DesktopModules/OpenContent/images/editcontent2.png",
                                RenderContext.EditUrl("key", addData.Key, "EditAddData"),
                                ActionType.Edit
                                )
                            );
                    }
                    else
                    {
                        actions.Add(
                            new MenuAction(
                                addData.Value.Title,
                                "~/DesktopModules/OpenContent/images/editcontent2.png",
                                DnnUrlUtils.NavigateUrl(addData.Value.DataTabId),
                                ActionType.Edit
                                )
                            );
                    }
                }
            }

            //Manage Form Submissions
            if (templateDefined && OpenContentUtils.FormExist(_settings.Template.ManifestFolderUri))
            {
                actions.Add(
                    new MenuAction(
                        "Submissions",
                        "~/DesktopModules/OpenContent/images/editcontent2.png",
                        RenderContext.EditUrl("Submissions"),
                        ActionType.Edit
                        )
                    );
            }

            //Edit Template Settings
            if (templateDefined && _settings.Template.SettingsNeeded())
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("EditSettings.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/editsettings2.png",
                        RenderContext.EditUrl("EditSettings"),
                        ActionType.Misc,
                        SecurityAccessLevel.AdminRights
                        )
                    );
            }

            //Edit Form Settings
            if (templateDefined && OpenContentUtils.FormExist(_settings.Template.ManifestFolderUri))
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("FormSettings.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/editsettings2.png",
                        RenderContext.EditUrl("formsettings"),
                        ActionType.Misc,
                        SecurityAccessLevel.AdminRights
                        )
                    );
            }

            //Edit Notifications Settings
            if (templateDefined)
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("Notifications.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/editsettings2.png",
                        RenderContext.EditUrl("notifications"),
                        ActionType.Misc,
                        SecurityAccessLevel.AdminRights
                        )
                    );
            }
            //if (templateDefined)
            //{
            //    actions.Add(ModuleContext.GetNextActionID(),
            //        Localization.GetString("Notifications.Action", LocalResourceFile),
            //        ModuleActionType.ContentOptions,
            //        "",
            //        "~/DesktopModules/OpenContent/images/editsettings2.png",
            //        ModuleContext.EditUrl("notifications"),
            //        false,
            //        SecurityAccessLevel.Admin,
            //        true,
            //        false);
            //}

            //Switch Template
            actions.Add(
                new MenuAction(
                    App.Services.Localizer.GetString("EditInit.Action", ResourceFile),
                    "~/DesktopModules/OpenContent/images/editinit.png",
                    RenderContext.EditUrl("EditInit"),
                    ActionType.Misc,
                    SecurityAccessLevel.AdminRights
                    )
                );

            //Edit Filter Settings
            if (templateDefined && _renderinfo.IsListMode)
            {
                if (_settings.Manifest.Index)
                {
                    actions.Add(
                        new MenuAction(
                            App.Services.Localizer.GetString("EditQuery.Action", ResourceFile),
                            "~/DesktopModules/OpenContent/images/editfilter.png",
                            RenderContext.EditUrl("EditQuery"),
                            ActionType.Misc,
                            SecurityAccessLevel.AdminRights
                            )
                        );
                }
            }

            //Form Builder
            if (templateDefined && OpenContentUtils.BuildersExist(_settings.Template.ManifestFolderUri))
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("Builder.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/formbuilder.png",
                        RenderContext.EditUrl("FormBuilder"),
                        ActionType.Misc,
                        SecurityAccessLevel.AdminRights
                        )
                    );
            }

            //Edit Template Files
            if (templateDefined)
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("EditTemplate.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/edittemplate.png",
                        RenderContext.EditUrl("EditTemplate"),
                        ActionType.Misc,
                        SecurityAccessLevel.SuperUserRights
                        )
                    );
            }

            //Edit Raw Data
            if (templateDefined && _settings.Manifest != null &&
                (template.DataNeeded() || template.SettingsNeeded() || template.Manifest.AdditionalDataDefined()) && !_settings.Manifest.DisableEdit)
            {
                actions.Add(
                    new MenuAction(
                        App.Services.Localizer.GetString("EditData.Action", ResourceFile),
                        "~/DesktopModules/OpenContent/images/edit.png",
                        isDetailPageRequest ? RenderContext.EditUrl("id", _renderinfo.DetailItemId, "EditData") : RenderContext.EditUrl("EditData"),
                        ActionType.Edit,
                        SecurityAccessLevel.SuperUserRights
                        )
                    );
            }

            //Template Exchange
            actions.Add(
                new MenuAction(
                    App.Services.Localizer.GetString("ShareTemplate.Action", ResourceFile),
                    "~/DesktopModules/OpenContent/images/exchange.png",
                    RenderContext.EditUrl("ShareTemplate"),
                    ActionType.Misc,
                    SecurityAccessLevel.SuperUserRights
                    )
                );

            //Clone Module
            actions.Add(
                new MenuAction(
                    App.Services.Localizer.GetString("CloneModule.Action", ResourceFile),
                    "~/DesktopModules/OpenContent/images/clonemodule.png",
                    RenderContext.EditUrl("CloneModule"),
                    ActionType.Misc,
                    SecurityAccessLevel.AdminRights
                    )
                );

            //Edit Global Settings
            actions.Add(
                new MenuAction(
                    App.Services.Localizer.GetString("EditGlobalSettings.Action", ResourceFile),
                    "~/DesktopModules/OpenContent/images/settings.png",
                    RenderContext.EditUrl("EditGlobalSettings"),
                    ActionType.Misc,
                    SecurityAccessLevel.SuperUserRights
                    )
                );

            //Help
            actions.Add(
                new MenuAction(
                    App.Services.Localizer.GetString("Help.Action", ResourceFile),
                    "~/DesktopModules/OpenContent/images/help.png",
                    "https://opencontent.readme.io",
                    ActionType.Misc,
                    SecurityAccessLevel.SuperUserRights,
                    true
                    )
                );

            return(actions);
        }