void ControlTreeDataLoader.LoadData() { EwfPage.Instance.AddDisplayLink(this); // NOTE: Currently this hidden field will always be persisted in page state whether the page cares about that or not. We should put this decision into the // hands of the page, maybe by making ToggleButton sort of like a form control such that it takes a boolean value in its constructor and allows access to // its post back value. var controlsToggled = false; EwfHiddenField.Create( this, EwfPage.Instance.PageState.GetValue(this, pageStateKey, false).ToString(), postBackValue => controlsToggled = getControlsToggled(postBackValue), EwfPage.Instance.DataUpdate, out controlsToggledHiddenFieldValueGetter, out controlsToggledHiddenFieldClientIdGetter); EwfPage.Instance.DataUpdate.AddModificationMethod( () => AppRequestState.AddNonTransactionalModificationMethod(() => EwfPage.Instance.PageState.SetValue(this, pageStateKey, controlsToggled))); if (TagKey == HtmlTextWriterTag.Button) { PostBackButton.AddButtonAttributes(this); } this.AddJavaScriptEventScript(JsWritingMethods.onclick, handlerName + "()"); CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); textControl = ActionControlStyle.SetUpControl(this, "", width, height, w => base.Width = w); }
internal void SetUpClickableControl(WebControl clickableControl) { if (resource == null && postBack == null && script == "") { return; } clickableControl.CssClass = clickableControl.CssClass.ConcatenateWithSpace("ewfClickable"); if (resource != null && EwfPage.Instance.IsAutoDataUpdater) { postBack = EwfLink.GetLinkPostBack(resource); resource = null; } Func <string> scriptGetter; if (resource != null) { scriptGetter = () => "location.href = '" + EwfPage.Instance.GetClientUrl(resource.GetUrl()) + "'; return false"; } else if (postBack != null) { EwfPage.Instance.AddPostBack(postBack); scriptGetter = () => PostBackButton.GetPostBackScript(postBack); } else { scriptGetter = () => script; } // Defer script generation until after all controls have IDs. EwfPage.Instance.PreRender += delegate { clickableControl.AddJavaScriptEventScript(JsWritingMethods.onclick, scriptGetter()); }; }
void ControlTreeDataLoader.LoadData() { if (TagKey == HtmlTextWriterTag.Button) { PostBackButton.AddButtonAttributes(this); } CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); ActionControlStyle.SetUpControl(this, "", Unit.Empty, Unit.Empty, width => { }); }
// NOTE: EVERYTHING should be done here. We shouldn't have LoadData. We should audit everyone using this control and see if we can improve things. // NOTE: This should also be full of delegates that run when events (such as deleting a file) are occurring. // NOTE: There should be a way to tell if a file was uploaded. void ControlTreeDataLoader.LoadData() { if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); }), new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), false); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToSingleElementArray(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile)) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); var thumbnailControl = BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator); if (thumbnailControl != null) { Controls.Add(thumbnailControl); } Controls.Add(controlStack); }
public BlobFileManager(int?fileCollectionId) { this.fileCollectionId = fileCollectionId; if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); })); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToCollection(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile), false, (postBackValue, validator) => { }) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); this.AddControlsReturnThis(BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator)); Controls.Add(controlStack); }
/// <summary> /// Checks that WindowToLaunch has been set and applies the attributes for this LaunchWindowLink. /// </summary> void ControlTreeDataLoader.LoadData() { if (TagKey == HtmlTextWriterTag.Button) { PostBackButton.AddButtonAttributes(this); } CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); ActionControlStyle.SetUpControl(this, ""); if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), this); } }
private void buildNavigationBox() { var jumpList = SelectList.CreateDropDown( from i in Enumerable.Range(-3, 7) select SelectListItem.Create(i, formatDateTimeForJumpList(adjustDateByNumberOfIntervals(date, i))), 0, autoPostBack: true); jumpList.Width = JumpListWidth; var numIntervals = 0; EwfPage.Instance.DataUpdate.AddTopValidationMethod((pbv, validator) => numIntervals = jumpList.ValidateAndGetSelectedItemIdInPostBack(pbv, validator)); EwfPage.Instance.DataUpdate.AddModificationMethod(() => dateModificationMethod(adjustDateByNumberOfIntervals(date, numIntervals))); var previousLink = new PostBackButton( PostBack.CreateFull(id: "prev", firstModificationMethod: () => dateModificationMethod(adjustDateByNumberOfIntervals(date, -1))), PreviousButton, usesSubmitBehavior: false); var todayLink = new PostBackButton( PostBack.CreateFull(id: "today", firstModificationMethod: () => dateModificationMethod(DateTime.Today)), CurrentDateButton, usesSubmitBehavior: false); var nextLink = new PostBackButton( PostBack.CreateFull(id: "next", firstModificationMethod: () => dateModificationMethod(adjustDateByNumberOfIntervals(date, 1))), NextButton, usesSubmitBehavior: false); var table = new DynamicTable { CssClass = "calendarViewHeader ewfNavigationBoxHeader", IsStandard = false }; var navControls = new Panel(); foreach (var postBackButton in new List <PostBackButton> { previousLink, todayLink, nextLink }) { navControls.Controls.Add(postBackButton); } table.AddRow(jumpList, navControls.ToCell(new TableCellSetup(classes: "calendarViewNavButtons".ToSingleElementArray()))); Controls.Add(table); }
void ControlTreeDataLoader.LoadData() { if (toolTipControl == null) { throw new ApplicationException("ToolTipControl must be set on ToolTipLink"); } if (TagKey == HtmlTextWriterTag.Button) { PostBackButton.AddButtonAttributes(this); } // NOTE: When this control is rendered as an anchor, the presence of an onclick attribute is necessary for it to be selected properly by our action // control CSS elements. This hack would not be necessary if Telerik used the onclick attribute to open the tool tip. this.AddJavaScriptEventScript(JsWritingMethods.onclick, ""); CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); ActionControlStyle.SetUpControl(this, "", Unit.Empty, Unit.Empty, width => { }); new ToolTip(toolTipControl, this, title: ToolTipTitle ?? "", sticky: true); }
// NOTE: EVERYTHING should be done here. We shouldn't have LoadData. We should audit everyone using this control and see if we can improve things. // NOTE: This should also be full of delegates that run when events (such as deleting a file) are occurring. // NOTE: There should be a way to tell if a file was uploaded. void ControlTreeDataLoader.LoadData() { if( fileCollectionId != null ) file = BlobFileOps.GetFirstFileFromCollection( fileCollectionId.Value ); var controlStack = ControlStack.Create( true ); if( file != null ) { var download = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId( "ewfFile", file.FileId.ToString() ), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return new PostBackAction( new SecondaryResponse( new BlobFileResponse( BlobFileOps.GetFirstFileFromCollection( fileCollectionId.Value ).FileId, () => true ), false ) ); } ), new TextActionControlStyle( Translation.DownloadExisting + " (" + file.FileName + ")" ), false ); controlStack.AddControls( download ); } else if( !HideNoExistingFileMessage ) controlStack.AddControls( new Label { Text = Translation.NoExistingFile } ); uploadedFile = new EwfFileUpload(); if( file != null ) { uploadedFile.SetInitialDisplay( false ); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToSingleElementArray(), new TextActionControlStyle( Translation.ClickHereToReplaceExistingFile ) ) { AlternateText = "" }; controlStack.AddControls( replaceExistingFileLink ); } controlStack.AddControls( uploadedFile ); var thumbnailControl = BlobFileOps.GetThumbnailControl( file, ThumbnailResourceInfoCreator ); if( thumbnailControl != null ) Controls.Add( thumbnailControl ); Controls.Add( controlStack ); }
void ControlTreeDataLoader.LoadData() { using (MiniProfiler.Current.Step("EWF - Load table data")) { FormState.ExecuteWithDataModificationsAndDefaultAction( dataModifications, () => { if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any())) { Visible = false; return; } SetUpTableAndCaption(this, style, classes, caption, subCaption); var visibleItemGroupsAndItems = new List <Tuple <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> > >(); foreach (var itemGroup in itemGroups) { var visibleItems = itemGroup.Items.Take(CurrentItemLimit - visibleItemGroupsAndItems.Sum(i => i.Item2.Count)).Select(i => i()); visibleItemGroupsAndItems.Add(Tuple.Create <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> >(itemGroup, visibleItems.ToImmutableArray())); if (visibleItemGroupsAndItems.Sum(i => i.Item2.Count) == CurrentItemLimit) { break; } } var fields = GetFields(specifiedFields, headItems.AsReadOnly(), visibleItemGroupsAndItems.SelectMany(i => i.Item2)); if (!fields.Any()) { fields = new EwfTableField().ToCollection(); } addColumnSpecifications(fields); var allVisibleItems = new List <EwfTableItem>(); var itemLimitingUpdateRegionSet = new UpdateRegionSet(); var headRows = buildRows( getItemLimitingAndGeneralActionsItem(fields.Count, itemLimitingUpdateRegionSet).Concat(getItemActionsItem(fields.Count)).ToList(), Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(), null, false, null, null, allVisibleItems).Concat(buildRows(headItems, fields, null, true, null, null, allVisibleItems)).ToArray(); if (headRows.Any()) { Controls.Add(new WebControl(HtmlTextWriterTag.Thead).AddControlsReturnThis(headRows)); } var bodyRowGroupsAndRows = new List <Tuple <WebControl, ImmutableArray <Control> > >(); var updateRegionSetListsAndStaticRowGroupCounts = new List <Tuple <IReadOnlyCollection <UpdateRegionSet>, int> >(); for (var visibleGroupIndex = 0; visibleGroupIndex < visibleItemGroupsAndItems.Count; visibleGroupIndex += 1) { var groupAndItems = visibleItemGroupsAndItems[visibleGroupIndex]; var useContrastForFirstRow = visibleItemGroupsAndItems.Where((group, i) => i < visibleGroupIndex).Sum(i => i.Item2.Count) % 2 == 1; var groupBodyRows = buildRows(groupAndItems.Item2, fields, useContrastForFirstRow, false, null, null, allVisibleItems).ToImmutableArray(); var rowGroup = new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis( buildRows( groupAndItems.Item1.GetHeadItems(fields.Count), Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(), null, true, null, null, allVisibleItems).Concat(new NamingPlaceholder(groupBodyRows).ToCollection())); bodyRowGroupsAndRows.Add(Tuple.Create(rowGroup, groupBodyRows)); var cachedVisibleGroupIndex = visibleGroupIndex; EwfPage.Instance.AddUpdateRegionLinker( new LegacyUpdateRegionLinker( rowGroup, "tail", from region in groupAndItems.Item1.RemainingData.Value.TailUpdateRegions let staticRowCount = itemGroups[cachedVisibleGroupIndex].Items.Count - region.UpdatingItemCount select new LegacyPreModificationUpdateRegion(region.Sets, () => groupBodyRows.Skip(staticRowCount), staticRowCount.ToString), arg => groupBodyRows.Skip(int.Parse(arg)))); // If item limiting is enabled, include all subsequent item groups in tail update regions since any number of items could be appended. if (defaultItemLimit != DataRowLimit.Unlimited) { updateRegionSetListsAndStaticRowGroupCounts.Add( Tuple.Create <IReadOnlyCollection <UpdateRegionSet>, int>( groupAndItems.Item1.RemainingData.Value.TailUpdateRegions.SelectMany(i => i.Sets).ToImmutableArray(), visibleGroupIndex + 1)); } } Controls.Add(new NamingPlaceholder(bodyRowGroupsAndRows.Select(i => i.Item1))); if (defaultItemLimit != DataRowLimit.Unlimited) { var oldItemLimit = CurrentItemLimit; var lowerItemLimit = new Lazy <int>(() => Math.Min(oldItemLimit, CurrentItemLimit)); var itemLimitingTailUpdateRegionControlGetter = new Func <int, IEnumerable <Control> >( staticItemCount => { var rowCount = 0; for (var groupIndex = 0; groupIndex < bodyRowGroupsAndRows.Count; groupIndex += 1) { var rows = bodyRowGroupsAndRows[groupIndex].Item2; rowCount += rows.Length; if (rowCount < staticItemCount) { continue; } return(rows.Skip(rows.Length - (rowCount - staticItemCount)).Concat(bodyRowGroupsAndRows.Skip(groupIndex + 1).Select(i => i.Item1))); } return(ImmutableArray <Control> .Empty); }); EwfPage.Instance.AddUpdateRegionLinker( new LegacyUpdateRegionLinker( this, "itemLimitingTail", new LegacyPreModificationUpdateRegion( itemLimitingUpdateRegionSet.ToCollection(), () => itemLimitingTailUpdateRegionControlGetter(lowerItemLimit.Value), () => lowerItemLimit.Value.ToString()).ToCollection(), arg => itemLimitingTailUpdateRegionControlGetter(int.Parse(arg)))); } EwfPage.Instance.AddUpdateRegionLinker( new LegacyUpdateRegionLinker( this, "tail", from region in tailUpdateRegions.Select(i => new { sets = i.Sets, staticRowGroupCount = itemGroups.Count - i.UpdatingItemCount }) .Concat(updateRegionSetListsAndStaticRowGroupCounts.Select(i => new { sets = i.Item1, staticRowGroupCount = i.Item2 })) select new LegacyPreModificationUpdateRegion( region.sets, () => bodyRowGroupsAndRows.Skip(region.staticRowGroupCount).Select(i => i.Item1), region.staticRowGroupCount.ToString), arg => bodyRowGroupsAndRows.Skip(int.Parse(arg)).Select(i => i.Item1))); var itemCount = itemGroups.Sum(i => i.Items.Count); var itemLimitingRowGroup = new List <Control>(); if (CurrentItemLimit < itemCount) { var nextLimit = EnumTools.GetValues <DataRowLimit>().First(i => i > (DataRowLimit)CurrentItemLimit); var itemIncrementCount = Math.Min((int)nextLimit, itemCount) - CurrentItemLimit; var button = new PostBackButton( new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")), usesSubmitBehavior: false, postBack: PostBack.CreateIntermediate( itemLimitingUpdateRegionSet.ToCollection(), id: PostBack.GetCompositeId(postBackIdBase, "showMore"), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit))); var item = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Count))); var useContrast = visibleItemGroupsAndItems.Sum(i => i.Item2.Count) % 2 == 1; itemLimitingRowGroup.Add( new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis( buildRows( item.ToCollection().ToList(), Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(), useContrast, false, null, null, allVisibleItems))); } Controls.Add( new NamingPlaceholder( itemLimitingRowGroup, updateRegionSets: itemLimitingUpdateRegionSet.ToCollection() .Concat( itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).ToImmutableArray().Concat(tailUpdateRegions).SelectMany(i => i.Sets)))); // Assert that every visible item in the table has the same number of cells and store a data structure for below. var cellPlaceholderListsForItems = TableOps.BuildCellPlaceholderListsForItems(allVisibleItems, fields.Count); if (!disableEmptyFieldDetection) { AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems); } }); } }
void ControlTreeDataLoader.LoadData() { var url = ""; if (destinationResourceInfo != null && !(destinationResourceInfo.AlternativeMode is DisabledResourceMode)) { url = destinationResourceInfo.GetUrl(); Attributes.Add("href", this.GetClientUrl(url)); } if (isPostBackButton && url.Any()) { var postBack = GetLinkPostBack(destinationResourceInfo); EwfPage.Instance.AddPostBack(postBack); PreRender += delegate { this.AddJavaScriptEventScript(JsWritingMethods.onclick, PostBackButton.GetPostBackScript(postBack)); }; } if (navigatesInNewWindow) { Attributes.Add("target", "_blank"); } if (popUpWindowSettings != null && url.Any()) { this.AddJavaScriptEventScript(JsWritingMethods.onclick, JsWritingMethods.GetPopUpWindowScript(url, this, popUpWindowSettings) + " return false"); } if (navigatesInOpeningWindow && (destinationResourceInfo == null || url.Any())) { var openingWindowNavigationScript = destinationResourceInfo != null ? "opener.document.location = '" + this.GetClientUrl(url) + "'; " : ""; this.AddJavaScriptEventScript(JsWritingMethods.onclick, openingWindowNavigationScript + "window.close(); return false"); } CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); if (destinationResourceInfo != null && destinationResourceInfo.AlternativeMode is NewContentResourceMode) { CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.NewContentClass); } ActionControlStyle.SetUpControl(this, url, width, height, setWidth); if (destinationResourceInfo != null && destinationResourceInfo.AlternativeMode is DisabledResourceMode) { var message = (destinationResourceInfo.AlternativeMode as DisabledResourceMode).Message; new ToolTip(EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(message.Any() ? message : Translation.ThePageYouRequestedIsDisabled), this); } else if (toolTip != null || toolTipControl != null) { new ToolTip(toolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(toolTip), this); } }
void ControlTreeDataLoader.LoadData() { FormState.ExecuteWithDataModificationsAndDefaultAction( dataModifications, () => { var modifiedCaption = caption; // Display the caption and the sub caption. if (defaultDataRowLimit != DataRowLimit.Unlimited) { var formattedDataRowCount = dataRowCount.ToString("N0"); if (caption.Length > 0) { modifiedCaption += " (" + formattedDataRowCount + ")"; } else { modifiedCaption = formattedDataRowCount + " items"; } } if (modifiedCaption.Length > 0) { captionTable.Visible = true; captionStack.AddControls(new Label { Text = modifiedCaption, CssClass = "ewfCaption" }); } if (subCaption.Length > 0) { captionTable.Visible = true; captionStack.AddText(subCaption); } // Row limiting if (defaultDataRowLimit != DataRowLimit.Unlimited) { captionStack.AddControls( new ControlLine( new LiteralControl("Show:"), getDataRowLimitControl(DataRowLimit.Fifty), getDataRowLimitControl(DataRowLimit.FiveHundred), getDataRowLimitControl(DataRowLimit.Unlimited))); } // Excel export if (allowExportToExcel) { actionLinks.Add( new ActionButtonSetup( "Export to Excel", new PostBackButton(PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, "excel"), actionGetter: ExportToExcel)))); } // Action links foreach (var actionLink in actionLinks) { captionTable.Visible = true; actionLinkStack.AddControls(actionLink.BuildButton((text, icon) => new TextActionControlStyle(text, icon: icon), false)); } // Selected row actions foreach (var button in selectedRowActionButtonsToAdd) { captionTable.Visible = true; actionLinkStack.AddControls(button); } foreach (var buttonToMethod in selectedRowDataModificationsToMethods) { var dataModification = buttonToMethod.Key; var method = buttonToMethod.Value; dataModification.AddModificationMethod( () => { foreach (var rowSetup in rowSetups) { if (rowSetup.UniqueIdentifier != null && ((EwfCheckBox)rowSetup.UnderlyingTableRow.Cells[0].Controls[0]).IsCheckedInPostBack( AppRequestState.Instance.EwfPageRequestState.PostBackValues)) { method(rowSetup.UniqueIdentifier); } } }); } if (selectedRowDataModificationsToMethods.Any()) { foreach (var rowSetup in rowSetups) { var cell = new TableCell { Width = Unit.Percentage(5), CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable") }; if (rowSetup.UniqueIdentifier != null) { var firstDm = selectedRowDataModificationsToMethods.First().Key; var pb = firstDm as PostBack; cell.Controls.Add(new EwfCheckBox(false, action: new PostBackFormAction(pb ?? EwfPage.Instance.DataUpdatePostBack))); } rowSetup.UnderlyingTableRow.Cells.AddAt(0, cell); } } // Reordering var filteredRowSetups = rowSetups.Where(rs => rs.RankId.HasValue).ToList(); for (var i = 0; i < filteredRowSetups.Count; i++) { var previousRowSetup = (i == 0 ? null : filteredRowSetups[i - 1]); var rowSetup = filteredRowSetups[i]; var nextRowSetup = ((i == filteredRowSetups.Count - 1) ? null : filteredRowSetups[i + 1]); var controlLine = new ControlLine(new Control[0]); if (previousRowSetup != null) { var upButton = new PostBackButton( new ButtonActionControlStyle(@"/\", ButtonSize.ShrinkWrap), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"), firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value))); controlLine.AddControls(upButton); } if (nextRowSetup != null) { var downButton = new PostBackButton( new ButtonActionControlStyle(@"\/", ButtonSize.ShrinkWrap), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"), firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value))); controlLine.AddControls(downButton); } // NOTE: What about rows that don't have a RankId? They need to have an empty cell so all rows have the same cell count. var cell = new TableCell { Width = Unit.Percentage(10), CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable") }; cell.Controls.Add(controlLine); rowSetup.UnderlyingTableRow.Cells.Add(cell); } if (HideIfEmpty && !HasContentRows) { Visible = false; } }); }
private Section test6( Action<string> setValue ) { var pb = PostBack.CreateFull( id: "test6" ); var box = FormItem.Create( "", new EwfTextBox( "", postBack: pb ), validationGetter: control => new EwfValidation( ( pbv, v ) => setValue( control.GetPostBackValue( pbv ) ), pb ) ).Control; var button = new PostBackButton( pb, new ButtonActionControlStyle( "OK" ), usesSubmitBehavior: false ); return new Section( "Post-back with non-default submit button. This post-back-value shouldn't show up when the page's submit button is submitted.", new WebControl[] { box, button }, style: SectionStyle.Box ); }
private void buildNavigationBox() { var jumpList = SelectList.CreateDropDown( from i in Enumerable.Range( -3, 7 ) select SelectListItem.Create( i, formatDateTimeForJumpList( adjustDateByNumberOfIntervals( date, i ) ) ), 0, autoPostBack: true ); jumpList.Width = JumpListWidth; var numIntervals = 0; EwfPage.Instance.DataUpdate.AddTopValidationMethod( ( pbv, validator ) => numIntervals = jumpList.ValidateAndGetSelectedItemIdInPostBack( pbv, validator ) ); EwfPage.Instance.DataUpdate.AddModificationMethod( () => dateModificationMethod( adjustDateByNumberOfIntervals( date, numIntervals ) ) ); var previousLink = new PostBackButton( PostBack.CreateFull( id: "prev", firstModificationMethod: () => dateModificationMethod( adjustDateByNumberOfIntervals( date, -1 ) ) ), PreviousButton, usesSubmitBehavior: false ); var todayLink = new PostBackButton( PostBack.CreateFull( id: "today", firstModificationMethod: () => dateModificationMethod( DateTime.Today ) ), CurrentDateButton, usesSubmitBehavior: false ); var nextLink = new PostBackButton( PostBack.CreateFull( id: "next", firstModificationMethod: () => dateModificationMethod( adjustDateByNumberOfIntervals( date, 1 ) ) ), NextButton, usesSubmitBehavior: false ); var table = new DynamicTable { CssClass = "calendarViewHeader ewfNavigationBoxHeader", IsStandard = false }; var navControls = new Panel(); foreach( var postBackButton in new List<PostBackButton> { previousLink, todayLink, nextLink } ) navControls.Controls.Add( postBackButton ); table.AddRow( jumpList, navControls.ToCell( new TableCellSetup( classes: "calendarViewNavButtons".ToSingleElementArray() ) ) ); Controls.Add( table ); }
void ControlTreeDataLoader.LoadData() { var isTextarea = rows > 1; textBox = new WebControl(isTextarea ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input); PreRender += delegate { if (!isTextarea) { textBox.Attributes.Add("type", masksCharacters ? "password" : "text"); } textBox.Attributes.Add("name", UniqueID); if (isTextarea) { textBox.Attributes.Add("rows", rows.ToString()); } if (maxLength.HasValue) { textBox.Attributes.Add("maxlength", maxLength.Value.ToString()); } if (readOnly) { textBox.Attributes.Add("readonly", "readonly"); } if (disableBrowserAutoComplete || autoCompleteService != null) { textBox.Attributes.Add("autocomplete", "off"); } if (suggestSpellCheck.HasValue) { textBox.Attributes.Add("spellcheck", suggestSpellCheck.Value.ToString().ToLower()); } var value = formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues); var valueOrWatermark = watermarkText.Any() && !value.Any() ? watermarkText : value; if (isTextarea) { AddTextareaValue(textBox, valueOrWatermark); } else if (!masksCharacters) { textBox.Attributes.Add("value", valueOrWatermark); } }; Controls.Add(textBox); if (watermarkText.Any()) { textBox.AddJavaScriptEventScript(JsWritingMethods.onfocus, "if( value == '" + watermarkText + "' ) value = ''"); textBox.AddJavaScriptEventScript(JsWritingMethods.onblur, "if( value == '' ) value = '" + watermarkText + "'"); EwfPage.Instance.ClientScript.RegisterOnSubmitStatement( GetType(), UniqueID + "watermark", "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == '" + watermarkText + "'; } ).val( '' )"); } var jsNeededForImplicitSubmission = postBack != null || autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect); if (postBack == null && (autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack))) { postBack = EwfPage.Instance.DataUpdatePostBack; } if (postBack != null && (!isTextarea || autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack))) { EwfPage.Instance.AddPostBack(postBack); } if (!isTextarea) { PreRender += delegate { PostBackButton.EnsureImplicitSubmission(this, jsNeededForImplicitSubmission ? postBack : null); } } ; if (autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect)) { PreRender += delegate { // Use setTimeout to prevent keypress and change from *both* triggering post-backs at the same time when Enter is pressed after a text change. textBox.AddJavaScriptEventScript( JsWritingMethods.onchange, "setTimeout( function() { " + PostBackButton.GetPostBackScript(postBack, includeReturnFalse: false) + "; }, 0 )"); }; } if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), textBox); } } string ControlWithJsInitLogic.GetJsInitStatements() { var script = new StringBuilder(); if (watermarkText.Any()) { var restorationStatement = "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == ''; } ).val( '" + watermarkText + "' );"; // The first line is for bfcache browsers; the second is for all others. See http://stackoverflow.com/q/1195440/35349. script.Append("$( window ).on( 'pagehide', function() { " + restorationStatement + " } );"); script.Append(restorationStatement); } if (autoCompleteService != null) { const int delay = 250; // Default delay is 300 ms. const int minCharacters = 3; var autocompleteOptions = new List <Tuple <string, string> >(); autocompleteOptions.Add(Tuple.Create("delay", delay.ToString())); autocompleteOptions.Add(Tuple.Create("minLength", minCharacters.ToString())); autocompleteOptions.Add(Tuple.Create("source", "'" + autoCompleteService.GetUrl() + "'")); if (autoCompleteOption != AutoCompleteOption.NoPostBack) { var handler = "function( event, ui ) {{ $( '#{0}' ).val( ui.item.value ); {1}; }}".FormatWith( textBox.ClientID, PostBackButton.GetPostBackScript(postBack)); autocompleteOptions.Add(Tuple.Create("select", handler)); } script.Append( @"$( '#" + textBox.ClientID + "' ).autocomplete( {{ {0} }} );".FormatWith( autocompleteOptions.Select(o => "{0}: {1}".FormatWith(o.Item1, o.Item2)).GetCommaDelimitedStringFromCollection())); } return(script.ToString()); } FormValue FormControl.FormValue { get { return(formValue); } }