
<!-- Список Periodic Tasks -->
<script type="text/x-just" data-just="periodic-tasks_list">
    <section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?project/<%- project_id %>" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>

            <span class="h1-header" >Periodic tasks</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/<%- project_id %>" onclick="return spajs.openURL(this.href);" ><%- pmProjects.model.items[project_id].name.slice(0, 20) %></a></li>
            <li class="active">Periodic tasks</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.open({ menuId:'project/<%- project_id %>/new-periodic-tasks'});  return false;" class="btn btn-primary" >Create periodic tasks</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <%= pmPeriodicTasks.searchFiled({query:query, project_id:project_id}) %>
                        <% if(pmPeriodicTasks.getTotalPages(pmPeriodicTasks.model.itemslist)){ %>
                            <div style="float: right; margin-right: 20px;" class="hidden-xs">
                                <%= pmPeriodicTasks.paginationHtml(pmPeriodicTasks.model.itemslist) %>
                            </div>
                        <% } %>

                    </div>
                    <div class="box-body">
                        <table class="table table-bordered multiple-select">
                            <tbody>
                                <tr>
                                    <th style="width: 45px" onclick=" $(this).parent().toggleClass('selected'); pmPeriodicTasks.toggleSelectAll($('.multiple-select tr'), $(this).parent().hasClass('selected')); 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>
                                    <th style="width: 400px;" class="hidden-sm visible-lg">Link</th>
                                    <th style="width: 95px;" class="hidden-xs">Kind</th>
                                    <th style="width: 95px;" class="hidden-xs">Type</th>
                                    <th style="width: 80px" class="hidden-xs hidden-sm">Active</th>
                                    <!--<th style="width: 95px;" class="hidden-xs">Actions</th>-->
                                    <th style="width: 95px;" >Actions</th>
                                </tr>
                                <% for(var i in pmPeriodicTasks.model.itemslist.results){ valid = pmPeriodicTasks.model.itemslist.results[i].id; %>
                                    <tr
                                        class="item-row item-<%- valid %>  <%- pmPeriodicTasks.model.selectedItems.justClass(valid, 'selected') %>"
                                        data-id="<%- valid %>" >
                                        <td class=""  onclick="pmPeriodicTasks.toggleSelect(<%- valid %>); return false;">
                                            <div class="ico-on fa fa-toggle-on"></div>
                                            <div class="ico-off fa  fa-toggle-off"></div>
                                        </td>
                                        <td>
                                            <a href="/?project/<%- pmPeriodicTasks.model.items[valid].project %>/periodic-task/<%- valid %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('name') %></a>
                                        </td>
                                        <td class="hidden-sm visible-lg">
                                            <% if(pmPeriodicTasks.model.items[valid].kind == "PLAYBOOK" || pmPeriodicTasks.model.items[valid].kind == "MODULE") { %>
                                                <a href="/?project/<%- pmPeriodicTasks.model.items[valid].project %>/periodic-task/<%- valid %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('mode') %></a>
                                            <% } else { %>
                                                    <% if(pmPeriodicTasks.model.items[valid].template_opt == null) { %>
                                                        <a href="/?template/<%- pmTasksTemplates.model.items[pmPeriodicTasks.model.items[valid].template].kind %>/<%- pmPeriodicTasks.model.items[valid].template %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" ><%= pmTasksTemplates.model.items[pmPeriodicTasks.model.items[valid].template].name %></a>
                                                    <% } else { %>
                                                         <a href="/?template/<%- pmTasksTemplates.model.items[pmPeriodicTasks.model.items[valid].template].kind %>/<%- pmPeriodicTasks.model.items[valid].template %>/option/<%- pmPeriodicTasks.model.items[valid].template_opt %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" ><%= pmTasksTemplates.model.items[pmPeriodicTasks.model.items[valid].template].name %> [<%= pmPeriodicTasks.model.items[valid].template_opt %>]</a>
                                                    <% } %>
                                            <% } %>
                                        </td>
                                        <td class="hidden-xs">
                                            <a href="/?project/<%- pmPeriodicTasks.model.items[valid].project %>/periodic-task/<%- valid %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('kind') %></a>
                                        </td>
                                        <td class="hidden-xs">
                                            <a href="/?project/<%- pmPeriodicTasks.model.items[valid].project %>/periodic-task/<%- valid %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('type') %></a>
                                        </td>
                                        <td style="width: 80px" class="hidden-xs hidden-sm pt-enabled pt-enabled-<%- valid %>">
                                                <% if(pmPeriodicTasks.model.items[valid].enabled) { %>
                                                    <i class="fa fa-check" style="font-size:20px;"></i>
                                                <% } %>
                                        </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(pmPeriodicTasks.deleteItem(<%- valid %>)); return false;" >Delete</a>
                                                    </li>
                                                    <li>

                                                            <a href="#" class="change-activation-<%- valid %>"
                                                                onclick="spajs.showLoader(pmPeriodicTasks.changeItemActivation(<%- valid %>)); return false;" >
                                                                <% if(pmPeriodicTasks.model.items[valid].enabled) { %>
                                                                    Deactivate
                                                                <% } else { %>
                                                                    Activate
                                                                <% } %>
                                                            </a>

                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <div class="btn-group <%- pmPeriodicTasks.model.justNotClass('selectedCount', 'hide') %>" role="group">
                            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                Actions on <%= pmPeriodicTasks.model.justText('selectedCount') %> items
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.deleteRows($('.multiple-select .item-row.selected'))); return false;" >Delete from this page</a>
                                </li> 
                                <li>
                                    <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.deleteSelected()); return false;" >Delete all selected elements</a>
                                </li>
                            </ul>
                        </div>
                        
                        <% if(!query){ %>
                            <div class="btn-group" role="group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    Select
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">  
                                    <li>
                                        <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.toggleSelectEachItem(true, <%- project_id %>)); return false;" >Select all</a>
                                    </li>
                                    <li class=" <%- pmPeriodicTasks.model.justNotClass('selectedCount', 'hide') %>" >
                                        <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.toggleSelectEachItem(false, <%- project_id %>)); return false;" >Unselect all</a>
                                    </li>
                                </ul>
                            </div>
                        <% } %>
                        <% if(pmPeriodicTasks.getTotalPages(pmPeriodicTasks.model.itemslist)){ %>
                                <%= pmPeriodicTasks.paginationHtml(pmPeriodicTasks.model.itemslist) %>
                        <% } %>
                    </div>
                </div>
            </section>
        </div>
    </section>
</script>

<!-- Список Periodic Tasks -->
<script type="text/x-just" data-just="linked-to-template-periodic-tasks_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" >Periodic tasks linked to 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">Periodic tasks</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.open({ menuId:'template/<%- pmObj.model.kind %>/<%- item_id %>/new-periodic-task'});  return false;" class="btn btn-primary" >Create periodic tasks</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                         <%= pmPeriodicTasks.searchFiled({query:query, project_id:project_id, template_id:item_id, template_kind:pmObj.model.kind}) %>
                        <% if(pmPeriodicTasks.getTotalPages(pmPeriodicTasks.model.itemslist)){ %>
                            <div style="float: right; margin-right: 20px;" class="hidden-xs">
                                <%= pmPeriodicTasks.paginationHtml(pmPeriodicTasks.model.itemslist) %>
                            </div>
                        <% } %>
                    </div>
                    <div class="box-body">
                        <table class="table table-bordered multiple-select">
                            <tbody>
                                <tr>
                                    <th style="width: 45px" onclick=" $(this).parent().toggleClass('selected'); pmPeriodicTasks.toggleSelectAll($('.multiple-select tr'), $(this).parent().hasClass('selected')); 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>
                                    <th style="width: 400px;" class="hidden-sm visible-lg">Link</th>
                                    <th style="width: 95px;" class="hidden-xs">Type</th>
                                    <th style="width: 80px" class="hidden-xs hidden-sm">Active</th>
                                    <!--<th style="width: 95px;" class="hidden-xs">Actions</th>-->
                                    <th style="width: 95px;" >Actions</th>
                                </tr>
                                <% for(var i in pmPeriodicTasks.model.itemslist.results){ valid = pmPeriodicTasks.model.itemslist.results[i].id; %>
                                    <tr
                                        class="item-row item-<%- valid %>  <%- pmPeriodicTasks.model.selectedItems.justClass(valid, 'selected') %>"
                                        data-id="<%- valid %>" >
                                        <td class=""  onclick="pmPeriodicTasks.toggleSelect(<%- valid %>); 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 %>/periodic-task/<%- valid %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('name') %></a>
                                        </td>
                                        <td class="hidden-sm visible-lg">
                                            <% if(pmPeriodicTasks.model.items[valid].template_opt == null) { %>
                                                <a href="/?template/<%- pmObj.model.items[pmPeriodicTasks.model.items[valid].template].kind %>/<%- pmPeriodicTasks.model.items[valid].template %>" class="item-name"
                                                onclick="return spajs.openURL(this.href);" ><%= pmObj.model.items[pmPeriodicTasks.model.items[valid].template].name %></a>
                                            <% } else { %>
                                                 <a href="/?template/<%- pmObj.model.items[pmPeriodicTasks.model.items[valid].template].kind %>/<%- pmPeriodicTasks.model.items[valid].template %>/option/<%- pmPeriodicTasks.model.items[valid].template_opt %>" class="item-name"
                                                onclick="return spajs.openURL(this.href);" ><%= pmObj.model.items[pmPeriodicTasks.model.items[valid].template].name %> [<%= pmPeriodicTasks.model.items[valid].template_opt %>]</a>
                                            <% } %>
                                        </td>
                                        <td class="hidden-xs">
                                            <a href="/?template/<%- pmObj.model.kind %>/<%- item_id %>/periodic-task/<%- valid %>" class="item-name"
                                                    onclick="return spajs.openURL(this.href);" ><%= pmPeriodicTasks.model.items[valid].justText('type') %></a>
                                        </td>
                                        <td style="width: 80px" class="hidden-xs hidden-sm pt-enabled pt-enabled-<%- valid %>">
                                                <% if(pmPeriodicTasks.model.items[valid].enabled) { %>
                                                    <i class="fa fa-check" style="font-size:20px;"></i>
                                                <% } %>
                                        </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(pmPeriodicTasks.deleteItem(<%- valid %>)); return false;" >Delete</a>
                                                    </li>
                                                    <li>

                                                            <a href="#" class="change-activation-<%- valid %>"
                                                                onclick="spajs.showLoader(pmPeriodicTasks.changeItemActivation(<%- valid %>)); return false;" >
                                                                <% if(pmPeriodicTasks.model.items[valid].enabled) { %>
                                                                    Deactivate
                                                                <% } else { %>
                                                                    Activate
                                                                <% } %>
                                                            </a>

                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <div class="btn-group <%- pmPeriodicTasks.model.justNotClass('selectedCount', 'hide') %>" role="group">
                            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                Actions on <%= pmPeriodicTasks.model.justText('selectedCount') %> items
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.deleteRows($('.multiple-select .item-row.selected'))); return false;" >Delete from this page</a>
                                </li>
                                <li>
                                    <a href="#" onclick="spajs.showLoader(pmPeriodicTasks.deleteSelected()); return false;" >Delete all selected elements</a>
                                </li>
                            </ul>
                        </div>
                        <% if(pmPeriodicTasks.getTotalPages(pmPeriodicTasks.model.itemslist)){ %>
                                <%= pmPeriodicTasks.paginationHtml(pmPeriodicTasks.model.itemslist) %>
                        <% } %>
                    </div>
                </div>
            </section>
        </div>
    </section>
</script>
 
<!-- Шаблон полей  Project Inventory и Playbook  -->
<script type="text/x-just" data-just="filed_type_selectInventoryKindPlaybookGroupModuleAndTime"> 
    <% if(item_id){ %>

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Kind</label>
            <select class="form-control"
                    id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_kind"
                    data-placeholder="Select kind"
                    onchange="pmPeriodicTasks.model.items[<%- item_id %>].kind = this.value;"
                    style="width:100%" >
                <option value="PLAYBOOK" <% if(pmPeriodicTasks.model.items[item_id].kind == 'PLAYBOOK'){ %>selected<% } %> >Playbook</option>
                <option value="MODULE" <% if(pmPeriodicTasks.model.items[item_id].kind == 'MODULE'){ %>selected<% } %> >Module</option>
                <option value="TEMPLATE" <% if(pmPeriodicTasks.model.items[item_id].kind == 'TEMPLATE'){ %>selected<% } %> >Template</option>
            </select>
            <div class="help-block"></div>
        </div>

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'PLAYBOOK' }) %>">
            <label class="control-label" >Playbook</label>
            <input type="text"
                    placeholder="Enter playbook name"
                    id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_playbook"
                    value="<%- pmPeriodicTasks.model.items[item_id].mode %>"
                    class="form-control"
                    maxlength="255">
            <div class="help-block"></div>
        </div>

        <div class="<%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %> ">
            <~ pmPeriodicTasks.model.selectedInventory>
                <%= pmGroups.groupsAutocompleteTemplate(pmPeriodicTasks.model.selectedInventory, pmPeriodicTasks.model.items[item_id].group) %>
            <~>
        </div>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12 <%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %>">
            <%= moduleArgsEditor.moduleFileds({
                    module:{value:pmPeriodicTasks.model.items[item_id].mode },
                    args:{value:pmPeriodicTasks.model.items[item_id].args }
                })
            %>
        </div>

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'TEMPLATE' }) %>">
            <%= pmPeriodicTasks.projectTemplatesAutocompletefiled.render(pmPeriodicTasks, {
                name:'template',
                title:'Template',
                getFiledValue:function(item_id){
                    if(pmPeriodicTasks.model.items[item_id].template_opt != null)
                    {
                        return pmPeriodicTasks.model.items[item_id].template + '/' + pmPeriodicTasks.model.items[item_id].template_opt;
                    }
                    else
                    {
                        return pmPeriodicTasks.model.items[item_id].template;
                    }
                },
                onchange:function(event){
                    console.log("onchange", event)
                    if(/[^0-9]/mg.test(event.value))
                    {
                        pmPeriodicTasks.selectInventory()
                    }
                    else
                    {
                        pmPeriodicTasks.selectInventory(event.value)
                    }
                }
            }, item_id, {}) %>
        </div>

        <~ pmPeriodicTasks.model.items[item_id].kind >
            <% if (pmPeriodicTasks.model.items[item_id].kind != "TEMPLATE") { %>
                <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
                    <div class="row">
                        <%= pmPeriodicTasks.inventoriesAutocompletefiled.render(pmPeriodicTasks, {
                            name:'inventory',
                            title:'Inventory',
                            getFiledValue:function(item_id){
                                return pmPeriodicTasks.model.items[item_id].inventory;
                            },
                            onchange:function(event){
                                console.log("onchange", event)
                                if(/[^0-9]/mg.test(event.value))
                                {
                                    pmPeriodicTasks.selectInventory()
                                }
                                else
                                {
                                    pmPeriodicTasks.selectInventory(event.value)
                                }
                            }
                        }, item_id, {}) %>
                    </div>
                </div>
            <% } %>
        <~>


        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
            <div class="row">

                <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                    <label class="control-label" >Type</label>
                    <select
                            onchange="pmPeriodicTasks.model.items[<%- item_id %>].type = this.value;"
                            id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_type"
                            class="form-control"
                            maxlength="255">
                            <option value="INTERVAL" <% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %>selected<% } %> >Interval schedule</option>
                            <option value="CRONTAB" <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %>selected<% } %> >Cron style schedule</option>
                    </select>
                    <div class="help-block"></div>
                </div>

                <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.items[item_id].justClass('type', 'hide', function(v){ return v != 'INTERVAL' }) %> ">
                    <label class="control-label" >Interval schedule</label>
                    <div class="input-group">
                        <input type="text"
                                placeholder="Enter time interval in seconds"
                                id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_schedule_INTERVAL"
                                value="<% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %><%- pmPeriodicTasks.model.items[item_id].schedule %><% } %>"
                                class="form-control"
                                maxlength="255"
                                onkeyup="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+(.)/g, '$1'); $('#interval-schedule-help').html('~ '+Math.floor(this.value/3600*100)/100+'h')"
                            >
                        <span class="input-group-addon" id="basic-addon2">sec</span>
                    </div>
                    <div class="help-block" id="interval-schedule-help">
                        <% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %>
                                ~<%- Math.floor(pmPeriodicTasks.model.items[item_id].schedule/3600*100)/100  %>h
                        <% } %>
                    </div>
                </div>

            </div>
        </div>

            <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12  <%- pmPeriodicTasks.model.items[item_id].justClass('type', 'hide', function(v){ return v != 'CRONTAB' }) %> ">
                <label class="control-label" >Schedule `CRONTAB`</label>
                <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %>
                    <%= crontabEditor.editor({string:pmPeriodicTasks.model.items[item_id].schedule}) %>
                <% }else{ %>
                    <%= crontabEditor.editor({string:''}) %>
                <% } %>
                <div class="help-block" id=""></div>
            </div>

    <% }else{ %>
        <!-- Не задан item_id -->
    <% } %>
</script>

<script type="text/x-just" data-just="filed_type_selectTemplateFromProjectToPT">
    <% if(item_id !== undefined) { %>

        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" >Kind</label>
            <select class="form-control"
                    id="periodic-tasks_<%- item_id %>_kind"
                    data-placeholder="Select kind"
                    style="width:100%" readonly disabled>
                <option value="TEMPLATE" selected>Template</option>
            </select>
            <div class="help-block"></div>
        </div>



        <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 disabled">
            <label class="control-label" >Template from project</label>
            <select class="form-control select2 inventory-source-value" id="templates-autocomplete" data-placeholder="Select template" style="width:100%" >
                    <option
                        <% if(pmObj.model.items[item_id].template == pmTasksTemplates.model.items[opt.template_id].id
                            && pmObj.model.items[item_id].template_opt == null){ %>  selected  <% } %>
                        value="<%- pmTasksTemplates.model.items[opt.template_id].id %>"><%- pmTasksTemplates.model.items[opt.template_id].name %>
                    </option>
                    <% if(pmTasksTemplates.model.items[opt.template_id].options_list.length != 0) { %>
                        <% for (var j in pmTasksTemplates.model.items[opt.template_id].options_list) { %>
                            <option
                                 <% if(pmObj.model.items[item_id].template == pmTasksTemplates.model.items[opt.template_id].id
                                   && pmObj.model.items[item_id].template_opt == pmTasksTemplates.model.items[opt.template_id].options_list[j]){ %>  selected  <% } %>
                            value="<%- pmTasksTemplates.model.items[opt.template_id].id %>/<%- pmTasksTemplates.model.items[opt.template_id].options_list[j] %>"><%- pmTasksTemplates.model.items[opt.template_id].name %> [<%- pmTasksTemplates.model.items[opt.template_id].options_list[j] %>]</option>
                        <% } %>
                    <% } %>
            </select>
        </div>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
            <div class="row">

                <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                    <label class="control-label" >Type</label>
                    <select
                            onchange="pmPeriodicTasks.model.items[<%- item_id %>].type = this.value;"
                            id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_type"
                            class="form-control"
                            maxlength="255">
                            <option value="INTERVAL" <% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %>selected<% } %> >Interval schedule</option>
                            <option value="CRONTAB" <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %>selected<% } %> >Cron style schedule</option>
                    </select>
                    <div class="help-block"></div>
                </div>

                <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.items[item_id].justClass('type', 'hide', function(v){ return v != 'INTERVAL' }) %> ">
                    <label class="control-label" >Interval schedule</label>
                    <div class="input-group">
                        <input type="text"
                                placeholder="Enter time interval in seconds"
                                id="periodic-tasks_<%- pmPeriodicTasks.model.items[item_id].id %>_schedule_INTERVAL"
                                value="<% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %><%- pmPeriodicTasks.model.items[item_id].schedule %><% } %>"
                                class="form-control"
                                maxlength="255"
                                onkeyup="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+(.)/g, '$1'); $('#interval-schedule-help').html('~ '+Math.floor(this.value/3600*100)/100+'h')"
                            >
                        <span class="input-group-addon" id="basic-addon2">sec</span>
                    </div>
                    <div class="help-block" id="interval-schedule-help">
                        <% if(pmPeriodicTasks.model.items[item_id].type == 'INTERVAL'){ %>
                                ~<%- Math.floor(pmPeriodicTasks.model.items[item_id].schedule/3600*100)/100  %>h
                        <% } %>
                    </div>
                </div>

            </div>
        </div>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12  <%- pmPeriodicTasks.model.items[item_id].justClass('type', 'hide', function(v){ return v != 'CRONTAB' }) %> ">
            <label class="control-label" >Schedule `CRONTAB`</label>
            <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %>
                <%= crontabEditor.editor({string:pmPeriodicTasks.model.items[item_id].schedule}) %>
            <% }else{ %>
                <%= crontabEditor.editor({string:''}) %>
            <% } %>
            <div class="help-block" id=""></div>
        </div>

    <% } %>

</script>

<!-- Страница создания periodic-task -->
<script type="text/x-just" data-just="periodic-tasks_page_vars_section">
  
    <div class="<%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'PLAYBOOK' }) %>">
        <%= jsonEditor.editor(PLAYBOOK_VARS, {prefix: "PLAYBOOK", block:'periodic_playbook', title1:'Arguments', title2:'Adding new argument'}) %>
    </div>

    <div class="<%- pmPeriodicTasks.model.items[item_id].justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %>">
        <%= jsonEditor.editor(MODULE_VARS, {prefix: "MODULE", block:'periodic_playbook', title1:'Arguments', title2:'Adding new argument'}) %>
    </div>

</script>

<!-- Страница создания periodic-task -->
<script type="text/x-just" data-just="periodic-tasks_new_page">
    <section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?project/<%- project_id %>/periodic-tasks" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>

            <span class="h1-header" >Create new periodic task</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/<%- project_id %>" onclick="return spajs.openURL(this.href);" ><%- pmProjects.model.items[project_id].name.slice(0, 20) %></a></li>
            <li><a href="<%- polemarch.opt.host %>/?project/<%- project_id %>/periodic-tasks" onclick="return spajs.openURL(this.href);" >Periodic tasks</a></li>
            <li class="active">New periodic task</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(pmPeriodicTasks.addItem(<%- project_id %>)); return false;" class="btn btn-primary" >Save task</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        New task<br>
                    </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" >Name</label>
                                <input type="text"
                                        placeholder="Enter name"
                                        id="new_periodic-tasks_name"
                                        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 boolean-select">
                                <label class="control-label" >Save in history</label>
                                <div class="form-control selected"
                                        onclick="$(this).toggleClass('selected');"
                                        onselectstart="return false"
                                        onmousedown="return false"
                                        style="cursor: pointer;"
                                        id="new_periodic-tasks_save_result"  >
                                    <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">Save result of task in history</div>
                            </div>
                        </div>


 
                        
                        <div class="row">
                        
                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Kind</label>
                                <select class="form-control"
                                        id="new_periodic-tasks_kind"
                                        data-placeholder="Select kind"
                                        onchange="pmPeriodicTasks.model.newitem.kind = this.value;"
                                        style="width:100%" >
                                    <option value="PLAYBOOK" selected >Playbook</option>
                                    <option value="MODULE" >Module</option>
                                    <option value="TEMPLATE" >Template</option>
                                </select>
                                <div class="help-block"></div>
                            </div>

                            <div class="<%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %>">
                                <~ pmPeriodicTasks.model.selectedInventory>
                                    <%= pmGroups.groupsAutocompleteTemplate(pmPeriodicTasks.model.selectedInventory) %>
                                <~>
                            </div>

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'PLAYBOOK' }) %>">
                                <label class="control-label" >Playbook</label>
                                <input type="text"
                                        placeholder="Enter playbook name"
                                        id="new_periodic-tasks_playbook"
                                        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 <%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'TEMPLATE' }) %>">
                                <%= pmPeriodicTasks.projectTemplatesAutocompletefiled.render(pmPeriodicTasks, {
                                name:'template',
                                title:'Template',
                                onchange:function(event){
                                    console.log("onchange", event)
                                    if(/[^0-9]/mg.test(event.value))
                                    {
                                        pmPeriodicTasks.selectInventory()
                                    }
                                    else
                                    {
                                        pmPeriodicTasks.selectInventory(event.value)
                                    }
                                }
                            }, null, {}) %>
                            </div>
                        </div>
                        
                        <div class="<%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %>">
                            <%= moduleArgsEditor.moduleFileds() %> 
                        </div>


                        <~ pmPeriodicTasks.model.newitem.kind >
                            <% if(pmPeriodicTasks.model.newitem.kind != "TEMPLATE") { %>
                                <div class="row">

                                    <%= pmPeriodicTasks.inventoriesAutocompletefiled.render(pmPeriodicTasks, {
                                        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))
                                            {
                                                pmPeriodicTasks.selectInventory()
                                            }
                                            else
                                            {
                                                pmPeriodicTasks.selectInventory(event.value)
                                            }
                                        }
                                    }, null, {}) %>
                                </div>
                            <% } %>
                        <~>
 
                        <div class="row">

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Type</label>
                                <select
                                        onchange="pmPeriodicTasks.model.newitem.type = this.value;"
                                        id="new_periodic-tasks_type"
                                        class="form-control"
                                        maxlength="255">
                                        <option value="INTERVAL" >Interval schedule</option>
                                        <option value="CRONTAB" >Cron style schedule</option>
                                </select>
                                <div class="help-block"></div>
                            </div>

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.newitem.justClass('type', 'hide', function(v){ return v != 'INTERVAL' }) %> ">
                                <label class="control-label" >Interval schedule</label>
                                <div class="input-group">
                                    <input type="text"
                                            placeholder="Enter time interval in seconds"
                                            id="new_periodic-tasks_schedule_INTERVAL"
                                            value=""
                                            class="form-control"
                                            maxlength="255"
                                            onkeyup="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+(.)/g, '$1'); $('#interval-schedule-help').html('~ '+Math.floor(this.value/3600*100)/100+'h')"
                                        >
                                    <span class="input-group-addon" id="basic-addon2">sec</span>
                                </div>
                                <div class="help-block" id="interval-schedule-help"></div>
                            </div> 
                        </div>
                        <div class="row">
                            <div class="form-group col-lg-12 <%- pmPeriodicTasks.model.newitem.justClass('type', 'hide', function(v){ return v != 'CRONTAB' }) %> ">
                                <label class="control-label" >Schedule `CRONTAB`</label>
                                <%= crontabEditor.editor({string:''}) %>
                                <div class="help-block" id=""></div>
                            </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>
                <div class="row <%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'PLAYBOOK' }) %>">
                    <%= jsonEditor.editor({}, {prefix: "PLAYBOOK", block:'periodic_playbook', title1:'Arguments', title2:'Adding new argument'}) %>
                </div>
                
                <div class="row <%- pmPeriodicTasks.model.newitem.justClass('kind', 'hide', function(v){ return v != 'MODULE' }) %>">
                    <%= jsonEditor.editor({}, {prefix: "MODULE", block:'periodic_module', title1:'Arguments', title2:'Adding new argument'}) %>
                </div>
                
            </section>
        </div>
    </section>
</script>


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

            <span class="h1-header" >Create new periodic task</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><a href="<%- polemarch.opt.host %>/?template/<%- pmObj.model.kind %>/<%- item_id %>/periodic-tasks" onclick="return spajs.openURL(this.href);" >Periodic tasks</a></li>
            <li class="active">New periodic tasks</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(pmPeriodicTasks.addItem(<%- project_id %>)); return false;" class="btn btn-primary" >Save task</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        New task<br>
                    </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" >Name</label>
                                <input type="text"
                                        placeholder="Enter name"
                                        id="new_periodic-tasks_name"
                                        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 boolean-select">
                                <label class="control-label" >Save in history</label>
                                <div class="form-control selected"
                                        onclick="$(this).toggleClass('selected');"
                                        onselectstart="return false"
                                        onmousedown="return false"
                                        style="cursor: pointer;"
                                        id="new_periodic-tasks_save_result"  >
                                    <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">Save result of task in history</div>
                            </div>
                        </div>


                        <div class="row">

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Kind</label>
                                <select class="form-control"
                                        id="new_periodic-tasks_kind"
                                        data-placeholder="Select kind"
                                        style="width:100%" readonly disabled>
                                    <option value="TEMPLATE" selected>Template</option>
                                </select>
                                <div class="help-block"></div>
                            </div>



                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 disabled">
                                <label class="control-label" >Template from project</label>
                                <select class="form-control select2 inventory-source-value" id="templates-autocomplete" data-placeholder="Select template" style="width:100%" >
                                        <option
                                            value="<%- pmObj.model.items[item_id].id %>"><%- pmObj.model.items[item_id].name %>
                                        </option>
                                        <% if(pmObj.model.items[item_id].options_list.length != 0) { %>
                                            <% for (var j in pmObj.model.items[item_id].options_list) { %>
                                                <option value="<%- pmObj.model.items[item_id].id %>/<%- pmObj.model.items[item_id].options_list[j] %>"><%- pmObj.model.items[item_id].name %> [<%- pmObj.model.items[item_id].options_list[j] %>]</option>
                                            <% } %>
                                        <% } %>
                                </select>
                            </div>
                        </div>



                        <div class="row">

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Type</label>
                                <select
                                        onchange="pmPeriodicTasks.model.newitem.type = this.value;"
                                        id="new_periodic-tasks_type"
                                        class="form-control"
                                        maxlength="255">
                                        <option value="INTERVAL" >Interval schedule</option>
                                        <option value="CRONTAB" >Cron style schedule</option>
                                </select>
                                <div class="help-block"></div>
                            </div>

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6 <%- pmPeriodicTasks.model.newitem.justClass('type', 'hide', function(v){ return v != 'INTERVAL' }) %> ">
                                <label class="control-label" >Interval schedule</label>
                                <div class="input-group">
                                    <input type="text"
                                            placeholder="Enter time interval in seconds"
                                            id="new_periodic-tasks_schedule_INTERVAL"
                                            value=""
                                            class="form-control"
                                            maxlength="255"
                                            onkeyup="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+(.)/g, '$1'); $('#interval-schedule-help').html('~ '+Math.floor(this.value/3600*100)/100+'h')"
                                        >
                                    <span class="input-group-addon" id="basic-addon2">sec</span>
                                </div>
                                <div class="help-block" id="interval-schedule-help"></div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group col-lg-12 <%- pmPeriodicTasks.model.newitem.justClass('type', 'hide', function(v){ return v != 'CRONTAB' }) %> ">
                                <label class="control-label" >Schedule `CRONTAB`</label>
                                <%= crontabEditor.editor({string:''}) %>
                                <div class="help-block" id=""></div>
                            </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>
    </section>
</script>

<!-- Шаблон для автокоплита шаблонов текущего проекта -->
<script type="text/x-just" data-just="filed_type_projectTemplatesAutocomplete">
    <% if(item_id){ %>
        <label class="control-label" >Template from project</label>
        <select class="form-control select2 inventory-source-value" id="templates-autocomplete" data-placeholder="Select template" style="width:100%"  onchange="if(<%- justCall(filed) %>.onchange) <%- justCall(filed) %>.onchange({value:this.value})" >
            <% for(var i in pmTasksTemplates.model.itemslist.results){ var val = pmTasksTemplates.model.itemslist.results[i] %>
                <option
                    <% if(pmObj.model.items[item_id].template == val.id && pmObj.model.items[item_id].template_opt == null){ %>  selected  <% } %>
                    value="<%- val.id %>"><%- val.name %>
                </option>
                <% if(val.options_list.length != 0) { %>
                    <% for (var j in val.options_list) { %>
                        <option <% if(pmObj.model.items[item_id].template == val.id && pmObj.model.items[item_id].template_opt == val.options_list[j]){ %>  selected  <% } %>
                            value="<%- val.id %>/<%- val.options_list[j] %>">
                                <%- val.name %> [<%- val.options_list[j] %>]
                        </option>
                    <% } %>
                <% } %>
            <% } %>
        </select>
        <div class="help-block"></div>
    <% }else{ %>
        <label class="control-label" >Template from project</label>
        <select class="form-control select2 inventory-source-value" id="templates-autocomplete"  data-placeholder="Select template" style="width:100%"  onchange="if(<%- justCall(filed) %>.onchange) <%- justCall(filed) %>.onchange({value:this.value})">
            <% for(var i in pmTasksTemplates.model.itemslist.results){ var val = pmTasksTemplates.model.itemslist.results[i] %>
                <option value="<%- val.id %>"><%- val.name %></option>
                <% if(val.options_list.length != 0) { %>
                    <% for (var j in val.options_list) { %>
                        <option value="<%- val.id %>/<%- val.options_list[j] %>"><%- val.name %> [<%- val.options_list[j] %>]</option>
                    <% } %>
                <% } %>
            <% } %>
        </select>
        <div class="help-block"></div>
    <% } %>
</script>

<!-- periodic task from template page -->
<script type="text/x-just" data-just="periodic-task-from-template-page">

    <!-- items_page -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item_from_template.back_link){ %><%- pmObj.model.page_item_from_template.back_link.apply(pmObj, [item_id, opt]) %><% }else{ %><%- polemarch.opt.host %>/?<%- pmObj.model.name %>/<%- pmObj.model.kind %>/<%= item_id %>/options<% } %>"
                onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>

            <span class="h1-header" ><%= pmObj.model.page_item_from_template.title.apply(pmObj, [item_id, opt]) %></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 %>/?templates/<%- pmTasksTemplates.model.items[opt.template_id].kind %>/<%= opt.template_id %>" onclick="return spajs.openURL(this.href);" ><%= pmTasksTemplates.model.items[opt.template_id].name %></a></li>
            <li><a href="<%- polemarch.opt.host %>/?templates/<%- pmTasksTemplates.model.items[opt.template_id].kind %>/<%= opt.template_id %>/periodic-tasks" onclick="return spajs.openURL(this.href);" >Periodic tasks</a></li>
            <li class="active"><%= pmObj.model.page_item_from_template.short_title.apply(pmObj, [item_id, opt]) %></li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-lg-12">
                <% if(pmObj.model.page_item_from_template.buttons){ %>
                    <% for(var i in  pmObj.model.page_item_from_template.buttons){ %>
                        <% if(pmObj.model.page_item_from_template.buttons[i].tpl){ %>
                            <%= pmObj.model.page_item_from_template.buttons[i].tpl.apply(pmObj, [item_id, opt]) %>
                        <% }else{ %>
                            <a
                                class="top-line-btn <% if(typeof pmObj.model.page_item_from_template.buttons[i].title == 'function'){ %>
                                            <%- pmObj.model.page_item_from_template.buttons[i].class.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item_from_template.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_item_from_template.buttons[i].link.apply(pmObj, [item_id, opt]) %>"
                                title="<%- pmObj.model.page_item_from_template.buttons[i].help || '' %>"
                                onclick="<%- pmObj.model.page_item_from_template.buttons[i].function.apply(pmObj, [item_id, opt]) %>" >
                                    <% if(typeof pmObj.model.page_item_from_template.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_item_from_template.buttons[i].title.apply(pmObj, [item_id, opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_item_from_template.buttons[i].title %>
                                    <% } %>
                            </a>
                        <% } %>
                    <% } %>
                <% } %>
            </div>
        </div>
        <br>

        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <%= pmObj.model.page_item_from_template.short_title.apply(pmObj, [item_id, opt]) %><br>
                        <div class="box-tools pull-right">
                        </div>
                    </div>
                    <div class="box-body">
                        <% for(var i in pmObj.model.page_item_from_template.fileds){ %>
                            <div class="row">
                                <% for(var j in pmObj.model.page_item_from_template.fileds[i]){ var filed = pmObj.model.page_item_from_template.fileds[i][j]; %>
                                        <%= filed.filed.render(pmObj, filed, item_id, opt) %>
                                <% } %>
                            </div>
                        <% } %>
                    </div>
                </div>
            </section>
            <% if(pmObj.model.page_item_from_template.sections){ %>
                <% for(var i in pmObj.model.page_item_from_template.sections){ %>
                    <%= pmObj.model.page_item_from_template.sections[i].apply(pmObj, [pmObj.model.page_item_from_template.sections[i], item_id, opt]) %>
                <% } %>
            <% } %>
        </div>
    </section>
    <!-- /items_page -->
</script>