public BLResponse<Author> GetAuthors(BLRequest blRequest){ return Client.Execute(proxy=>{ var u= Authors.Get(proxy); var r = new BLResponse<Author>(); if(!IsCayita(blRequest)) r.Result=u; else { HtmlDiv div = new HtmlDiv( ){Name="Author"}; var itag = new HtmlIcon(){ Class="button-add icon-plus-sign", Name="Author" }; div.AddHtmlTag(itag); div.AddHtmlTag(BuildAuthorGrid(u)); HtmlDiv formDiv = new HtmlDiv(){Id="div-form-edit"}; formDiv.Style.Hidden=true; var form = BuildAuthorForm(); form.AddCssClass("span6"); form.Title="Author's Data"; formDiv.AddHtmlTag(form); r.Html= div.ToString()+formDiv.ToString(); } return r; }); }
HtmlGrid<User> BuildUserGrid (List<User> users){ var grid = new HtmlGrid<User>(){Name="User"}; grid.DataSource= users; grid.Css = new Bootstrap(); grid.AddGridColum( c=> { c.CellRenderFunc=(row,index,dt)=> row.Id; c.HeaderText="Id"; c.Hidden=true; }); grid.AddGridColum( c=> { c.CellRenderFunc= (row,index,dt)=> row.Name; c.HeaderText="Name"; }); grid.AddGridColum( c=> { c.HeaderText="City"; c.CellRenderFunc=(row,index,dt)=> row.City; }); grid.AddGridColum( c=> { c.CellRenderFunc= (row,index,dt)=> row.Address; c.HeaderText="Address"; }); grid.AddGridColum( c=> { c.HeaderText="Birthday"; c.CellRenderFunc=(row,index,dt)=> row.DoB.Format("MM/dd/yyy"); c.CellStyle.TextAlign="center"; }); grid.AddGridColum( c=> { c.HeaderText="E-Mail"; c.CellRenderFunc=(row,index,dt)=> row.Email; }); grid.AddGridColum( c=> { c.HeaderText="Rating"; c.CellRenderFunc=(row,index,dt)=>{ dt.Parent.AddCssClass(row.Rating==10?"success":row.Rating<6?"warning":"" ); return row.Rating; }; c.CellStyle.TextAlign="center"; }); grid.AddGridColum( c=> { c.HeaderText="Level"; c.CellRenderFunc=(row,index,dt)=> { c.CellStyle.Color= row.Level=="A"?"green": row.Level=="B"?"orange":"red"; return row.Level; }; c.CellStyle.TextAlign="center"; }); grid.AddGridColum( c=> { c.HeaderText="Active?"; c.CellRenderFunc=(row,index,dt)=> { dt.Parent.Style.Color=row.IsActive?"black":"grey"; //return row.IsActive.Format(); var itag = new HtmlIcon(){ Class= row.IsActive? "icon-ok-circle":"icon-ban-circle", }; return itag; }; c.CellStyle.TextAlign="center"; }); grid.AddGridColum( c=> { c.HeaderText=""; c.CellStyle.Width=new WidthProperty(){Unit="%",Value=10}; c.CellRenderFunc=(row,index,dt)=>{ var idiv = new HtmlDiv(); var itag = new HtmlIcon(){ Name="User", Class="button-edit icon-edit", Url= "api/User/read/{0}".Fmt( row.Id) }; itag.Style.Margin.Left= 5; idiv.AddHtmlTag(itag); itag = new HtmlIcon(){ Class="button-delete icon-remove", Url= "api/User/destroy/{0}".Fmt( row.Id) }; itag.Style.Margin.Left= 5; itag.Style.Color="red"; idiv.AddHtmlTag(itag); return idiv; }; }); return grid; }
HtmlGrid<Author> BuildAuthorGrid (List<Author> users){ var grid = new HtmlGrid<Author>(){Name="Author"}; grid.DataSource= users; grid.Css = new Bootstrap(); grid.AddGridColum( c=> { c.CellRenderFunc=(row,index,dt)=> row.Id; c.HeaderText="Id"; c.Hidden=true; }); grid.AddGridColum( c=> { c.CellRenderFunc= (row,index,dt)=> row.Name; c.HeaderText="Name"; }); grid.AddGridColum( c=> { c.HeaderText="City"; c.CellRenderFunc=(row,index,dt)=> row.City; }); grid.AddGridColum( c=> { c.CellRenderFunc= (row,index,dt)=> row.Comments; c.HeaderText="Comments"; }); grid.AddGridColum( c=> { c.HeaderText="Active?"; c.CellRenderFunc=(row,index,dt)=> { dt.Parent.Style.Color=row.Active?"black":"grey"; var itag = new HtmlIcon(){ Class= row.Active? "icon-ok-circle":"icon-ban-circle", }; return itag; }; c.CellStyle.TextAlign="center"; }); grid.AddGridColum( c=> { c.HeaderText=""; c.CellStyle.Width=new WidthProperty(){Unit="%",Value=10}; c.CellRenderFunc=(row,index,dt)=>{ var idiv = new HtmlDiv(); var itag = new HtmlIcon(){ Name="Author", Class="button-edit icon-edit", Url= "api/Author/read/{0}".Fmt( row.Id) }; itag.Style.Margin.Left=5; idiv.AddHtmlTag(itag); itag = new HtmlIcon(){ Class="button-delete icon-remove", Url= "api/Author/destroy/{0}".Fmt( row.Id) }; itag.Style.Margin.Left=5; itag.Style.Color="red"; idiv.AddHtmlTag(itag); return idiv; }; }); return grid; }
HtmlGrid<SalesByVendor> BuildSalesByVendorGrid(List<SalesByVendor> sbv, string mailTarget=null){ HtmlGrid<SalesByVendor> g = new HtmlGrid<SalesByVendor>(); g.DataSource= sbv; if(! mailTarget.IsNullOrEmpty()) g.GridStyle= new GreyGridStyle(); // css = Inline Style else g.Css = new CayitaGridGrey(); // css = Style Sheet g.Title= "Sales by Vendor"; g.Id="sales-by-vendor"; g.FootNote= "Target by vendor : {0}".Fmt(targetByVendor.Format()); g.AddGridColum( c=> { c.HeaderText="Vendor"; c.CellRenderFunc=(row,index,dt)=> row.Vendor; c.FooterRenderFunc= ()=>"Total Sales ===>"; }); g.AddGridColum( c=> { c.HeaderText="Total"; c.CellRenderFunc=(row,index,dt)=> row.Total.Format(); c.CellStyle.TextAlign="right"; c.FooterRenderFunc=()=> sbv.Sum(f=>f.Total).Format(); c.FooterCellStyle.TextAlign="right"; }); g.AddGridColum( c=> { c.CellRenderFunc=(row,index,dt)=>{ Cayita.HtmlWidgets.Core.TagBase r ; if(mailTarget.IsNullOrEmpty()) { r= new HtmlIcon(){Class="icon-circle"}; } else{ r= new HtmlParagragh(){Text= row.Total>=targetByVendor?"+":"x" }; } r.Style.Color= row.Total>targetByVendor?"green":"red"; return r; }; }); g.AddGridColum( c=> { c.CellRenderFunc=(row,index,dt)=>{ HtmlLink link = new HtmlLink(); link.Url= "#"+row.Vendor.ReplaceAll(" ","-"); link.Text="see details"; return link.ToString(); }; }); return g; }