protected void Page_Load(object sender, EventArgs e) { BXIBlock block = null; sectionId = base.GetRequestInt("id"); if (sectionId > 0) hfSectionId.Value = sectionId.ToString(); else Int32.TryParse(hfSectionId.Value, out sectionId); iblockId = base.GetRequestInt("iblock_id"); if (sectionId > 0) { //section = BXIBlockSection.GetById(sectionId,BXTextEncoder.EmptyTextEncoder); BXIBlockSectionCollection sectionCol = BXIBlockSection.GetList( new BXFilter(new BXFilterItem(BXIBlockSection.Fields.ID, BXSqlFilterOperators.Equal, sectionId)), null, iblockId > 0 ? new BXSelectAdd(BXIBlockSection.Fields.CustomFields[iblockId]) : null, null, BXTextEncoder.EmptyTextEncoder ); if ((section = sectionCol.Count > 0 ? sectionCol[0] : null) == null) { sectionId = 0; hfSectionId.Value = sectionId.ToString(); } } if (sectionId > 0) { iblockId = section.IBlockId; hfIBlockId.Value = iblockId.ToString(); block = BXIBlock.GetById(iblockId, BXTextEncoder.EmptyTextEncoder); typeId = block.TypeId; hfTypeId.Value = typeId.ToString(); } else { //iblockId = base.GetRequestInt("iblock_id"); if (iblockId > 0) hfIBlockId.Value = iblockId.ToString(); else Int32.TryParse(hfIBlockId.Value, out iblockId); block = null; if (iblockId > 0) { block = BXIBlock.GetById(iblockId, BXTextEncoder.EmptyTextEncoder); if (block == null) { iblockId = 0; hfIBlockId.Value = iblockId.ToString(); } } if (iblockId > 0) { typeId = block.TypeId; hfTypeId.Value = typeId.ToString(); } else { typeId = base.GetRequestInt("type_id"); Page.Response.Redirect(String.Format("IBlockAdmin.aspx?type_id={0}", typeId)); } } propertyEntryName = BXIBlockSection.GetCustomFieldsKey(iblockId); currentIBlock = block; int sectionIdTmp = base.GetRequestInt("section_id"); if (sectionIdTmp > 0) { redirectSectionId = sectionIdTmp; if (sectionId > 0 && section.SectionId != redirectSectionId) redirectSectionId = section.SectionId; } else { redirectSectionId = 0; if (sectionId > 0) redirectSectionId = section.SectionId; } if (!this.BXUser.IsCanOperate("IBlockView", "iblock", iblockId)) BXAuthentication.AuthenticationRequired(); currentUserCanModifySection = this.BXUser.IsCanOperate("IBlockModifyStructure", "iblock", iblockId.ToString()); string success = base.GetRequestString("success"); if ("Y".Equals(success, StringComparison.InvariantCultureIgnoreCase)) successMessage.Visible = true; else successMessage.Visible = false; bxweDescription.Visible = BXIBlockModule.UseVisualEditor(); tbDescription.Visible = !BXIBlockModule.UseVisualEditor(); rblDescriptionType.Visible = !BXIBlockModule.UseVisualEditor(); CustomFieldList1.EntityId = propertyEntryName; if (section != null) CustomFieldList1.Load(section.CustomValues); if (!Page.IsPostBack) LoadData(); }
private bool CreateSection() { try { if (!currentUserCanModifySection) throw new Exception(GetMessageRaw("Exception.YouDontHaveRightsToCreateNewSection")); BXFile fImage = SaveFile("preview"); BXFile fDetailImage = SaveFile("detail"); int sort; int.TryParse(tbSort.Text, out sort); int parentSectionId; int.TryParse(ddlParentSection.SelectedValue, out parentSectionId); redirectSectionId = parentSectionId; string descr = null; BXTextType descrType = BXTextType.Text; if (BXIBlockModule.UseVisualEditor()) { descr = bxweDescription.Content; descrType = (bxweDescription.StartMode == BXWebEditor.StartModeType.PlainText) ? BXTextType.Text : BXTextType.Html; } else { descr = tbDescription.Text; descrType = ("text".Equals(rblDescriptionType.SelectedValue, StringComparison.InvariantCultureIgnoreCase) ? BXTextType.Text : BXTextType.Html); } section =new BXIBlockSection( iblockId, parentSectionId, tbName.Text ); section.Active = cbActive.Checked; section.Sort = (sort > 0 ? sort : 500); section.ImageId = (fImage != null) ? fImage.Id : 0; section.DetailImageId = (fDetailImage != null) ? fDetailImage.Id : 0; section.Description = descr; section.DescriptionType = descrType; section.Code = tbCode.Text; section.XmlId = tbXmlId.Text; section.CreatedBy = (this.BXUser.Identity as BXIdentity).Id; if (CustomFieldList1.HasItems) section.CustomValues.Override(CustomFieldList1.Save()); section.Create(); if (section.Id <= 0 ) throw new Exception(GetMessageRaw("Exception.SectionCreationFailed")); sectionId = section.Id; hfSectionId.Value = sectionId.ToString(); iblockId = section.IBlockId; hfIBlockId.Value = iblockId.ToString(); //if (CustomFieldList1.HasItems) // BXCustomEntityManager.SaveEntity(propertyEntryName, section.Id, CustomFieldList1.Save()); return true; } catch (BXEventException e) { foreach (string s in e.Messages) errorMassage.AddErrorMessage(s); } catch (Exception e) { errorMassage.AddErrorMessage(e.Message); } return false; }
public void SaveAlbumInfo(int parentAlbumId, string title, string description) { BXIBlockSection sec; if (AlbumId > 0 && this.Action=="edit") { sec = BXIBlockSection.GetById(AlbumId); sec.SectionId = parentAlbumId; sec.Name = title; sec.DescriptionType = BXTextType.Text; sec.Description = description; sec.Update(); } else if (this.Action=="add"){ sec = new BXIBlockSection(Parameters.Get("IBlockId", 0), parentAlbumId, title ); sec.Active = true; sec.Description = description; sec.DescriptionType = BXTextType.Text; sec.Sort=500; sec.Code=string.Empty; sec.XmlId = string.Empty; sec.Save(); } string url; if (!String.IsNullOrEmpty(BackUrl)) url = BackUrl; else if (EnableSef) { Results["AlbumId"] = (parentAlbumId > 0) ? parentAlbumId.ToString() : string.Empty; if (AlbumId > 0) { url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), ComponentCache); } else { url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, ComponentCache); } } else { if (parentAlbumId > 0) { url = string.Format("{0}?{1}={2}", Request.Path, Parameters.Get<string>("ParamAlbum", "Album"), parentAlbumId); } else { url = Request.Path; } } if (Parameters.Get<bool>("EnableAjax", false) && !IsComponentDesignMode) { string script = string.Format("setTimeout(\"PageTransfer('{0}');\",0);", url); ScriptManager.RegisterStartupScript(Page, typeof(Page), "AJAX_BUTTON_CLICK", script, true); } else Response.Redirect(url); }
private void InitPage() { if (initCalled) return; initCalled = true; iblockId = base.GetRequestInt("iblock_id"); if (iblockId > 0) hfIBlockId.Value = iblockId.ToString(); Int32.TryParse(hfIBlockId.Value, out iblockId); if (iblockId > 0) { iblock = BXIBlock.GetById(iblockId); if (iblock == null) { iblockId = 0; hfIBlockId.Value = iblockId.ToString(); } } if (iblockId > 0) { typeId = iblock.TypeId; hfTypeId.Value = typeId.ToString(); type = BXIBlockType.GetById(typeId); if (type == null) Response.Redirect("IBlockTypeList.aspx"); } else { typeId = base.GetRequestInt("type_id"); if (typeId > 0) hfTypeId.Value = typeId.ToString(); Int32.TryParse(hfTypeId.Value, out typeId); Page.Response.Redirect(String.Format("IBlockAdmin.aspx?type_id={0}", typeId)); } if (!BXIBlock.IsUserCanOperate(iblockId, BXIBlock.Operations.IBlockAdminRead)) BXAuthentication.AuthenticationRequired(); filterSectionId.Values.Add(new ListItem(GetMessageRaw("Any"), "")); filterSectionId.Values.Add(new ListItem(GetMessageRaw("TopLevel"), "0")); BXIBlockSectionCollection sections = BXIBlockSection.GetList( new BXFilter(new BXFilterItem(BXIBlockSection.Fields.IBlock.ID, BXSqlFilterOperators.Equal, iblockId)), new BXOrderBy(new BXOrderByPair(BXIBlockSection.Fields.LeftMargin, BXOrderByDirection.Asc)), null, null, BXTextEncoder.EmptyTextEncoder ); foreach (BXIBlockSection section in sections) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < section.DepthLevel; i++) sb.Append(" . "); sb.Append(section.Name); filterSectionId.Values.Add(new ListItem(sb.ToString(), section.Id.ToString())); } canModifySections = BXIBlock.IsUserCanOperate(iblockId, BXIBlock.Operations.IBlockModifySections); canModifyElements = BXIBlock.IsUserCanOperate(iblockId, BXIBlock.Operations.IBlockModifyElements); AddSectionButton.Visible = canModifySections; AddElementButton.Visible = canModifyElements; int sectionId = GetElementSectionId(0); currentSection = (sectionId == 0) ? null :BXIBlockSection.GetById(sectionId); }
public override bool ProcessCommand(string commandName, BXParamsBag<object> commandParameters, System.Collections.Generic.List<string> commandErrors) { int albumId = (int)commandParameters["Id"]; int parentAlbumId = (int)commandParameters["ParentId"]; BXIBlockSection sec; if (albumId > 0) { sec = BXIBlockSection.GetById(albumId); sec.SectionId = parentAlbumId; sec.Name = commandParameters["Title"].ToString(); sec.Description = commandParameters["Description"].ToString(); sec.Update(); } else { sec = new BXIBlockSection(Parameters.Get("IBlockId", 0), parentAlbumId, commandParameters["Title"].ToString() ); sec.Active = true; sec.Description = commandParameters["Description"].ToString(); sec.DescriptionType = BXTextType.Text; sec.Sort = 500; sec.Code = string.Empty; sec.XmlId = string.Empty; sec.Save(); } string url; if (EnableSef) { Results["AlbumId"] = (albumId > 0) ? albumId.ToString() : string.Empty; if (albumId > 0) { url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), ComponentCache); } else { url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, ComponentCache); } } else { if (albumId > 0) { url = string.Format("{0}?{1}={2}", Request.Path, Parameters.Get<string>("ParamAlbum", "Album"), albumId); } else { url = Request.Path; } } if (Parameters.Get<bool>("EnableAjax", false) && !IsComponentDesignMode) { string script = string.Format("setTimeout(\"PageTransfer('{0}');\",0);", url); ScriptManager.RegisterStartupScript(Page, typeof(Page), "AJAX_BUTTON_CLICK", script, true); } else Response.Redirect(url); return true; //return base.ProcessCommand(commandName, commandParameters, commandErrors); }