
<script  type="text/x-just" style="display: none;" data-just="pagination">
<% if(totalPage > 1){ %>
        <ul class="pagination no-margin pull-right">
            <% if(totalPage < 21){ %>
                <% for(var i = 0; i < totalPage; i++){ %>
                    <% if(i == currentPage){ %>
                        <li><a href="<%- url.replace(/\/page\/[0-9]+/igm, '') + '/page/'+(i+1) %>" onclick="return spajs.openURL(this.href);" style="background-color: #d2d6de;"><%- i+1 %></a></li>
                    <% }else{ %>
                        <li><a href="<%- url.replace(/\/page\/[0-9]+/igm, '') + '/page/'+(i+1) %>" onclick="return spajs.openURL(this.href);" ><%- i+1 %></a></li>
                    <% } %>
                <% } %>
            <% }else{ %>
                <% for(var i = 0; i < totalPage; i++){ %>
                    <% if(i == currentPage){ %>
                        <li><a href="<%- url.replace(/\/page\/[0-9]+/igm, '') + '/page/'+(i+1) %>" onclick="return spajs.openURL(this.href);" style="background-color: #d2d6de;"><%- i+1 %></a></li>
                    <% }else{ %>
                        <% if(Math.abs(i - currentPage) > 5 && i > 3 && totalPage - i > 3){ %>
                            <% if( dotShow == false){ %>
                                <% dotShow = true %>
                                <li><a href="<%- url.replace(/\/page\/[0-9]+/igm, '') + '/page/'+(i+1) %>" onclick="return spajs.openURL(this.href);">..</a></li>
                            <% } %>
                        <% }else{ %>
                            <% dotShow = false %>
                            <li><a href="<%- url.replace(/\/page\/[0-9]+/igm, '') + '/page/'+(i+1) %>" onclick="return spajs.openURL(this.href);" ><%- i+1 %></a></li>
                        <% } %>
                    <% } %>
                <% } %>
            <% } %>
        </ul>
<% } %>
</script>

<script  type="text/x-just" style="display: none;" data-just="searchFiled">
    <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 %>.search($('#search-query-input').val(), <%- opt.className %>.model.searchAdditionalData));"
        >
        <div class="input-group-addon" onclick="spajs.showLoader(<%- opt.className %>.search($('#search-query-input').val(), <%- opt.className %>.model.searchAdditionalData));">
            <span class="glyphicon glyphicon-search" ></span>
        </div>
    </div>
</script>



<!-- Список сущностей -->
<script type="text/x-just" data-just="items_list">
    <!-- items_list -->
    <section class="content-header">
        <h1>
            <%- pmObj.model.page_list.title %> 
        </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 class="active"><%- pmObj.model.page_list.short_title %></li>
        </ol>
    </section>


    <section class="content"> 
        <div class="row">
            <div class="col-lg-12">
                <% if(pmObj.model.page_list.buttons){ %>
                    <% for(var i in  pmObj.model.page_list.buttons){ %>
                        <% if(pmObj.model.page_list.buttons[i].tpl){ %>
                            <%= pmObj.model.page_list.buttons[i].tpl.apply(pmObj, [opt]) %>
                        <% }else{ %> 
                            <a 
                                class="top-line-btn <% if(typeof pmObj.model.page_list.buttons[i].class == 'function'){ %>
                                            <%- pmObj.model.page_list.buttons[i].class.apply(pmObj, [opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_list.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_list.buttons[i].link.apply(pmObj, [opt]) %>"
                                title="<%- pmObj.model.page_list.buttons[i].help || '' %>"
                                onclick="<% if(typeof pmObj.model.page_list.buttons[i].onclick == 'function'){ %>
                                        return <%- pmObj.model.className %>.model.page_list.buttons[<%- i %>].onclick.apply(<%- pmObj.model.className %>, [event])
                                    <% }else{ %>
                                        <%- pmObj.model.page_list.buttons[i].function.apply(pmObj, [opt]) %>
                                    <% } %>" >
                                    <% if(typeof pmObj.model.page_list.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_list.buttons[i].title.apply(pmObj, [opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_list.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.searchFiled({query:query}) %> 
                        <% if(pmObj.getTotalPages(pmObj.model.itemslist)){ %>
                            <div style="float: right; margin-right: 20px;" class="hidden-xs">
                                <%= pmObj.paginationHtml(pmObj.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'); <%- pmObj.model.className %>.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>
                                    <% for(var j in pmObj.model.page_list.fileds){ %>
                                        <th 
                                            <% if(pmObj.model.page_list.fileds[j].style){ %><%= pmObj.model.page_list.fileds[j].style.apply(pmObj,[undefined, opt]) %><% } %> 
                                            <% if(pmObj.model.page_list.fileds[j].class){ %><%= pmObj.model.page_list.fileds[j].class.apply(pmObj,[undefined, opt]) %><% } %>  >
                                                <%- pmObj.model.page_list.fileds[j].title %>
                                        </th> 
                                    <% } %>
                                    <th style="width: 95px;" >Actions</th>
                                </tr>
                                <% for(var i in pmObj.model.itemslist.results){ %>
                                    <tr
                                        class="item-row item-<%- pmObj.model.itemslist.results[i].id %>  <%- pmObj.model.selectedItems.justClass(pmObj.model.itemslist.results[i].id, 'selected') %>"
                                        data-id="<%- pmObj.model.itemslist.results[i].id %>" >
                                        <td class=""  onclick="<%- pmObj.model.className %>.toggleSelect(<%- pmObj.model.itemslist.results[i].id %>); return false;">
                                            <div class="ico-on fa fa-toggle-on"></div>
                                            <div class="ico-off fa  fa-toggle-off"></div>
                                        </td>
                                        <% for(var j in pmObj.model.page_list.fileds){ %>
                                            <td
                                                <% if(pmObj.model.page_list.fileds[j].style){ %><%= pmObj.model.page_list.fileds[j].style.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %><% } %>
                                                <% if(pmObj.model.page_list.fileds[j].class){ %><%= pmObj.model.page_list.fileds[j].class.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %><% } %>
                                            >
                                                <% if(!pmObj.model.page_list.fileds[j].value){ %>
                                                    <a href="/?<%- pmObj.model.page_name %>/<%- pmObj.model.itemslist.results[i].id %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" ><%- pmObj.model.itemslist.results[i][pmObj.model.page_list.fileds[j].name] %></a>
                                                <% }else{ %>
                                                    <%= pmObj.model.page_list.fileds[j].value.apply(pmObj, [pmObj.model.itemslist.results[i], pmObj.model.page_list.fileds[j].name, opt]) %>
                                                <% } %>
                                            </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">
                                                    <% for(var j in pmObj.model.page_list.actions){ %>
                                                        <% if(!pmObj.model.page_list.actions[j].title){ %>
                                                            <li role="separator" class="divider"></li>
                                                        <% }else{ %>
                                                            <li>
                                                                <a href="<%- pmObj.model.page_list.actions[j].link.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>"
                                                                    onclick="<%- pmObj.model.page_list.actions[j].function.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>"
                                                                    class="<% if(typeof pmObj.model.page_list.actions[j].class == 'function'){ %>
                                                                            <%- pmObj.model.page_list.actions[j].class.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>
                                                                       <% }else{ %>
                                                                            <%- pmObj.model.page_list.actions[j].class || '' %>
                                                                       <% } %>"
                                                                >
                                                                        <% if(typeof pmObj.model.page_list.actions[j].title == 'function'){ %>
                                                                            <%= pmObj.model.page_list.actions[j].title.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>
                                                                        <% }else{ %>
                                                                            <%- pmObj.model.page_list.actions[j].title %>
                                                                        <% } %>

                                                                </a>
                                                            </li>
                                                        <% } %>
                                                    <% } %>
                                                    <!-- -->
                                                    <% if(pmObj.model.itemslist.results[i].options_list) { %>
                                                         <% if(pmObj.model.itemslist.results[i].options_list.length!=0) { %>
                                                            <li role="separator" class="divider"></li>
                                                            <% for(var k in pmObj.model.itemslist.results[i].options_list) { %>
                                                                <li>
                                                                    <a href="#"
                                                                    onclick="<%- pmObj.model.page_list.actions[j].function.apply(pmObj, [pmObj.model.itemslist.results[i], pmObj.model.itemslist.results[i].options_list[k], opt]) %>">
                                                                        Execute with <%= pmObj.model.itemslist.results[i].options_list[k] %>
                                                                    </a>
                                                                </li>
                                                                <% } %>
                                                            <% } %>
                                                    <% } %>
                                                    <!-- -->

                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <div class="btn-group <%- pmObj.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 <%= pmObj.model.justText('selectedCount') %> items
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="#"
                                        onclick="spajs.showLoader(<%- pmObj.model.className %>.deleteRows($('.multiple-select .item-row.selected'))); return false;" >Delete from this page</a>
                                </li> 
                                <li>
                                    <a href="#" onclick="spajs.showLoader(<%- pmObj.model.className %>.deleteSelected()); return false;" >Delete all selected elements</a>
                                </li>
                                <% for(var j in pmObj.model.page_list.actionsOnSelected){ %> 
                                    <% if(!pmObj.model.page_list.actionsOnSelected[j].title){ %>
                                        <li role="separator" class="divider"></li>
                                    <% }else{ %>
                                        <li>
                                            <a href="<%- pmObj.model.page_list.actionsOnSelected[j].link.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>"
                                                onclick="<%- pmObj.model.page_list.actionsOnSelected[j].function.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>" >
                                                    <% if(typeof pmObj.model.page_list.actionsOnSelected[j].title == 'function'){ %>
                                                        <%= pmObj.model.page_list.actionsOnSelected[j].title.apply(pmObj, [pmObj.model.itemslist.results[i], opt]) %>
                                                    <% }else{ %>
                                                        <%- pmObj.model.page_list.actionsOnSelected[j].title %>
                                                    <% } %>
                                            </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(<%- pmObj.model.className %>.toggleSelectEachItem(true)); return false;" >Select all</a>
                                    </li>
                                    <li class=" <%- pmObj.model.justNotClass('selectedCount', 'hide') %>" >
                                        <a href="#" onclick="spajs.showLoader(<%- pmObj.model.className %>.toggleSelectEachItem(false)); return false;" >Unselect all</a>
                                    </li>
                                </ul>
                            </div>
                        <% } %>
                        <% if(pmObj.getTotalPages(pmObj.model.itemslist)){ %>
                                <%= pmObj.paginationHtml(pmObj.model.itemslist) %>
                        <% } %>
                    </div>
                </div>
            </section>
        </div>
    </section>
    <!-- /items_list -->
</script>

<!-- Список сущностей со страницы другого класса Например groups/1/hosts -->
<script type="text/x-just" data-just="items_list_from_another_class">
    <!-- items_list_from_another_class -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item_from_another_class.back_link){ %><%- pmObj.model.page_item_from_another_class.back_link.apply(pmObj, [item_id, opt]) %><% }else{ %><%- polemarch.opt.host %>/?<%- opt.back_link %><% } %>"
                onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>
            <%- pmObj.model.page_list_from_another_class.title %>
        </h1>
        <% if(pmObj.model.parentObjectsData !== undefined) {
            var link1 = ""+ polemarch.opt.host+ "/?"; %>
            <ol class="breadcrumb">
                 <li><a href="<%- polemarch.opt.host %>" onclick="return spajs.openURL(this.href);" ><i class="fa fa-dashboard"></i> Home</a></li>
                 <% for(var j in pmObj.model.parentObjectsData) {
                    var parent1 =  pmObj.model.parentObjectsData[j]; %>
                    <li><a href="<%- link1 %><%- parent1.parent_type_plural %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parent1.parent_type_plural) %></a></li>
                    <li><a href="<%- link1 %><%- parent1.parent_type %>/<%- parent1.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parent1.item_name %></a></li>
                    <% link1 += "" + parent1.parent_type + "/" + parent1.parent_item + "/" %>
                 <% } %>
                 <li class="active"><%- pmObj.model.page_list_from_another_class.short_title %></li>
            </ol>
        <% } else { %>
            <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 %>/?<%- parentObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parentObj.model.name) %></a></li>
                <li><a href="<%- polemarch.opt.host %>/?<%- parentObj.model.page_name %>/<%- opt.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parentObj.model.items[opt.parent_item].name %></a></li>
                <li class="active"><%- pmObj.model.page_list_from_another_class.short_title %></li>
            </ol>
        <% } %>

    </section>

    <section class="content">
        <div class="row">
            <div class="col-lg-12">
                <% if(pmObj.model.page_list_from_another_class.buttons){ %>
                    <% for(var i in  pmObj.model.page_list_from_another_class.buttons){ %>
                        <% if(pmObj.model.page_list_from_another_class.buttons[i].tpl){ %>
                            <%= pmObj.model.page_list_from_another_class.buttons[i].tpl.apply(pmObj, [opt]) %>
                        <% }else{ %>
                            <a
                                class="top-line-btn <% if(typeof pmObj.model.page_list_from_another_class.buttons[i].class == 'function'){ %>
                                            <%- pmObj.model.page_list_from_another_class.buttons[i].class.apply(pmObj, [opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_list_from_another_class.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_list_from_another_class.buttons[i].link.apply(pmObj, [opt]) %>"
                                title="<%- pmObj.model.page_list_from_another_class.buttons[i].help || '' %>"
                                onclick="<% if(typeof pmObj.model.page_list_from_another_class.buttons[i].onclick == 'function'){ %>
                                        <%- pmObj.model.className %>.model.page_list_from_another_class.buttons[<%- i %>].onclick.apply(<%- pmObj.model.className %>, [event])
                                    <% }else{ %>
                                        <%- pmObj.model.page_list_from_another_class.buttons[i].function.apply(pmObj, [opt]) %>
                                    <% } %>" >
                                    <% if(typeof pmObj.model.page_list_from_another_class.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_list_from_another_class.buttons[i].title.apply(pmObj, [opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_list_from_another_class.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.searchFiled({query:query, parent_type: opt.parent_type, parent_item: opt.parent_item}) %>
                        <%= spajs.just.render("add_existing_item_to_parent", {pmObj:pmObj, parentObj:parentObj, parent_item:opt.parent_item}) %>
                        <% if(pmObj.getTotalPages(pmObj.model.itemslistForParent)){ %>
                            <div style="float: right; margin-right: 20px;" class="hidden-xs">
                                <%= pmObj.paginationHtml(pmObj.model.itemslistForParent) %>
                            </div>
                        <% } %>
                    </div>
                    <div class="box-body">
                        <table class="table table-bordered multiple-select">
                            <tbody>
                                <tr>
                                    <th style="width: 45px" onclick=" $(this).parent().toggleClass('selected'); <%- pmObj.model.className %>.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>
                                    <% for(var j in pmObj.model.page_list_from_another_class.fileds){ %>
                                        <th
                                            <% if(pmObj.model.page_list_from_another_class.fileds[j].style){ %><%= pmObj.model.page_list_from_another_class.fileds[j].style.apply(pmObj,[undefined, opt]) %><% } %>
                                            <% if(pmObj.model.page_list_from_another_class.fileds[j].class){ %><%= pmObj.model.page_list_from_another_class.fileds[j].class.apply(pmObj,[undefined, opt]) %><% } %>  >
                                                <%- pmObj.model.page_list_from_another_class.fileds[j].title %>
                                        </th>
                                    <% } %>
                                    <th style="width: 95px;" >Actions</th>
                                </tr>
                                <% for(var i in pmObj.model.itemslistForParent.results){ %>
                                    <tr
                                        class="item-row item-<%- pmObj.model.itemslistForParent.results[i].id %>  <%- pmObj.model.selectedItems.justClass(pmObj.model.itemslistForParent.results[i].id, 'selected') %>"
                                        data-id="<%- pmObj.model.itemslistForParent.results[i].id %>" >
                                        <td class=""  onclick="<%- pmObj.model.className %>.toggleSelect(<%- pmObj.model.itemslistForParent.results[i].id %>); return false;">
                                            <div class="ico-on fa fa-toggle-on"></div>
                                            <div class="ico-off fa  fa-toggle-off"></div>
                                        </td>
                                        <% for(var j in pmObj.model.page_list_from_another_class.fileds){ %>
                                            <td
                                                <% if(pmObj.model.page_list_from_another_class.fileds[j].style){ %><%= pmObj.model.page_list_from_another_class.fileds[j].style.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %><% } %>
                                                <% if(pmObj.model.page_list_from_another_class.fileds[j].class){ %><%= pmObj.model.page_list_from_another_class.fileds[j].class.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %><% } %>
                                            >
                                                <% if(!pmObj.model.page_list_from_another_class.fileds[j].value){ %>
                                                    <a href="/?<%- opt.link_with_parents %>/<%- pmObj.model.page_name %>/<%- pmObj.model.itemslistForParent.results[i].id %>" class="item-name"
                                                        onclick="return spajs.openURL(this.href);" ><%- pmObj.model.itemslistForParent.results[i][pmObj.model.page_list_from_another_class.fileds[j].name] %></a>
                                                <% }else{ %>
                                                    <%= pmObj.model.page_list_from_another_class.fileds[j].value.apply(pmObj, [pmObj.model.itemslistForParent.results[i], pmObj.model.page_list_from_another_class.fileds[j].name, opt]) %>
                                                <% } %>
                                            </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">
                                                    <% for(var j in pmObj.model.page_list_from_another_class.actions){ %>
                                                        <% if(!pmObj.model.page_list_from_another_class.actions[j].title){ %>
                                                            <li role="separator" class="divider"></li>
                                                        <% }else{ %>
                                                            <li>
                                                                <a href="<%- pmObj.model.page_list_from_another_class.actions[j].link.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>"
                                                                    onclick="<%- pmObj.model.page_list_from_another_class.actions[j].function.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>"
                                                                    class="<% if(typeof pmObj.model.page_list_from_another_class.actions[j].class == 'function'){ %>
                                                                            <%- pmObj.model.page_list_from_another_class.actions[j].class.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>
                                                                       <% }else{ %>
                                                                            <%- pmObj.model.page_list_from_another_class.actions[j].class || '' %>
                                                                       <% } %>"
                                                                >
                                                                        <% if(typeof pmObj.model.page_list_from_another_class.actions[j].title == 'function'){ %>
                                                                            <%= pmObj.model.page_list_from_another_class.actions[j].title.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>
                                                                        <% }else{ %>
                                                                            <%- pmObj.model.page_list_from_another_class.actions[j].title %>
                                                                        <% } %>

                                                                </a>
                                                            </li>
                                                        <% } %>
                                                    <% } %>
                                                    <!-- -->
                                                    <% if(pmObj.model.itemslistForParent.results[i].options_list) { %>
                                                         <% if(pmObj.model.itemslistForParent.results[i].options_list.length!=0) { %>
                                                            <li role="separator" class="divider"></li>
                                                            <% for(var k in pmObj.model.itemslistForParent.results[i].options_list) { %>
                                                                <li>
                                                                    <a href="#"
                                                                    onclick="<%- pmObj.model.page_list_from_another_class.actions[j].function.apply(pmObj, [pmObj.model.itemslistForParent.results[i], pmObj.model.itemslistForParent.results[i].options_list[k], opt]) %>">
                                                                        Execute with <%= pmObj.model.itemslistForParent.results[i].options_list[k] %>
                                                                    </a>
                                                                </li>
                                                                <% } %>
                                                            <% } %>
                                                    <% } %>
                                                    <!-- -->

                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <div class="btn-group <%- pmObj.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 <%= pmObj.model.justText('selectedCount') %> items
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <% for(var j in pmObj.model.page_list_from_another_class.actionsOnSelected){ %>
                                    <% if(!pmObj.model.page_list_from_another_class.actionsOnSelected[j].title){ %>
                                        <li role="separator" class="divider"></li>
                                    <% }else{ %>
                                        <li>
                                            <a href="<%- pmObj.model.page_list_from_another_class.actionsOnSelected[j].link.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>"
                                                onclick="<%- pmObj.model.page_list_from_another_class.actionsOnSelected[j].function.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>" >
                                                    <% if(typeof pmObj.model.page_list_from_another_class.actionsOnSelected[j].title == 'function'){ %>
                                                        <%= pmObj.model.page_list_from_another_class.actionsOnSelected[j].title.apply(pmObj, [pmObj.model.itemslistForParent.results[i], opt]) %>
                                                    <% }else{ %>
                                                        <%- pmObj.model.page_list_from_another_class.actionsOnSelected[j].title %>
                                                    <% } %>
                                            </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(<%- pmObj.model.className %>.toggleSelectEachItem(true)); return false;" >Select all</a>-->
                                    <!--</li>-->
                                    <!--<li class=" <%- pmObj.model.justNotClass('selectedCount', 'hide') %>" >-->
                                        <!--<a href="#" onclick="spajs.showLoader(<%- pmObj.model.className %>.toggleSelectEachItem(false)); return false;" >Unselect all</a>-->
                                    <!--</li>-->
                                <!--</ul>-->
                            <!--</div>-->
                        <!--<% } %>-->
                        <% if(pmObj.getTotalPages(pmObj.model.itemslistForParent)){ %>
                                <%= pmObj.paginationHtml(pmObj.model.itemslistForParent) %>
                        <% } %>
                    </div>
                </div>
            </section>
        </div>
    </section>
    <!-- /items_list_from_another_class -->
</script>
  
<!-- Страница создания сущьности -->
<script type="text/x-just" data-just="items_new_page">
    <!-- items_new_page -->
    <section class="content-header">
        <h1>
            <% if(opt.parent_type === undefined && opt.parent_item === undefined) { %>
                <a href="<%- polemarch.opt.host %>/?<%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                    <span class="glyphicon glyphicon-arrow-left"></span>
                </a>
            <% } else { %>
                <a href="<%- polemarch.opt.host %>/?<%- opt.back_link %>" 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_new.title %></span>

        </h1>
        <% if(opt.parent_type === undefined && opt.parent_item === undefined) { %>
            <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 %>/?<%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- pmObj.model.page_list.short_title %></a></li>
                <li class="active"><%- pmObj.model.page_new.short_title %></li>
            </ol>
        <% } else { %>
            <% if(pmObj.model.parentObjectsData !== undefined) {
                var link1 = ""+ polemarch.opt.host+ "/?"; %>
                <ol class="breadcrumb">
                     <li><a href="<%- polemarch.opt.host %>" onclick="return spajs.openURL(this.href);" ><i class="fa fa-dashboard"></i> Home</a></li>
                     <% var link1 = ""+ polemarch.opt.host+ "/?";
                        for(var j in pmObj.model.parentObjectsData) {
                        var parent1 =  pmObj.model.parentObjectsData[j]; %>
                        <li><a href="<%- link1 %><%- parent1.parent_type_plural %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parent1.parent_type_plural) %></a></li>
                        <li><a href="<%- link1 %><%- parent1.parent_type %>/<%- parent1.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parent1.item_name %></a></li>
                        <% link1 += "" + parent1.parent_type + "/" + parent1.parent_item + "/" %>
                     <% } %>
                     <li><a href="<%- link1 %><%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(pmObj.model.name) %></a></li>
                     <li class="active"><%- pmObj.model.page_new.short_title %></li>
                </ol>
            <% } else { %>
                 <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 %>/?<%- parentObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parentObj.model.name) %></a></li>
                    <li><a href="<%- polemarch.opt.host %>/?<%- parentObj.model.page_name %>/<%- opt.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parentObj.model.items[opt.parent_item].name %></a></li>
                    <li><a href="<%- polemarch.opt.host %>/?<%- parentObj.model.page_name %>/<%- opt.parent_item %>/<%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(pmObj.model.name) %></a></li>
                    <li class="active"><%- pmObj.model.page_new.short_title %></li>
                </ol>
            <% } %>
        <% } %>

    </section>

    <section class="content">
        <div class="row">
            <div class="col-lg-12">
                <button type="button" onclick="spajs.showLoader(<%- pmObj.model.className %>.addItem('<%- opt.parent_type %>', <%- opt.parent_item %>)); return false;" class="btn btn-primary" >Create</button>
                <% if(pmObj.model.page_new.buttons){ %>
                    <% for(var i in  pmObj.model.page_new.buttons){ %>
                        <% if(pmObj.model.page_new.buttons[i].tpl){ %>
                            <%= pmObj.model.page_new.buttons[i].tpl.apply(pmObj, [opt]) %>
                        <% }else{ %> 
                            <a 
                                class="top-line-btn <% if(typeof pmObj.model.page_new.buttons[i].title == 'function'){ %>
                                            <%- pmObj.model.page_new.buttons[i].class.apply(pmObj, [opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_new.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_new.buttons[i].link.apply(pmObj, [opt]) %>"
                                title="<%- pmObj.model.page_new.buttons[i].help || '' %>"
                                onclick="<%- pmObj.model.page_new.buttons[i].function.apply(pmObj, [opt]) %>" >
                                    <% if(typeof pmObj.model.page_new.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_new.buttons[i].title.apply(pmObj, [opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_new.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_new.short_title %><br>
                    </div>
                    <div class="box-body"> 
                        <% for(var i in pmObj.model.page_new.fileds){ %>
                            <div class="row">
                                <% for(var j in pmObj.model.page_new.fileds[i]){ var filed = pmObj.model.page_new.fileds[i][j]; %>
                                        <%= filed.filed.render(pmObj, filed) %>
                                <% } %>
                            </div>
                        <% } %> 
                    </div>
                </div>
            </section>
            <% if(pmObj.model.page_new.sections){ %>
                <% for(var i in pmObj.model.page_new.sections){ %>
                    <%= pmObj.model.page_new.sections[i].apply(pmObj, [pmObj.model.page_new.sections[i], opt]) %>
                <% } %>
            <% } %>
        </div>
    </section>
    <!-- /items_new_page -->
</script>

<!-- Страница сущьности -->
<script type="text/x-just" data-just="items_page"> 
    
    <!-- items_page -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item.back_link){ %><%- pmObj.model.page_item.back_link.apply(pmObj, [item_id, opt]) %><% }else{ %><%- polemarch.opt.host %>/?<%- pmObj.model.name %><% } %>" 
                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.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 %>/?<%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%= pmObj.model.page_list.short_title %></a></li>
            <li class="active"><%= pmObj.model.page_item.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.buttons){ %>
                    <% for(var i in  pmObj.model.page_item.buttons){ %>
                        <% if(pmObj.model.page_item.buttons[i].tpl){ %>
                            <%= pmObj.model.page_item.buttons[i].tpl.apply(pmObj, [item_id, opt]) %>
                        <% }else{ %> 
                            <a 
                                class="top-line-btn <% if(typeof pmObj.model.page_item.buttons[i].class == 'function'){ %>
                                            <%- pmObj.model.page_item.buttons[i].class.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_item.buttons[i].link.apply(pmObj, [item_id, opt]) %>"
                                title="<% if(typeof pmObj.model.page_item.buttons[i].help == 'function'){ %>
                                            <%- pmObj.model.page_item.buttons[i].help.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item.buttons[i].help || '' %>
                                       <% } %>"
                                onclick="<%- pmObj.model.page_item.buttons[i].function.apply(pmObj, [item_id, opt]) %>" >
                                    <% if(typeof pmObj.model.page_item.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_item.buttons[i].title.apply(pmObj, [item_id, opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_item.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.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.fileds){ %>
                            <div class="row">
                                <% for(var j in pmObj.model.page_item.fileds[i]){ var filed = pmObj.model.page_item.fileds[i][j]; %>
                                        <%= filed.filed.render(pmObj, filed, item_id, opt) %>
                                <% } %>
                            </div>
                        <% } %>  
                    </div>
                </div>
            </section>
            <% if(pmObj.model.page_item.sections){ %>
                <% for(var i in pmObj.model.page_item.sections){ %>
                    <%= pmObj.model.page_item.sections[i].apply(pmObj, [pmObj.model.page_item.sections[i], item_id, opt]) %>
                <% } %>
            <% } %>
        </div>
    </section>
    <!-- /items_page -->
</script>

<!-- Страница сущности со страницы родительского класса-->
<script type="text/x-just" data-just="items_page_from_another_class">

    <!-- items_page_from_another_class -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item_from_another_class.back_link){ %><%- pmObj.model.page_item_from_another_class.back_link.apply(pmObj, [item_id, opt]) %><% }else{ %><%- polemarch.opt.host %>/?<%- opt.back_link %><% } %>"
                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_another_class.title.apply(pmObj, [item_id, opt]) %></span>

        </h1>
         <% if(pmObj.model.parentObjectsData !== undefined) {
            var link1 = ""+ polemarch.opt.host+ "/?"; %>
            <ol class="breadcrumb">
                 <li><a href="<%- polemarch.opt.host %>" onclick="return spajs.openURL(this.href);" ><i class="fa fa-dashboard"></i> Home</a></li>
                 <% var link1 = ""+ polemarch.opt.host+ "/?";
                    for(var j in pmObj.model.parentObjectsData) {
                    var parent1 =  pmObj.model.parentObjectsData[j]; %>
                    <li><a href="<%- link1 %><%- parent1.parent_type_plural %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parent1.parent_type_plural) %></a></li>
                    <li><a href="<%- link1 %><%- parent1.parent_type %>/<%- parent1.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parent1.item_name %></a></li>
                    <% link1 += "" + parent1.parent_type + "/" + parent1.parent_item + "/" %>
                 <% } %>
                 <li><a href="<%- link1 %><%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(pmObj.model.name) %></a></li>
                 <li class="active"><%- pmObj.model.items[item_id].name %></li>
            </ol>
        <% } else { %>
             <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 %>/?<%- parentObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(parentObj.model.name) %></a></li>
                <li><a href="<%- polemarch.opt.host %>/?<%- parentObj.model.page_name %>/<%- opt.parent_item %>" onclick="return spajs.openURL(this.href);" ><%- parentObj.model.items[opt.parent_item].name %></a></li>
                <li><a href="<%- polemarch.opt.host %>/?<%- parentObj.model.page_name %>/<%- opt.parent_item %>/<%- pmObj.model.name %>" onclick="return spajs.openURL(this.href);" ><%- capitalizeString(pmObj.model.name) %></a></li>
                <li class="active"><%- pmObj.model.items[item_id].name %></li>
            </ol>
        <% } %>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-lg-12">
                <% if(pmObj.model.page_item_from_another_class.buttons){ %>
                    <% for(var i in  pmObj.model.page_item_from_another_class.buttons){ %>
                        <% if(pmObj.model.page_item_from_another_class.buttons[i].tpl){ %>
                            <%= pmObj.model.page_item_from_another_class.buttons[i].tpl.apply(pmObj, [item_id, opt]) %>
                        <% }else{ %>
                            <a
                                class="top-line-btn <% if(typeof pmObj.model.page_item_from_another_class.buttons[i].class == 'function'){ %>
                                            <%- pmObj.model.page_item_from_another_class.buttons[i].class.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item_from_another_class.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_item_from_another_class.buttons[i].link.apply(pmObj, [item_id, opt]) %>"
                                title="<% if(typeof pmObj.model.page_item_from_another_class.buttons[i].help == 'function'){ %>
                                            <%- pmObj.model.page_item_from_another_class.buttons[i].help.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item_from_another_class.buttons[i].help || '' %>
                                       <% } %>"
                                onclick="<%- pmObj.model.page_item_from_another_class.buttons[i].function.apply(pmObj, [item_id, opt]) %>" >
                                    <% if(typeof pmObj.model.page_item_from_another_class.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_item_from_another_class.buttons[i].title.apply(pmObj, [item_id, opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_item_from_another_class.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_another_class.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_another_class.fileds){ %>
                            <div class="row">
                                <% for(var j in pmObj.model.page_item_from_another_class.fileds[i]){ var filed = pmObj.model.page_item_from_another_class.fileds[i][j]; %>
                                        <%= filed.filed.render(pmObj, filed, item_id, opt) %>
                                <% } %>
                            </div>
                        <% } %>
                    </div>
                </div>
            </section>
            <% if(pmObj.model.page_item_from_another_class.sections){ %>
                <% for(var i in pmObj.model.page_item_from_another_class.sections){ %>
                    <%= pmObj.model.page_item_from_another_class.sections[i].apply(pmObj, [pmObj.model.page_item_from_another_class.sections[i], item_id, opt]) %>
                <% } %>
            <% } %>
        </div>
    </section>
    <!-- /items_page_from_another_class -->
</script>

<script type="text/x-just" data-just="add_existing_item_to_parent">
    <div class="form-group input-group col-lg-2 add-existing-item"  style="float: right; margin-bottom: 0px;">
        <select class="form-control select2" id="add_existing_item_to_parent" data-child-type="<%- pmObj.model.name %>" data-placeholder="Add existing <%- pmObj.model.page_name %>" style="width:100%; float:left;">
            <option></option>
            <% for(var i in pmObj.model.itemslist.results){
               var item_id = pmObj.model.itemslist.results[i].id;
               var bool = false; %>
                <% for(var j in parentObj.model.items[parent_item][pmObj.model.name]) {
                   var childItem = parentObj.model.items[parent_item][pmObj.model.name][j]; %>
                   <% if(childItem.id == item_id) { bool = true } %>
                <% } %>
                <% if(bool == false) { %>
                     <option
                    value="<%- pmObj.model.itemslist.results[i].id %>"
                    ><%- pmObj.model.itemslist.results[i].name %></option>
                <% } %>
            <% } %>
        </select>
        <div class="input-group-addon" onclick="spajs.showLoader(<%- pmObj.model.className %>.addExistingChildItemToParent('<%- parentObj.model.page_name %>', <%- parent_item %>));">
            <span class="glyphicon glyphicon-plus"></span>
        </div>
    </div>
</script>
