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() { 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(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); }
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); }
/// <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, "", Unit.Empty, Unit.Empty, width => { }); 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); }
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()); }
string EtherealControl.GetJsInitStatements() { return("$( '#" + control.ClientID + "' ).dialog( { autoOpen: " + open.ToString().ToLower() + ", width: 600, hide: 'fade', show: 'fade', " + (postBack != null ? "buttons: { 'Cancel': function() { $( this ).dialog( 'close' ) }, 'Continue': function() { " + PostBackButton.GetPostBackScript(postBack) + "; } }, " : "") + "draggable: false, modal: true, resizable: false" + (title.Any() ? ", title: '" + title + "'" : "") + " } );"); }
void ControlTreeDataLoader.LoadData() { 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 => new TextActionControlStyle(text), 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(DataAccessState.Current.PrimaryDatabaseConnection, 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, postBack: 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( PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"), firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value)), new ButtonActionControlStyle(@"/\", ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false); controlLine.AddControls(upButton); } if (nextRowSetup != null) { var downButton = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"), firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value)), new ButtonActionControlStyle(@"\/", ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false); 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; } }
void ControlTreeDataLoader.LoadData() { if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any())) { Visible = false; return; } SetUpTableAndCaption(this, style, classes, caption, subCaption); var visibleItemGroupsAndItems = new List <KeyValuePair <EwfTableItemGroup, List <EwfTableItem> > >(); foreach (var itemGroup in itemGroups) { var visibleItems = itemGroup.Items.Take(CurrentItemLimit - visibleItemGroupsAndItems.Sum(i => i.Value.Count)).Select(i => i()); visibleItemGroupsAndItems.Add(new KeyValuePair <EwfTableItemGroup, List <EwfTableItem> >(itemGroup, visibleItems.ToList())); if (visibleItemGroupsAndItems.Sum(i => i.Value.Count) == CurrentItemLimit) { break; } } var fields = GetFields(specifiedFields, headItems.AsReadOnly(), visibleItemGroupsAndItems.SelectMany(i => i.Value)); if (!fields.Any()) { fields = new EwfTableField().ToSingleElementArray(); } addColumnSpecifications(fields); var allVisibleItems = new List <EwfTableItem>(); var headRows = buildRows( getItemLimitingAndGeneralActionsItem(fields.Length).Concat(getItemActionsItem(fields.Length)).ToList(), Enumerable.Repeat(new EwfTableField(), fields.Length).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)); } for (var visibleGroupIndex = 0; visibleGroupIndex < visibleItemGroupsAndItems.Count; visibleGroupIndex += 1) { var groupAndItems = visibleItemGroupsAndItems[visibleGroupIndex]; var groupHeadItems = new List <EwfTableItem>(); // NOTE: Set up group-level general actions. EwfTableItemGroup.GetGroupHeadItem( int visibleItemsInGroup ) // NOTE: Set up group-level check box selection (if enabled) and group-level check box actions (if they exist). Make sure all items in the group have identical lists. EwfTableItemGroup.GetGroupItemActionsItem() // NOTE: Check box actions should show an error if clicked and no items are selected; this caused confusion in M+Vision. // NOTE: Combine the above into one method that returns a list of items. var useContrastForFirstRow = visibleItemGroupsAndItems.Where((group, i) => i < visibleGroupIndex).Sum(i => i.Value.Count) % 2 == 1; Controls.Add( new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis( buildRows(groupHeadItems, Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(), null, true, null, null, allVisibleItems) .Concat(buildRows(groupAndItems.Value, fields, useContrastForFirstRow, false, null, null, allVisibleItems)))); } var itemCount = itemGroups.Sum(i => i.Items.Count); 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( PostBack.CreateFull( id: PostBack.GetCompositeId(postBackIdBase, "showMore"), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit)), new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")), usesSubmitBehavior: false); var item = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Length))); var useContrast = visibleItemGroupsAndItems.Sum(i => i.Value.Count) % 2 == 1; Controls.Add( new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis( buildRows( item.ToSingleElementArray().ToList(), Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(), useContrast, false, null, null, allVisibleItems))); } // 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.Length); 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() { 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) { EwfPage.Instance.AddPostBack(postBack); } 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); } }