Ejemplo n.º 1
0
		public static DropdownTab DropdownTab(TabPanel parent , string text, string iconClass)
		{
			var o = UI.Cast<DropdownTab> (DropdownMenu(text,iconClass));

			o.SetToAtomProperty ("add", (Action<Tab>)((tab) => {
				o.Nav.Add(tab.Item);
				parent.Content.Append (tab.Body);
			}));

			var i = new HtmlListItem ("dropdown");
			jQuery.FromElement (i).Append (o).Append (o.Nav);
			parent.Links.Append (i);
			return o;
		}
Ejemplo n.º 2
0
		public static Nav CreateNavBase(string navType=null)
		{
			var l = new HtmlList ("nav{0}".Fmt (navType.IsNullOrEmpty()?"":" "+navType)).As<Nav>();

			l.SetToAtomProperty("addDropdownMenu", (Action<DropdownMenu> )(m=>{
				var i = new HtmlListItem();
				m.AddTo(i);
				if(l.ClassList.Contains("nav-list")) jQuery.Select(".caret",m).AddClass("pull-right");
				l.Append(i);
			}));

			l.SetToAtomProperty("addDropdownSubmenu", (Action<DropdownSubmenu> )(m=>{
				var i = new HtmlListItem();
				m.AddTo(i);
				l.Append(i);
			}));

			l.SetToAtomProperty ("addItem", (Action<HtmlListItem>)((i) => jQuery.FromElement (l).Append (i)));

			l.SetToAtomProperty ("removeItem", (Action<string>)
			                     ((v) => jQuery.Select (SelectFn(v), l).Remove ()));

			l.SetToAtomProperty ("removeAll", (Action)(() => jQuery.FromElement (l).Empty ()));

			l.SetToAtomProperty ("disableItem", (Action<string,bool?>)((v,d) => {
				var j = jQuery.Select (SelectFn(v), l);
				if (!d.HasValue || d.Value)
					j.AddClass ("disabled");
				else
					j.RemoveClass ("disabled");
			}));

			l.SetToAtomProperty ("disableAll", (Action<bool?>)((d) => {
				var j = jQuery.Select (ItemSelector, l);
				if (!d.HasValue || d.Value)
					j.AddClass ("disabled");
				else
					j.RemoveClass ("disabled");
			}));

			l.SetToAtomProperty ("addValue", (Action<string,string,jQueryEventHandler,bool,string>)
			                     ((v,t,h,d,i) => l.Add (new NavItem(v, t, h, d, i))));

			l.SetToAtomProperty ("addDivider", (Action<string>)((v) => l.Add (new HtmlListItem(v))));

			l.SetToAtomProperty ("loadList", (Action<IEnumerable<string>>)((list) => {
				StringBuilder s = new StringBuilder ();
				int v = 0;
				foreach (var d in list) {
					s.Append (new NavItem( (v++).ToString(), d).OuterHTML);
				}
				jQuery.FromElement (l).Append (s.ToString());
			}));

			l.SetToAtomProperty ("loadNavItemList", (Action<IEnumerable<NavItem>>)((lst) => {
				StringBuilder s = new StringBuilder ();
				foreach (var d in lst) {
					s.Append (d.OuterHTML);
				}
				jQuery.FromElement (l).Append (s.ToString());
			}));

			l.SetToAtomProperty ("loadData", (Action<IEnumerable<object>,Func<object,NavItem>>)((lst,fn) => {
				StringBuilder s = new StringBuilder ();
				foreach (var d in lst) {
					s.Append (fn(d).OuterHTML);
				}
				jQuery.FromElement (l).Append (s.ToString());
			}));


			l.SetToAtomProperty ("getItem", (Func<string, NavItem>)(v => {
				var j = jQuery.Select (SelectFn(v), l);
				if(j.Length== 0) return null;
				return j.GetElement(0).As<NavItem>();
			}));

			l.SetToAtomProperty ("selectItem", (Action<string>)(v => {
				var j = jQuery.Select (SelectFn(v), l);
				if(j.Length==0 || j.HasClass("disabled")) return;
				j.Trigger(SelectEventName);
			}));

			l.SetToAtomProperty ("add_selected", (Action<jQueryEventHandler>)
			                     (ev => On(l, SelectEventName , ev, ItemSelector)));

			l.SetToAtomProperty ("remove_selected", (Action<jQueryEventHandler>)
			                     (ev => Off (l,SelectEventName, ev, ItemSelector)));

			return l;
		}
Ejemplo n.º 3
0
		public static NavItem NavItem(string value, string text, jQueryEventHandler handler, bool disable, string iconClassName)
		{
			var i = new HtmlListItem ().As<NavItem>();
			i.SetAttribute ("value", value);

			if (disable)
				jQuery.FromElement (i).AddClass ("disabled");

			i.Handler = handler;

			i._icon = new CssIcon (iconClassName);
			i._anchor = new Anchor ();

			jQuery.FromElement (i._anchor).Append (i._icon);
			i._anchor.Text = text??value;

			jQuery.FromElement (i).Append (i._anchor);


			SetToAtomProperty (i, "get_text", (Func<string>)(() => i._anchor.Text));
			SetToAtomProperty (i, "set_text", (Action<string>)((v) => i._anchor.Text=v));

			SetToAtomProperty (i, "get_value", (Func<string>)(() => i.GetAttribute ("value").ToString () ?? "" ));
			SetToAtomProperty (i, "set_value", (Action<string>)((v) => i.SetAttribute ("value", v) ));

			SetToAtomProperty (i, "get_iconClass", (Func<string>)(() => i._icon.ClassName));
			SetToAtomProperty (i, "set_iconClass", (Action<string>)((v) => i._icon.ClassName = v));

			SetToAtomProperty (i, "is_disabled", (Func<bool>)(() =>
			             jQuery.FromElement (i).HasClass ("disabled")));

			SetToAtomProperty (i, "disable",(Action<bool>)((d) =>{
				if(d)jQuery.FromElement (i).AddClass ("disabled");
				else jQuery.FromElement (i).RemoveClass ("disabled");
			}));

			i.Clicked += ev=>{
				if( i.Disabled ) return;
				var h = i.Handler;
				if (h!=null) h(ev);
			};

			return i;

		}