Exemplo n.º 1
0
        public static MenuItemBuilder AddToolbarItem(this MenuItemFactory menu,
                                                     object ocaption, object ohint,
                                                     object actionname, object controllername, object objectRoute,
                                                     object useRouteDic, bool IsSubMenu = false,
                                                     string html_id = "")
        {
            RouteValueDictionary rdict;

            if (!(bool)(useRouteDic ?? false))
            {
                rdict = new RouteValueDictionary(objectRoute);
            }
            else if (objectRoute != null)
            {
                rdict = (RouteValueDictionary)objectRoute;
            }
            else
            {
                rdict = new RouteValueDictionary();
            }

            string str_action, str_controller, str_area;

            str_action = UpMisc.SplitActionString(actionname, out str_controller, out str_area);
            try
            {
                if (str_controller == "")
                {
                    str_controller = (string)controllername.ToString();
                }
                if (str_area != "")
                {
                    if (rdict.ContainsKey("area")) //containkey ไม่สนใจตัวพิมพ์เล็ก/ใหญ่ ใส่อย่างไรก็ได้
                    {
                        rdict.Remove("area");
                    }
                    rdict.Add("area", str_area);
                }
            }
            catch
            {
            }

            string classname, attacheddata = "";

            if (!IsSubMenu)
            {
                classname = "toolbaritem";
            }
            else
            {
                classname = "toolbarsubmenu";
            }

            string          caption = (ocaption ?? "-").ToString();
            MenuItemBuilder result  = menu.Add().Text(" " + caption);

            if ((str_action != null) && (str_action.ToString() != "") &&
                (str_controller != null) && (str_controller != ""))
            {
                if (html_id == "toolbardatebutton") //ถ้าเป็นปุ่มวันที่ ไม่ต้องใส่ action ให้
                {
                    classname += "";                //ไม่ถือว่า disable นะ
                }
                else if ((html_id == "toolbarsavebutton") ||
                         (html_id == "toolbarsaveclosebutton") ||
                         (html_id == "toolbargiveupbutton") ||
                         (html_id == "toolbardeletebutton") ||
                         (html_id == "tbdetailsavebutton") ||
                         (html_id == "tbdetailgiveupbutton") ||
                         (html_id == "tbdetailclosebutton")) //ถ้าเป็นปุ่ม Save/GiveUp/Delete action ที่ส่งมาคือชื่อปุ่ม
                {
                    attacheddata = str_action.ToString();
                }
                else if ((str_action.ToString() != "#"))
                {
                    result = result.Action(str_action.ToString(), str_controller.ToString(), rdict);
                }
            }
            else
            {
                if (IsSubMenu)
                {
                    result = result.Visible(false);
                }
                result     = result.Enabled(false);
                classname += " toolbarinactive";
            }

            //ใส่ hint ให้ปุ่มซะหน่อย
            string hint = (ohint ?? "").ToString();

            if (hint == "")
            {
                hint = caption;
            }
            result = result.ImageHtmlAttributes(new { @class = classname, style = "margin-left:auto;margin-right:auto;" });
            if (html_id == "")
            {
                result = result.HtmlAttributes(new { @class = classname, title = hint });
            }
            else
            {
                result = result.HtmlAttributes(new { @class = classname, title = hint, id = html_id, data = attacheddata });
            }
            return(result);
        }