Exemplo n.º 1
0
 private void IncludeResourses(Page page, TemplateManifest template)
 {
     if (template != null)
     {
         //JavaScript.RequestRegistration()
         //string templateBase = template.FilePath.Replace("$.hbs", ".hbs");
         var cssfilename = new FileUri(Path.ChangeExtension(template.MainTemplateUri().FilePath, "css"));
         if (cssfilename.FileExists)
         {
             ClientResourceManager.RegisterStyleSheet(page, page.ResolveUrl(cssfilename.UrlFilePath), FileOrder.Css.PortalCss);
         }
         var jsfilename = new FileUri(Path.ChangeExtension(template.MainTemplateUri().FilePath, "js"));
         if (jsfilename.FileExists)
         {
             ClientResourceManager.RegisterScript(page, page.ResolveUrl(jsfilename.UrlFilePath), FileOrder.Js.DefaultPriority + 100);
         }
         ClientResourceManager.RegisterScript(page, page.ResolveUrl("~/DesktopModules/OpenContent/js/opencontent.js"), FileOrder.Js.DefaultPriority);
     }
 }
Exemplo n.º 2
0
        protected void cmdSaveDefault_Click(object sender, EventArgs e)
        {
            if (sourceList.SelectedValue == DATATYPE_DATA)
            {
                var module = OpenContentModuleConfig.Create(this.ModuleConfiguration, PortalSettings);
                TemplateManifest template = module.Settings.Template;

                if (template != null)
                {
                    var dataFilename = template.MainTemplateUri().PhysicalFullDirectory + "\\data.json";
                    if (template.IsListTemplate)
                    {
                        string itemId = Request.QueryString["id"];
                        if (!string.IsNullOrEmpty(itemId))
                        {
                            File.WriteAllText(dataFilename, txtSource.Text);
                        }
                        else
                        {
                            JArray lst = null;
                            if (!string.IsNullOrEmpty(txtSource.Text))
                            {
                                lst = JArray.Parse(txtSource.Text);
                                if (lst.Count > 0)
                                {
                                    File.WriteAllText(dataFilename, lst[0].ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        File.WriteAllText(dataFilename, txtSource.Text);
                    }
                }
            }
            else if (sourceList.SelectedValue == DATATYPE_SETTINGS)
            {
                var module = OpenContentModuleConfig.Create(this.ModuleConfiguration, PortalSettings);
                TemplateManifest template = module.Settings.Template;
                var settingsFilename      = template.MainTemplateUri().PhysicalFullDirectory + "\\" + template.Key.ShortKey + "-data.json";
                File.WriteAllText(settingsFilename, txtSource.Text);
            }
            else if (sourceList.SelectedValue == DATATYPE_FILTER)
            {
                var module = OpenContentModuleConfig.Create(this.ModuleConfiguration, PortalSettings);
                TemplateManifest template = module.Settings.Template;
                var settingsFilename      = template.MainTemplateUri().PhysicalFullDirectory + "\\" + "filter-data.json";
                File.WriteAllText(settingsFilename, txtSource.Text);
            }
            else
            {
                //SaveAdditionalData(sourceList.SelectedValue);
            }
        }
Exemplo n.º 3
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 ;
            }
        }