1+ @*
2+ * GriddlyButton renderer using Bootstrap html and styles
3+ * http://griddly.com
4+ * Copyright 2013-2021 Chris Hynes and Data Research Group, Inc.
5+ * Licensed under MIT (https://github.com/programcsharp/griddly/blob/master/LICENSE)
6+ *
7+ * WARNING: Don't edit this file -- it'll be overwitten when you upgrade.
8+ * Use the static properties on GriddlySettings to make config changes.
9+ *
10+ *@
11+ @using Griddly .Mvc
12+ @using Microsoft .AspNetCore .Html ;
13+ @model GriddlyButton
14+ @{
15+ bool isListOnly = ViewBag .IsListOnly == true ;
16+ var css = (GriddlyCss ?)ViewBag .GriddlyCss ?? GriddlySettings .DefaultCss ;
17+
18+ Func < (GriddlyButton button , bool isDropdown , bool isMenuItem ), IHtmlContent > RenderLink = @< text > @{
19+
20+ var button = item .button ;
21+
22+ if (button .ArgumentTemplate != null )
23+ {
24+ button .Argument = button .ArgumentTemplate (ViewData [" ResolveContext" ]).ToString ();
25+ }
26+
27+ string href = null ;
28+ if (button .Action != GriddlyButtonAction .Modal && (button .Action != GriddlyButtonAction .Navigate || (item .isDropdown && button .DropdownCaret != GriddlyDropdownCaret .Split )))
29+ {
30+ href = " javascript:;" ;
31+ }
32+ else if ((button .Action == GriddlyButtonAction .Navigate && (! item .isDropdown || button .DropdownCaret == GriddlyDropdownCaret .Split )) || (button .Action == GriddlyButtonAction .Modal && ! string .IsNullOrWhiteSpace (button .Target )))
33+ {
34+ href = button .Argument ;
35+ }
36+ else if (button .Action == GriddlyButtonAction .Modal && string .IsNullOrWhiteSpace (button .Target ))
37+ {
38+ href = " #" + button .Argument ;
39+ }
40+
41+ bool clearSelectionOnAction = button .ClearSelectionOnAction ?? (button .Action == GriddlyButtonAction .Ajax || button .Action == GriddlyButtonAction .AjaxBulk );
42+
43+ < a data - role = " griddly-button" class = " @(!item.isMenuItem ? css.ButtonDefault : null) @button.ClassName @(item.isDropdown && button.DropdownCaret != GriddlyDropdownCaret.Split ? " dropdown - toggle " : null) @(!button.Enabled || button.EnableOnSelection == true ? " disabled " : null) @(!string.IsNullOrWhiteSpace(button.Icon) ? " btn - with - icon " : null) @(item.isMenuItem && css.IsBootstrap4 ? " dropdown - item " : null)"
44+ @* onclick = " @(button.Action == GriddlyButtonAction.Javascript ? button.Argument : null)" * @
45+ title = " @button.Title"
46+ @Html .AttributeIf (" target" , button .Action == GriddlyButtonAction .Navigate && ! string .IsNullOrWhiteSpace (button .Target ), button .Target )
47+ href = " @(href ?? " javscript : void ()" )"
48+ @Html .AttributeIf (" data-toggle" , button .Action != GriddlyButtonAction .Navigate && button .Action != GriddlyButtonAction .Javascript , button .Action .ToString ().ToLower ())
49+ @Html .AttributeIf (" data-toggle" , item .isDropdown && button .DropdownCaret != GriddlyDropdownCaret .Split , " dropdown" )
50+ @Html .AttributeIf (" data-onclick" , button .Action == GriddlyButtonAction .Javascript && ! string .IsNullOrWhiteSpace (button .Argument ), button .Argument )
51+ @Html .AttributeIf (" data-url" , button .Action == GriddlyButtonAction .Ajax || button .Action == GriddlyButtonAction .AjaxBulk || button .Action == GriddlyButtonAction .Post || button .Action == GriddlyButtonAction .PostCriteria , button .Argument )
52+ @Html .AttributeIf (" data-target" , button .Action != GriddlyButtonAction .Navigate && ! string .IsNullOrWhiteSpace (button .Target ), button .Target )
53+ @Html .AttributeIf (" data-enable-on-selection" , button .EnableOnSelection , button .EnableOnSelection .ToString ().ToLower ())
54+ @Html .AttributeIf (" data-clear-selection-on-action" , clearSelectionOnAction , clearSelectionOnAction .ToString ().ToLower ())
55+ @Html .AttributeIf (" data-confirm-message" , button .ConfirmMessage != null , button .ConfirmMessage )
56+ @Html .AttributeIf (" data-confirm-prompt-function" , button .ConfirmPromptFunction != null , button .ConfirmPromptFunction )
57+ @Html .AttributeIf (" data-rowids" , button .RowIds != null , button .RowIds != null ? Html .Encode (Json .Serialize (button .RowIds .Select (x => x .ToLower ()).ToArray ())) : null )
58+ @Html .AttributeIf (" data-append-rowids-to-url" , (button .Action == GriddlyButtonAction .Modal || button .Action == GriddlyButtonAction .Navigate ) && button .AppendRowIdsToUrl , " " )
59+ @if (button .HtmlAttributes != null ) { foreach (var attr in button .HtmlAttributes ) { < text > @attr .Key = " @attr.Value" < / text > } }>
60+
61+ @if (! string .IsNullOrWhiteSpace (button .Icon ) && GriddlySettings .IconTemplate != null )
62+ {
63+ @GriddlySettings .IconTemplate (button )
64+ }
65+
66+ @if (button .TextTemplate != null )
67+ {
68+ @button .TextTemplate (button )
69+ }
70+ @button .Text
71+
72+ @if (item .isDropdown && button .DropdownCaret == GriddlyDropdownCaret .Inline && ! css .IsBootstrap4 )
73+ {
74+ < span class = " @css.Icons.CaretDown" >< / span >
75+ }
76+ < / a >
77+ }< / text > ;
78+
79+ Func <List <GriddlyButton >, IHtmlContent > RenderList = @< text > @{
80+ foreach (GriddlyButton button in item )
81+ {
82+ if (css .IsBootstrap4 )
83+ {
84+ if (button .IsSeparator )
85+ {
86+ < div class = " dropdown-divider" >< / div >
87+ }
88+ else if (button is GriddlyHtmlButton )
89+ {@(((GriddlyHtmlButton )button ).HtmlTemplate (button ))}
90+ else
91+ {@RenderLink ((button , false , true ))}
92+ }
93+ else
94+ {
95+ if (button .IsSeparator )
96+ {
97+ < li class = " divider" >< / li >
98+ }
99+ else
100+ {
101+ < li class = " @(!button.Enabled || button.EnableOnSelection == true ? " disabled " : null)" @Html .AttributeIf (" data-enable-on-selection" , button .EnableOnSelection , button .EnableOnSelection .ToString ().ToLower ())>
102+ @if (button is GriddlyHtmlButton )
103+ {@(((GriddlyHtmlButton )button ).HtmlTemplate (button ))}
104+ else
105+ {@RenderLink ((button , false , true ))}
106+ < / li >
107+ }
108+ }
109+ }
110+ }< / text > ;
111+ }
112+
113+ @if (Model is GriddlyHtmlButton )
114+ {
115+ @( ((GriddlyHtmlButton )Model ).HtmlTemplate (Model ))
116+ }
117+ else if (! Model .Buttons .Any ())
118+ {
119+ @RenderLink((Model , false , false ))
120+ }
121+ else
122+ {
123+ if (! isListOnly )
124+ {
125+ < div class = " btn-group" >
126+ @RenderLink ((Model , true , false ))
127+ @if (Model .DropdownCaret == GriddlyDropdownCaret .Split )
128+ {
129+ < button type = " button" class = " dropdown-toggle dropdown-toggle-split @css.ButtonDefault" data - toggle = " dropdown" >
130+ @if (! css .IsBootstrap4 )
131+ {
132+ < span class = " @css.Icons.CaretDown" >< / span >
133+ }
134+ < / button >
135+ }
136+ @if (css .IsBootstrap4 )
137+ {
138+ < div class = " dropdown-menu @(Model.AlignRight ? " dropdown - menu - right float - right " : " " )" >
139+ @RenderList (Model .Buttons )
140+ < / div >
141+ }
142+ else
143+ {
144+ < ul class = " dropdown-menu @(Model.AlignRight ? " pull - right " : " " )" >
145+ @RenderList (Model .Buttons )
146+ < / ul >
147+ }
148+ < / div >
149+ }
150+ else
151+ {
152+ @RenderList(Model.Buttons)
153+ }
154+ }
0 commit comments