private string GetClickScript( BocBooleanValueRenderingContext renderingContext, BocBooleanValueResourceSet resourceSet, bool isEnabled) { string script = "return false;"; if (!isEnabled) { return(script); } string requiredFlag = renderingContext.Control.IsRequired ? "true" : "false"; var scriptBuilder = new StringBuilder(500); scriptBuilder.Append("BocBooleanValue_SelectNextCheckboxValue ("); scriptBuilder.Append("'").Append(resourceSet.ResourceKey).Append("'"); scriptBuilder.Append(", "); scriptBuilder.Append("$(this).parent().children('a').children('img').first()[0]"); scriptBuilder.Append(", "); if (renderingContext.Control.ShowDescription) { scriptBuilder.Append("$(this).parent().children('span').first()[0]"); } else { scriptBuilder.Append("null"); } scriptBuilder.Append(", "); scriptBuilder.Append("$(this).parent().children('input').first()[0]"); scriptBuilder.Append(", "); scriptBuilder.Append(requiredFlag); scriptBuilder.Append(", "); AppendStringValueOrNullToScript(scriptBuilder, renderingContext.Control.TrueDescription); scriptBuilder.Append(", "); AppendStringValueOrNullToScript(scriptBuilder, renderingContext.Control.FalseDescription); scriptBuilder.Append(", "); AppendStringValueOrNullToScript(scriptBuilder, renderingContext.Control.NullDescription); scriptBuilder.Append(");"); if (renderingContext.Control.IsAutoPostBackEnabled) { scriptBuilder.Append(renderingContext.Control.Page.ClientScript.GetPostBackEventReference(renderingContext.Control, "")).Append(";"); } scriptBuilder.Append("return false;"); return(scriptBuilder.ToString()); }
private BocBooleanValueResourceSet CreateDefaultResourceSet(IBocBooleanValue control) { IResourceManager resourceManager = control.GetResourceManager(); BocBooleanValueResourceSet resourceSet = new BocBooleanValueResourceSet( c_defaultResourceGroup, GetResourceUrl(c_trueIcon), GetResourceUrl(c_falseIcon), GetResourceUrl(c_nullIcon), resourceManager.GetString(BocBooleanValue.ResourceIdentifier.TrueDescription), resourceManager.GetString(BocBooleanValue.ResourceIdentifier.FalseDescription), resourceManager.GetString(BocBooleanValue.ResourceIdentifier.NullDescription) ); return(resourceSet); }
private void PrepareVisibleControls( BocBooleanValueRenderingContext renderingContext, BocBooleanValueResourceSet resourceSet, Image imageControl, Label labelControl) { string imageUrl; string description; if (!renderingContext.Control.Value.HasValue) { imageUrl = resourceSet.NullIconUrl; description = string.IsNullOrEmpty(renderingContext.Control.NullDescription) ? resourceSet.DefaultNullDescription : renderingContext.Control.NullDescription; } else if (renderingContext.Control.Value.Value) { imageUrl = resourceSet.TrueIconUrl; description = string.IsNullOrEmpty(renderingContext.Control.TrueDescription) ? resourceSet.DefaultTrueDescription : renderingContext.Control.TrueDescription; } else { imageUrl = resourceSet.FalseIconUrl; description = string.IsNullOrEmpty(renderingContext.Control.FalseDescription) ? resourceSet.DefaultFalseDescription : renderingContext.Control.FalseDescription; } imageControl.AlternateText = description; imageControl.ImageUrl = imageUrl; if (renderingContext.Control.ShowDescription) { labelControl.Text = description; } labelControl.Width = Unit.Empty; labelControl.Height = Unit.Empty; labelControl.ApplyStyle(renderingContext.Control.LabelStyle); }
public void SetUp() { Initialize(); _resourceSet = new BocBooleanValueResourceSet( "ResourceKey", "TrueIconUrl", "FalseIconUrl", "NullIconUrl", "DefaultTrueDescription", "DefaultFalseDescription", "DefaultNullDescription" ); _booleanValue = MockRepository.GenerateMock <IBocBooleanValue>(); var clientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>(); _booleanValue.Stub(mock => mock.ClientID).Return(c_clientID); _booleanValue.Stub(stub => stub.ControlType).Return("BocBooleanValue"); _booleanValue.Stub(mock => mock.GetValueName()).Return(c_keyValueName); _booleanValue.Stub(mock => mock.GetDisplayValueName()).Return(c_displayValueName); string startupScriptKey = typeof(BocBooleanValueRenderer).FullName + "_Startup_" + _resourceSet.ResourceKey; _startupScript = string.Format( "BocBooleanValue_InitializeGlobals ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}');", _resourceSet.ResourceKey, "true", "false", "null", ScriptUtility.EscapeClientScript(_resourceSet.DefaultTrueDescription), ScriptUtility.EscapeClientScript(_resourceSet.DefaultFalseDescription), ScriptUtility.EscapeClientScript(_resourceSet.DefaultNullDescription), _resourceSet.TrueIconUrl, _resourceSet.FalseIconUrl, _resourceSet.NullIconUrl); clientScriptManagerMock.Expect(mock => mock.RegisterStartupScriptBlock(_booleanValue, typeof(BocBooleanValueRenderer), startupScriptKey, _startupScript)); clientScriptManagerMock.Stub(mock => mock.IsStartupScriptRegistered(Arg <Type> .Is.NotNull, Arg <string> .Is.NotNull)).Return(false); clientScriptManagerMock.Stub(mock => mock.GetPostBackEventReference(_booleanValue, string.Empty)).Return(c_postbackEventReference); _clickScript = "BocBooleanValue_SelectNextCheckboxValue ('ResourceKey', $(this).parent().children('a').children('img').first()[0], " + "$(this).parent().children('span').first()[0], $(this).parent().children('input').first()[0], false, " + "'" + c_trueDescription + "', '" + c_falseDescription + "', '" + c_nullDescription + "');return false;"; _keyDownScript = "BocBooleanValue_OnKeyDown (this);"; var pageStub = MockRepository.GenerateStub <IPage>(); pageStub.Stub(stub => stub.ClientScript).Return(clientScriptManagerMock); _booleanValue.Stub(mock => mock.Value).PropertyBehavior(); _booleanValue.Stub(mock => mock.IsDesignMode).Return(false); _booleanValue.Stub(mock => mock.ShowDescription).Return(true); _booleanValue.Stub(mock => mock.Page).Return(pageStub); _booleanValue.Stub(mock => mock.TrueDescription).Return(c_trueDescription); _booleanValue.Stub(mock => mock.FalseDescription).Return(c_falseDescription); _booleanValue.Stub(mock => mock.NullDescription).Return(c_nullDescription); _booleanValue.Stub(mock => mock.CssClass).PropertyBehavior(); StateBag stateBag = new StateBag(); _booleanValue.Stub(mock => mock.Attributes).Return(new AttributeCollection(stateBag)); _booleanValue.Stub(mock => mock.Style).Return(_booleanValue.Attributes.CssStyle); _booleanValue.Stub(mock => mock.LabelStyle).Return(new Style(stateBag)); _booleanValue.Stub(mock => mock.ControlStyle).Return(new Style(stateBag)); _booleanValue.Stub(stub => stub.CreateResourceSet()).Return(_resourceSet); }
private void RegisterStarupScriptIfNeeded(BocBooleanValueRenderingContext renderingContext, BocBooleanValueResourceSet resourceSet) { string startUpScriptKey = s_startUpScriptKeyPrefix + resourceSet.ResourceKey; if (!renderingContext.Control.Page.ClientScript.IsStartupScriptRegistered(typeof(BocBooleanValueRenderer), startUpScriptKey)) { string trueValue = true.ToString(); string falseValue = false.ToString(); string nullValue = c_nullString; string startupScript = string.Format( "BocBooleanValue_InitializeGlobals ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}');", resourceSet.ResourceKey, trueValue, falseValue, nullValue, ScriptUtility.EscapeClientScript(resourceSet.DefaultTrueDescription), ScriptUtility.EscapeClientScript(resourceSet.DefaultFalseDescription), ScriptUtility.EscapeClientScript(resourceSet.DefaultNullDescription), resourceSet.TrueIconUrl, resourceSet.FalseIconUrl, resourceSet.NullIconUrl); renderingContext.Control.Page.ClientScript.RegisterStartupScriptBlock( renderingContext.Control, typeof(BocBooleanValueRenderer), startUpScriptKey, startupScript); } }
private string GetClickScript(BocBooleanValueRenderingContext renderingContext, BocBooleanValueResourceSet resourceSet, Image imageControl, Label labelControl, HiddenField hiddenFieldControl, bool isEnabled) { string script = "return false;"; if (!isEnabled) { return(script); } string requiredFlag = renderingContext.Control.IsRequired ? "true" : "false"; string image = "document.getElementById ('" + imageControl.ClientID + "')"; string label = renderingContext.Control.ShowDescription ? "document.getElementById ('" + labelControl.ClientID + "')" : "null"; string hiddenField = "document.getElementById ('" + hiddenFieldControl.ClientID + "')"; script = "BocBooleanValue_SelectNextCheckboxValue (" + "'" + resourceSet.ResourceKey + "', " + image + ", " + label + ", " + hiddenField + ", " + requiredFlag + ", " + (string.IsNullOrEmpty(renderingContext.Control.TrueDescription) ? "null" : "'" + ScriptUtility.EscapeClientScript(renderingContext.Control.TrueDescription) + "'") + ", " + (string.IsNullOrEmpty(renderingContext.Control.FalseDescription) ? "null" : "'" + ScriptUtility.EscapeClientScript(renderingContext.Control.FalseDescription) + "'") + ", " + (string.IsNullOrEmpty(renderingContext.Control.NullDescription) ? "null" : "'" + ScriptUtility.EscapeClientScript(renderingContext.Control.NullDescription) + "'") + ");"; if (renderingContext.Control.IsAutoPostBackEnabled) { script += renderingContext.Control.Page.ClientScript.GetPostBackEventReference(renderingContext.Control, "") + ";"; } script += "return false;"; return(script); }