{% import os %}

<div class="x-dialog x-dialog-remote">
    <div class="x-dialog-title">
        移动分组 <input type="button" class="x-dialog-close" value="关闭"/>
    </div>
    <div class="x-dialog-body" style="height: 500px;">
        <input class="hide" id="path" value="{{path}}">
        <div class="col-md-12 nav-path">
            <a href="{{_server_home}}/fs/{{os.path.dirname(path)}}">返回</a> 
            文件路径: {{path}}
        </div>

        <div class="col-md-12">
        	{% for index, item in enumerate(scripts) %}
              	<button class="plugin btn">{{item}}</button>
        	{% end %}
        </div>

        <div id="resultDiv" class="col-md-12">
            <div class="panel-title">
                结果
                <a id="pluginEditLink" class="hide link float-right" href="#">编辑脚本</a>
            </div>
            <div id="result" class="col-md-12">
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

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

	$(".plugin").click(function (event) {
		var name = $(event.target).text();
		var path = $("#path").val();
		showResult("开始执行 " + name);
		runPlugin(name, false);
        $("#pluginEditLink").removeClass("hide")
            .attr("href", "/system/script/edit?name=" + name);
	});

    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);
            });
    }
</script>
