public override JToken GetModelAsJson(bool onlyData = false, bool onlyMainData = false)
        {
            if (_portalSettings == null)
            {
                onlyData = true;
            }
            JObject model      = new JObject();
            var     itemsModel = model;

            ExtendModel(model, onlyData, onlyMainData);
            ExtendSchemaOptions(itemsModel, onlyData || onlyMainData);
            ExtendItemsModel(itemsModel, onlyData || onlyMainData);

            if (!onlyData && !onlyMainData)
            {
                itemsModel["Context"]["RssUrl"] = _portalSettings.PortalAlias.HTTPAlias +
                                                  "/DesktopModules/OpenContent/API/RssAPI/GetFeed?moduleId=" + _module.ViewModule.ModuleID + "&tabId=" + _detailTabId;
            }
            JArray items = new JArray();;

            itemsModel["Items"] = items;
            //string editRole = Manifest.GetEditRole();
            if (_dataList != null && _dataList.Any())
            {
                var mainUrl = Globals.NavigateURL(_detailTabId, false, _portalSettings, "", GetCurrentCultureCode(), "");
                foreach (var item in _dataList)
                {
                    JObject dyn     = item.Data as JObject;
                    JObject context = new JObject();
                    dyn["Context"] = context;
                    context["Id"]  = item.Id;
                    EnhanceSelect2(dyn, onlyData);
                    JsonUtils.SimplifyJson(dyn, GetCurrentCultureCode());
                    EnhanceUser(dyn, item.CreatedByUserId);
                    EnhanceImages(dyn, itemsModel);
                    if (onlyData)
                    {
                        RemoveNoData(itemsModel);
                    }
                    else
                    {
                        var editStatus = !_manifest.DisableEdit && IsEditAllowed(item.CreatedByUserId);
                        context["IsEditable"] = editStatus;
                        if (HasEditPermissions(item.CreatedByUserId))
                        {
                            context["EditUrl"] = DnnUrlUtils.EditUrl("id", item.Id, _module.ViewModule.ModuleID, _portalSettings);
                        }
                        context["DetailUrl"] = GenerateDetailUrl(item, dyn, _manifest, _detailTabId);
                        context["MainUrl"]   = mainUrl;
                    }
                    items.Add(dyn);
                }
            }
            return(model);
        }
예제 #2
0
 private void ExtendModelSingle(JObject model)
 {
     if (_data != null)
     {
         var context = model["Context"];
         if (Detail)
         {
             context["DetailUrl"] = GenerateDetailUrl(_data, model, _manifest, _detailTabId);
             context["Id"]        = _data.Id;
             var editIsAllowed = !_manifest.DisableEdit && IsEditAllowed(_data.CreatedByUserId);
             context["EditUrl"] = editIsAllowed ? DnnUrlUtils.EditUrl("id", _data.Id, _module.ViewModule.ModuleID, _portalSettings) : "";
         }
     }
 }
예제 #3
0
 private void ExtendModelSingle(JObject model)
 {
     if (_data != null)
     {
         var context = model["Context"];
         if (Detail)
         {
             string url = "";
             if (!string.IsNullOrEmpty(_manifest?.DetailUrl))
             {
                 HandlebarsEngine hbEngine = new HandlebarsEngine();
                 var dynForHBS             = JsonUtils.JsonToDictionary(model.ToString());
                 url = hbEngine.Execute(_manifest.DetailUrl, dynForHBS);
                 url = HttpUtility.HtmlDecode(url);
             }
             context["DetailUrl"] = Globals.NavigateURL(_detailTabId, false, _portalSettings, "", GetCurrentCultureCode(), url.CleanupUrl(), "id=" + _data.Id);
             context["Id"]        = _data.Id;
             var editIsAllowed = !_manifest.DisableEdit && IsEditAllowed(_data.CreatedByUserId);
             context["EditUrl"] = editIsAllowed ? DnnUrlUtils.EditUrl("id", _data.Id, _module.ViewModule.ModuleID, _portalSettings) : "";
         }
     }
 }
        private void ExtendItemsModel(JObject model, bool onlyData)
        {
            if (_portalSettings == null)
            {
                onlyData = true;
            }

            if (!onlyData)
            {
                // include CONTEXT in the Model
                JObject context;
                if (model["Context"] is JObject)
                {
                    context = model["Context"] as JObject;
                }
                else
                {
                    context          = new JObject();
                    model["Context"] = context;
                }
                context["AddUrl"] = DnnUrlUtils.EditUrl(_module.ViewModule.ModuleID, _portalSettings);
            }
        }
예제 #5
0
        public override JToken GetModelAsJson(bool onlyData = false, bool onlyMainData = false)
        {
            if (_portalSettings == null)
            {
                onlyData = true;
            }
            JObject model      = new JObject();
            var     itemsModel = model;

            ExtendModel(model, onlyData, onlyMainData);
            ExtendSchemaOptions(itemsModel, onlyData || onlyMainData);
            ExtendItemsModel(itemsModel, onlyData || onlyMainData);

            if (!onlyData && !onlyMainData)
            {
                itemsModel["Context"]["RssUrl"] = _portalSettings.PortalAlias.HTTPAlias +
                                                  "/DesktopModules/OpenContent/API/RssAPI/GetFeed?moduleId=" + _module.ViewModule.ModuleID + "&tabId=" + _detailTabId;
            }
            JArray items = new JArray();;

            itemsModel["Items"] = items;
            //string editRole = Manifest.GetEditRole();
            if (_dataList != null && _dataList.Any())
            {
                var mainUrl = Globals.NavigateURL(_detailTabId, false, _portalSettings, "", GetCurrentCultureCode(), "");
                foreach (var item in _dataList)
                {
                    JObject dyn     = item.Data as JObject;
                    JObject context = new JObject();
                    dyn["Context"] = context;
                    context["Id"]  = item.Id;
                    if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
                    {
                        JsonUtils.SimplifyJson(dyn, GetCurrentCultureCode());
                    }
                    EnhanceSelect2(dyn);
                    EnhanceUser(dyn, item.CreatedByUserId);
                    EnhanceImages(dyn, itemsModel);

                    if (onlyData)
                    {
                        RemoveNoData(itemsModel);
                    }
                    else
                    {
                        string url = "";
                        if (!string.IsNullOrEmpty(_manifest.DetailUrl))
                        {
                            HandlebarsEngine hbEngine = new HandlebarsEngine();
                            var dynForHBS             = JsonUtils.JsonToDictionary(dyn.ToString());
                            url = hbEngine.Execute(_manifest.DetailUrl, dynForHBS);
                            url = HttpUtility.HtmlDecode(url);
                        }
                        var editStatus = !_manifest.DisableEdit && IsEditAllowed(item.CreatedByUserId);
                        context["IsEditable"] = editStatus;
                        if (HasEditPermissions(item.CreatedByUserId))
                        {
                            context["EditUrl"] = DnnUrlUtils.EditUrl("id", item.Id, _module.ViewModule.ModuleID, _portalSettings);
                        }
                        context["DetailUrl"] = Globals.NavigateURL(_detailTabId, false, _portalSettings, "", GetCurrentCultureCode(), UrlHelpers.CleanupUrl(url), "id=" + item.Id);
                        context["MainUrl"]   = mainUrl;
                    }
                    items.Add(dyn);
                }
            }
            return(model);
        }
예제 #6
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) : "";
                }
            }
        }
예제 #7
0
        private JToken GetModelAsJsonFromList(bool onlyData)
        {
            JObject model = new JObject();

            if (!onlyData)
            {
                CompleteModel(model, onlyData);
                model["Context"]["RssUrl"] = PortalSettings.PortalAlias.HTTPAlias +
                                             "/DesktopModules/OpenContent/API/RssAPI/GetFeed?moduleId=" + Module.ModuleID + "&tabId=" + MainTabId;
            }
            JArray items = new JArray();;

            model["Items"] = items;
            string editRole = Manifest.GetEditRole();

            if (DataList != null && DataList.Any())
            {
                foreach (var item in DataList)
                {
                    JObject dyn = item.Data as JObject;
                    if (LocaleController.Instance.GetLocales(PortalId).Count > 1)
                    {
                        JsonUtils.SimplifyJson(dyn, GetCurrentCultureCode());
                    }
                    if (Manifest != null && Manifest.AdditionalDataExists() && model["AdditionalData"] != null && model["Options"] != null)
                    {
                        JsonUtils.LookupJson(dyn, model["AdditionalData"] as JObject, model["Options"] as JObject);
                    }
                    if (Options != null && model["Options"] != null)
                    {
                        JsonUtils.ImagesJson(dyn, Options, model["Options"] as JObject, IsEditable);
                    }
                    JObject context = new JObject();
                    dyn["Context"] = context;
                    context["Id"]  = item.Id;
                    if (onlyData)
                    {
                        if (model["Settings"] != null)
                        {
                            model.Remove("Settings");
                        }
                        if (model["Schema"] != null)
                        {
                            model.Remove("Schema");
                        }
                        if (model["Options"] != null)
                        {
                            model.Remove("Options");
                        }
                        if (model["AdditionalData"] != null)
                        {
                            model.Remove("AdditionalData");
                        }
                    }
                    else
                    {
                        string url = "";
                        if (Manifest != null && !string.IsNullOrEmpty(Manifest.DetailUrl))
                        {
                            HandlebarsEngine hbEngine  = new HandlebarsEngine();
                            dynamic          dynForHBS = JsonUtils.JsonToDynamic(dyn.ToString());
                            url = hbEngine.Execute(Manifest.DetailUrl, dynForHBS);
                            url = HttpUtility.HtmlDecode(url);
                        }

                        var editStatus = GetEditStatus(item.CreatedByUserId);
                        context["IsEditable"] = editStatus;
                        context["EditUrl"]    = editStatus ? DnnUrlUtils.EditUrl("id", item.Id, Module.ModuleID, PortalSettings) : "";
                        context["DetailUrl"]  = Globals.NavigateURL(MainTabId, false, PortalSettings, "", GetCurrentCultureCode(), url.CleanupUrl(), "id=" + item.Id);
                        context["MainUrl"]    = Globals.NavigateURL(MainTabId, false, PortalSettings, "", GetCurrentCultureCode(), "");
                    }
                    items.Add(dyn);
                }
            }
            return(model);
        }
 internal string EditUrl(int moduleId)
 {
     return(DnnUrlUtils.EditUrl(moduleId, _portalSettings));
 }
 public string EditUrl(string id, string itemId, int viewModuleModuleId)
 {
     return(DnnUrlUtils.EditUrl(id, itemId, viewModuleModuleId, _portalSettings));
 }