コード例 #1
0
        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);
            }
        }
コード例 #2
0
        private string GetItemScript(int itemIndex)
        {
            const string itemTemplate = "new ListMenuItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8})";
            var          menuItem     = (WebMenuItem)_control.MenuItems[itemIndex];

            string href;
            string target = "null";

            if (menuItem.Command.Type == CommandType.Href)
            {
                href   = menuItem.Command.HrefCommand.FormatHref(itemIndex.ToString(), menuItem.ItemID);
                href   = "'" + href + "'";
                target = "'" + menuItem.Command.HrefCommand.Target + "'";
            }
            else
            {
                string argument = itemIndex.ToString();
                href = _control.Page.ClientScript.GetPostBackClientHyperlink(_control, argument) + ";";
                href = ScriptUtility.EscapeClientScript(href);
                href = "'" + href + "'";
            }

            return(string.Format(
                       itemTemplate,
                       _control.ClientID + "_" + itemIndex,
                       menuItem.Category,
                       menuItem.Style != WebMenuItemStyle.Icon ? "'" + menuItem.Text + "'" : "null",
                       menuItem.Style != WebMenuItemStyle.Text ? "'" + menuItem.Icon.Url.TrimStart('~') + "'" : "null",
                       menuItem.Style != WebMenuItemStyle.Text ? "'" + menuItem.DisabledIcon.Url.TrimStart('~') + "'" : "null",
                       (int)menuItem.RequiredSelection,
                       (itemIndex == 4) ? "true" : "false",
                       href,
                       target));
        }
コード例 #3
0
        private void AppendMenuItem(DropDownMenuRenderingContext renderingContext, StringBuilder stringBuilder, WebMenuItem menuItem, int menuItemIndex)
        {
            string href   = "null";
            string target = "null";

            bool isCommandEnabled = true;

            if (menuItem.Command != null)
            {
                bool isActive = menuItem.Command.Show == CommandShow.Always ||
                                renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.ReadOnly ||
                                !renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.EditMode;

                isCommandEnabled = isActive && menuItem.Command.Type != CommandType.None;
                if (isCommandEnabled)
                {
                    bool isPostBackCommand = menuItem.Command.Type == CommandType.Event ||
                                             menuItem.Command.Type == CommandType.WxeFunction;
                    if (isPostBackCommand)
                    {
                        // Clientside script creates an anchor with href="#" and onclick=function
                        string argument = menuItemIndex.ToString();
                        href = renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, argument);
                        href = ScriptUtility.EscapeClientScript(href);
                        href = "'" + href + "'";
                    }
                    else if (menuItem.Command.Type == CommandType.Href)
                    {
                        href   = menuItem.Command.HrefCommand.FormatHref(menuItemIndex.ToString(), menuItem.ItemID);
                        href   = "'" + renderingContext.Control.ResolveClientUrl(href) + "'";
                        target = "'" + menuItem.Command.HrefCommand.Target + "'";
                    }
                }
            }

            bool showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;

            string icon         = GetIconUrl(renderingContext, menuItem, showIcon);
            string disabledIcon = GetDisabledIconUrl(renderingContext, menuItem, showIcon);
            string text         = showText ? "'" + menuItem.Text + "'" : "null";

            bool isDisabled = !menuItem.EvaluateEnabled() || !isCommandEnabled;

            stringBuilder.AppendFormat(
                "\t\tnew DropDownMenu_ItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8})",
                menuItemIndex,
                menuItem.Category,
                text,
                icon,
                disabledIcon,
                (int)menuItem.RequiredSelection,
                isDisabled ? "true" : "false",
                href,
                target);
        }
コード例 #4
0
 protected void AppendStringValueOrNullToScript(StringBuilder scriptBuilder, string stringValue)
 {
     if (string.IsNullOrEmpty(stringValue))
     {
         scriptBuilder.Append("null");
     }
     else
     {
         scriptBuilder.Append("'").Append(ScriptUtility.EscapeClientScript(stringValue)).Append("'");
     }
 }
コード例 #5
0
        private string GetStatusIsSubmittingMessage()
        {
            string           statusIsSubmittingMessage = "null";
            IResourceManager resourceManager           = GetResourceManager();

            if (_page.IsStatusIsSubmittingMessageEnabled)
            {
                string temp;
                if (string.IsNullOrEmpty(_page.StatusIsSubmittingMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.StatusIsSubmittingMessage);
                }
                else
                {
                    temp = _page.StatusIsSubmittingMessage;
                }
                statusIsSubmittingMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";
            }

            return(statusIsSubmittingMessage);
        }
コード例 #6
0
        private string GetAbortMessage()
        {
            string           abortMessage    = "null";
            IResourceManager resourceManager = GetResourceManager();

            if (_page.IsAbortConfirmationEnabled)
            {
                string temp;
                if (string.IsNullOrEmpty(_page.AbortMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.AbortMessage);
                }
                else
                {
                    temp = _page.AbortMessage;
                }
                abortMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";
            }

            return(abortMessage);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        private void AppendMenuItem(DropDownMenuRenderingContext renderingContext, StringBuilder stringBuilder, WebMenuItem menuItem, int menuItemIndex)
        {
            string href   = "null";
            string target = "null";

            bool isCommandEnabled = true;
            var  diagnosticMetadataTriggersNavigation = false;
            var  diagnosticMetadataTriggersPostBack   = false;

            if (menuItem.Command != null)
            {
                bool isActive = menuItem.Command.Show == CommandShow.Always ||
                                renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.ReadOnly ||
                                !renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.EditMode;

                isCommandEnabled = isActive && menuItem.Command.Type != CommandType.None;
                if (isCommandEnabled)
                {
                    bool isPostBackCommand = menuItem.Command.Type == CommandType.Event ||
                                             menuItem.Command.Type == CommandType.WxeFunction;
                    if (isPostBackCommand)
                    {
                        // Clientside script creates an anchor with href="#" and onclick=function
                        string argument = menuItemIndex.ToString();
                        href = renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, argument);
                        href = ScriptUtility.EscapeClientScript(href);
                        href = "'" + href + "'";

                        diagnosticMetadataTriggersPostBack = true;
                    }
                    else if (menuItem.Command.Type == CommandType.Href)
                    {
                        href   = menuItem.Command.HrefCommand.FormatHref(menuItemIndex.ToString(), menuItem.ItemID);
                        href   = "'" + renderingContext.Control.ResolveClientUrl(href) + "'";
                        target = "'" + menuItem.Command.HrefCommand.Target + "'";

                        diagnosticMetadataTriggersNavigation = true;
                    }
                }
            }

            bool showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;

            string icon                   = GetIconUrl(renderingContext, menuItem, showIcon);
            string disabledIcon           = GetDisabledIconUrl(renderingContext, menuItem, showIcon);
            string text                   = showText ? "'" + menuItem.Text + "'" : "null";
            string diagnosticMetadataText = showText ? menuItem.Text : "";

            var diagnosticMetadataJson = "null";

            if (IsDiagnosticMetadataRenderingEnabled)
            {
                var htmlID = renderingContext.Control.ClientID + "_" + menuItemIndex;
                // Note: the output of diagnosticMetadataText is enclosed by single quotes, as it may contain double quotes.
                diagnosticMetadataJson = string.Format(
                    "{{\"{0}\":\"{1}\", \"{2}\":\"{3}\", \"{4}\":\"{5}\", \"{6}\":\"{7}\", \"{8}\":'{9}'}}",
                    HtmlTextWriterAttribute.Id,
                    htmlID,
                    DiagnosticMetadataAttributes.TriggersNavigation,
                    diagnosticMetadataTriggersNavigation.ToString().ToLower(),
                    DiagnosticMetadataAttributes.TriggersPostBack,
                    diagnosticMetadataTriggersPostBack.ToString().ToLower(),
                    DiagnosticMetadataAttributes.ItemID,
                    menuItem.ItemID,
                    DiagnosticMetadataAttributes.Content,
                    HtmlUtility.StripHtmlTags(diagnosticMetadataText ?? ""));
            }

            bool isDisabled = !menuItem.EvaluateEnabled() || !isCommandEnabled;

            stringBuilder.AppendFormat(
                "\t\tnew DropDownMenu_ItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})",
                menuItemIndex,
                menuItem.Category,
                text,
                icon,
                disabledIcon,
                (int)menuItem.RequiredSelection,
                isDisabled ? "true" : "false",
                href,
                target,
                diagnosticMetadataJson);
        }
コード例 #9
0
        private void RegisterWxeInitializationScript()
        {
            IResourceManager resourceManager = GetResourceManager();

            string     temp;
            WxeContext wxeContext = WxeContext.Current;

            int    refreshInterval = 0;
            string refreshPath     = "null";
            string abortPath       = "null";

            if (WxeHandler.IsSessionManagementEnabled)
            {
                //  Ensure the registration of "__doPostBack" on the page.
                temp = _page.ClientScript.GetPostBackEventReference(_page, null);

                bool isAbortEnabled = _page.IsAbortEnabled;

                string resumePath = wxeContext.GetPath(wxeContext.FunctionToken, null);

                if (WxeHandler.IsSessionRefreshEnabled)
                {
                    refreshInterval = WxeHandler.RefreshInterval * 60000;
                    refreshPath     = "'" + resumePath + "&" + WxeHandler.Parameters.WxeAction + "=" + WxeHandler.Actions.Refresh + "'";
                }

                if (isAbortEnabled)
                {
                    abortPath = "'" + resumePath + "&" + WxeHandler.Parameters.WxeAction + "=" + WxeHandler.Actions.Abort + "'";
                }
            }

            string statusIsAbortingMessage = "null";
            string statusIsCachedMessage   = "null";

            if (_page.AreStatusMessagesEnabled)
            {
                if (string.IsNullOrEmpty(_page.StatusIsAbortingMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.StatusIsAbortingMessage);
                }
                else
                {
                    temp = _page.StatusIsAbortingMessage;
                }
                statusIsAbortingMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";

                if (string.IsNullOrEmpty(_page.StatusIsCachedMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.StatusIsCachedMessage);
                }
                else
                {
                    temp = _page.StatusIsCachedMessage;
                }
                statusIsCachedMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";
            }

            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnLoad, "WxePage_OnLoad", "WxePage_OnLoad");
            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnAbort, "WxePage_OnAbort", "WxePage_OnAbort");
            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnUnload, "WxePage_OnUnload", "WxePage_OnUnload");
            _page.CheckFormStateFunction = "WxePage_CheckFormState";

            string isCacheDetectionEnabled = _page.AreOutOfSequencePostBacksEnabled ? "false" : "true";

            StringBuilder initScript = new StringBuilder(500);

            initScript.AppendLine("WxePage_Context.SetInstance (new WxePage_Context (");
            initScript.AppendLine("    ").Append(isCacheDetectionEnabled).AppendLine(",");
            initScript.AppendLine("    ").Append(refreshInterval).AppendLine(",");
            initScript.AppendLine("    ").Append(refreshPath).AppendLine(",");
            initScript.AppendLine("    ").Append(abortPath).AppendLine(",");
            initScript.AppendLine("    ").Append(statusIsAbortingMessage).AppendLine(",");
            initScript.AppendLine("    ").Append(statusIsCachedMessage).AppendLine("));");

            _page.ClientScript.RegisterClientScriptBlock(_page, typeof(WxePageInfo), "wxeInitialize", initScript.ToString());
        }
コード例 #10
0
        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);
        }