Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
 /// <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));
     }
 }
Esempio n. 3
0
        //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);
        }
Esempio n. 6
0
        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++;
                }
            }
        }
Esempio n. 7
0
        /// <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();
            }
        }
Esempio n. 8
0
        private void Refresh()
        {
            IList <Contact> authors = null;
            string          range   = string.Empty;

            AuthorsListBox.Items.Clear();

            //Find selected bucket
            if (AtoELink.Font.Bold)
            {
                range = Constants.A_EAuthors;
            }
            else if (FtoJLink.Font.Bold)
            {
                range = Constants.F_JAuthors;
            }
            else if (KtoOLink.Font.Bold)
            {
                range = Constants.K_OAuthors;
            }
            else if (PtoTLink.Font.Bold)
            {
                range = Constants.P_TAuthors;
            }
            else if (UtoZLink.Font.Bold)
            {
                range = Constants.U_ZAuthors;
            }
            else if (OtherLink.Font.Bold)
            {
                range = Constants.OtherAuthors;
            }

            int fetchRecordCount = 0;
            int totalRecords     = 0;

            //Calculate fetched record count
            if (PageIndex > 0)
            {
                fetchRecordCount = PageSize * this.PageIndex;
            }

            //Fetch authors
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
            {
                if (IsSecurityAwareControl)
                {
                    if (AuthenticatedToken != null)
                    {
                        authors = (IList <Contact>)dataAccess.GetAuthors(this.AuthenticatedToken, range,
                                                                         FilterTextBox.Text.Trim(), PageSize, fetchRecordCount, out totalRecords);
                    }
                }
                else
                {
                    authors = (IList <Contact>)dataAccess.GetAuthors(null, range,
                                                                     FilterTextBox.Text.Trim(), PageSize, fetchRecordCount, out totalRecords);
                }
            }

            //Set Page count.
            if (totalRecords > 0 && totalRecords > PageSize)
            {
                PageCount = Convert.ToInt32(Math.Ceiling((double)totalRecords / PageSize));
            }
            else
            {
                PageCount = 0;
            }

            //Set status of Next and Previous navigation buttons
            NextButton.Enabled = PrevButton.Enabled = false;
            NextButton.Enabled = PageCount == 1 | PageCount <= (PageIndex + 1) ? false : true;
            PrevButton.Enabled = PageIndex == 0 ? false : true;

            if (authors != null)
            {
                foreach (Contact contact in authors)
                {
                    string title = contact.Title;
                    contact.Title = HttpUtility.HtmlEncode(CoreHelper.FitString(CoreHelper.GetTitleByResourceType(contact), 30));

                    Person person = contact as Person;
                    if (person != null)
                    {
                        if (!string.IsNullOrEmpty(person.FirstName) || !string.IsNullOrEmpty(person.LastName))
                        {
                            contact.Title += "(" + title + ")";
                        }
                    }
                }
            }

            AuthorsListBox.DataSource = authors;
            AuthorsListBox.DataBind();
        }
Esempio n. 9
0
        /// <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++;
                    }
                }
            }
        }
Esempio n. 10
0
        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);
        }