
<!-- Страница module_run_page in projects -->
<script type="text/x-just" data-just="module_run_page">
    <section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?project/<%- item_id %>" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>
            <span class="h1-header" >Execute ansible module</span>

        </h1>
        <ol class="breadcrumb">
            <li><a href="<%- polemarch.opt.host %>" onclick="return spajs.openURL(this.href);" ><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="<%- polemarch.opt.host %>/?projects" onclick="return spajs.openURL(this.href);" >Projects</a></li>
            <li><a href="<%- polemarch.opt.host %>/?project/<%- item_id %>" onclick="return spajs.openURL(this.href);" ><%- pmProjects.model.items[item_id].name.slice(0, 20) %></a></li>
            <li class="active">Execute ansible module</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(pmAnsibleModule.execute(<%- item_id %>, pmModuleTemplates.inventoriesAutocompletefiled.getValue(), pmGroups.getGroupsAutocompleteValue(), $('#module-autocomplete').val())); return false;" class="btn btn-warning" >Execute</button>

        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        Execute ansible module
                    </div>
                    <div class="box-body">

                        <div class="row"> 
                            <%= pmModuleTemplates.inventoriesAutocompletefiled.render(pmModuleTemplates, {
                                name:'inventory',
                                title:'Inventory',
                                getFiledValue:function(item_id){ 
                                    return this.model.items[item_id].data.inventory;
                                },
                                onchange:function(event){ 
                                    console.log("onchange", event) 
                                    if(/[^0-9]/mg.test(event.value))
                                    {
                                        pmModuleTemplates.selectInventory()
                                    }
                                    else
                                    {
                                        pmModuleTemplates.selectInventory(event.value)
                                    }
                                }
                            }, null, {}) %>
                            
                            <~ pmModuleTemplates.model.selectedInventory> 
                                <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory) %> 
                            <~>
                        </div>

                        <%= moduleArgsEditor.moduleFileds() %>  
                    </div>
                </div>
            </section>
        </div>
        <div class="row">
            <%= jsonEditor.editor({}, {block:'module', title1:'Arguments', title2:'Adding new argument', select2:true}) %>
        </div>
    </section>
</script>

<!-- Список templates_list -->
<script type="text/x-just" data-just="fastcommand_widget"> 
    <section class="col-lg-12 col-sm-12 col-xs-12">
        <div class="box box-info
        <% for(var j in pmDashboard.model.widgets[0]){  %>
            <% if(pmDashboard.model.widgets[0][j].name == 'pmwAnsibleModuleWidget' && pmDashboard.model.widgets[0][j].collapse) { %>
              collapsed-box
            <% } %>
        <% } %>
        ">
            <div class="box-header with-border cursor-move1">
                Run shell command

                <div class="pull-right">
                    <button type="button" class="btn btn-sm w-btn" data-widget="collapse" onclick="pmDashboard.setNewWidgetCollapseValue(this)">
                        <i
                            <% for(var j in pmDashboard.model.widgets[0]){  %>
                                <% if(pmDashboard.model.widgets[0][j].name == 'pmwAnsibleModuleWidget' && pmDashboard.model.widgets[0][j].collapse==true) { %>
                                   class="fa fa-plus"
                                <% } %>
                                <% if(pmDashboard.model.widgets[0][j].name == 'pmwAnsibleModuleWidget' && pmDashboard.model.widgets[0][j].collapse==false) { %>
                                   class="fa fa-minus"
                                <% } %>
                            <% } %>
                        ></i>
                    </button>
                    <button type="button" class="btn btn-sm w-btn" data-widget="remove" onclick="pmDashboard.setNewWidgetActiveValue(this)"><i class="fa fa-times"></i></button>
                </div>
            </div>
            <div class="box-body">
                <div class="row">
                
                    <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                        <label class="control-label" >Project</label>
                        <select
                            class="form-control select2"
                            id="projects-autocomplete"
                            data-placeholder="Select project"
                            style="width:100%" 
                        >
                            <option selected value="0" disabled>Not set</option>
                            <% for(var i in pmProjects.model.itemslist.results){ %>
                                <option
                                    value="<%- pmProjects.model.itemslist.results[i].id %>"
                                    ><%- pmProjects.model.itemslist.results[i].name %></option>
                            <% } %>
                        </select>
                    </div>
                    
                
                    <%= pmModuleTemplates.inventoriesAutocompletefiled.render(pmModuleTemplates, {
                        name:'inventory',
                        title:'Inventory',
                        getFiledValue:function(item_id){ 
                            return this.model.items[item_id].data.inventory;
                        },
                        onchange:function(event){ 
                            console.log("onchange", event) 
                            if(/[^0-9]/mg.test(event.value))
                            {
                                pmModuleTemplates.selectInventory()
                            }
                            else
                            {
                                pmModuleTemplates.selectInventory(event.value)
                            }
                        }
                    }, null, {}) %>
  
                    <~ pmModuleTemplates.model.selectedInventory>
                        <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory) %>
                    <~>
                    
                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-8 col-sm-12">
                        <label class="control-label" >Shell command</label>
                        <div class="input-group">
                            <input type="text"
                                    class="form-control"
                                    value=""
                                    id="module-args-string"
                                    onchange=""
                                    onpaste=""
                                    onkeypress="if((event.keyCode === 10 || event.keyCode === 13)){ spajs.showLoader(pmAnsibleModule.fastCommandWidget_RunBtn()) }" >
                            <span class="input-group-btn" onclick=" " >
                                <button 
                                class="btn btn-primary"
                                type="button"
                                onclick="spajs.showLoader(pmAnsibleModule.fastCommandWidget_RunBtn())"
                                ><span class="glyphicon glyphicon-send"></span> Run command</button> 
                            </span>
                        </div> 
                    </div>
                </div>
            </div> 
        </div>
    </section> 
</script>

