<commit_before>{% extends "base.html" %}

{% block title %}{{ skilltree.name }}{% endblock %}

{% block content %}
    {% load bootstrap3 %}
    <h2>{{ skilltree.name }}</h2>
    <button class="btn btn-primary" data-toggle="modal" data-target="#create_branch">
        {% bootstrap_icon "plus" %} Create Branch
    </button>
    <ul id="branch-list"></ul>
{% endblock %}

{% block modals %}
    <div class="modal fade" id="create_branch" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <form method="post" class="form" action="javascript:void(0)">
                {% csrf_token %}
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Create Branch</h4>
                    </div>
                    <div class="modal-body">
                        {% bootstrap_form skill_tree_branch_form %}
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}

{% block javascript %}
    <script type="text/javascript">
        $(document).ready(function() {
            Backbone.Tastypie.csrfToken = $("input[name=csrfmiddlewaretoken]").value;
            
            var Branch = Backbone.Model.extend({
                defaults: function() {
                    return {
                        name: "Default"
                    };
                }
            });
            
            var BranchList = Backbone.Collection.extend({
                model: Branch,
                url: '/api/v1/skill_tree_branch/'
            });
            
            var branches = new BranchList;
            
            var BranchView = Backbone.View.extend({
                tagName: "li",
                className: "branch",
                
                initialize: function() {
                    this.listenTo(this.model, "change", this.render);
                },
                
                render: function() {
                    this.$el.html(this.model.attributes.name);
                    return this;
                }
            });
            
            var AppView = Backbone.View.extend({
                el: $("body"),
                
                events: {
                    "submit form": "createBranch",
                },
                
                initialize: function() {
                    this.input_name = $('#id_name');
                    this.input_skill_tree = $('#id_skill_tree');
                    
                    this.listenTo(branches, 'add', this.addOne);
                    this.listenTo(branches, 'reset', this.addAll);
                    //this.listenTo(branches, 'all', this.render);
                    
                    branches.fetch();
                },
                
                render: function() {
                    //console.log('rendered');
                },
                
                addOne: function(branch) {
                    var view = new BranchView({model: branch});
                    this.$("#branch-list").append(view.render().el);
                },
                
                addAll: function() {
                    branches.each(this.addOne, this);
                },
                
                createBranch: function(event) {
                    event.preventDefault();
                    $('#create_branch').modal('hide');
                    branches.create({
                        name: this.input_name.val(),
                        skill_tree: "/api/v1/user/" + this.input_skill_tree.val() + "/"
                    });
                    this.input_name.val();
                }
            });
            
            var App = new AppView;
        });
    </script>
{% endblock %}<commit_msg>add tabs<commit_after>{% extends "base.html" %}

{% block title %}{{ skilltree.name }}{% endblock %}

{% block content %}
    {% load bootstrap3 %}
    <h2>{{ skilltree.name }}</h2>
    <div class="pull-right">
        <button class="btn btn-primary" data-toggle="modal" data-target="#create_branch">
            {% bootstrap_icon "plus" %} Create Branch
        </button>
    </div>
    <ul class="nav nav-tabs" id="branch-nav"></ul>
    <div class="tab-content" id="branch-tabs"></div>
{% endblock %}

{% block modals %}
    <div class="modal fade" id="create_branch" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <form method="post" class="form" action="javascript:void(0)">
                {% csrf_token %}
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Create Branch</h4>
                    </div>
                    <div class="modal-body">
                        {% bootstrap_form skill_tree_branch_form %}
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}

{% block javascript %}
    <script type="text/javascript">
        $(document).ready(function() {
            Backbone.Tastypie.csrfToken = $("input[name=csrfmiddlewaretoken]").value;
            
            var Branch = Backbone.Model.extend({
                defaults: function() {
                    return {
                        name: "Default"
                    };
                }
            });
            
            var BranchList = Backbone.Collection.extend({
                model: Branch,
                url: '/api/v1/skill_tree_branch/'
            });
            
            var branches = new BranchList;
            
            var BranchNavView = Backbone.View.extend({
                tagName: "li",
                className: function() {
                    var classes = "nav-item";
                    if(this.model == branches.first()) {
                        classes += " active";
                    }
                    return classes;
                },
                template: _.template($('#branch-nav-template').html()),
                
                initialize: function() {
                    this.listenTo(this.model, "change", this.render);
                },
                
                render: function() {
                    this.$el.html(this.template(this.model.toJSON()));
                    return this;
                }
            });
            
            var BranchTabView = Backbone.View.extend({
                tagName: "div",
                className: function() {
                    var classes = "tab-pane";
                    if(this.model == branches.first()) {
                        classes += " active";
                    }
                    return classes;
                },
                template: _.template($('#branch-tab-template').html()),
                
                id: function() {
                    return "branch-" + this.model.attributes.id;
                },
                
                initialize: function() {
                    this.listenTo(this.model, "change", this.render);
                },
                
                render: function() {
                    this.$el.html(this.template(this.model.toJSON()));
                    return this;
                }
            });
            
            var AppView = Backbone.View.extend({
                el: $("body"),
                
                events: {
                    "submit form": "createBranch",
                },
                
                initialize: function() {
                    this.input_name = $('#id_name');
                    this.input_skill_tree = $('#id_skill_tree');
                    
                    this.listenTo(branches, 'add', this.addOne);
                    this.listenTo(branches, 'reset', this.addAll);
                    //this.listenTo(branches, 'all', this.render);
                    
                    branches.fetch();
                },
                
                render: function() {
                    //console.log('rendered');
                },
                
                addOne: function(branch) {
                    var nav_view = new BranchNavView({model: branch});
                    this.$("#branch-nav").append(nav_view.render().el);                    
                    var tab_view = new BranchTabView({model: branch});
                    this.$("#branch-tabs").append(tab_view.render().el);
                },
                
                addAll: function() {
                    branches.each(this.addOne, this);
                },
                
                createBranch: function(event) {
                    event.preventDefault();
                    $('#create_branch').modal('hide');
                    branches.create({
                        name: this.input_name.val(),
                        skill_tree: "/api/v1/user/" + this.input_skill_tree.val() + "/"
                    });
                    this.input_name.val();
                }
            });
            
            var App = new AppView;
        });
    </script>
    
    <script type="text/template" id="branch-nav-template">
        <a href="#branch-<%- id %>" data-toggle="tab"><%- name %></a>
    </script>
    
    <script type="text/template" id="branch-tab-template">
        Name: <%- name %>
    </script>
{% endblock %}
{'fraction_non_alphanumeric': 0.133531451213472, 'fraction_numerical': 0.0017830609212481426, 'mean_word_length': 1.1042100875364735, 'pattern_counts': {'":': 2, '<': 76, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4725839', 'n_tokens_mistral': 2577, 'n_tokens_neox': 2375, 'n_words': 427}