protected void BindControls() { if (this.moduleDefId > -1) { ModuleDefinition moduleDef = new ModuleDefinition(moduleDefId); //if (moduleDef.SiteID != siteSettings.SiteID) return; lnkModuleDefinition.Text = ResourceHelper.GetResourceString(moduleDef.ResourceFile, moduleDef.FeatureName); lnkModuleDefinition.ToolTip = lnkModuleDefinition.Text; lnkModuleDefinition.NavigateUrl = SiteRoot + "/Admin/ModuleDefinitions.aspx?defid=" + moduleDefId.ToString(); ArrayList defSettings = ModuleSettings.GetDefaultSettings(this.moduleDefId); this.grdSettings.DataSource = defSettings; this.grdSettings.DataBind(); } }
private void PopulateCustomSettings() { // these are the Settings attached to the Module Definition DefaultSettings = ModuleSettings.GetDefaultSettings(this.module.ModuleDefId); // these are the settings attached to the module instance ArrayList customSettingValues = ModuleSettings.GetCustomSettingValues(this.module.ModuleId); foreach (CustomModuleSetting s in DefaultSettings) { bool found = false; foreach (CustomModuleSetting v in customSettingValues) { if (v.SettingName == s.SettingName) { found = true; AddSettingControl(v); } } if (!found) { // if a new module setting has been added since the // last version upgrade, the code might reach this // it means a Module Definition Setting was found for which there is not // a Module Setting on this instance of the module, so we need to add the setting ModuleSettings.CreateModuleSetting( module.ModuleGuid, moduleId, s.SettingName, s.SettingValue, s.SettingControlType, s.SettingValidationRegex, s.ControlSrc, s.HelpKey, s.SortOrder); // add control with default settings AddSettingControl(s); } } }
private void btnSave_Click(Object sender, EventArgs e) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to call Page.Validate()"); } Page.Validate(); if (Page.IsValid) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to call Page IsValid = true"); } bool ok = true; bool needToReIndex = false; int currentPageId = module.PageId; int newPageId = module.PageId; if (module.ModuleId > -1) { if (isAdmin) { string viewRoles = string.Empty; foreach (ListItem item in cblViewRoles.Items) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage inside loop of Role ListItems"); } if (item.Selected == true) { viewRoles = viewRoles + item.Value + ";"; } } string previousViewRoles = this.module.ViewRoles; this.module.ViewRoles = viewRoles; if (previousViewRoles != viewRoles) { needToReIndex = true; } string editRoles = string.Empty; if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to loop through Role ListItems"); } foreach (ListItem item in authEditRoles.Items) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage inside loop of Role ListItems"); } if (item.Selected == true) { editRoles = editRoles + item.Value + ";"; } } this.module.AuthorizedEditRoles = editRoles; string draftEdits = string.Empty; foreach (ListItem item in draftEditRoles.Items) { if (item.Selected == true) { draftEdits = draftEdits + item.Value + ";"; } } this.module.DraftEditRoles = draftEdits; } if (tabGeneralSettings.Visible) { this.module.ModuleTitle = moduleTitle.Text; this.module.CacheTime = int.Parse(cacheTime.Text); this.module.ShowTitle = chkShowTitle.Checked; this.module.AvailableForMyPage = this.chkAvailableForMyPage.Checked; this.module.AllowMultipleInstancesOnMyPage = this.chkAllowMultipleInstancesOnMyPage.Checked; this.module.Icon = this.ddIcons.SelectedValue; this.module.HideFromAuthenticated = chkHideFromAuth.Checked; this.module.HideFromUnauthenticated = chkHideFromUnauth.Checked; if (this.divParentPage.Visible) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to check Page dropdown"); } newPageId = int.Parse(this.ddPages.SelectedValue); if (newPageId != currentPageId) { needToReIndex = true; Module.UpdatePage(currentPageId, newPageId, this.module.ModuleId); } this.module.PageId = newPageId; } if (this.isAdmin) { if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to check user dropdown"); } if (this.scUser.Value.Length > 0) { try { this.module.EditUserId = int.Parse(this.scUser.Value); } catch (ArgumentException) { } catch (FormatException) { } catch (OverflowException) { } } else { this.module.EditUserId = 0; } } } if (log.IsDebugEnabled) { log.Debug("ModuleSettingsPage about to Save Module"); } this.module.Save(); if (needToReIndex) { // if content is moved from 1 page to another, need to reindex both pages // to keep view permissions in sync IndexHelper.RebuildPageIndexAsync(CurrentPage); PageSettings newPage = new PageSettings(siteSettings.SiteId, newPageId); newPage.PageIndex = 0; IndexHelper.RebuildPageIndexAsync(newPage); } ArrayList defaultSettings = ModuleSettings.GetDefaultSettings(this.module.ModuleDefId); foreach (CustomModuleSetting s in defaultSettings) { if (s.SettingControlType == string.Empty) { continue; } ok = true; Object oSettingLabel = GetGlobalResourceObject("Resource", s.SettingName + "RegexWarning"); String settingLabel = String.Empty; if (oSettingLabel == null) { settingLabel = "Regex Warning"; } else { settingLabel = oSettingLabel.ToString(); } string settingValue = string.Empty; if (s.SettingName == "WebPartModuleWebPartSetting") { ModuleSettings.UpdateModuleSetting(this.module.ModuleGuid, moduleId, s.SettingName, ddWebParts.SelectedValue); } else { if (s.SettingControlType == "ISettingControl") { string controlID = "uc" + moduleId.ToString(CultureInfo.InvariantCulture) + s.SettingName; Control c = PlaceHolderAdvancedSettings.FindControl(controlID); if (c != null) { if (c is ISettingControl) { ISettingControl isc = c as ISettingControl; settingValue = isc.GetValue(); } else { ok = false; } } else { log.Error("could not find control for " + s.SettingName); ok = false; } } else { settingValue = Request.Params.Get(s.SettingName + this.moduleId.ToString(CultureInfo.InvariantCulture)); if (s.SettingControlType == "CheckBox") { if (settingValue == "on") { settingValue = "true"; } else { settingValue = "false"; } } else { if (s.SettingValidationRegex.Length > 0) { if (!Regex.IsMatch(settingValue, s.SettingValidationRegex)) { ok = false; this.lblValidationSummary.Text += "<br />" + settingLabel; } } } } if (ok) { ModuleSettings.UpdateModuleSetting(this.module.ModuleGuid, moduleId, s.SettingName, settingValue); } } } } if (ok) { CacheHelper.TouchCacheDependencyFile(cacheDependencyKey); WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl()); return; } } }