{% extends base %}

{% block head %}
<style type="text/css">
    .plugin {
        margin-top: 5px;
    }

    .nav-path {
        padding: 5px;
        background-color: #eee;
    }
</style>
{% end %}

{% block body %}
{% import os %}
<div class="card">
{% include mod_fs_path.html %}
<input class="hide" id="path" value="{{path}}">
<input class="col-md-12" id="searchName" placeholder="执行命令">
<div id="resultDiv" class="col-md-12">
    <div class="output-title">
        结果
        <a id="pluginEditLink" class="hide link float-right" href="#">编辑脚本</a>
    </div>
    <div id="result" class="col-md-12 output-body">
    </div>
</div>
</div>

<script type="text/javascript">

    function showResult(text) {
        $("#resultDiv").show();
        $("#result").html(text);
    }

    function runPlugin(name, confirmed) {
        if (name == "") {
            return;
        }
        var path = $("#path").val();
        var inputText = $("#inputText").val();
        showResult("开始执行 " + name + " ...");
        $.post("/fs_api/run_plugin", 
            {
                name: name,
                path: path,
                confirmed: confirmed,
                input: inputText
            },
            function (result) {
                showResult(result.data);
                $("#pluginEditLink").removeClass("hide")
                    .attr("href", "/system/script/edit?name=commands/" + result.name);
            });
    };

    $("#searchName").keyup(function (event) {
        var keyCode = event.keyCode || event.which;
        if (keyCode == 13) {
            // 回车
            runPlugin($(this).val(), false);
            return;
        }
    })
</script>
{% end %}

{% block aside %}
    {% include fs/mod_aside.html %}
{% end %}

