aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/templates/collections/add.html
blob: 478c80fb302e021acc80f5e10c19561a9eeca423 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<div id="myModal">
    <div class="modal-header">
        <h2>Define or Add to Collection</h2>
        <p>You have two choices: Name a new collection
        or add to an existing collection.</p>
    </div>
    <div class="modal-body" style="margin-left: 20px;">
      <form action="/collections/new"
	    method="POST"
	    target="_blank"
	    data-validate="parsley"
	    id="add_form"
	    class="form-inline">
            {% if traits is defined %}
            <input type="hidden" name="traits" value="{{ traits }}" />
            {% else %}
            <input type="hidden" name="hash" value="{{ hash }}" />
            {% endif %}
            {% if collections|length > 0 %}
            <fieldset>
              <legend>1. Add to an existing collection</legend>
              <div style="margin-left: 20px;">
                <select name="existing_collection" class="form-control" style="width: 80%;">
                {% for col in collections %}
                    {% if loop.index == 1 %}
                    <option value="{{ col.id }}:{{ col.name }}" selected>{{ col.name }}</option>
                    {% else %}
                    <option value="{{ col.id }}:{{ col.name }}">{{ col.name }}</option>
                    {% endif %}
                {% endfor %}
                </select>
                <input type="button" style="display: inline;" id="make_default" value="Make Default">
              <br><br>
              <button type="submit" name="add_to_existing" class="btn btn-primary">Add</button>
              </div>
            </fieldset>
            {% endif %}
            <hr />
            <fieldset>
              <legend>{% if collections|length > 0 %}2. {% else %}{% endif %}Create a new collection</legend>
              <div style="margin-left: 20px;">
                <input type="text" name="new_collection" placeholder=" Name of new collection..."
                    data-trigger="change" data-minlength="5" data-maxlength="50" style="width: 100%">
                <button type="submit" name="create_new" class="btn btn-primary" style="margin-top: 20px;">Create collection</button>
                {% if uc is not defined %}
                <span class="help-block">This collection will be saved to your computer for a year (or until you clear your cache).</span>
                {% endif %}
              </div>
            </fieldset>
        </form>
    </div>
</div>

<script>
  $('#add_form').parsley();
  $('#add_form').on('submit', function(){
    parent.jQuery.colorbox.close();
  });

  make_default = function() {
    alert("The current collection is now your default collection.")
    let uc_id = $('[name=existing_collection] option:selected').val().split(":")[0]
    $.cookie('default_collection', uc_id, {
        expires: 365,
        path: '/'
    });

    let default_collection_id = $.cookie('default_collection');
  };

  $("#make_default").on("click", function(){
    make_default();
  });

  apply_default = function() {
    let default_collection_id = $.cookie('default_collection');
    if (default_collection_id) {
      let the_option = $('[name=existing_collection] option').filter(function() {
        return ($(this).val().split(":")[0] == default_collection_id);
      })
      the_option.prop('selected', true);
    }
  }

  apply_default();
</script>