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

        <~ pmModuleTemplates.model.selectedInventory> 
            <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory, pmModuleTemplates.model.items[item_id].data.group) %>
        <~>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
            <%= moduleArgsEditor.moduleFileds({
                    module:{value:pmModuleTemplates.model.items[item_id].data.module },
                    args:{value:pmModuleTemplates.model.items[item_id].data.args }
                }) 
            %>
        </div>
        
    <% }else{ %>
        <!-- Не задан item_id -->
    <% } %>
</script>



<script type="text/x-just" data-just="templates_new_module_page">
<section class="content-header">
        <h1>
            <a href="<%- polemarch.opt.host %>/?templates" onclick="return spajs.openURL(this.href);" class="btn btn-default" >
                <span class="glyphicon glyphicon-arrow-left"></span>
            </a>
            <span class="h1-header" >New template for run module</span>

        </h1>
        <ol class="breadcrumb">
            <li><a href="<%- polemarch.opt.host %>" onclick="return spajs.openURL(this.href);" ><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="<%- polemarch.opt.host %>/?templates" onclick="return spajs.openURL(this.href);" >Templates</a></li>
            <li class="active">New module template</li>
        </ol>
    </section>

    <section class="content">
        <button type="button" onclick="spajs.showLoader(pmModuleTemplates.addItem()); return false;" class="btn btn-primary" >Create</button>
        <br>
        <br>
        <div class="row">
            <section class="col-lg-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        Run module template
                    </div>
                    <div class="box-body">

                        <div class="row">
                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Template name</label>
                                <input type="text"
                                        placeholder="Enter name"
                                        id="Templates-name"
                                        value=""
                                        class="form-control"
                                        maxlength="255">
                                <div class="help-block"></div>
                            </div>

                            <div class="form-group col-lg-4 col-xs-12 col-sm-6 col-md-6">
                                <label class="control-label" >Project</label>
                                <select class="form-control select2" id="projects-autocomplete" data-placeholder="Select project" style="width:100%" > 
                                    <% for(var i in pmProjects.model.itemslist.results){ %>
                                        <option 
                                            value="<%- pmProjects.model.itemslist.results[i].id %>"
                                            ><%- pmProjects.model.itemslist.results[i].name %></option>
                                    <% } %>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                        
                            <%= pmModuleTemplates.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))
                                    {
                                        pmModuleTemplates.selectInventory()
                                    }
                                    else
                                    {
                                        pmModuleTemplates.selectInventory(event.value)
                                    }
                                }
                            }, null, {}) %> 
 
                            <~ pmModuleTemplates.model.selectedInventory>
                                <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory) %>
                            <~>
                        </div>

                        <%= moduleArgsEditor.moduleFileds() %>

                        <div class="row">
                            <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
                                <label class="control-label">Notes</label>
                                <textarea class="form-control" style="resize:vertical; min-height:75px;"
                                placeholder="Not required field, just for your notes" id="filed_notes"></textarea>
                                <div class="help-block"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <div class="row">
            <%= jsonEditor.editor({}, {block:'module', title1:'Arguments', title2:'Adding new argument', select2:true}) %>
        </div>
    </section>
</script>

<!-- new option page -->
<script type="text/x-just" data-just="new_option_page">

    <!-- items_page -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item_new_option.back_link){ %><%- pmObj.model.page_item_new_option.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_new_option.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><a href="<%- polemarch.opt.host %>/?<%- pmObj.model.name %>/<%- pmObj.model.kind %>/<%= item_id %>" onclick="return spajs.openURL(this.href);" ><%= pmObj.model.page_item.short_title.apply(pmObj, [item_id, opt]) %></a></li>
            <li class="active">New option</li>
        </ol>
    </section>

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

<!-- option page -->
<script type="text/x-just" data-just="module_option_page">

    <!-- items_page -->
    <section class="content-header">
        <h1>
            <a href="<% if(pmObj.model.page_item_option.back_link){ %><%- pmObj.model.page_item_option.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_option.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><a href="<%- polemarch.opt.host %>/?<%- pmObj.model.name %>/<%- pmObj.model.kind %>/<%= item_id %>" onclick="return spajs.openURL(this.href);" ><%= pmObj.model.page_item.short_title.apply(pmObj, [item_id, opt]) %></a></li>
            <li class="active"><%= pmObj.model.page_item_option.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_option.buttons){ %>
                    <% for(var i in  pmObj.model.page_item_option.buttons){ %>
                        <% if(pmObj.model.page_item_option.buttons[i].tpl){ %>
                            <%= pmObj.model.page_item_option.buttons[i].tpl.apply(pmObj, [item_id, opt]) %>
                        <% }else{ %>
                            <a
                                class="top-line-btn <% if(typeof pmObj.model.page_item_option.buttons[i].title == 'function'){ %>
                                            <%- pmObj.model.page_item_option.buttons[i].class.apply(pmObj, [item_id, opt]) %>
                                       <% }else{ %>
                                            <%- pmObj.model.page_item_option.buttons[i].class %>
                                       <% } %>"
                                href="<%- pmObj.model.page_item_option.buttons[i].link.apply(pmObj, [item_id, opt]) %>"
                                title="<%- pmObj.model.page_item_option.buttons[i].help || '' %>"
                                onclick="<%- pmObj.model.page_item_option.buttons[i].function.apply(pmObj, [item_id, opt]) %>" >
                                    <% if(typeof pmObj.model.page_item_option.buttons[i].title == 'function'){ %>
                                        <%= pmObj.model.page_item_option.buttons[i].title.apply(pmObj, [item_id, opt]) %>
                                    <% }else{ %>
                                        <%= pmObj.model.page_item_option.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_option.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_option.fileds){ %>
                            <div class="row">
                                <% for(var j in pmObj.model.page_item_option.fileds[i]){ var filed = pmObj.model.page_item_option.fileds[i][j]; %>
                                        <%= filed.filed.render(pmObj, filed, item_id, opt) %>
                                <% } %>
                            </div>
                        <% } %>
                    </div>
                </div>
            </section>
            <% if(pmObj.model.page_item_option.sections){ %>
                <% for(var i in pmObj.model.page_item_option.sections){ %>
                    <%= pmObj.model.page_item_option.sections[i].apply(pmObj, [pmObj.model.page_item_option.sections[i], item_id, opt]) %>
                <% } %>
            <% } %>
        </div>
    </section>
    <!-- /items_page -->
</script>



<!-- Шаблон полей  Project Inventory и Playbook  для new option page -->
<script type="text/x-just" data-just="filed_type_selectProjectInventoryGroupAndModuleForNewOption">
    <% if(item_id){ %>
        <~ pmModuleTemplates.model.selectedInventory>
            <% if(pmModuleTemplates.model.items[item_id].data){ %>
                <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory, pmModuleTemplates.model.items[item_id].data.group) %>
            <% } %>
        <~>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
            <%= moduleArgsEditor.moduleFileds({
                    module:{value:pmModuleTemplates.model.items[item_id].data.module },
                    args:{value:pmModuleTemplates.model.items[item_id].data.args }
                })
            %>
        </div>

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


<!-- Шаблон полей  Project Inventory и Playbook  для option page -->
<script type="text/x-just" data-just="filed_type_selectProjectInventoryGroupAndModuleForOption">
    <% if(item_id){ %>
        <~ pmModuleTemplates.model.selectedInventory>
            <% if(pmModuleTemplates.model.items[item_id].dataForOption){ %>
                <%= pmGroups.groupsAutocompleteTemplate(pmModuleTemplates.model.selectedInventory, pmModuleTemplates.model.items[item_id].dataForOption.group) %>
            <% } %>
        <~>

        <div class="form-group col-lg-12 col-xs-12 col-sm-12 col-md-12">
            <%= moduleArgsEditor.moduleFileds({
                    module:{value:pmModuleTemplates.model.items[item_id].dataForOption.module },
                    args:{value:pmModuleTemplates.model.items[item_id].dataForOption.args }
                })
            %>
        </div>

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