I'm running my website on ie8 in compatablity View on. I"m using ASP.net 2008 V3.5 Sp1. When ever I click to expand a node I get an error "Microsoft JScript runtime error: Array length must be assigned a finite positive number" in prototype.js. I can view the Javascript
What's happening is that this.length is equals 0 so when the code subtracts 1 it become -1 which isn't a valid value.
Here's my code
| shift: function() { |
| var result = this[0]; |
| for (var i = 0; i < this.length - 1; i++) |
| this[i] = this[i + 1]; |
| this.length--; |
| return result; |
| }, |
What's happening is that this.length is equals 0 so when the code subtracts 1 it become -1 which isn't a valid value.
Here's my code
| <%@ Register TagPrefix="radG" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="ContentTitle" runat="server"> |
| Documents |
| </asp:Content> |
| <asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server"> |
| <script type="text/javascript"> |
| function RowContextMenu(sender, e) |
| { |
| var menu = $find("<%= cRadMenu.ClientID %>"); |
| if(menu != null) |
| { |
| var index = e.get_itemIndexHierarchical(); |
| //------------------------------------- |
| // var item = menu.findItemByText("Add"); |
| //var parentItem = item.get_parent(); |
| //Removes the item from the items collection of the clicked item's parent |
| //item.hide(); |
| //if(item != null) |
| // menu.delete(item); |
| document.getElementById("radGridClickedRowIndex").value = index; |
| var eevt = e.get_domEvent(); |
| menu.show(evt); |
| evt.cancelBubble = true; |
| if (evt.stopPropagation) |
| { |
| evt.stopPropagation(); |
| } |
| } |
| /* |
| var contextMenu = $find("<%= cRadMenu.ClientID %>"); |
| document.getElementById("radGridClickedRowIndex").value = index; |
| if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) |
| { |
| contextMenu.show(e); |
| } |
| $telerik.cancelRawEvent(e);*/ |
| } |
| </script> |
| <h1>Documents</h1> |
| <div class="row"> |
| <div class="left_text_column" style="width:350px;border-right:solid 1px #eee;padding-bottom:10px"> |
| <radG:RadTreeView |
| ID="RadTreeView1" |
| runat="server" |
| SingleExpandPath ="true" |
| ExpandAnimation-Type="OutQuint" |
| ExpandAnimation-Duration="600" |
| OnNodeClick="RadTreeView1_NodeClick" |
| OnNodeExpand = "RadTreeView1_NodeExpand" |
| > |
| </radG:RadTreeView> |
| </div> |
| <radG:RadContextMenu |
| id="cRadMenu" |
| Runat="server" |
| Skin="WebBlue" |
| OnItemClick="RadMenu1_ItemClick" |
| > |
| <Items> |
| <radG:RadMenuItem Text="Delete"/> |
| <radG:RadMenuItem Text="Edit"/> |
| </Items> |
| </radG:RadContextMenu> |
| <div class="right_text_column" style="width:590px"> |
| <radG:RadGrid |
| ID="RadGrid1" |
| OnItemCommand="RadGrid1_ItemCommand" |
| runat="server" |
| HorizontalAlign="NotSet" |
| Skin="WebBlue" |
| AutoGenerateColumns="False" |
| OnItemDataBound="RadGrid1_ItemDataBound" |
| OnNeedDataSource="RadGrid1_OnNeedDataSource" |
| OnInsertCommand="RadGrid1_InsertCommand" |
| > |
| <MasterTableView DataKeyNames= "Id" EditMode ="EditForms" > |
| <Columns> |
| <radG:GridTemplateColumn HeaderText="Name" SortExpression="DocumentName"> |
| <ItemTemplate> |
| <asp:LinkButton ID="lbLink" CommandName="Download" CommandArgument='<%# Bind("FileLocation")%>' runat="server" Text='<%# Bind("Name")%>' Enabled='<%# !(bool)(DataBinder.Eval(Container, "DataItem.Disabled"))%>'></asp:LinkButton> |
| </ItemTemplate> |
| </radG:GridTemplateColumn> |
| <radG:GridBoundColumn AllowSorting="true" DataField="Description" HeaderText="Description" SortExpression="Description"></radG:GridBoundColumn> |
| <radG:GridBoundColumn AllowSorting="true" DataField="TypeName" HeaderText="Type" SortExpression="TypeName" ></radG:GridBoundColumn> |
| <radG:GridBoundColumn AllowSorting="true" DataField="FileSizeString" HeaderText="Size" SortExpression="FileSize" ></radG:GridBoundColumn> |
| </Columns> |
| <RowIndicatorColumn UniqueName="RowIndicator" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <EditFormSettings EditFormType="Template"> |
| <FormTemplate> |
| <div style="clear:both;margin:3px;"> |
| <label for="docFileUpload">File:</label> |
| <asp:FileUpload ID="docFileUpload" runat="server" width="70%"/> |
| <asp:TextBox |
| ID="txtDescription" |
| runat="server" |
| Width="90%" |
| Text='<%# Bind( "Description") %>' |
| > |
| </asp:TextBox> |
| <asp:RegularExpressionValidator |
| id="regExDocValidator1" runat="server" |
| ErrorMessage="Upload .zip, .jpg, .gif, .pdf & .doc only." |
| ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.pdf|.PDF|.doc|.DOC|.ZIP|.zip)$" |
| ControlToValidate="docFileUpload" ValidationGroup="uploadValidationGroup" Display="Dynamic"></asp:RegularExpressionValidator> |
| </div> |
| <div style="clear:both;margin:3px;"> |
| <asp:Button ID="btnUpdate" |
| Text='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "Insert" : "Update" %>' |
| runat="server" |
| CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>' |
| > |
| </asp:Button> |
| <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" |
| CommandName="Cancel"></asp:Button> |
| </div> |
| </FormTemplate> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings> |
| <ClientEvents OnRowContextMenu="RowContextMenu" > |
| </ClientEvents> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| <FilterMenu HoverBackColor="LightSteelBlue" HoverBorderColor="Navy" NotSelectedImageUrl="~/RadControls/Grid/Skins/Outlook/NotSelectedMenu.gif" |
| SelectColumnBackColor="Control" SelectedImageUrl="~/RadControls/Grid/Skins/Outlook/SelectedMenu.gif" |
| TextColumnBackColor="Window"> |
| </FilterMenu> |
| </radG:RadGrid> |
| <asp:HiddenField ID="hfDocId" runat="server" /> |
| <input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" /> |
| </div> |
| </div> |
| </asp:Content> |
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Collections; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using System.Data.SqlClient; |
| using System.IO; |
| using Telerik.Web.UI; |
| namespace TDMSF15.Documents |
| { |
| public partial class Default : System.Web.UI.Page |
| { |
| string ConString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; |
| RadTreeNode rtn = null; |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!Page.IsPostBack) |
| { |
| Session["TreeID"] = 0; |
| GenerateTreeView(); |
| /* MembershipUser u = Membership.GetUser(Page.User.Identity.Name); |
| if (!Roles.IsUserInRole(u.UserName, Globals.Role_Administrator) && |
| !Roles.IsUserInRole(u.UserName, Globals.Role_DataEntry)) |
| { |
| cRadMenu.Enabled = false; |
| cRadMenu.Visible = false; |
| }*/ |
| } |
| } |
| public void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| // if (e.CommandName != "Download") |
| // return; |
| RadTreeNode node = this.RadTreeView1.SelectedNode; |
| MembershipUser u = Membership.GetUser(Page.User.Identity.Name); |
| if (e.CommandName == RadGrid.InitInsertCommandName) |
| { |
| //Add new" button clicked |
| e.Canceled = true; |
| //Prepare an IDictionary with the predefined values |
| System.Collections.Specialized.ListDictionary newValues = new |
| System.Collections.Specialized.ListDictionary(); |
| newValues["Description"] = string.Empty; |
| newValues["ReadOnly"] = false; |
| //Insert the item and rebind |
| this.rtn = node; |
| e.Item.OwnerTableView.InsertItem(newValues); |
| // RadGrid1.Rebind(); |
| } |
| else |
| if (e.CommandName == "Download") |
| { |
| string fileName = e.CommandArgument.ToString(); |
| string fileLocation = Path.Combine(Globals.uploadDir, fileName); |
| if (!File.Exists(fileLocation)) |
| { |
| throw new Exception("File [" + fileLocation + "] does not exisits"); |
| } |
| FileInfo file = new FileInfo(fileLocation); |
| Response.Clear(); |
| Response.AddHeader("content-disposition", "attachment;filename=" + file.Name); |
| Response.AddHeader("Content-Length", file.Length.ToString()); |
| Response.Buffer = true; |
| Response.ContentType = "application/octet-stream"; |
| Response.WriteFile(file.FullName); |
| } |
| else if (e.CommandName == "Update") |
| { |
| /* if (!Roles.IsUserInRole(u.UserName, Globals.Role_Administrator) && |
| !Roles.IsUserInRole(u.UserName, Globals.Role_DataEntry)) |
| { |
| return; |
| }*/ |
| //get File |
| FileUpload fileUpload = (FileUpload)e.Item.FindControl("docFileUpload"); |
| //TextBox name = (TextBox)e.Item.FindControl("txtName"); |
| TextBox description = (TextBox)e.Item.FindControl("txtDescription"); |
| //int radGridClickedRowIndex; |
| //radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]); |
| int docId = (int) RadGrid1.MasterTableView.DataKeyValues[Convert.ToInt32(e.Item.ItemIndex)]["Id"]; |
| if (docId > 0) |
| { |
| Domain.TDMSDocument doc = null; |
| if (LxT.Common.Utilities.StringUtil.GetIntValue(this.hfDocId.Value, -1) |
| == Domain.TDMSDocument.globalDocument) |
| doc = (Domain.TDMSDocument)Persistence.TDMSHelpers.GetDocumentHelper().Select(docId); |
| else |
| doc = (Domain.TDMSDocument)Persistence.TDMSHelpers.GetUploadedDocumentHelper().Select(docId); |
| //doc.Name = name.Text; |
| doc.Description = description.Text; |
| doc.modifiedBy = User.Identity.Name; |
| if (fileUpload.HasFile) |
| { |
| doc.FileSize = fileUpload.PostedFile.ContentLength; |
| string newFileLocation = doc.FileLocation.Replace(doc.Name, |
| fileUpload.FileName); |
| string _filePath = Path.Combine(Globals.uploadDir, |
| newFileLocation/*fileUpload.FileName*/); |
| doc.Name = fileUpload.FileName; |
| //delete old file |
| File.Delete(Path.Combine(Globals.uploadDir, |
| doc.FileLocation)); |
| doc.FileLocation = newFileLocation; |
| //save ew file |
| fileUpload.SaveAs(_filePath); |
| } |
| if (LxT.Common.Utilities.StringUtil.GetIntValue(this.hfDocId.Value, -1) |
| == Domain.TDMSDocument.globalDocument) |
| Persistence.TDMSHelpers.GetDocumentHelper().Update(doc); |
| else |
| Persistence.TDMSHelpers.GetUploadedDocumentHelper().Update(doc); |
| } |
| LoadGridData(node); |
| } |
| else if (e.CommandName == "Cancel") |
| { |
| LoadGridData(node); |
| } |
| } |
| private void GenerateTreeView() |
| { |
| SqlConnection dbCon = new SqlConnection(ConString); |
| dbCon.Open(); |
| SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM DocumentTree ORDER BY TreeOrder", dbCon); |
| DataSet ds = new DataSet(); |
| adapter.Fill(ds); |
| ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["TreeId"], ds.Tables[0].Columns["parentId"]); |
| foreach (DataRow dbRow in ds.Tables[0].Rows) |
| { |
| string documentId = null; |
| string stage = string.Empty; |
| int substage = Globals.nullInt; |
| int objectType = Globals.nullInt; |
| bool allowAdd = false; |
| string folder = string.Empty; |
| if (dbRow["DocumentType"] != DBNull.Value) |
| documentId = (string)dbRow["DocumentType"]; |
| if (dbRow["stage"] != DBNull.Value) |
| stage = (string)dbRow["stage"]; |
| if (dbRow["substage"] != DBNull.Value) |
| substage = (int)dbRow["substage"]; |
| if (dbRow["objecttype"] != DBNull.Value) |
| objectType = (int)dbRow["objecttype"]; |
| if (dbRow["allowAdd"] != DBNull.Value) |
| allowAdd = (bool)dbRow["allowAdd"]; |
| if (dbRow["folder"] != DBNull.Value) |
| folder = (string)dbRow["folder"]; |
| string readRoles = string.Empty; |
| string editDeleteRoles = string.Empty; |
| string addRoles = string.Empty; |
| if (dbRow["ViewList"] != DBNull.Value) |
| readRoles = (string)dbRow["ViewList"]; |
| if (dbRow["EditDeleteList"] != DBNull.Value) |
| editDeleteRoles = (string)dbRow["EditDeleteList"]; |
| if (dbRow["AddList"] != DBNull.Value) |
| addRoles = (string)dbRow["AddList"]; |
| if (dbRow.IsNull("parentId")) |
| { |
| RadTreeNode node = CreateNode(dbRow["NodeName"].ToString(), false, dbRow["TreeId"].ToString(), documentId, stage, |
| substage, objectType, allowAdd, folder, |
| readRoles, editDeleteRoles, addRoles); |
| RadTreeView1.Nodes.Add(node); |
| RecursivelyPopulate(dbRow, node); |
| } |
| } |
| } |
| public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| System.Drawing.Color c = System.Drawing.Color.FromName("#eeeeee"); |
| if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem) |
| { |
| // int id = (Int32)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"]; |
| Domain.TDMSUploadedDocument d = e.Item.DataItem as Domain.TDMSUploadedDocument; |
| if (d != null) |
| { |
| if (d.StageTypeId == Globals.Stage_NDI_Reinspection) |
| { |
| e.Item.BackColor = c; |
| } |
| } |
| } |
| } |
| private void RecursivelyPopulate(DataRow dbRow, RadTreeNode node) |
| { |
| foreach (DataRow childRow in dbRow.GetChildRows("NodeRelation")) |
| { |
| string documentId = null; |
| string stage = string.Empty; |
| int substage = Globals.nullInt; |
| int objectType = Globals.nullInt; |
| bool allowAdd = false; |
| string folder = string.Empty; |
| if (childRow["DocumentType"] != DBNull.Value) |
| documentId = (string)childRow["DocumentType"]; |
| if (childRow["stage"] != DBNull.Value) |
| stage = (string)childRow["stage"]; |
| if (childRow["substage"] != DBNull.Value) |
| substage = (int)childRow["substage"]; |
| if (childRow["objecttype"] != DBNull.Value) |
| objectType = (int)childRow["objecttype"]; |
| if (childRow["allowAdd"] != DBNull.Value) |
| allowAdd = (bool)childRow["allowAdd"]; |
| if (childRow["folder"] != DBNull.Value) |
| folder = (string)childRow["folder"]; |
| // childNode.ExpandMode = ExpandMode.ServerSide; |
| string readRoles = string.Empty; |
| string editDeleteRoles = string.Empty; |
| string addRoles = string.Empty; |
| if (dbRow["ViewList"] != DBNull.Value) |
| readRoles = (string)dbRow["ViewList"]; |
| if (dbRow["EditDeleteList"] != DBNull.Value) |
| editDeleteRoles = (string)dbRow["EditDeleteList"]; |
| if (dbRow["AddList"] != DBNull.Value) |
| addRoles = (string)dbRow["AddList"]; |
| RadTreeNode childNode = CreateNode(childRow["NodeName"].ToString(), false, childRow["TreeId"].ToString(), documentId, |
| stage, substage, objectType, allowAdd, folder, |
| readRoles, editDeleteRoles, addRoles); |
| childNode.PostBack = true; |
| node.Nodes.Add(childNode); |
| RecursivelyPopulate(childRow, childNode); |
| } |
| } |
| protected void ProcessComponent(RadTreeNode nodeClicked, string docType, string stageId, int subStageId, int objectType) |
| { |
| nodeClicked.Nodes.Clear(); |
| /*int objectType = Globals.nullInt; |
| if (stageId == Globals.Stage_NDI) |
| { |
| objectType = (int)Globals.StatusObjects.Part; |
| }*/ |
| //get information from database, and add new nodes |
| ArrayList dl = Persistence.TDMSHelpers.GetUploadedDocumentHelper().SelectComponentsByDocumentType(docType, stageId, subStageId, objectType) as ArrayList; |
| foreach (LxT.Common.Utilities.Enumerated.EnumeratedSimple es in dl) |
| { |
| RadTreeNode node = new RadTreeNode(es.Name); |
| node.Attributes.Add("ID", es.Id.ToString()); |
| node.PostBack = true; |
| node.ExpandMode = Telerik.Web.UI.TreeNodeExpandMode.ServerSide; |
| node.ImageUrl = "../images/folder.gif"; |
| node.Expanded = false; |
| node.Attributes.Add("comp", "yes"); |
| node.Attributes.Add("doc", docType); |
| node.Attributes.Add("stage", stageId); |
| node.Attributes.Add("substage", subStageId.ToString()); |
| node.Attributes.Add("objectType", objectType.ToString()); |
| node.Attributes.Add("readRoles", nodeClicked.Attributes["readRoles"]); |
| node.Attributes.Add("addRoles", nodeClicked.Attributes["addRoles"]); |
| node.Attributes.Add("editDeleteRoles", nodeClicked.Attributes["editDeleteRoles"]); |
| nodeClicked.Nodes.Add(node); |
| } |
| } |
| private RadTreeNode CreateNode(string text, bool expanded, string id, string documentType, |
| string stage, int subStage, int objectType, bool allowAdd, string folder, |
| string readRoles, string editDeleteRoles, string addRoles) |
| { |
| RadTreeNode node = new RadTreeNode(text); |
| node.Expanded = expanded; |
| node.ImageUrl = "../images/folder.gif"; |
| node.Attributes.Add("ID",id); |
| node.PostBack = true; |
| //node.ExpandMode = ExpandMode.ServerSide; |
| int Id = LxT.Common.Utilities.StringUtil.ToIntIndex(id); |
| node.Attributes.Add("folder", folder); |
| node.Attributes.Add("allowAdd", allowAdd.ToString()); |
| node.Attributes.Add("readRoles", readRoles); |
| node.Attributes.Add("addRoles", addRoles); |
| node.Attributes.Add("editDeleteRoles", editDeleteRoles); |
| if(!string.IsNullOrEmpty(documentType)) |
| { |
| node.PostBack = true; |
| node.ExpandMode = TreeNodeExpandMode.ServerSide; |
| node.Attributes.Add("doc", documentType); |
| if (!string.IsNullOrEmpty(stage)) |
| { |
| node.Attributes.Add("stage", stage.ToString()); |
| } |
| if (subStage != Globals.nullInt) |
| { |
| node.Attributes.Add("subStage", subStage.ToString()); |
| } |
| if (objectType != Globals.nullInt) |
| { |
| node.Attributes.Add("objectType", objectType.ToString()); |
| } |
| } |
| return node; |
| } |
| protected void ProcessSection(RadTreeNode nodeClicked) |
| { |
| nodeClicked.Nodes.Clear(); |
| int objectType = LxT.Common.Utilities.StringUtil.GetIntValue(nodeClicked.Attributes["objectType"], |
| Globals.nullInt); |
| string stageId = nodeClicked.Attributes["stage"]; |
| //get information from database, and add new nodes |
| ArrayList dl = Persistence.TDMSHelpers.GetUploadedDocumentHelper().SelectSectionsByDocumentType(nodeClicked.Attributes["doc"], |
| LxT.Common.Utilities.StringUtil.GetIntValue(nodeClicked.Attributes["ID"], 0), |
| nodeClicked.Attributes["stage"], |
| LxT.Common.Utilities.StringUtil.GetIntValue(nodeClicked.Attributes["substage"], |
| Globals.nullInt ), |
| objectType |
| ) as ArrayList; |
| foreach (LxT.Common.Utilities.Enumerated.EnumeratedSimpleTxt es in dl) |
| { |
| RadTreeNode node = new RadTreeNode(es.IdTxt); |
| node.Attributes.Add("ID",es.Name); |
| node.PostBack = true; |
| if (objectType != (int)Globals.StatusObjects.Section) |
| { |
| node.ExpandMode = Telerik.Web.UI.TreeNodeExpandMode.ServerSide; |
| } |
| node.ImageUrl = "../images/folder.gif"; |
| node.Expanded = false; |
| node.Attributes.Add("type", Globals.StatusObjects.Section.ToString()); |
| node.Attributes.Add("doc", nodeClicked.Attributes["doc"]); |
| node.Attributes.Add("stage", nodeClicked.Attributes["stage"]); |
| node.Attributes.Add("substage", nodeClicked.Attributes["substage"]); |
| node.Attributes.Add("readRoles", nodeClicked.Attributes["readRoles"]); |
| node.Attributes.Add("addRoles", nodeClicked.Attributes["addRoles"]); |
| node.Attributes.Add("editDeleteRoles", nodeClicked.Attributes["editDeleteRoles"]); |
| nodeClicked.Nodes.Add(node); |
| } |
| } |
| protected void ProcessPart(RadTreeNode nodeClicked) |
| { |
| nodeClicked.Nodes.Clear(); |
| //get information from database, and add new nodes |
| ArrayList dl = Persistence.TDMSHelpers.GetUploadedDocumentHelper().SelectPartsByDocumentType( |
| nodeClicked.Attributes["doc"], nodeClicked.Attributes["ID"], |
| nodeClicked.Attributes["stage"], |
| LxT.Common.Utilities.StringUtil.GetIntValue(nodeClicked.Attributes["substage"], |
| Globals.nullInt)) as ArrayList; |
| foreach (LxT.Common.Utilities.Enumerated.EnumeratedSimpleTxt es in dl) |
| { |
| if (!string.IsNullOrEmpty(es.IdTxt)) |
| { |
| RadTreeNode node = new RadTreeNode(es.IdTxt); |
| node.Attributes.Add("ID",es.Name); |
| node.PostBack = true; |
| node.PostBack = true; |
| node.ExpandMode = TreeNodeExpandMode.ServerSide; |
| node.ImageUrl = "../images/folder.gif"; |
| node.Attributes.Add("type", Globals.StatusObjects.Part.ToString()); |
| node.Attributes.Add("doc", nodeClicked.Attributes["doc"]); |
| node.Attributes.Add("partid", es.IdTxt.Substring(4, 3)); |
| node.Attributes.Add("section", nodeClicked.Attributes["ID"]); |
| node.Attributes.Add("stage", nodeClicked.Attributes["stage"]); |
| node.Attributes.Add("substage", nodeClicked.Attributes["substage"]); |
| node.Attributes.Add("readRoles", nodeClicked.Attributes["readRoles"]); |
| node.Attributes.Add("addRoles", nodeClicked.Attributes["addRoles"]); |
| node.Attributes.Add("editDeleteRoles", nodeClicked.Attributes["editDeleteRoles"]); |
| nodeClicked.Nodes.Add(node); |
| } |
| } |
| } |
| protected void ProcessSubPart(RadTreeNode nodeClicked) |
| { |
| nodeClicked.Nodes.Clear(); |
| //get information from database, and add new nodes |
| ArrayList dl = Persistence.TDMSHelpers.GetUploadedDocumentHelper().SelectSubPartsByDocumentType( |
| nodeClicked.Attributes["doc"], nodeClicked.Attributes["section"], |
| nodeClicked.Attributes["stage"], |
| LxT.Common.Utilities.StringUtil.GetIntValue(nodeClicked.Attributes["substage"], |
| Globals.nullInt), |
| nodeClicked.Attributes["partid"] |
| ) as ArrayList; |
| foreach (LxT.Common.Utilities.Enumerated.EnumeratedSimpleTxt es in dl) |
| { |
| if (!string.IsNullOrEmpty(es.IdTxt)) |
| { |
| RadTreeNode node = new RadTreeNode(es.IdTxt); |
| node.Attributes.Add("ID",es.Name); |
| node.PostBack = true; |
| node.ImageUrl = "../images/folder.gif"; |
| node.Attributes.Add("type", Globals.StatusObjects.Part.ToString()); |
| node.Attributes.Add("doc", nodeClicked.Attributes["doc"]); |
| node.Attributes.Add("stage", nodeClicked.Attributes["stage"]); |
| node.Attributes.Add("substage", nodeClicked.Attributes["substage"]); |
| node.Attributes.Add("readRoles", nodeClicked.Attributes["readRoles"]); |
| node.Attributes.Add("addRoles", nodeClicked.Attributes["addRoles"]); |
| node.Attributes.Add("editDeleteRoles", nodeClicked.Attributes["editDeleteRoles"]); |
| nodeClicked.Nodes.Add(node); |
| } |
| } |
| } |
| protected void RadTreeView1_NodeExpand(object o, RadTreeNodeEventArgs e) |
| { |
| if (e.Node.Attributes["type"] != null) |
| { |
| if (e.Node.Attributes["partid"] == null) |
| ProcessPart( e.Node); |
| else |
| ProcessSubPart( e.Node); |
| } |
| else if (e.Node.Attributes["comp"] != null) |
| { |
| ProcessSection(e.Node); |
| } |
| else if (!string.IsNullOrEmpty(e.Node.Attributes["doc"])) |
| { |
| //i actually want it to fail here if doc id is not integer |
| string doc = e.Node.Attributes["doc"]; |
| string stage = e.Node.Attributes["stage"]; |
| int subStage = LxT.Common.Utilities.StringUtil.GetIntValue(e.Node.Attributes["substage"], Globals.nullInt); |
| int objectType = LxT.Common.Utilities.StringUtil.GetIntValue(e.Node.Attributes["objecttype"], Globals.nullInt); |
| ProcessComponent( e.Node, doc, stage, subStage, objectType); |
| } |
| e.Node.Expanded = true; |
| } |
| protected void LoadGridData(RadTreeNode node) |
| { |
| MembershipUser u = Membership.GetUser(Page.User.Identity.Name); |
| ArrayList al = null; |
| //WebProfile p = new WebProfile(Context.Profile); |
| if (node == null) |
| { |
| RadGrid1.DataSource = new ArrayList(); |
| } |
| else |
| { |
| TDMSF15.Domain.DocumentPermissions dp = new TDMSF15.Domain.DocumentPermissions(); |
| dp.Read = node.Attributes["readRoles"]; |
| dp.Add = node.Attributes["addRoles"]; |
| dp.EditDelete = node.Attributes["editDeleteRoles"]; |
| if (node.Attributes["type"] != null) |
| { |
| if (node.Attributes["type"].CompareTo(Globals.StatusObjects.Section.ToString()) == 0) |
| { |
| al = new ArrayList(Persistence.TDMSHelpers.GetUploadedDocumentHelper().Select( |
| node.Attributes["ID"], null, node.Attributes["doc"], |
| node.Attributes["stage"], node.Attributes["substage"])); |
| } |
| else |
| { |
| al = new ArrayList(Persistence.TDMSHelpers.GetUploadedDocumentHelper().Select( |
| null, node.Attributes["ID"], node.Attributes["doc"], |
| node.Attributes["stage"], node.Attributes["substage"])); |
| } |
| hfDocId.Value = Domain.TDMSDocument.uploadedDocument.ToString(); |
| } |
| else |
| { |
| al = new ArrayList(Persistence.TDMSHelpers.GetDocumentHelper().SelectDocumentByTreeId(LxT.Common.Utilities.StringUtil.GetIntValue(node.Attributes["ID"], -1))); |
| hfDocId.Value = Domain.TDMSDocument.globalDocument.ToString(); |
| } |
| string[] roles = dp.readRoles; |
| bool read = false; |
| foreach (string r in roles) |
| { |
| if (!string.IsNullOrEmpty(r)) |
| { |
| if (Roles.IsUserInRole(u.UserName, r)) |
| { |
| read = true; |
| break; |
| } |
| } |
| } |
| if (!read) |
| { |
| foreach (Domain.TDMSDocument d in al) |
| { |
| d.Disabled = true; |
| } |
| } |
| RadGrid1.DataSource = al; |
| } |
| //RadGrid1.DataBind(); |
| /* System.Collections.Specialized.ListDictionary newValues = new |
| System.Collections.Specialized.ListDictionary(); |
| newValues["Description"] = ""; |
| //Insert the item and rebind |
| RadGrid1.MasterTableView.InsertItem(newValues); |
| RadGrid1.MasterTableView.IsItemInserted = true; |
| if (RadGrid1.MasterTableView.Items.Count == 0) |
| { |
| RadGrid1.MasterTableView.IsItemInserted = true; |
| }*/ |
| } |
| protected void RadGrid1_OnNeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| LoadGridData(rtn); |
| } |
| protected void RadTreeView1_NodeClick(object o, RadTreeNodeEventArgs e) |
| { |
| if (RadGrid1.MasterTableView.IsItemInserted == true) RadGrid1.MasterTableView.IsItemInserted = false; |
| MembershipUser u = Membership.GetUser(Page.User.Identity.Name); |
| string[] roles = null; |
| /*if (Roles.IsUserInRole(u.UserName, Globals.Role_DataEntry) || Roles.IsUserInRole(u.UserName, Globals.Role_Administrator)) |
| {*/ |
| TDMSF15.Domain.DocumentPermissions dp = new TDMSF15.Domain.DocumentPermissions(); |
| dp.Read = e.Node.Attributes["readRoles"]; |
| dp.Add = e.Node.Attributes["addRoles"]; |
| dp.EditDelete = e.Node.Attributes["editDeleteRoles"]; |
| bool add = LxT.Common.Utilities.StringUtil.GetBooleanValue(e.Node.Attributes["allowAdd"], false); |
| if (add) |
| { |
| roles = dp.addRoles; |
| add = false; |
| foreach (string r in roles) |
| { |
| if (!string.IsNullOrEmpty(r)) |
| { |
| if (Roles.IsUserInRole(u.UserName, r)) |
| { |
| add = true; |
| break; |
| } |
| } |
| } |
| if(add) |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; |
| else |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
| } |
| else |
| { |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
| } |
| roles = dp.editDeleteRoles; |
| bool editDelete = false; |
| foreach (string r in roles) |
| { |
| if (!string.IsNullOrEmpty(r)) |
| { |
| if (Roles.IsUserInRole(u.UserName, r)) |
| { |
| editDelete = true; |
| break; |
| } |
| } |
| } |
| if (editDelete) |
| { |
| cRadMenu.Enabled = true; |
| cRadMenu.Visible = true; |
| } |
| else |
| { |
| cRadMenu.Enabled = false; |
| cRadMenu.Visible = false; |
| } |
| /* } |
| else |
| { |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
| }*/ |
| rtn = e.Node; |
| RadGrid1.Rebind(); |
| //LoadGridData(e.Node); |
| } |
| protected virtual void RadGrid1_InsertCommand(object source,GridCommandEventArgs e) |
| { |
| //get File |
| // MembershipUser u = Membership.GetUser(Page.User.Identity.Name); |
| // if (!Roles.IsUserInRole(u.UserName, Globals.Role_Administrator) && |
| //!Roles.IsUserInRole(u.UserName, Globals.Role_DataEntry)) |
| // { |
| // cRadMenu.Enabled = false; |
| // cRadMenu.Visible = false; |
| // } |
| FileUpload fileUpload = (FileUpload)e.Item.FindControl("docFileUpload"); |
| TextBox description = (TextBox)e.Item.FindControl("txtDescription"); |
| rtn = this.RadTreeView1.SelectedNode; |
| bool add = LxT.Common.Utilities.StringUtil.GetBooleanValue(rtn.Attributes["allowAdd"], false); |
| if (fileUpload.HasFile && add) |
| { |
| int _fileSize = fileUpload.PostedFile.ContentLength; |
| string mds = Globals.Mds.Replace(' ', '-'); |
| string homeFolder = Path.Combine(mds, rtn.Attributes["folder"]); |
| //string homeFolder = rtn.Attributes["folder"]; |
| string _filePath = Path.Combine(Globals.uploadDir, homeFolder); |
| Persistence.DocumentHelper uph = Persistence.TDMSHelpers.GetDocumentHelper(); |
| uph.CreateDirectory(_filePath); |
| _filePath = Path.Combine(_filePath, fileUpload.FileName); |
| fileUpload.SaveAs(_filePath); |
| _filePath = Path.Combine(homeFolder, fileUpload.FileName); |
| Domain.TDMSDocument doc = new Domain.TDMSUploadedDocument(); |
| doc.createdBy = Page.User.Identity.Name; |
| doc.modifiedBy = Page.User.Identity.Name; |
| doc.Description = description.Text; |
| doc.Name = fileUpload.FileName; |
| doc.FileSize = _fileSize; |
| doc.FileLocation = _filePath; |
| doc.TreeId = Int32.Parse(rtn.Attributes["ID"]); |
| uph.Insert(doc); |
| RadGrid1.MasterTableView.IsItemInserted = false; |
| RadGrid1.Rebind(); |
| } |
| } |
| protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) |
| { |
| int radGridClickedRowIndex; |
| radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]); |
| /*RadTreeNode node*/ this.rtn = this.RadTreeView1.SelectedNode; |
| switch (e.Item.Text) |
| { |
| case "Delete": |
| int docId = (int) RadGrid1.MasterTableView.DataKeyValues[radGridClickedRowIndex]["Id"]; |
| if (docId > 0) |
| { |
| if(LxT.Common.Utilities.StringUtil.GetIntValue(this.hfDocId.Value, -1) |
| == Domain.TDMSDocument.globalDocument) |
| Persistence.TDMSHelpers.GetDocumentHelper().Delete(docId); |
| else |
| Persistence.TDMSHelpers.GetUploadedDocumentHelper().Delete(docId); |
| } |
| //LoadGridData(node); |
| RadGrid1.Rebind(); |
| break; |
| case "Edit": |
| RadGrid1.Items[radGridClickedRowIndex].Edit = true; |
| RadGrid1.Rebind(); |
| //LoadGridData(node); |
| break; |
| } |
| } |
| } |
| } |