PageRenderTime 13ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Helpers/ExtensionsHelper.cshtml

#
Razor | 225 lines | 205 code | 18 blank | 2 comment | 29 complexity | 7f01e2eecd4f96c11fd6046959cc5e7a MD5 | raw file
  1@using BlogEngine.Core
  2@using BlogEngine.Core.Web.Extensions
  3
  4@helper GetExtensions(bool isenabled)
  5{
  6    var extensions = ExtensionManager.Extensions.Where(x => x.Key != "MetaExtension").ToList();
  7    var tableId = "tblEnabledExtensions";
  8    var onClick = "$(this).text($(this).text() == 'Show' ? 'Hide' : 'Show'); $.cookie('ToggleDisabledExtensions', $(this).text(), { expires: 30 }); return Toggle('tblDisabledExtensions');";
  9    var disabledDisplay = "";
 10    
 11    extensions.Sort(
 12        (e1, e2) => e1.Value.Priority == e2.Value.Priority ? string.CompareOrdinal(e1.Key, e2.Key) : e1.Value.Priority.CompareTo(e2.Value.Priority));
 13
 14    List<ManagedExtension> manExtensions = new List<ManagedExtension>();
 15
 16    foreach (KeyValuePair<string, ManagedExtension> ext in extensions)
 17    {
 18        var oExt = ExtensionManager.GetExtension(@ext.Key);
 19        
 20        if (oExt.Enabled == isenabled)
 21        {
 22            manExtensions.Add(oExt);
 23        }
 24    }
 25
 26    if(!isenabled)
 27    {
 28        @* show/hide disabled extensions *@
 29        var ShowHide = "Hide";
 30        if (Request.Cookies["ToggleDisabledExtensions"] == null)
 31        {
 32            var cookie = new HttpCookie("ToggleDisabledExtensions", "Hide") { Expires = DateTime.Now.AddMonths(1) };
 33            Response.Cookies.Add(cookie);
 34        }
 35        else
 36        {
 37            ShowHide = Request.Cookies["ToggleDisabledExtensions"].Value;
 38
 39            if (ShowHide == "Show")
 40            {
 41                disabledDisplay = "display: none";
 42            }
 43        }
 44        onClick = onClick.Replace("[x]", "{ expires: 30 }");
 45        tableId = "tblDisabledExtensions";
 46        <h2 style="margin-top:20px">Disabled Extensions (@manExtensions.Count) <a href="#" id="DisabledToggle" onclick="@Html.Raw(@onClick)" class="toggle">@ShowHide</a></h2>
 47    }
 48    else{
 49        <h2 class="gallery-hdr">@Resources.labels.extensions (@manExtensions.Count)</h2>
 50    }
 51    
 52        
 53    <table id="@tableId" class="beTable rounded" style="@disabledDisplay">
 54        <thead>
 55        <tr>
 56            <th width="150">Name</th>
 57            <th width="60">Version</th>
 58	        <th width="auto">Description</th>
 59            <th width="150">Author</th>
 60            <th width="60">Priority</th>
 61            <th width="80">&nbsp;</th>
 62        </tr>
 63        </thead>
 64        <tbody>
 65        @{
 66            var cnt = 0;
 67            var cls = "";
 68            var id = "";
 69            foreach (var x in manExtensions)
 70            {
 71                cnt++;
 72                cls = (cnt % 2 == 0) ? "alt" : "";
 73                id = "ext_" + x.Name;
 74                var enabled = @x.Enabled ? @Resources.labels.disable : @Resources.labels.enable;
 75                var statusLink = Utils.RelativeWebRoot + "admin/Extensions/SetStatus.cshtml?ext={0}&act={1}";
 76                statusLink = string.Format(statusLink, x.Name, !x.Enabled);
 77                var actClass = isenabled ? "unapproveAction" : "approveAction";
 78                var pkg = BlogEngine.Core.Packaging.PackageRepository.GetPackage(x.Name);
 79                        
 80                <tr id="@id" class="@cls">
 81                    <td>@x.Name</td>
 82                    <td>@x.Version</td>
 83                    <td>@Html.Raw(x.Description)</td>
 84                    <td>@Html.Raw(x.Author)</td>
 85                    <td>@x.Priority</td>
 86                    <td>
 87                    <ul class="rowTools">
 88                        <li>
 89                            <a class="toolsAction" href="#"><span class="">Tools</span></a>
 90                            <ul class="rowToolsMenu">
 91                                <li><a href="@statusLink" class="@actClass">@enabled</a></li>
 92                                <li><a href="#" onclick="$('#txtPriority').val('@x.Priority'); $('#hdnExtensionName').val('@x.Name');" class="changePriority rightsAction">@Resources.labels.priority</a></li>
 93                                <li><a href="@Href(Utils.RelativeWebRoot + "admin/Extensions/Editor.cshtml?id=")@x.Name" class="viewButton viewAction">View</a></li>
 94                                @if(pkg != null && pkg.Location == "I"){
 95                                <li><a href="#" id="a-@x.Name" onclick="UninstallExtension('@x.Name'); return false;" class="deleteAction">@Resources.labels.delete</a></li> 
 96                                }
 97                            </ul>
 98                        </li>
 99                    </ul>
100                    </td>
101                </tr>
102            }      
103        }         
104        </tbody>
105    </table>
106}
107
108@helper GetBlogExtensions(bool isenabled)
109    {
110    var extensions = ExtensionManager.Extensions.Where(x => x.Key != "MetaExtension").ToList();
111    var tableId = "tblEnabledExtensions";
112    var onClick = "$(this).text($(this).text() == 'Show' ? 'Hide' : 'Show'); $.cookie('ToggleDisabledExtensions', $(this).text(), { expires: 30 }); return Toggle('tblDisabledExtensions');";
113    var disabledDisplay = "";
114
115    extensions.Sort(
116        (e1, e2) => e1.Value.Priority == e2.Value.Priority ? string.CompareOrdinal(e1.Key, e2.Key) : e1.Value.Priority.CompareTo(e2.Value.Priority));
117
118    List<ManagedExtension> manExtensions = new List<ManagedExtension>();
119
120    foreach (KeyValuePair<string, ManagedExtension> ext in extensions)
121    {
122        var oExt = ExtensionManager.GetExtension(@ext.Key);
123        if (oExt.Enabled)
124        {
125            if (oExt.Blogs.Contains(Blog.CurrentInstance.Id))
126            {
127                if (!isenabled)
128                {
129                    manExtensions.Add(oExt);
130                }
131            }
132            else
133            {
134                if (isenabled)
135                {
136                    manExtensions.Add(oExt);
137                }
138            }
139        }
140    }
141
142    if (isenabled)
143    {
144        <h2 class="gallery-hdr">@Resources.labels.extensions (@manExtensions.Count)</h2>
145    }
146    else
147    {
148        if (manExtensions.Count > 0)
149        {
150            @* show/hide disabled extensions *@
151            var ShowHide = "Hide";
152            if (Request.Cookies["ToggleDisabledExtensions"] == null)
153            {
154                var cookie = new HttpCookie("ToggleDisabledExtensions", "Hide") { Expires = DateTime.Now.AddMonths(1) };
155                Response.Cookies.Add(cookie);
156            }
157            else
158            {
159                ShowHide = Request.Cookies["ToggleDisabledExtensions"].Value;
160
161                if (ShowHide == "Show")
162                {
163                    disabledDisplay = "display: none";
164                }
165            }
166            onClick = onClick.Replace("[x]", "{ expires: 30 }");
167            tableId = "tblDisabledExtensions";
168            <h2 style="margin-top:20px">Disabled Extensions (@manExtensions.Count) <a href="#" id="DisabledToggle" onclick="@Html.Raw(@onClick)" class="toggle">@ShowHide</a></h2>
169        }
170    }
171
172    if (manExtensions.Count > 0)
173    {  
174    <table id="@tableId" class="beTable rounded" style="@disabledDisplay">
175        <thead>
176        <tr>
177            <th width="150">Name</th>
178            <th width="60">Version</th>
179	        <th width="auto">Description</th>
180            <th width="150">Author</th>
181            <th width="80">&nbsp;</th>
182        </tr>
183        </thead>
184        <tbody>
185        @{
186        var cnt = 0;
187        var cls = "";
188        foreach (var x in manExtensions)
189        {
190            cnt++;
191            cls = (cnt % 2 == 0) ? "alt" : "";
192            var enabled = @x.Enabled ? @Resources.labels.disable : @Resources.labels.enable;
193            var statusLink = Utils.RelativeWebRoot + "admin/Extensions/SetStatusForBlog.cshtml?ext={0}&act={1}";
194            statusLink = string.Format(statusLink, x.Name, !isenabled);
195            var actClass = isenabled ? "unapproveAction" : "approveAction";
196                        
197                <tr class="@cls">
198                    <td>@x.Name</td>
199                    <td>@x.Version</td>
200                    <td>@Html.Raw(x.Description)</td>
201                    <td>@Html.Raw(x.Author)</td>
202                    <td>
203                    <ul class="rowTools">
204                        <li>
205                            <a class="toolsAction" href="#"><span class="">Tools</span></a>
206                            <ul class="rowToolsMenu">
207                            @if (isenabled)
208                            {
209                                <li><a href="@statusLink" class="@actClass">@Resources.labels.disable</a></li>
210                            }
211                            else
212                            {
213                                <li><a href="@statusLink" class="@actClass">@Resources.labels.enable</a></li>
214                            }
215                            </ul>
216                        </li>
217                    </ul>
218                    </td>
219                </tr>
220        }      
221        }         
222        </tbody>
223    </table>
224    }
225}