
<!-- Список templates_list -->
<script type="text/x-just" data-just="templates_widget">
    <section class="col-lg-6 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 == 'pmwTasksTemplatesWidget' && kind=='Task'){ %>
                <% if(pmDashboard.model.widgets[0][j].collapse) { %>
                     collapsed-box
                <% } %>
            <% } %>
            <% if(pmDashboard.model.widgets[0][j].name == 'pmwModulesTemplatesWidget' && kind=='Module'){ %>
                <% if(pmDashboard.model.widgets[0][j].collapse) { %>
                     collapsed-box
                <% } %>
            <% } %>
        <% } %>
        ">
            <div class="box-header with-border cursor-move1">

                Templates <%- kind %>

                <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 == 'pmwTasksTemplatesWidget' && kind=='Task'){ %>
                                    <% if(pmDashboard.model.widgets[0][j].collapse) { %>
                                        class="fa fa-plus"
                                    <% } else { %>
                                        class="fa fa-minus"
                                    <% } %>
                                <% } %>
                                <% if(pmDashboard.model.widgets[0][j].name == 'pmwModulesTemplatesWidget' && kind=='Module'){ %>
                                    <% if(pmDashboard.model.widgets[0][j].collapse) { %>
                                        class="fa fa-plus"
                                    <% } else { %>
                                        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">
                <table class="table table-bordered">
                    <tbody>
                        <tr>
                            <th>Name</th>
                            <th style="width: 105px;" >Actions</th>
                        </tr>
                        <% for(var i in pmTasksTemplates.model.itemslist.results){  val = pmTasksTemplates.model.itemslist.results[i]; %>
                            <% if(val.kind == kind) { %>
                                <tr
                                    class="item-row item-<%- val.id %>"
                                    data-id="<%- val.id %>" >
                                    <td>
                                        <a href="/?template/<%- val.kind %>/<%- val.id %>" class="item-name"
                                                onclick="return spajs.openURL(this.href);" ><%- val.name %></a>
                                    </td>
                                    <td>
                                        <div class="btn-group" role="group">
                                            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                Actions
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right">
                                                <li><a href="#" onclick="spajs.showLoader(pmTemplates.model.kindObjects['<%- val.kind %>'].execute(<%- val.id %>)); return false;">Execute</a> </li>

                                                <% if(val.options_list) { %>
                                                    <% if(val.options_list.length!=0) { %>
                                                        <li role="separator" class="divider"></li>
                                                    <% } %>
                                                    <% for(var k in val.options_list) { %>
                                                        <li>
                                                            <a href="#"
                                                            onclick="spajs.showLoader(pmTemplates.model.kindObjects['<%- val.kind %>'].execute(<%- val.id %>, '<%- val.options_list[k] %>')); return false;">
                                                                Execute with <%= val.options_list[k] %>
                                                            </a>
                                                        </li>
                                                        <% } %>
                                                <% } %>

                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            <% } %>
                        <% } %>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
</script>


<!-- Шаблон полей  Project Inventory и Playbook  -->
<script type="text/x-just" data-just="filed_type_selectProjectInventoryAndPlaybook"> 
    <% if(item_id){ %> 
        
        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Project</label> 
            <select
            onchange="pmTasksTemplates.selectProject(this.value);"
            class="form-control select2"
            id="projects-autocomplete"
            data-placeholder="Select project"
            style="width:100%" > 
                <% for(var i in pmProjects.model.itemslist.results){ %>
                    <option
                        <% if(pmTasksTemplates.model.items[item_id].data.project == pmProjects.model.itemslist.results[i].id){ %>  selected  <% } %>
                        value="<%- pmProjects.model.itemslist.results[i].id %>"
                        ><%- pmProjects.model.itemslist.results[i].name %></option>
                <% } %>
            </select> 
        </div>
        
        <%= pmTasksTemplates.inventoriesAutocompletefiled.render(pmTasksTemplates, {
            name:'inventory',
            title:'Inventory',
            getFiledValue:function(item_id){ 
                return this.model.items[item_id].data.inventory;
            },
        }, item_id, {}) %>
 
        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Playbook</label>
            <input type="text"
                    class="playbook-autocomplete form-control"
                    id="playbook-autocomplete"
                    value="<% if(pmTasksTemplates.model.items[item_id].data.playbook){ %><%- pmTasksTemplates.model.items[item_id].data.playbook %><% } %>">
        </div>
    <% }else{ %>
        <!-- Не задан item_id -->
    <% } %>
</script>

<!-- Шаблон полей  Project Inventory и Playbook for new option  -->
<script type="text/x-just" data-just="filed_type_selectProjectInventoryAndPlaybookForNewOption">
    <% if(item_id){ %>


        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Playbook</label>
            <input type="text"
                    class="playbook-autocomplete form-control"
                    id="playbook-autocomplete"
                    value="<% if(pmTasksTemplates.model.items[item_id].data.playbook){ %><%- pmTasksTemplates.model.items[item_id].data.playbook %><% } %>">
        </div>
    <% }else{ %>
        <!-- Не задан item_id -->
    <% } %>
</script>

<!-- Шаблон полей  Project Inventory и Playbook for  option  -->
<script type="text/x-just" data-just="filed_type_selectProjectInventoryAndPlaybookForOption">
    <% if(item_id){ %>


        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Playbook</label>
            <input type="text"
                    class="playbook-autocomplete form-control"
                    id="playbook-autocomplete"
                    value="<% if(pmTasksTemplates.model.items[item_id].data.playbook){ %><%- pmTasksTemplates.model.items[item_id].dataForOption.playbook %><% } %>">
        </div>
    <% }else{ %>
        <!-- Не задан item_id -->
    <% } %>
</script>

<!-- linked periodic tasks on task template page -->
<script type="text/x-just" data-just="linked_periodic_tasks">
    <% if ( pmObj.model.linkedPeriodicTasks !== undefined &&
     pmObj.model.linkedPeriodicTasks.length != 0) { %>
        <section class="col-lg-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    Linked periodic tasks <br>
                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-lg-12">
                            <% for (var i in pmObj.model.linkedPeriodicTasks) {
                                var linked = pmObj.model.linkedPeriodicTasks[i]; %>
                                <% if(linked.template == item_id) { %>
                                    <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                        <label class="control-label">Periodic task</label>
                                        <a href="<%- polemarch.opt.host %>/?project/<%= linked.project %>/periodic-task/<%= linked.id %>" onclick="return spajs.openURL(this.href);">
                                            <%= linked.name %>
                                        </a>
                                    </div>
                                <% } %>
                            <% } %>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <% } %>
</script>

<script type="text/x-just" data-just="templates_new_page">
<section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?templates" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>
            <span class="h1-header" >New template for run playbook</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 %>/?templates" onclick="return spajs.openURL(this.href);" >Templates</a></li>
            <li class="active">New template</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(pmTasksTemplates.addItem()); return false;" class="btn btn-primary" >Create</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        Run playbook template
                    </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" >Template name</label>
                                <input type="text"
                                        placeholder="Enter name"
                                        id="Templates-name"
                                        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">
                                <label class="control-label" >Project</label>
                                <select
                                onchange="pmTasksTemplates.selectProject(this.value);"
                                class="form-control select2"
                                id="projects-autocomplete"
                                data-placeholder="Select project"
                                style="width:100%" > 
                                    <% 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>
                        </div>
                        <div class="row">
                         
                            <%= pmTasksTemplates.inventoriesAutocompletefiled.render(pmTasksTemplates, {
                                name:'inventory',
                                title:'Inventory',
                                getFiledValue:function(item_id){ 
                                    return this.model.items[item_id].data.inventory;
                                },
                            }, null, {}) %>
                            
                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Playbook</label>
                                <input type="text"
                                        class="playbook-autocomplete form-control"
                                        id="playbook-autocomplete"
                                        value="">
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
                                <label class="control-label">Notes</label>
                                <textarea class="form-control" style="resize:vertical; min-height:75px;"
                                placeholder="Not required field, just for your notes" id="filed_notes"></textarea>
                                <div class="help-block"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <div class="row">
            <%= jsonEditor.editor({}, {block:'playbook', title1:'Arguments', title2:'Adding new argument', select2:true}) %>
        </div>
    </section>
</script>

<!-- шаблон страницы списка опций шаблона -->
<script type="text/x-just" data-just="template_options_list">
    <section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?template/<%- pmObj.model.kind %>/<%- item_id %>" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>

            <span class="h1-header" >Options for template <%- pmObj.model.items[item_id].name %></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 %>/?templates" onclick="return spajs.openURL(this.href);" >Templates</a></li>
            <li><a href="<%- polemarch.opt.host %>/?template/<%- pmObj.model.kind %>/<%- item_id %>" onclick="return spajs.openURL(this.href);" ><%- pmObj.model.items[item_id].name.slice(0, 20) %></a></li>
            <li class="active">Options</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(<%- pmObj.model.className %>.setNewOption(<%- item_id %>));  return false;" class="btn btn-primary" >Create new option</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info" id="options_list">
                    <div class="box-header with-border">
                         <%= pmObj.searchFiledForTemplateOptions({query:query, template_id:item_id}) %>

                    </div>
                    <div class="box-body">
                    <~ pmObj.model.items[item_id].options>
                        <table class="table table-bordered multiple-select" id="options_list_table">
                            <tbody>
                                <tr>
                                    <th style="width: 45px" onclick="$(this).parent().toggleClass('selected'); <%- pmObj.model.className %>.toggleSelectAllOptions($('#options_list tr'), $(this).parent().hasClass('selected'), 'options_list') ;return false;" class="global-select" >
                                        <div class="ico-on fa fa-toggle-on"></div>
                                        <div class="ico-off fa  fa-toggle-off"></div>
                                    </th>
                                    <th>Name</th>
                                    <% if(pmObj.model.className == "pmTasksTemplates") { %>
                                        <th style="width: 95px;" class="hidden-xs">Playbook</th>
                                    <% } else { %>
                                        <th style="width: 95px;" class="hidden-xs">Module</th>
                                        <th style="width: 95px;" class="hidden-xs hidden-1100">Args</th>
                                        <th style="width: 95px;" class="hidden-xs hidden-1200">Group</th>
                                    <% } %>
                                    <th style="width: 350px;" class="hidden-xs hidden-sm">Vars</th>
                                    <th style="width: 95px;" >Actions</th>
                                </tr>
                                <% for(var i in pmObj.model.items[item_id].options){ option = pmObj.model.items[item_id].options[i]; %>
                                    <tr
                                        class="item-row item-<%- i %> "
                                        data-id="<%- i %>" >
                                        <td class=""  onclick="<%- pmObj.model.className %>.toggleSelectOption(this, 'options_list'); return false;">
                                            <div class="ico-on fa fa-toggle-on"></div>
                                            <div class="ico-off fa  fa-toggle-off"></div>
                                        </td>
                                        <td>
                                            <a href="/?template/<%- pmObj.model.kind %>/<%- item_id %>/option/<%- i %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= i %></a>
                                        </td>
                                        <% if(pmObj.model.className == "pmTasksTemplates") { %>
                                            <td class="hidden-xs">
                                                <a href="/?template/<%- pmObj.model.kind %>/<%- item_id %>/option/<%- i %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" >
                                                    <% if(option.playbook !== undefined) { %>
                                                        <%- option.playbook %>
                                                    <% } else { %>
                                                        <%- pmObj.model.items[item_id].data.playbook %>
                                                    <% } %>
                                                </a>
                                            </td>
                                        <% } else { %>
                                               <td class="hidden-xs">
                                                   <a href="/?template/<%- pmObj.model.kind %>/<%- item_id %>/option/<%- i %>" class="item-name"
                                                           onclick="return spajs.openURL(this.href);" >
                                                       <% if(option.module !== undefined) { %>
                                                           <%- option.module %>
                                                       <% } else { %>
                                                           <%- pmObj.model.items[item_id].data.module %>
                                                       <% } %>
                                                   </a>
                                               </td>
                                                <td class="hidden-xs hidden-1100">
                                                       <% if(option.args !== undefined) { %>
                                                           <%- option.args %>
                                                       <% } else { %>
                                                           <%- pmObj.model.items[item_id].data.args %>
                                                       <% } %>
                                               </td>
                                               <td class="hidden-xs hidden-1200">
                                                       <% if(option.group !== undefined) { %>
                                                           <%- option.group %>
                                                       <% } else { %>
                                                           <%- pmObj.model.items[item_id].data.group %>
                                                       <% } %>
                                               </td>
                                        <% } %>
                                        <td class="hidden-xs hidden-sm">
                                            <% if(option.vars !== undefined) { %>
                                                <ul class="option-vars">
                                                    <% for(var j in option.vars) { %>
                                                        <li><b><%- j %></b><% if(option.vars[j] != "") { %>: <%- option.vars[j] %><% } %></li>
                                                    <% } %>
                                                </ul>
                                            <% } %>
                                        </td>
                                        <td >
                                            <div class="btn-group" role="group">
                                                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    Actions
                                                    <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu dropdown-menu-right">
                                                    <li>
                                                        <a href="#"
                                                            onclick="spajs.showLoader(pmTemplates.model.kindObjects['<%- pmObj.model.kind %>'].execute(<%- item_id %>, '<%- i %>')); return false;" >
                                                            Execute
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a href="#"
                                                            onclick="spajs.showLoader(<%- pmObj.model.className %>.removeOption(<%- item_id %>, '<%- i %>')); return false;" >Delete</a>
                                                    </li>

                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                        <~>
                    </div>
                     <div class="box-footer clearfix">
                        <div class="btn-group hide actions_button" role="group">
                            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <~ pmObj.model.selectedOptionsCount>
                                Actions <%= pmObj.model.selectedOptionsCount %> on items
                                <~>
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="#"
                                        onclick="spajs.showLoader(<%- pmObj.model.className %>.removeSelectedOptions(<%- item_id %>, <%- pmObj.model.className %>.model.selectedOptions)); return false;" >Delete selected</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</script>

<!-- Поле поиска для страницы списка опций шаблона-->
<script  type="text/x-just" style="display: none;" data-just="searchFiledForTemplateOptions">
    <div class="input-group col-lg-2" style="float: right;">
        <input
            type="text"
            id="search-query-input"
            placeholder="Search by name"
            class="form-control"
            maxlength="255"
            value="<%- opt.query %>"
            onkeyup="if(event.keyCode == 13) spajs.showLoader(<%- opt.className %>.searchTemplateOptions($('#search-query-input').val(), <%- opt.className %>.model.searchAdditionalData));"
        >
        <div class="input-group-addon" onclick="spajs.showLoader(<%- opt.className %>.searchTemplateOptions($('#search-query-input').val(), <%- opt.className %>.model.searchAdditionalData));">
            <span class="glyphicon glyphicon-search" ></span>
        </div>
    </div>
</script>
