
<!-- Шаблон поля Repository type  -->
<script type="text/x-just" data-just="filed_type_selectRepositoryType"> 
    <% if(!item_id){ %>
        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Repository type</label>
            <select class="form-control select2" id="new_project_type" onchange="pmProjects.model.repository_type = this.value;" data-placeholder="Select a type" >
                <% for(var i in pmProjects.model.supportedRepos){ %>
                    <option
                        <% if(pmProjects.model.repository_type = pmProjects.model.supportedRepos[i]){ %>selected<% } %> 
                        value="<%- pmProjects.model.supportedRepos[i] %>" ><%- pmProjects.model.supportedRepos[i] %></option>
                <% } %>
            </select>
            <div class="help-block"></div>
        </div> 

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6  <%- pmProjects.model.justClass('repository_type', 'hide', function(v){ return v == 'MANUAL' }) %>">
            <label class="control-label" >Repository URL</label>
            <input type="text"  placeholder="Enter project repository"  id="new_project_repository" value=""  class="form-control" maxlength="255">

            <div class="help-block" onmouseenter="$(this).children().popover();">
                Enter <%= pmProjects.model.justText('repository_type') %> project repository url
                <span class="glyphicon glyphicon-question-sign  <%- pmProjects.model.justClass('repository_type', 'hide', function(v){ return v != 'GIT' }) %>"
                        role="button"
                        data-trigger="hover"
                        title=""
                        data-placement="top"
                        data-html="true"
                        data-content="For example repository URL make be like this: `http://UserName@gitlab.com/UserName/ProjectRepository.git`"
                        data-original-title="GIT project repository URL"></span>

                <span class="glyphicon glyphicon-question-sign  <%- pmProjects.model.justClass('repository_type', 'hide', function(v){ return v != 'TAR' }) %>"
                        role="button"
                        data-trigger="hover"
                        title=""
                        data-placement="top"
                        data-html="true"
                        data-content="For example repository URL make be like this: `http://example.com/ProjectRepository.tar`"
                        data-original-title="TAR project repository URL"></span>
            </div>
        </div>

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmProjects.model.justClass('repository_type', 'hide', function(v){ return v == 'TAR' || v == 'MANUAL' }) %>">
            <label class="control-label" >Repository password</label>
            <input type="password"  placeholder="Enter repository password"  id="new_project_password" value=""  class="form-control" maxlength="255">
            <div class="help-block"></div>
        </div>

        <!-- -->
         <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmProjects.model.justClass('repository_type', 'hide', function(v){ return v == 'TAR' || v == 'MANUAL' }) %>">
            <label class="control-label" >Branch</label>
            <input type="text"
                    placeholder="Enter branch name"
                    id="new_project_branch"
                    value=""
                    class="form-control"
                    maxlength="255">
            <div class="help-block"></div>
        </div>
        <!-- -->

    <% }else{ %>  
        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Repository type</label>
            <input type="text" disabled  placeholder="Enter project name" id="project_<%- pmObj.model.items[item_id].id %>_type" value="<%- pmProjects.model.items[item_id].vars.repo_type %>"  class="form-control" maxlength="255">
            <div class="help-block"></div>
        </div>  
        
        <% if(pmObj.model.items[item_id].vars.repo_type != "MANUAL"){ %>
            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                <label class="control-label" >Repository URL</label>
                <input type="text"  placeholder="Enter project repository"  id="project_<%- pmObj.model.items[item_id].id %>_repository" value="<%- pmObj.model.items[item_id].repository %>"  class="form-control" maxlength="255">
                <div class="help-block" onmouseenter="$(this).children().popover();"> 
                    Enter <%= pmObj.model.justText('repository_type') %> project repository url
                    <span class="glyphicon glyphicon-question-sign  <%- pmObj.model.justClass('repository_type', 'hide', function(v){ return v != 'GIT' }) %>"
                        role="button"
                        data-trigger="hover"
                        title=""
                        data-placement="top"
                        data-html="true"
                        data-content="For example repository URL make be like this: `http://UserName@gitlab.com/UserName/ProjectRepository.git`"
                        data-original-title="GIT project repository URL"></span>

                    <span class="glyphicon glyphicon-question-sign  <%- pmObj.model.justClass('repository_type', 'hide', function(v){ return v != 'TAR' }) %>"
                            role="button"
                            data-trigger="hover"
                            title=""
                            data-placement="top"
                            data-html="true"
                            data-content="For example repository URL make be like this: `http://example.com/ProjectRepository.tar`"
                            data-original-title="TAR project repository URL"></span>

                </div>
            </div>
        <% } %>
        <% if(pmObj.model.items[item_id].vars.repo_type != "TAR" && pmObj.model.items[item_id].vars.repo_type != "MANUAL"){ %>
            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                <label class="control-label" >Repository password</label>
                <input type="password" 
                        placeholder="Enter repository password"
                        id="project_<%- pmObj.model.items[item_id].id %>_password"

                        <% if(pmObj.model.items[item_id].vars.repo_password) { %>
                            value="<%- pmObj.model.items[item_id].vars.repo_password %>"
                        <% } else { %>
                            value=""
                        <% } %>
                        class="form-control"
                        maxlength="255">
                <div class="help-block"></div>
            </div>

            <!-- -->
            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6" id="branch_block">
                <%= pmProjects.renderBranchInput(item_id) %>
            </div>
            <!-- -->

        <% } %>
    <% } %>
</script>


<script type="text/x-just" data-just="pmTasksTemplates_btn_importFromFile">

    <span class="btn btn-default textfile" style="margin-left: 10px;" >
        <input type="file" class="input-file"  onchange="spajs.showLoader(pmTasksTemplates.importFromFile(event, <%- item_id %>));"  >
        <span class="glyphicon glyphicon-file"></span> Import templates
    </span>
</script>

<script type="text/x-just" data-just="projects_run_playbook">
<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" >Project `<%= pmProjects.model.items[item_id].justText('name') %>` run playbook options</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">Project tasks</li>
        </ol>
    </section>

    <section class="content">
        <button type="button"
                onclick="spajs.showLoader(pmProjects.executePlaybook(<%- item_id %>)); 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">
                        Run playbook
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="form-group col-lg-4">
                                <label class="control-label" >Playbook</label>
                                <input type="text"
                                        class="playbook-autocomplete form-control"
                                        id="playbook-autocomplete"
                                        value="">
                            </div>

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

                            <!--
                            <div class="form-group col-lg-4">
                                <label class="control-label" >Inventory</label>
                                <select class="form-control select2"
                                        id="inventories-autocomplete" 
                                        data-placeholder="Select inventory" 
                                        style="width:100%"  
                                        onchange="pmProjects.model.selectedInventory = this.value;"
                                >
                                    <option selected value="0" disabled>Not set</option>
                                    <% for(var i in pmInventories.model.itemslist.results){ %>
                                        <option
                                            value="<%- pmInventories.model.itemslist.results[i].id %>"
                                            ><%- pmInventories.model.itemslist.results[i].name %></option>
                                    <% } %>
                                </select>
                            </div>-->
                            
                            <~ pmProjects.model.selectedInventory>
                                <%= pmGroups.groupsAutocompleteTemplate(pmProjects.model.selectedInventory) %>
                            <~>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <div class="row">
            <%= jsonEditor.editor({}, {block:'playbook', title1:'Arguments', title2:'Adding new argument', select2:true, excluded_options:['limit']}) %>
        </div>
    </section>
</script>


<script type="text/x-just" data-just="branch_input">

                <label class="control-label" >Branch</label>
                <% if(pmObj.model.items[item_id].vars.repo_branch!=undefined) { %>
                    <% if(pmObj.model.items[item_id].branch!=pmObj.model.items[item_id].vars.repo_branch) { %>
                    <div style="display: flex; overflow:hidden;">
                        <div style="position:relative;">
                            <input type="text"
                                    placeholder="Enter branch name"
                                    value="<%- pmObj.model.items[item_id].branch %>"
                                    class="form-control"
                                    maxlength="255"
                                    disabled
                                    style="width: <%= (pmObj.model.items[item_id].branch.length +1)*8 +35 %>px; border-right:none; float:left;">
                            <div class="form-control" style="width: 35px;  border-left:none; float:left; border-right:none; position:absolute; right:0px;" disabled>
                                        <i class="glyphicon glyphicon-arrow-right"></i>
                                    </div>

                        </div>
                        <div style="flex:1;">
                            <div style="width: 100%; position:relative;">
                                <input type="text"
                                        placeholder="Enter branch name"
                                        id="project_<%- pmObj.model.items[item_id].id %>_branch"
                                        value="<%- pmObj.model.items[item_id].vars.repo_branch %>"
                                        class="form-control"
                                        maxlength="255"
                                        style="float:left;"
                                        onfocusout="pmProjects.checkBranchInput(<%= item_id %>);">



                                <span class="clear-input-and-paste" onclick="pmProjects.clearAndPasteBranchInput(<%= item_id %>,'#project_<%- pmObj.model.items[item_id].id %>_branch');">
                                    <span class="glyphicon glyphicon-remove"></span>
                                </span>
                            </div>

                        </div>
                    </div>

                    <% } else { %>
                        <input type="text"
                                placeholder="Enter branch name"
                                id="project_<%- pmObj.model.items[item_id].id %>_branch"
                                value="<%- pmObj.model.items[item_id].branch %>"
                                class="form-control"
                                maxlength="255"
                                onfocusout="pmProjects.checkBranchInput(<%= item_id %>);">


                    <% } %>
                <% } else { %>
                    <input type="text"
                                    placeholder="Enter branch name"
                                    id="project_<%- pmObj.model.items[item_id].id %>_branch"
                                    value="<%- pmObj.model.items[item_id].branch %>"
                                    class="form-control"
                                    maxlength="255"
                                    onfocusout="pmProjects.checkBranchInput(<%= item_id %>);">


                 <% } %>

                <div class="help-block"></div>



</script>


<!-- Шаблон boolean repo_sync_on_run -->
<script type="text/x-just" data-just="filed_type_repo_sync_on_run">
    <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 boolean-select">
        <label class="control-label" >Update before execution</label>
        <div class="form-control <% if(item_id && pmObj.model.items[item_id].vars.repo_sync_on_run
                                    && pmObj.model.items[item_id].vars.repo_sync_on_run == true){ %>
                                    selected
                                 <% } %>"
                onclick="$(this).toggleClass('selected');"
                onselectstart="return false"
                onmousedown="return false"
                style="cursor: pointer;"
                id="filed_<%- filed.name %>">
            <div class="ico-on fa fa-toggle-on"></div>
            <div class="ico-off fa  fa-toggle-off"></div>
            <div class="boolean-title" >Boolean value</div>
        </div>
        <div class="help-block"><%- filed.help || '' %></div>
    </div>
</script>


<script type="text/x-just" data-just="project_readme">
    <~ pmObj.model.items[item_id].readme_content >
        <% if(pmObj.model.items[item_id].readme_content != null) { %>
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                         Readme<% if(pmObj.model.items[item_id].readme_ext != null) { %><%= pmObj.model.items[item_id].readme_ext %> <% }  %> <br>
                        <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> </button>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="readme_content col-lg-12 col-xs-12 col-sm-12 col-md-12">
                                <%= trim(pmObj.model.items[item_id].readme_content) %>
                            </div>
                        </div>
                    </div>
                 </div>
            </section>
        <% } %>
    <~>
</script>
