/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!CheckPermissions("cms.widgets", PERMISSION_MODIFY)) { return; } // Create new widget info if new widget if (WidgetInfo == null) { // Parent webpart must be set if ((WidgetWebpartId == 0) || (WidgetCategoryId == 0)) { return; } WidgetInfo = new WidgetInfo(); WidgetInfo.WidgetWebPartID = WidgetWebpartId; WidgetInfo.WidgetCategoryID = WidgetCategoryId; } txtCodeName.Text = TextHelper.LimitLength(txtCodeName.Text.Trim(), 100, ""); txtDisplayName.Text = TextHelper.LimitLength(txtDisplayName.Text.Trim(), 100, ""); // Perform validation string errorMessage = new Validator().NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage).IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).Result; if (errorMessage == "") { // If name changed, check if new name is unique if (CMSString.Compare(WidgetInfo.WidgetName, txtCodeName.Text, true) != 0) { WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo(txtCodeName.Text); if (widget != null) { ShowError(GetString("general.codenameexists")); return; } } WidgetInfo.WidgetName = txtCodeName.Text; WidgetInfo.WidgetDisplayName = txtDisplayName.Text; WidgetInfo.WidgetDescription = txtDescription.Text; WidgetInfo.WidgetLayoutID = ValidationHelper.GetInteger(ucLayouts.Value, 0); WidgetInfo.WidgetCategoryID = ValidationHelper.GetInteger(categorySelector.Value, WidgetInfo.WidgetCategoryID); WidgetInfo.WidgetSkipInsertProperties = chkSkipInsertProperties.Checked; WidgetInfoProvider.SetWidgetInfo(WidgetInfo); ShowChangesSaved(); // Raise save for frame reload RaiseOnSaved(); } else { ShowError(errorMessage); } }
private void updateVersionView() { try { int luaId = getSelectedLuaId(); WidgetInfo winfo = ((WidgetInfo)Program.allLuas[luaId]); if (winfo.active == 1) { checkBoxActive.CheckState = CheckState.Checked; } else { checkBoxActive.CheckState = CheckState.Unchecked; } textBoxChangelog.Text = winfo.changelog; updateFiles(luaId); toggleVersionDisplayElements(true); } catch (Exception) { textBoxChangelog.Text = ""; checkBoxActive.CheckState = CheckState.Unchecked; updateFiles(0); toggleVersionDisplayElements(false); } }
public TextInput(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { // load fonts font = HfGDesign.MenuFont (screen); spriteBatch = new SpriteBatch (screen.device); }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { InitializeComponents(); // Get the widget ID widgetId = QueryHelper.GetInteger("widgetID", 0); // Select widget category on dropdown list wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if (wi != null) { if (!RequestHelper.IsPostBack()) { int counter = 1; string codenameBase = TextHelper.LimitLength(wi.WidgetName, 98, ""); Regex regexCodename = RegexHelper.GetRegex("^(.*?)_(\\d+)$"); Regex regexDisplayName = RegexHelper.GetRegex("^(.*?)\\((\\d+)\\)$"); Match match = regexCodename.Match(wi.WidgetName); if (match.Success && (match.Groups.Count == 3)) { // Incremental codename codenameBase = match.Groups[1].Value; counter = ValidationHelper.GetInteger(match.Groups[2].Value, 1); } // Find unique widget name while (WidgetInfoProvider.GetWidgetInfo(codenameBase + "_" + counter) != null) { counter++; } // New names string newWidgetName = codenameBase + "_" + counter; string newWidgetDisplayName = wi.WidgetDisplayName; match = regexDisplayName.Match(wi.WidgetDisplayName); if (match.Success && (match.Groups.Count == 3)) { // Incremental display name newWidgetDisplayName = match.Groups[1].Value + "(" + counter + ")"; } else { // Full display name newWidgetDisplayName = wi.WidgetDisplayName + "(" + counter + ")"; } txtWidgetDisplayName.Text = newWidgetDisplayName; txtWidgetName.Text = newWidgetName; categorySelector.Value = wi.WidgetCategoryID; } } }
public static WidgetItem CreateItem(WidgetInfo info) { WidgetItem item = new WidgetItem(); item.WidgetID = info.WidgetID; item.Name = info.Name; item.Title = info.Title; item.Info = info; return(item); }
public void ReturnWidget(IWidget itemWidget) { if (!_itemWidgets.TryGetValue(itemWidget.GetType(), out List <WidgetInfo> widgets)) { throw new Exception("Return widget before creation"); } WidgetInfo widgetInfo = widgets.Find(w => w.itemWidget == itemWidget); itemWidget.go.SetActive(false); widgetInfo.isActive = false; }
/// <summary> /// OK click handler, save changes. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if (wi != null) { wi.WidgetDocumentation = htmlText.ResolvedValue; WidgetInfoProvider.SetWidgetInfo(wi); ShowChangesSaved(); } }
public TextInputDialog(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { var textInputInfo = new WidgetInfo () { RelativePosition = TextInputPosition, RelativeSize = TextInputSize, RelativePadding = () => new Vector2 (0.005f, 0.005f), ForegroundColor = () => Color.Black, BackgroundColor = () => Color.White }; TextInput = new TextInput (screen, textInputInfo, DisplayLayer.SubMenu); }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); return(PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, false)); } return(null); }
/// <summary> /// OK click handler, save changes. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if (wi != null) { wi.WidgetDocumentation = htmlText.ResolvedValue; WidgetInfoProvider.SetWidgetInfo(wi); lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } }
/// <summary> /// Combines widget info with default XML system propertiers. /// </summary> /// <param name="fi">Widget form info</param> /// <param name="wi">Widget info object</param> public DataRow CombineWithDefaultValues(FormInfo fi, WidgetInfo wi) { if ((!String.IsNullOrEmpty(wi.WidgetDefaultValues)) && (String.Compare(wi.WidgetDefaultValues, "<form></form>", false) != 0)) { // Apply changed values DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr, wi.WidgetDefaultValues); return(dr); } return(fi.GetDataRow()); }
private void LoadMyWidgetInfos() { try { mListMyWidgetInfos.Clear(); WebRequest webRequest = new WebRequest(); webRequest.Session = CurrentApp.Session; webRequest.Code = (int)S1200Codes.GetUserWidgetList; webRequest.ListData.Add(CurrentApp.Session.UserID.ToString()); Service12001Client client = new Service12001Client( WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service12001")); WebReturn webReturn = client.DoOperation(webRequest); client.Close(); if (!webReturn.Result) { ShowException(string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return; } if (webReturn.ListData == null) { ShowException(string.Format("Fail.\tListData is null")); return; } OperationReturn optReturn; for (int i = 0; i < webReturn.ListData.Count; i++) { string strInfo = webReturn.ListData[i]; optReturn = XMLHelper.DeserializeObject <WidgetInfo>(strInfo); if (!optReturn.Result) { ShowException(string.Format("WSFail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } WidgetInfo info = optReturn.Data as WidgetInfo; if (info == null) { ShowException(string.Format("WidgetInfo is null")); return; } mListMyWidgetInfos.Add(info); } CurrentApp.WriteLog("LoadMyWidgetInfos", string.Format("Load end.\t{0}", mListMyWidgetInfos.Count)); } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { widgetId = QueryHelper.GetInteger("widgetid", 0); this.Title = "Widget part documentation"; // Resource string btnOk.Text = GetString("General.Ok"); string[,] actions = new string[2, 12]; WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); // set Documentation header - "View documentation" + "Generate Documentation" if (wi != null) { // Generate doucmentation action actions[0, 0] = "HyperLink"; actions[0, 1] = GetString("webparteditdocumentation.view"); actions[0, 3] = "~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx?widgetid=" + wi.WidgetName; actions[0, 5] = GetImageUrl("CMSModules/CMS_WebParts/viewdocumentation.png"); actions[0, 11] = "_blank"; if (SettingsKeyProvider.DevelopmentMode) { // Generate doucmentation action actions[1, 0] = "HyperLink"; actions[1, 1] = GetString("webparteditdocumentation.generate"); actions[1, 3] = "~/CMSPages/Dialogs/Documentation.aspx?widget=" + wi.WidgetName; actions[1, 5] = GetImageUrl("CMSModules/CMS_WebParts/generatedocumentation.png"); actions[1, 11] = "_blank"; } } this.CurrentMaster.HeaderActions.Actions = actions; // HTML editor settings htmlText.AutoDetectLanguage = false; htmlText.DefaultLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; htmlText.EditorAreaCSS = ""; htmlText.ToolbarSet = "SimpleEdit"; // Load data if (!RequestHelper.IsPostBack()) { if (wi != null) { htmlText.ResolvedValue = wi.WidgetDocumentation; } } }
private void updateGameWidgetInfo(int gameWidgetId) { WidgetInfo winfo = (WidgetInfo)Program.allGameWidgets[gameWidgetId]; if (gameWidgetId == 0) { this.toggleGameWidgetInfoDisplayElements(false); return; } textBoxGameWidgetName.Text = winfo.headerName; textBoxGameWidgetDescription.Text = winfo.headerDescription; this.toggleGameWidgetInfoDisplayElements(true); }
private void buttonSaveGameWidgetInfo_Click(object sender, EventArgs e) { try { Program.fetcher.updateModWidget(this.getSelectedGameWidgetId(), textBoxGameWidgetName.Text, textBoxGameWidgetDescription.Text); WidgetInfo current = (WidgetInfo)Program.allGameWidgets[this.getSelectedGameWidgetId()]; current.headerName = textBoxGameWidgetName.Text; current.description = textBoxGameWidgetDescription.Text; } catch (Exception ex) { MessageBox.Show("Exception occured: " + ex.Message); } }
public VerticalMenu(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { info.RelativeSize = () => new Vector2 ( RelativeItemSize (-1).X, RelativeItemSize (-1).Y * Items.Count + Info.RelativePadding ().Y * (Items.Count - 1) ); RelativeItemSize = (i) => new Vector2 (300, 0); RelativeItemPosition = (n) => { return Info.RelativePosition () + new Vector2 (0, (RelativeItemSize (-1).Y + Info.RelativePadding ().Y) * n); }; Border = Border.Zero; spriteBatch = new SpriteBatch (screen.device); }
private void saveVersion_Click(object sender, EventArgs e) { int check = 1; if (!checkBoxActive.Checked) { check = 0; } Program.fetcher.updateLuaVersion(getSelectedLuaId(), textBoxChangelog.Text, check); WidgetInfo current = this.getSelectedLua(); current.changelog = textBoxChangelog.Text; current.active = check; }
/// <summary> /// Rturns TRUE if selector is used in group widget. /// </summary> private bool IsGroupPollWidget() { int widgetId = QueryHelper.GetInteger("widgetid", 0); string widgetName = QueryHelper.GetString("widgetname", null); WidgetInfo widget = null; if (widgetId > 0) { widget = WidgetInfoProvider.GetWidgetInfo(widgetId); } else if (widgetName != null) { widget = WidgetInfoProvider.GetWidgetInfo(widgetName); } return((widget != null) && (widget.WidgetName.IndexOf("grouppoll", StringComparison.InvariantCultureIgnoreCase) != -1)); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Check "read" permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Widget", "Read")) { RedirectToAccessDenied("CMS.Widget", "Read"); } widgetId = QueryHelper.GetInteger("widgetId", 0); widget = WidgetInfoProvider.GetWidgetInfo(widgetId); if (widget != null) { string currentWidget = widget.WidgetDisplayName; WidgetCategoryInfo categoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(widget.WidgetCategoryID); // Initialize Master Page string[,] pageTitleTabs = new string[3, 4]; pageTitleTabs[0, 0] = GetString("widgets.title"); pageTitleTabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx"); pageTitleTabs[0, 2] = "_parent"; pageTitleTabs[0, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx") + "'; }"; if (categoryInfo != null) { pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(categoryInfo.WidgetCategoryDisplayName); pageTitleTabs[1, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx?categoryid=" + widget.WidgetCategoryID); pageTitleTabs[1, 2] = "_parent"; pageTitleTabs[1, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?categoryid=" + widget.WidgetCategoryID) + "'; }"; pageTitleTabs[2, 0] = HTMLHelper.HTMLEncode(currentWidget); pageTitleTabs[2, 1] = ""; pageTitleTabs[2, 2] = ""; } // Set masterpage this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_Widget/object.png"); this.CurrentMaster.Title.HelpTopicName = "widget_general"; this.CurrentMaster.Title.HelpName = "helpTopic"; this.CurrentMaster.Title.Breadcrumbs = pageTitleTabs; // Tabs InitalizeTabs(); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Check "read" permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Widget", "Read")) { RedirectToAccessDenied("CMS.Widget", "Read"); } widgetId = QueryHelper.GetInteger("widgetId", 0); widget = WidgetInfoProvider.GetWidgetInfo(widgetId); if (widget != null) { string currentWidget = widget.WidgetDisplayName; WidgetCategoryInfo categoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(widget.WidgetCategoryID); // Initialize Master Page string[,] pageTitleTabs = new string[3, 4]; pageTitleTabs[0, 0] = GetString("widgets.title"); pageTitleTabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx"); pageTitleTabs[0, 2] = "_parent"; pageTitleTabs[0, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx") + "'; }"; if (categoryInfo != null) { pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(categoryInfo.WidgetCategoryDisplayName); pageTitleTabs[1, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx?categoryid=" + widget.WidgetCategoryID); pageTitleTabs[1, 2] = "_parent"; pageTitleTabs[1, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?categoryid=" + widget.WidgetCategoryID) + "'; }"; pageTitleTabs[2, 0] = HTMLHelper.HTMLEncode(currentWidget); pageTitleTabs[2, 1] = ""; pageTitleTabs[2, 2] = ""; } // Set masterpage CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_Widget/object.png"); CurrentMaster.Title.HelpTopicName = "widget_general"; CurrentMaster.Title.HelpName = "helpTopic"; CurrentMaster.Title.Breadcrumbs = pageTitleTabs; // Tabs InitalizeTabs(); } }
public Dialog(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { IsVisible = true; Done = () => { IsVisible = false; }; // create a new SpriteBatch, which can be used to draw textures spriteBatch = new SpriteBatch (screen.device); // menu WidgetInfo menuInfo = new WidgetInfo (); buttons = new Menu (screen, menuInfo, DisplayLayer.Menu); buttons.ItemForegroundColor = ButtonForegroundColor; buttons.ItemBackgroundColor = ButtonBackgroundColor; buttons.ItemAlignX = HorizontalAlignment.Center; buttons.ItemAlignY = VerticalAlignment.Center; }
public ConfirmDialog(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { // text Text = new string[] {}; // actions Action onYesClick = () => { OnYesClick (); if (CanClose) { Done (); } }; Action onNoClick = () => { OnNoClick (); Done (); }; Action onCancelClick = () => { OnCancelClick (); Done (); }; // buttons buttons.RelativeItemPosition = RelativeButtonPosition; buttons.RelativeItemSize = RelativeButtonSize; var itemInfo = new MenuItemInfo () { Text = "Yes", OnClick = onYesClick }; buttons.AddButton (itemInfo); itemInfo = new MenuItemInfo () { Text = "No", OnClick = onNoClick }; buttons.AddButton (itemInfo); itemInfo = new MenuItemInfo () { Text = "Cancel", OnClick = onCancelClick }; buttons.AddButton (itemInfo); }
public ColorPicker(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { info.BackgroundColor = () => Color.Black; info.ForegroundColor = () => Color.White; info.AlignX = HorizontalAlignment.Left; info.AlignY = VerticalAlignment.Top; // colors colors = new List<Color> (CreateColors (64)); colors.Sort (Utilities.ColorHelper.SortColorsByLuminance); tiles = new List<Vector2> (CreateTiles (colors)); // create a new SpriteBatch, which can be used to draw textures spriteBatch = new SpriteBatch (screen.device); info.RelativePosition = () => (Vector2.One - info.RelativeSize ()) / 2; info.RelativeSize = () => { float sqrt = (float)Math.Ceiling (Math.Sqrt (colors.Count)); return tileSize * sqrt; }; }
/// <summary> /// Generate documentation page. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); webPartId = QueryHelper.GetString("webPartId", String.Empty); if (webPartId != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(webPartId); } string aliasPath = QueryHelper.GetString("aliaspath", String.Empty); // Ensure correct view mode if (String.IsNullOrEmpty(aliasPath)) { // Ensure the dashboard mode for the dialog if (QueryHelper.Contains("dashboard")) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = QueryHelper.GetString("dashboard", String.Empty); PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty); } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } // If widgetId is in query create widget documentation widgetID = QueryHelper.GetString("widgetId", String.Empty); if (widgetID != String.Empty) { // Get widget from instance string zoneId = QueryHelper.GetString("zoneid", String.Empty); Guid instanceGuid = QueryHelper.GetGuid("instanceGuid", Guid.Empty); int templateID = QueryHelper.GetInteger("templateID", 0); bool newItem = QueryHelper.GetBoolean("isNew", false); bool isInline = QueryHelper.GetBoolean("Inline", false); PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateID); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (isInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!newItem) { wi = WidgetInfoProvider.GetWidgetInfo(widgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(itemDescription); // Get description from parent weboart if webpart is inherited if ((wpi != null) && ((wpi.WebPartDescription == null || wpi.WebPartDescription == "") && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } }
/// <summary> /// Generate form info for widget. /// </summary> /// <param name="wi">Widget info</param> private FormInfo CreateFormInfo(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); return FormHelper.GetWidgetFormInfo(wi.WidgetName, String.Empty, widgetProperties, null, false); } return null; }
protected void Page_Load(object sender, EventArgs e) { // Security test if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } // Add link to external stylesheet CSSHelper.RegisterCSSLink(this, "~/App_Themes/Default/CMSDesk.css"); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); DataSet ds = null; DataSet cds = null; // Check init settings bool allWidgets = QueryHelper.GetBoolean("allWidgets", false); bool allWebParts = QueryHelper.GetBoolean("allWebparts", false); // Get webpart (widget) from querystring - only if no allwidget or allwebparts set bool isWebpartInQuery = false; bool isWidgetInQuery = false; String webpartQueryParam = String.Empty; //If not show all widgets or webparts - check if any widget or webpart is present if ((!allWidgets) && (!allWebParts)) { webpartQueryParam = QueryHelper.GetString("webpart", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWebpartInQuery = true; } else { webpartQueryParam = QueryHelper.GetString("widget", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWidgetInQuery = true; } } } // Set development option if is required if (QueryHelper.GetString("details", "0") == "1") { development = true; } // Generate all webparts if (allWebParts) { // Get all webpart categories cds = WebPartCategoryInfoProvider.GetAllCategories(); } // Generate all widgets else if (allWidgets) { // Get all widget categories cds = WidgetCategoryInfoProvider.GetWidgetCategories(String.Empty, String.Empty, 0, String.Empty); } // Generate single webpart else if (isWebpartInQuery) { // Split weparts string[] webparts = webpartQueryParam.Split(';'); if (webparts.Length > 0) { string webpartWhere = SqlHelperClass.GetWhereCondition("WebpartName", webparts); ds = WebPartInfoProvider.GetWebParts(webpartWhere, null); // If any webparts found if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WebpartCategoryID"], "NULL") + ","); } string ctWhere = "CategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WebPartCategoryInfoProvider.GetCategories(ctWhere, null); } } } // Generate single widget else if (isWidgetInQuery) { string[] widgets = webpartQueryParam.Split(';'); if (widgets.Length > 0) { string widgetsWhere = SqlHelperClass.GetWhereCondition("WidgetName", widgets); ds = WidgetInfoProvider.GetWidgets(widgetsWhere, null, 0, String.Empty); } if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WidgetCategoryID"], "NULL") + ","); } string ctWhere = "WidgetCategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WidgetCategoryInfoProvider.GetWidgetCategories(ctWhere, null, 0, String.Empty); } } if (allWidgets || isWidgetInQuery) { documentationTitle = "Kentico CMS Widgets"; Page.Header.Title = "Widgets documentation"; } if (!allWebParts && !allWidgets && !isWebpartInQuery && !isWidgetInQuery) { pnlContent.Visible = false; pnlInfo.Visible = true; } // Check whether at least one category is present if (!DataHelper.DataSourceIsEmpty(cds)) { string namePrefix = ((isWidgetInQuery) || (allWidgets)) ? "Widget" : String.Empty; // Loop through all web part categories foreach (DataRow cdr in cds.Tables[0].Rows) { // Get all webpart in the categories if (allWebParts) { ds = WebPartInfoProvider.GetAllWebParts(Convert.ToInt32(cdr["CategoryId"])); } // Get all widgets in the category else if (allWidgets) { int categoryID = Convert.ToInt32(cdr["WidgetCategoryId"]); ds = WidgetInfoProvider.GetWidgets("WidgetCategoryID = " + categoryID.ToString(), null, 0, null); } // Check whether current category contains at least one webpart if (!DataHelper.DataSourceIsEmpty(ds)) { // Generate category name code menu += "<br /><strong>" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + "</strong><br /><br />"; // Loop through all web web parts in categories foreach (DataRow dr in ds.Tables[0].Rows) { // Init isImagePresent = false; undocumentedProperties = 0; documentation = 0; // Webpart (Widget) information string itemDisplayName = String.Empty; string itemDescription = String.Empty; string itemDocumentation = String.Empty; string itemType = String.Empty; int itemID = 0; WebPartInfo wpi = null; WidgetInfo wi = null; // Set webpart info if ((isWebpartInQuery) || (allWebParts)) { wpi = new WebPartInfo(dr); if (wpi != null) { itemDisplayName = wpi.WebPartDisplayName; itemDescription = wpi.WebPartDescription; itemDocumentation = wpi.WebPartDocumentation; itemID = wpi.WebPartID; itemType = PortalObjectType.WEBPART; if (wpi.WebPartCategoryID != ValidationHelper.GetInteger(cdr["CategoryId"], 0)) { wpi = null; } } } // Set widget info else if ((isWidgetInQuery) || (allWidgets)) { wi = new WidgetInfo(dr); if (wi != null) { itemDisplayName = wi.WidgetDisplayName; itemDescription = wi.WidgetDescription; itemDocumentation = wi.WidgetDocumentation; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; if (wi.WidgetCategoryID != ValidationHelper.GetInteger(cdr["WidgetCategoryId"], 0)) { wi = null; } } } // Check whether web part (widget) exists if ((wpi != null) || (wi != null)) { // Link GUID Guid mguid = Guid.NewGuid(); // Whether description is present in webpart bool isDescription = false; // Image url string wimgurl = GetItemImage(itemID, itemType); // Set description text string descriptionText = itemDescription; // Parent webpart info WebPartInfo pwpi = null; // If webpart look for parent's description and documentation if (wpi != null) { // Get parent description if webpart is inherited if (wpi.WebPartParentID > 0) { pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { if ((descriptionText == null || descriptionText.Trim() == "")) { // Set description from parent descriptionText = pwpi.WebPartDescription; } // Set documentation text from parent if WebPart is inherited if ((wpi.WebPartDocumentation == null) || (wpi.WebPartDocumentation.Trim() == "")) { itemDocumentation = pwpi.WebPartDocumentation; if (!String.IsNullOrEmpty(itemDocumentation)) { documentation = 2; } } } } } // Set description as present if (descriptionText.Trim().Length > 0) { isDescription = true; } // Generate HTML for menu and content menu += " <a href=\"#_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(itemDisplayName) + "</a> "; // Generate webpart header content += "<table style=\"width:100%;\"><tr><td><h1><a name=\"_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + " > " + HTMLHelper.HTMLEncode(itemDisplayName) + "</a></h1></td><td style=\"text-align:right;\"> <a href=\"#top\" class=\"noprint\">top</a></td></tr></table>"; // Generate WebPart content content += @"<table style=""width: 100%; height: 200px; border: solid 1px #DDDDDD;""> <tr> <td style=""width: 50%; text-align:center; border-right: solid 1px #DDDDDD; vertical-align: middle;margin-left: auto; margin-right:auto; text-align:center;""> <img src=""" + wimgurl + @""" alt=""imageTeaser""> </td> <td style=""width: 50%; vertical-align: center;text-align:center;"">" + HTMLHelper.HTMLEncode(descriptionText) + @" </td> </tr> </table>"; // Properties content content += "<div class=\"DocumentationWebPartsProperties\">"; // Generate content if (wpi != null) { GenerateDocContent(CreateFormInfo(wpi)); } else if (wi != null) { GenerateDocContent(CreateFormInfo(wi)); } // Close content area content += "</div>"; // Generate documentation text content content += "<br /><div style=\"border: solid 1px #dddddd;width: 100%;\">" + DataHelper.GetNotEmpty(HTMLHelper.ResolveUrls(itemDocumentation, null), "<strong>Additional documentation text is not provided.</strong>") + "</div>"; // Set page break tag for print content += "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />"; // If development is required - highlight missing description, images and doc. text if (development) { // Check image if (!isImagePresent) { menu += "<span style=\"color:Brown;\">image </span>"; } // Check properties if (undocumentedProperties > 0) { menu += "<span style=\"color:Red;\">properties(" + undocumentedProperties + ") </span>"; } // Check properties if (!isDescription) { menu += "<span style=\"color:#37627F;\">description </span>"; } // Check documentation text if (String.IsNullOrEmpty(itemDocumentation)) { documentation = 1; } switch (documentation) { // Display information about missing documentation case 1: menu += "<span style=\"color:Green;\">documentation </span>"; break; // Display information about inherited documentation case 2: menu += "<span style=\"color:Green;\">documentation (inherited) </span>"; break; } } menu += "<br />"; } } } } } ltlContent.Text = menu + "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />" + content; }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, false); return fi; } return null; }
public KnotSaveConfirmDialog(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder, Knot knot) : base(screen, info, drawOrder) { Info.RelativeSize = () => new Vector2 (0.500f, 0.250f); Info.RelativePadding = () => new Vector2 (0.016f, 0.016f); Text = new string[] { "Do you want to save the changes?" }; TextInput.InputText = knot.Name; string originalName = knot.Name; OnYesClick += () => { Console.WriteLine ("OnYesClick"); if (TextInput.InputText.Length == 0) { Console.WriteLine ("Name is empty!"); CanClose = false; } else if (originalName.Length > 0 && originalName == TextInput.InputText) { Console.WriteLine ("Name has not been changed: " + TextInput.InputText); try { knot.Save (); } catch (IOException ex) { Console.WriteLine (ex); knot.Save (new KnotFileIO (), knot.MetaData.Filename); } CanClose = true; } else { Console.WriteLine ("Name has been changed: " + TextInput.InputText); try { knot.Name = TextInput.InputText; knot.Save (); } catch (IOException ex) { Console.WriteLine (ex); knot.Save (new KnotFileIO (), knot.MetaData.Filename); } CanClose = true; } if (CanClose) { screen.NextState = GameScreens.StartScreen; } }; OnNoClick += () => { Console.WriteLine ("OnNoClick"); screen.NextState = GameScreens.StartScreen; }; }
/// <summary> /// Button OK click handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Trim text values txtWidgetName.Text = TextHelper.LimitLength(txtWidgetName.Text.Trim(), 100, ""); txtWidgetDisplayName.Text = TextHelper.LimitLength(txtWidgetDisplayName.Text.Trim(), 100, ""); // Validate the text box fields string errorMessage = new Validator() .NotEmpty(txtWidgetName.Text, rfvWidgetName.ErrorMessage) .NotEmpty(txtWidgetDisplayName.Text, rfvWidgetDisplayName.ErrorMessage) .IsCodeName(txtWidgetName.Text, GetString("general.InvalidCodeName")) .Result; // Check if widget with same name exists if (WidgetInfoProvider.GetWidgetInfo(txtWidgetName.Text) != null) { errorMessage = GetString("general.codenameexists"); } if (errorMessage == "") { // Clone widget info WidgetInfo nwi = new WidgetInfo(wi, false); // Modify info data nwi.WidgetID = 0; nwi.WidgetGUID = Guid.NewGuid(); nwi.WidgetName = txtWidgetName.Text; nwi.WidgetDisplayName = txtWidgetDisplayName.Text; nwi.WidgetCategoryID = ValidationHelper.GetInteger(categorySelector.Value, 0); // Add new web part to database WidgetInfoProvider.SetWidgetInfo(nwi); // Clone widget security DataSet ds = WidgetRoleInfoProvider.GetWidgetRoles("WidgetID = " + wi.WidgetID, null, 0, null); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { WidgetRoleInfo nwri = new WidgetRoleInfo(dr); nwri.WidgetID = nwi.WidgetID; WidgetRoleInfoProvider.SetWidgetRoleInfo(nwri); } } // Update widget category counts WidgetCategoryInfoProvider.UpdateCategoryWidgetChildCount(0, nwi.WidgetCategoryID); // Duplicate associated thumbnail MetaFileInfoProvider.CopyMetaFiles(wi.WidgetID, nwi.WidgetID, PortalObjectType.WIDGET, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null); string script = String.Empty; string refreshLink = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?widgetid=" + nwi.WidgetID + "&reload=true"); if (QueryHelper.GetBoolean("reloadAll", true)) { // Refresh web part tree and select/edit new widget script = "wopener.location = '" + refreshLink + "';"; } else { script += "wopener.parent.parent.frames['widgettree'].location.href ='" + refreshLink + "';"; } script += "window.close();"; ltlScript.Text = ScriptHelper.GetScript(script); } else { lblError.Text = errorMessage; lblError.Visible = true; } }
/// <summary> /// Combines widget info with default XML system propertiers. /// </summary> /// <param name="fi">Widget form info</param> /// <param name="wi">Widget info object</param> public DataRow CombineWithDefaultValues(FormInfo fi, WidgetInfo wi) { if ((!String.IsNullOrEmpty(wi.WidgetDefaultValues)) && (String.Compare(wi.WidgetDefaultValues, "<form></form>", false) != 0)) { // Apply changed values DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr, wi.WidgetDefaultValues); return dr; } return fi.GetDataRow(); }
/// <summary> /// Creates new widget with setting from parent webpart. /// </summary> /// <param name="parentWebpartId">ID of parent webpart</param> /// <param name="categoryId">ID of parent widget category</param> /// <returns>Created widget info</returns> private WidgetInfo NewWidget(int parentWebpartId, int categoryId) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(parentWebpartId); // Widget cannot be created from inherited webpart if ((wpi != null) && (wpi.WebPartParentID == 0)) { // Set widget according to parent webpart WidgetInfo wi = new WidgetInfo(); wi.WidgetName = FindUniqueWidgetName(wpi.WebPartName, 100); wi.WidgetDisplayName = wpi.WebPartDisplayName; wi.WidgetDescription = wpi.WebPartDescription; wi.WidgetDocumentation = wpi.WebPartDocumentation; wi.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(wpi.WebPartProperties, "visible", "false"); wi.WidgetWebPartID = parentWebpartId; wi.WidgetCategoryID = categoryId; // Save new widget to DB WidgetInfoProvider.SetWidgetInfo(wi); // Get thumbnail image from webpart DataSet ds = MetaFileInfoProvider.GetMetaFiles(wpi.WebPartID, PortalObjectType.WEBPART, null, null, null, null, 1); if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mfi = new MetaFileInfo(ds.Tables[0].Rows[0]); mfi.Generalized.EnsureBinaryData(); mfi.MetaFileID = 0; mfi.MetaFileGUID = Guid.NewGuid(); mfi.MetaFileObjectID = wi.WidgetID; mfi.MetaFileObjectType = PortalObjectType.WIDGET; MetaFileInfoProvider.SetMetaFileInfo(mfi); } // Return ID of newly created widget return wi; } return null; }
protected override void OnLoad(EventArgs e) { plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); if (WebpartID != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID); } // Ensure correct view mode if (String.IsNullOrEmpty(AliasPath)) { // Ensure the dashboard mode for the dialog if (!string.IsNullOrEmpty(DashboardName)) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = DashboardName; PortalContext.DashboardSiteName = DashboardSiteName; } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (WidgetID != 0) { PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(ZoneID); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (IsInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID wi = WidgetInfoProvider.GetWidgetInfo(WidgetID); } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; String itemIcon = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = WebPartInfo.OBJECT_TYPE; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; itemIcon = PortalHelper.GetIconHtml(wpi.WebPartThumbnailGUID, wpi.WebPartIconClass ?? PortalHelper.DefaultWebPartIconClass); } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = WidgetInfo.OBJECT_TYPE; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; itemIcon = PortalHelper.GetIconHtml(wi.WidgetThumbnailGUID, wi.WidgetIconClass ?? PortalHelper.DefaultWidgetIconClass); } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) icon ltrImage.Text = itemIcon; // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription)); // Get description from parent weboart if webpart is inherited if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } ScriptHelper.RegisterJQuery(Page); string script = @" $cmsj(document.body).ready(initializeResize); function initializeResize () { resizeareainternal(); $cmsj(window).resize(function() { resizeareainternal(); }); } function resizeareainternal () { var height = document.body.clientHeight ; var panel = document.getElementById ('" + divScrolable.ClientID + @"'); // Get parent footer to count proper height (with padding included) var footer = $cmsj('#divFooter'); panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px'; }"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script)); // Init tabs tabControlElem.UsePostback = true; tabControlElem.AddTab(new UITabItem() { Text = GetString("webparts.documentation"), }); tabControlElem.AddTab(new UITabItem() { Text = GetString("general.properties"), }); // Disable caching Response.Cache.SetNoStore(); base.OnLoad(e); }
public Menu(GameScreen screen, WidgetInfo info, DisplayLayer drawOrder) : base(screen, info, drawOrder) { Items = new List<MenuItem> (); }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); return PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, false); } return null; }
/// <summary> /// Loads the widget form. /// </summary> private void LoadForm() { // Setup basic form on live site formCustom.AllowMacroEditing = false; formCustom.IsLiveSite = IsLiveSite; // Load settings if (!String.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWidget = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!String.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Try to find the widget variant in the database and set its VariantID if (IsNewVariant) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(properties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateId, variantName, false); // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } EnsureDashboard(); if (!String.IsNullOrEmpty(WidgetId) && !IsInline) { if (CurrentPageInfo == null) { ShowError(GetString("Widgets.Properties.aliasnotfound")); pnlFormArea.Visible = false; return; } // Get template instance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(CurrentPageInfo); if (!IsNewWidget) { // Get the instance of widget widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId); if (widgetInstance == null) { ShowError(GetString("Widgets.Properties.WidgetNotFound")); pnlFormArea.Visible = false; return; } if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { widgetInstance = CurrentPageInfo.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId); widgetInstance = widgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID)); // Set the widget variant mode if (widgetInstance != null) { VariantMode = widgetInstance.VariantMode; } } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } // Keep xml version if (widgetInstance != null) { xmlVersion = widgetInstance.XMLVersion; } UIContext.EditedObject = wi; // Get the zone to which it inserts WebPartZoneInstance zone = templateInstance.GetZone(ZoneId); if ((ZoneType == WidgetZoneTypeEnum.None) && (zone != null)) { ZoneType = zone.WidgetZoneType; } // Check security var currentUser = MembershipContext.AuthenticatedUser; switch (ZoneType) { // Group zone => Only group widgets and group admin case WidgetZoneTypeEnum.Group: // Should always be, only group widget are allowed in group zone if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(CurrentPageInfo.NodeGroupID) && ((PortalContext.ViewMode != ViewModeEnum.Design) || ((PortalContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design")))))) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for editor zones case WidgetZoneTypeEnum.Editor: if (!wi.WidgetForEditor) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!wi.WidgetForUser) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for dashboard zones case WidgetZoneTypeEnum.Dashboard: if (!wi.WidgetForDashboard) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; } // Check security if ((ZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } // Get form schemas wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(ZoneType); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), ZoneType), widgetProperties, zoneTypeDefinition, true, wi.WidgetDefaultValues); if (fi != null) { fi.ContextResolver.Settings.RelatedObject = templateInstance; // Check if there are some editable properties var ffi = fi.GetFields(true, false).ToList<FormFieldInfo>(); if ((ffi == null) || (ffi.Count == 0)) { ShowInformation(GetString("widgets.emptyproperties")); } DataRow dr = fi.GetDataRow(); // Load overridden values for new widget if (IsNewWidget || (xmlVersion > 0)) { fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible); } if (IsNewWidget) { // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(wi.WidgetDisplayName)); } // Load values from existing widget LoadDataRowFromWidget(dr, fi); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.ExtendedControls.ControlContext.WIDGET_PROPERTIES; } } if (IsInline) { // Load text definition from session string definition = ValidationHelper.GetString(SessionHelper.GetValue("WidgetDefinition"), string.Empty); if (String.IsNullOrEmpty(definition)) { definition = Request.Form[hdnWidgetDefinition.UniqueID]; } else { hdnWidgetDefinition.Value = definition; } Hashtable parameters = null; string widgetName = string.Empty; if (IsNewWidget) { // New widget - load widget info by id if (!String.IsNullOrEmpty(WidgetId)) { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } else { // Try to get widget from codename widgetName = QueryHelper.GetString("WidgetName", String.Empty); wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } } else { if (definition == null) { DisplayError("widget.failedtoload"); return; } // Parse definition parameters = CMSDialogHelper.GetHashTableFromString(definition); // Trim control name if (parameters["name"] != null) { widgetName = parameters["name"].ToString(); } wi = WidgetInfoProvider.GetWidgetInfo(widgetName); } if (wi == null) { DisplayError("widget.failedtoload"); return; } // If widget cant be used as inline if (!wi.WidgetForInline) { DisplayError("widget.cantbeusedasinline"); return; } // Test permission for user var currentUser = MembershipContext.AuthenticatedUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated())) { isValidWidget = false; OnNotAllowed(this, null); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true, wi.WidgetDefaultValues); if (fi != null) { // Check if there are some editable properties mFields = fi.GetFields(true, true); if ((mFields == null) || !mFields.Any()) { ShowInformation(GetString("widgets.emptyproperties")); } // Get datarows with required columns DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi); if (IsNewWidget) { // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible); } else { foreach (string key in parameters.Keys) { object value = parameters[key]; // Test if given property exists if (dr.Table.Columns.Contains(key) && (value != null)) { try { dr[key] = DataHelper.ConvertValue(value, dr.Table.Columns[key].DataType); } catch { } } } } // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.ExtendedControls.ControlContext.WIDGET_PROPERTIES; } } }
/// <summary> /// Creates widget. Called when the "Create widget" button is pressed. /// </summary> private bool CreateWidget() { // Get parent webpart and category for widget WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("AbuseReport"); WidgetCategoryInfo category = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory"); // Widget cannot be created from inherited webpart if ((webpart != null) && (webpart.WebPartParentID == 0) && (category != null)) { // Create new widget object WidgetInfo newWidget = new WidgetInfo(); // Set the properties from parent webpart newWidget.WidgetName = "MyNewWidget"; newWidget.WidgetDisplayName = "My new widget"; newWidget.WidgetDescription = webpart.WebPartDescription; newWidget.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(webpart.WebPartProperties, "visible", "false"); newWidget.WidgetWebPartID = webpart.WebPartID; newWidget.WidgetCategoryID = category.WidgetCategoryID; // Save new widget WidgetInfoProvider.SetWidgetInfo(newWidget); return true; } return false; }
protected void Page_Load(object sender, EventArgs e) { widgetInfo = WidgetInfoProvider.GetWidgetInfo(WidgetID); if (widgetInfo != null) { webpartInfo = WebPartInfoProvider.GetWebPartInfo(widgetInfo.WidgetWebPartID); fieldEditor.DisplayIn = FormInfo.DISPLAY_CONTEXT_DASHBOARD; if (webpartInfo != null) { // Merge class and alternative form definitions string formDef = FormHelper.MergeFormDefinitions(webpartInfo.WebPartProperties, widgetInfo.WidgetProperties); // Use alternative form mode for field editor fieldEditor.Mode = FieldEditorModeEnum.General; fieldEditor.FormDefinition = formDef; fieldEditor.IsAlternativeForm = true; // Use same control for widgets as for webparts fieldEditor.DisplayedControls = FieldEditorControlsEnum.Controls; // Handle definition update (move up, move down, delete, OK button) fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate; } } else { fieldEditor.Visible = false; ShowError(GetString("general.invalidid")); } }
/// <summary> /// Gets and bulk updates widgets. Called when the "Get and bulk update widgets" button is pressed. /// Expects the CreateWidget method to be run first. /// </summary> private bool GetAndBulkUpdateWidgets() { // Prepare the parameters string where = "WidgetName LIKE N'MyNewWidget%'"; string orderBy = ""; int topN = 0; string columns = ""; // Get the data DataSet widgets = WidgetInfoProvider .GetWidgets() .Where(where) .OrderBy(orderBy) .TopN(topN) .Columns(columns); if (!DataHelper.DataSourceIsEmpty(widgets)) { // Loop through the individual items foreach (DataRow widgetDr in widgets.Tables[0].Rows) { // Create object from DataRow WidgetInfo modifyWidget = new WidgetInfo(widgetDr); // Update the properties modifyWidget.WidgetDisplayName = modifyWidget.WidgetDisplayName.ToUpper(); // Save the changes WidgetInfoProvider.SetWidgetInfo(modifyWidget); } return true; } return false; }
protected override void OnLoad(EventArgs e) { plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); if (WebpartID != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID); } // Ensure correct view mode if (String.IsNullOrEmpty(AliasPath)) { // Ensure the dashboard mode for the dialog if (!string.IsNullOrEmpty(DashboardName)) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = DashboardName; PortalContext.DashboardSiteName = DashboardSiteName; } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (WidgetID != String.Empty) { PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(ZoneID); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (IsInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!IsNew) { wi = WidgetInfoProvider.GetWidgetInfo(WidgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription)); // Get description from parent weboart if webpart is inherited if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } ScriptHelper.RegisterJQuery(Page); string script = @" $j(document.body).ready(initializeResize); function initializeResize () { resizeareainternal(); $j(window).resize(function() { resizeareainternal(); }); } function resizeareainternal () { var height = document.body.clientHeight ; var panel = document.getElementById ('" + divScrolable.ClientID + @"'); // Get parent footer to count proper height (with padding included) var footer = $j('.PageFooterLine'); panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px'; }"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script)); string[,] tabs = new string[4, 4]; tabs[0, 0] = GetString("webparts.documentation"); tabs[1, 0] = GetString("general.properties"); tabControlElem.Tabs = tabs; tabControlElem.UsePostback = true; // Disable caching Response.Cache.SetNoStore(); base.OnLoad(e); }
/// <summary> /// Load XML with default values (remove keys already overriden in properties tab). /// </summary> /// <param name="wi">Web part info</param> /// <param name="formDef">String XML definition of default values of webpart</param> private XmlDocument LoadDefaultValuesXML(WidgetInfo wi, string formDef) { // Test if there is any default properties set string properties = "<form></form>"; if (wi.WidgetProperties != String.Empty) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); } } XmlDocument xmlProperties = new XmlDocument(); xmlProperties.LoadXml(properties); // Load default system xml XmlDocument xmlDefault = new XmlDocument(); xmlDefault.LoadXml(formDef); // Filter overriden properties - remove properties with same name as in system XML XmlNodeList defaultList = xmlDefault.SelectNodes(@"//field"); foreach (XmlNode node in defaultList) { string columnName = node.Attributes["column"].Value.ToString(); XmlNodeList propertiesList = xmlProperties.SelectNodes("//field[@column=\"" + columnName + "\"]"); //This property already set in properties tab if (propertiesList.Count > 0) { node.ParentNode.RemoveChild(node); } } // Filter empty categories XmlNodeList nodes = xmlDefault.DocumentElement.ChildNodes; for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; if (node.Name.ToLower() == "category") { // Find next category if (i < nodes.Count - 1) { XmlNode nextNode = nodes[i + 1]; if (nextNode.Name.ToLower() == "category") { // Delete actual category node.ParentNode.RemoveChild(node); i--; } } } } // Test if last category is not empty nodes = xmlDefault.DocumentElement.ChildNodes; if (nodes.Count > 0) { XmlNode lastNode = nodes[nodes.Count - 1]; if (lastNode.Name.ToLower() == "category") { lastNode.ParentNode.RemoveChild(lastNode); } } return xmlDefault; }