/// <summary> /// Sets the value of all subject related controls. /// </summary> private void SetSubjectControlValues(object entity) { _subjectLabel.Text = GlobalResource.AssociationSubjectLabel; if (entity != null) { string title = CoreHelper.UpdateEmptyTitle(CoreHelper.GetTitleByResourceType((Resource)entity)); SubjectDisplayLink.Text = System.Web.HttpUtility.HtmlEncode(CoreHelper.FitString(title, 40)); } }
/// <summary> /// Creates a node for the tree view control. /// </summary> /// <param name="nodeValue">Supplemental data about the node that is not displayed.</param> /// <param name="nodeText">The text to be displayed for the node.</param> protected static TreeNode CreateNode(string nodeValue, string nodeText) { TreeNode node = new TreeNode(); node.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle(nodeText), 40)); node.ToolTip = nodeText; node.Value = nodeValue; return(node); }
public static string GetFileName(string fileTitle, string fileExtension) { string extension = fileExtension; if (!string.IsNullOrEmpty(extension) && !extension.StartsWith(Constants.Dot, StringComparison.Ordinal)) { extension = Constants.Dot + extension; } return(CoreHelper.UpdateEmptyTitle(fileTitle) + extension); }
//Adds resource link to the list. private void AddResourceLinkToList(BulletedList list, Resource res) { string linkText = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle( CoreHelper.GetTitleByResourceType(res)), _maxTitleCharWidth)); string linkUrl = string.Empty; linkUrl = string.Format(CultureInfo.CurrentCulture, ViewUrl, res.Id); ListItem item = new ListItem(linkText, linkUrl); //TODO - The following attribute is added for showing tooltip - but it does not work. item.Attributes.Add("title", linkText); list.Items.Add(new ListItem(linkText, linkUrl)); }
/// <summary> /// Populate tree view from data source. /// </summary> protected override void PopulateTree() { if (!this.Page.IsPostBack) { resource = GetScholarlyWorkItem(); _subjectLabel.Text = GlobalResource.CategoryAssociationSubjectLabel; _subjectLink.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle( CoreHelper.GetTitleByResourceType(resource)), _maxCharShownTree)); _subjectLink.NavigateUrl = string.Format(CultureInfo.CurrentCulture, SubjectNavigationUrl, resource.Id); BindTreeView(true); } }
private TreeNode CreateNode(CategoryNode category) { TreeNode node = new TreeNode(); node.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle(category.Title), _maxCharShownTree)); node.ToolTip = category.Title; node.Value = category.Id.ToString(); if (IsSecurityAwareControl) { node.ShowCheckBox = false; if (AuthenticatedToken != null) { if (HasAccess(category.Id)) { node.NavigateUrl = string.Format(CultureInfo.CurrentCulture, TreeNodeNavigationUrl, category.Id); node.ShowCheckBox = true; } else { node.SelectAction = TreeNodeSelectAction.None; } } } else { node.NavigateUrl = string.Format(CultureInfo.CurrentCulture, TreeNodeNavigationUrl, category.Id); node.ShowCheckBox = true; } //Hide checkbox for subject categoryNode. if (category.Id == ResourceItemId) { node.ShowCheckBox = false; } else { if (node.ShowCheckBox.Value == true) { int count = resource.CategoryNodes.Where(Tuple => Tuple.Id == category.Id).Count(); if (count > 0) { node.Checked = true; } } } return(node); }
private void BindRelatedFiles() { if (DataSource.Files != null && DataSource.Files.Count > 0) { int index = 0; foreach (File file in DataSource.Files) { if (UserPermissions == null || (UserPermissions.Keys.Contains(file.Id) && UserPermissions[file.Id].Contains(UserResourcePermissions.Read))) { HyperLink link = new HyperLink(); link.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle(CoreHelper.GetTitleByResourceType(file)), _maxTitleCharWidth)); if (!string.IsNullOrEmpty(FilesLink)) { link.NavigateUrl = string.Format(CultureInfo.CurrentCulture, FilesLink, file.Id); } this.Files.Controls.Add(link); if (index < (DataSource.Files.Count - 1)) { Label commalbl = new Label(); commalbl.Text = _comma; this.Files.Controls.Add(commalbl); } } if (index >= _maxFilesCount - 1) { if (index < (DataSource.Files.Count - 1)) { Label etcLbl = new Label(); etcLbl.Text = _etc; this.Files.Controls.Add(etcLbl); } break; } index++; } } }
/// <summary> /// Fills DropDownList with root CategoryNodes. /// </summary> private void PopulateRootNodeDropDown() { RootNodeDropDown.Items.Clear(); using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext())) { IList <CategoryNode> rootNodeList = dataAccess.GetRootCategoryNodes(); if (rootNodeList != null && rootNodeList.Count > 0) { foreach (CategoryNode node in rootNodeList) { node.Title = CoreHelper.FitString(CoreHelper.UpdateEmptyTitle(node.Title), _maxCharShownTree); } } RootNodeDropDown.DataSource = rootNodeList; RootNodeDropDown.DataBind(); } }
/// <summary> /// Updates the status of controls base on DataSource. /// </summary> public override void DataBind() { base.DataBind(); if (DataSource != null) { this.TitleHeader.Text = GlobalResource.TitleText + _colan; //Set title with link this.ResourceTitle.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle( CoreHelper.GetTitleByResourceType(DataSource)), _maxTitleCharWidth)) + " (" + DataSource.GetType().Name + ")"; if (!string.IsNullOrEmpty(TitleLink) && (UserPermissions == null || (UserPermissions.Keys.Contains(DataSource.Id) && UserPermissions[DataSource.Id].Contains(UserResourcePermissions.Read)))) { this.ResourceTitle.NavigateUrl = string.Format(CultureInfo.CurrentCulture, TitleLink, DataSource.Id); } else { this.ResourceTitle.NavigateUrl = string.Empty; } //Set date based on ShowDate value. if (ShowDate == DateType.DateAdded) { this.DateAddedHeader.Text = GlobalResource.DateAddedText + _colan; this.DateAdded.Text = DataSource.DateAdded != null?DataSource.DateAdded.Value.ToString() : string.Empty; } else { this.DateAddedHeader.Text = GlobalResource.DateModifiedText + _colan; this.DateAdded.Text = DataSource.DateModified != null?DataSource.DateModified.Value.ToString() : string.Empty; } //Set Description. this.Description.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(DataSource.Description, _maxDescriptionCharWidth)); //Set files. BindRelatedFiles(); //set authors. ScholarlyWork resource = DataSource as ScholarlyWork; if (resource != null && resource.Authors != null && resource.Authors.Count > 0) { int index = 0; foreach (Contact author in resource.Authors) { if (UserPermissions == null || (UserPermissions.Keys.Contains(author.Id) && UserPermissions[author.Id].Contains(UserResourcePermissions.Read))) { HyperLink link = new HyperLink(); link.Text = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.UpdateEmptyTitle(CoreHelper.GetTitleByResourceType(author)), _maxTitleCharWidth)); if (!string.IsNullOrEmpty(AuthorsLink)) { link.NavigateUrl = string.Format(CultureInfo.CurrentCulture, AuthorsLink, author.Id); } this.Authors.Controls.Add(link); if (index < (resource.Authors.Count - 1)) { Label commalbl = new Label(); commalbl.Text = _comma; this.Authors.Controls.Add(commalbl); } } if (index >= _maxAuthorsCount - 1) { if (index < (resource.Authors.Count - 1)) { Label etcLbl = new Label(); etcLbl.Text = _etc; this.Authors.Controls.Add(etcLbl); } break; } index++; } } } }
private bool PopulateBodyPanelWithRelatedDownloads(Guid fileId, NavigationProperty navigationProperty) { bool success = false; List <File> relatedResources = null; IDictionary <Guid, IEnumerable <string> > userPermissions = null; if (this.DesignMode) { relatedResources = GetDesignTimeRelatedFiles(); } else { if (!IsSecurityAwareControl) { relatedResources = GetRelatedFiles(fileId, navigationProperty); } else { //If control is security aware the get resources as well as their respective user permissions. IEnumerable <ResourcePermissions <File> > resourcesWithPermissions = GetRelatedFiles(AuthenticatedToken, fileId, navigationProperty); if (resourcesWithPermissions != null) { relatedResources = resourcesWithPermissions.Select(tuple => tuple.Resource).ToList(); userPermissions = resourcesWithPermissions.ToDictionary(tuple => tuple.Resource.Id, tuple => tuple.Permissions); } } } if (relatedResources != null && relatedResources.Count > 0) { Table table = new Table(); table.Width = Unit.Percentage(100); foreach (File file in relatedResources) { //if control is security unaware OR if control is security aware and user is having //Read permission on the resource then only set the link. if (!IsSecurityAwareControl || (userPermissions.Keys.Contains(file.Id) && userPermissions[file.Id].Contains(UserResourcePermissions.Read))) { using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext())) { string fileSize = dataAccess.GetUploadedFileSize(file); if (!string.IsNullOrEmpty(fileSize)) { TableRow tr = new TableRow(); TableCell td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.VerticalAlign = VerticalAlign.Top; td.Width = Unit.Percentage(70); LinkButton fileNameLink = new LinkButton(); fileNameLink.ID = file.Id.ToString(); fileNameLink.Text = HttpUtility.HtmlEncode(CoreHelper.FitString( CoreHelper.UpdateEmptyTitle(CoreHelper.GetFileName(file.Title, file.FileExtension)), _maxTitleCharWidth)); fileNameLink.Click += new EventHandler(fileNameLink_Click); td.Controls.Add(fileNameLink); tr.Cells.Add(td); td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.VerticalAlign = VerticalAlign.Top; Label fileSizeLabel = new Label(); fileSizeLabel.Text = fileSize; td.Controls.Add(fileSizeLabel); tr.Cells.Add(td); table.Rows.Add(tr); } } } } BodyPanel.Controls.Add(table); success = true; } return(success); }