using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.GlobalHelper; using CMS.UIControls; public partial class CMSModules_Content_Controls_Dialogs_YouTube_YouTubeSizes : CMSUserControl { #region "Variables" private int mMaxSideSize = 60; private string mOnSelectedItemClick = ""; #endregion #region "Public properties" /// /// Gets or sets the maximal size of the rectangle in preview. /// public int MaxSideSize { get { return mMaxSideSize; } set { mMaxSideSize = value; } } /// /// Gets or sets the JavaScript code which is prcessed when some size is clicked. /// public string OnSelectedItemClick { get { return mOnSelectedItemClick; } set { mOnSelectedItemClick = value; } } /// /// Gets or sets the width. /// public int SelectedWidth { get { return ValidationHelper.GetInteger(hdnWidth.Value, 0); } set { hdnWidth.Value = value.ToString(); } } /// /// Gets or sets the height. /// public int SelectedHeight { get { return ValidationHelper.GetInteger(hdnHeight.Value, 0); } set { hdnHeight.Value = value.ToString(); } } #endregion protected void Page_Load(object sender, EventArgs e) { // Register scripts ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "YouTubeSizes", ScriptHelper.GetScript( "function setSizes(width, height) { \n" + " var widthElem = document.getElementById('" + hdnWidth.ClientID + "'); \n" + " var heightElem = document.getElementById('" + hdnHeight.ClientID + "'); \n" + " if ((widthElem != null) && (heightElem != null)) { \n" + " widthElem.value = width; \n" + " heightElem.value = height; \n" + OnSelectedItemClick + "; \n" + " } \n" + "} \n")); } #region "Public methods" /// /// Loads the sizes previews. /// /// Array with sizes (two items per box) public void LoadSizes(int[] sizes) { plcSizes.Controls.Clear(); if (sizes.Length > 1) { int max = sizes[0]; for (int i = 0; i < sizes.Length; i++) { if (sizes[i] > max) { max = sizes[i]; } } double coef = ((double)MaxSideSize) / max; plcSizes.Controls.Add(new LiteralControl("
")); for (int i = 0; i < sizes.Length; i += 2) { plcSizes.Controls.Add(new LiteralControl("
" + sizes[i] + " x " + sizes[i + 1] + "
")); } plcSizes.Controls.Add(new LiteralControl("
")); } } #endregion }