PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Extensions/Editor.cshtml

#
Razor | 124 lines | 109 code | 15 blank | 0 comment | 11 complexity | 891e20109f8c91cb33f1cdf0ee3a8dcc MD5 | raw file
  1@using System.IO
  2@using System.Linq
  3@using System.Reflection
  4@using App_Code;
  5@using BlogEngine.Core
  6@using BlogEngine.Core.Web.Extensions
  7@{
  8    Page.Title = Resources.labels.extensions;
  9    Layout = "../_Layout.cshtml";
 10
 11    Security.DemandUserHasRight(Rights.AccessAdminPages, true);
 12    if (!WebUtils.CheckIfPrimaryBlog(false)) { return; }
 13
 14    var extName = Request.QueryString["id"];
 15    if (string.IsNullOrWhiteSpace(extName))
 16    {
 17        Response.Redirect("default.cshtml");
 18        return;
 19    }
 20
 21    var ext = ExtensionManager.GetExtension(extName);
 22    if (ext == null)
 23    {
 24        Response.Redirect("default.cshtml");
 25        return;
 26    }
 27
 28    var extensionFilename = ext.GetPathAndFilename(false);
 29    var canWrite = Utils.CanWrite(Href(Utils.ApplicationRelativeWebRoot + "App_Code/Extensions"));
 30    var fileExists = !string.IsNullOrWhiteSpace(extensionFilename) && File.Exists(extensionFilename);
 31    
 32    var editLink = "";   
 33    if (canWrite)
 34    {
 35        editLink = "<a class=\"extEdit\" onclick=\"return ShowEditor();\" href=\"#\">" + Resources.labels.edit + "</a>";
 36    }
 37
 38    var val = string.Format("Source for [{0}] not found", extensionFilename);
 39    try
 40    {
 41        if (fileExists)
 42        {
 43            val = File.ReadAllText(extensionFilename);
 44        }
 45    }
 46    catch (Exception ex)
 47    {
 48        Utils.Log("admin/Extensions/Editor.cshtml", ex);
 49    }
 50}
 51
 52<link rel="stylesheet" href="@Href(Utils.RelativeWebRoot + "Styles/syntaxhighlighter/shCore.css")" type="text/css" />
 53<link rel="stylesheet" href="@Href(Utils.RelativeWebRoot + "Styles/syntaxhighlighter/shThemeDefault.css")" type="text/css" />
 54<script src="@Href(Utils.RelativeWebRoot + "Scripts/syntaxhighlighter/shCore.js")" type="text/javascript"></script>
 55<script src="@Href(Utils.RelativeWebRoot + "Scripts/syntaxhighlighter/shBrushCSharp.js")" type="text/javascript"></script>
 56<script src="@Href(Utils.RelativeWebRoot + "Scripts/syntaxhighlighter/shBrushCss.js")" type="text/javascript"></script>
 57<script type="text/javascript">SyntaxHighlighter.all();</script>
 58<script type="text/javascript">
 59    function ShowEditor() {
 60        $('#extensionViewer').fadeOut();
 61        $('#extensionEditor').fadeIn();
 62        $('#saveArea').fadeIn();
 63        return false;
 64    }
 65
 66    function CancelEdit() {
 67        CloseEditor();
 68        return false;
 69    }
 70
 71    function BtnSaveClick() {
 72        var dto = { "sourceCode": $('#txtSourceCode').val(), "extensionName": $('#hdnExtensionName').val() };
 73        $.ajax({
 74            url: SiteVars.ApplicationRelativeWebRoot + "admin/AjaxHelper.aspx/UpdateExtensionSourceCode",
 75            data: JSON.stringify(dto),
 76            type: "POST",
 77            contentType: "application/json; charset=utf-8",
 78            dataType: "json",
 79            beforeSend: onAjaxBeforeSend,
 80            success: function (result) {
 81                var rt = result.d;
 82                if (rt == true) {
 83                    ShowStatus("success", "Source code updated");
 84                    window.location.reload();
 85                }
 86                else {
 87                    ShowStatus("warning", "Error saving source code");
 88                }
 89            }
 90        });
 91        
 92        CloseEditor();
 93        return false;
 94    }
 95
 96    function CloseEditor() {
 97        $('#extensionViewer').fadeIn();
 98        $('#extensionEditor').fadeOut();
 99        $('#saveArea').fadeOut();
100    }
101</script>
102
103<div class="content-box-outer">
104
105	<div class="content-box-full">
106        <h1>@Resources.labels.sourceViewer: @extName @Html.Raw(editLink)</h1>
107        <div id="extensionViewer">
108<pre class="brush: c-sharp;">// @extensionFilename
109
110@val</pre>
111
112        </div>
113        <div id="extensionEditor" style="display:none">
114            <textarea id="txtSourceCode" style="width: 100%; min-height: 350px;">
115@val
116            </textarea>
117        </div>
118        <div id="saveArea" style="padding:5px 0 0 0; display: none">
119            <input type="button" id="btnSave" class="btn primary" value="@Resources.labels.save" onclick="return BtnSaveClick()"  />
120            @Resources.labels.or <a href="" onclick="return CancelEdit();">@Resources.labels.cancel</a>
121        </div>
122	</div>
123    <input type="hidden" id="hdnExtensionName" value="@extName" />
124</div>