Ejemplo n.º 1
0
        public JsonNetResult ChangeButtonCheckStateAjax(int identifier, bool checkValue)
        {
            JsonModel jsonModel;

            try
            {
                StateButtonModel buttonModel = StateButtonManager.GetButton(identifier);
                buttonModel.IsChecked = checkValue;
                jsonModel             = JsonModel.CreateFromObject(new { Identifier = identifier, IsChecked = buttonModel.IsChecked });
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }
            return(new JsonNetResult(jsonModel));
        }
        /// <summary>
        /// Compose html for a state button
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="model"></param>
        /// <param name="isResultButton">True if it's a result button</param>
        /// <returns></returns>
        public static MvcHtmlString StateButton(this HtmlHelper htmlHelper, StateButtonModel model, bool isResultButton)
        {
            var buttonTooltip = model.Tooltip;

            if (string.IsNullOrEmpty(buttonTooltip))
            {
                buttonTooltip = string.Format("{0} {1}", Resources.Resource.SharedButtonSettingToolTip, model.Title);
            }

            var buttonClass = "btn-default";

            if (model.IsEnabled)
            {
                buttonClass =
                    model.IsCurrent ?
                    "btn-active"
                        :
                    isResultButton && model.HasSettings ?
                    "btn-success"
                            :
                    model.IsSettingsDefault ?
                    "btn-primary"
                                :
                    "btn-changedsettings";
            }

            var checkButtonIconClass = "icon-check-empty";
            var checkButtonTooltip   = Resources.Resource.SharedButtonCheckToolTip;

            if (model.IsChecked)
            {
                checkButtonIconClass = "icon-check";
                checkButtonTooltip   = Resources.Resource.SharedButtonUnCheckToolTip;
            }

            var buttonHtml = string.Empty;

            if (!isResultButton)
            {
                var infoAttributes = InitButtonAttributes(
                    string.Format("noTooltip {0}", buttonClass),
                    null,
                    true);

                infoAttributes.Add("title", model.Title);
                infoAttributes.Add("data-toggle", "popover");
                infoAttributes.Add("data-placement", "top");
                infoAttributes.Add("data-trigger", "click");
                infoAttributes.Add("data-content", buttonTooltip);

                buttonHtml += GetElementHtml(
                    "span",
                    infoAttributes,
                    GetElementHtml("i", new Dictionary <string, string>()
                {
                    { "class", "icon-white icon-info" }
                }));
            }

            if (model.Identifier == StateButtonIdentifier.DataProvidersMetadataSearch)
            {
                var attributes = InitButtonAttributes(
                    buttonClass,
                    GetUrl(htmlHelper, model.DynamicPageInfo.Controller, model.DynamicPageInfo.Action),
                    model.IsEnabled);

                attributes.Add("title", buttonTooltip);
                attributes.Add("data-placement", "bottom");

                buttonHtml += GetBootstrapButtonHtml(
                    attributes,
                    string.Format(
                        "{0}&nbsp;{1}",
                        model.Title,
                        GetElementHtml("i", new Dictionary <string, string>()
                {
                    { "class", "icon-search icon-white" }
                })));
            }
            else
            {
                if (model.ShowCheckbox && !isResultButton)
                {
                    var attributes = InitButtonAttributes(
                        buttonClass,
                        "#",
                        model.IsEnabled);

                    attributes.Add("title", checkButtonTooltip);
                    attributes.Add("data-placement", "bottom");
                    attributes.Add(
                        "onclick",
                        string.Format("AnalysisPortal.checkBoxClick(this, {0}); return false;", (int)model.Identifier));

                    buttonHtml += GetBootstrapButtonHtml(
                        attributes,
                        GetElementHtml("i", new Dictionary <string, string>()
                    {
                        { "class", string.Format("{0} icon-white", checkButtonIconClass) }
                    }));
                }

                var buttonAttributes = InitButtonAttributes(
                    buttonClass,
                    GetUrl(htmlHelper, model.DynamicPageInfo.Controller, model.DynamicPageInfo.Action),
                    model.IsEnabled);

                buttonHtml += GetBootstrapButtonHtml(
                    buttonAttributes,
                    string.Format(
                        "{0}{1}",
                        string.IsNullOrEmpty(model.Title) ? string.Empty : string.Format("{0}&nbsp;&nbsp;", model.Title),
                        isResultButton ?
                        GetElementHtml("i", new Dictionary <string, string>()
                {
                    { "class", string.Format("icon-white {0}", "icon-bar-chart") },
                    { "data-identifier", model.Identifier.ToString() }
                }) : null));

                if (model.Children != null)
                {
                    var dropDownAttributes = InitButtonAttributes(
                        buttonClass,
                        "#",
                        model.IsEnabled);

                    dropDownAttributes.Add("data-toggle", "dropdown");

                    //Create the link that will trigger the drop down and add the icon to the link
                    buttonHtml += GetBootstrapButtonHtml(
                        dropDownAttributes,
                        GetElementHtml("i", new Dictionary <string, string>()
                    {
                        { "class", "icon-caret-down icon-white" }
                    }));

                    //Create the drop down menu
                    var dropDownMenu = new TagBuilder("ul")
                    {
                        InnerHtml = string.Join(
                            "",
                            from b in model.Children
                            where !string.IsNullOrEmpty(b.Title)
                            select new TagBuilder("li")
                        {
                            Attributes = { new KeyValuePair <string, string>("class", b.IsCurrent ? "btn-active" : "") },
                            InnerHtml  = htmlHelper.ActionLink(
                                b.Title,
                                b.DynamicPageInfo.Action,
                                b.DynamicPageInfo.Controller,
                                null,
                                b.IsEnabled ? (object)new { title = b.Tooltip, data_placement = "right" } : new { disabled = "disabled" }).ToHtmlString()
                        }.ToString())
                    };
                    dropDownMenu.MergeAttribute("class", "dropdown-menu");

                    buttonHtml += dropDownMenu.ToString();
                }
            }

            //Create a div and add all controls to it
            var btnGroup = new TagBuilder("div")
            {
                InnerHtml = buttonHtml
            };

            btnGroup.MergeAttribute("class", "btn-group");

            return(MvcHtmlString.Create(btnGroup.ToString()));
        }