Blame view

web/view/home.html.jinja2 18 KB
9390ec89   Goutte   Initial experimen...
1
2
3
4
{% extends 'layout.html.jinja2' %}
{% set menu_section = 'home' %}
{% block title %}Home{% endblock %}

4900d232   Goutte   Add the time inte...
5
6
7
{# This is the main template file, along with the layout. #}
{# The engine is Jinja2, close to Twig (yet not as good) #}

9390ec89   Goutte   Initial experimen...
8
9
{% block content %}

4cf497e0   Goutte   Make the targets ...
10
{% macro target_button(target) -%}
1ab47144   Goutte   Add new menus, up...
11
    <div class="target {{ target.slug }} {{ 'locked' if target.locked else ('active' if target.default) }}"
80352490   Goutte   Multi model suppo...
12
13
         data-target-slug="{{ target.slug }}">
      <img width="64px" height="64px"
d1c44c51   Goutte   Enable Earth
14
           src="{{ static('img/target/'~target.slug~'_256.png') }}"
80352490   Goutte   Multi model suppo...
15
16
17
18
           title="{{ target.title }}"
           alt="{{ target.name }}">
      <img width="64px" height="64px"
           src="{{ static('img/target/empty_128.png') }}"
60b73eb1   Goutte   Change temperatur...
19
20
           title="No data at specified interval for {{ target.title }}."
           alt="NO DATA"
80352490   Goutte   Multi model suppo...
21
           class="decorator empty">
60b73eb1   Goutte   Change temperatur...
22
23
24
25
26
      <img width="64px" height="64px"
           src="{{ static('img/target/error_128.png') }}"
           title="There was an error with {{ target.title }}."
           alt="ERROR"
           class="decorator error">
80352490   Goutte   Multi model suppo...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      <div class="decorator loading" title="Loading data for {{ target.title }}…">
        <div class="small-loader-container">
          <div class="small-loader-circle-1">
            <div class="small-loader-circle-2">
              <div class="small-loader-circle-3">
                <div class="small-loader-circle-4">
                  <div class="small-loader-circle-5">
                    <div class="small-loader-circle-6">
                      <div class="small-loader-circle-7">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
4cf497e0   Goutte   Make the targets ...
46
47
{%- endmacro %}

1ab47144   Goutte   Add new menus, up...
48
49
50
{#############################################################################}

{% macro icon(name,solid=false) %}<i class="fa{{ 's' if solid }} fa-{{ name }}" aria-hidden="true"></i>{% endmacro %}
9c0c4509   Goutte   Add a loader to t...
51

dfa1f66e   Goutte   Move the layers b...
52
53
{#############################################################################}

9c0c4509   Goutte   Add a loader to t...
54
55
56
57
58
59
60
61
62
<div id="plots_loader">
  <p class="loader-text">Loading Heliopropa&hellip;<br>This might take a while.</p>
  <div id="plots_loader_img1" class="img"></div>
  <div id="plots_loader_img2" class="img"></div>
  <div id="plots_loader_img3" class="img"></div>
  <div id="plots_loader_img4" class="img"></div>
  <div id="plots_loader_img5" class="img"></div>
</div>

f6ed8d85   Goutte   Rework layout as ...
63
64
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">

f6ed8d85   Goutte   Rework layout as ...
65
  <div class="mdl-layout__drawer">
297a7dfc   Goutte   Add support for i...
66

dd8621f8   Goutte   Play some accordi...
67
68
69
70
71
72
73
    <details open>
      <summary>
        <span class="mdl-layout-title" title="Two years maximum.">{{ icon('calendar') }} Time Interval</span>
      </summary>

      <form id="form_time_interval" action="#">
        <div class="mdl-textfield mdl-js-textfield">
26733e9f   Goutte   Make the animatio...
74
75
          <input type="date" id="started_at" name="started_at" title="The UTC date of the beginning of the interval to observe." class="mdl-textfield__input">
          <input type="date" id="stopped_at" name="stopped_at" title="The UTC date of the end of the interval to observe. (exclusive)" class="mdl-textfield__input">
dd8621f8   Goutte   Play some accordi...
76
        </div>
26733e9f   Goutte   Make the animatio...
77
        <input type="submit" id="apply_new_interval" value="Load new interval" title="Two years maximum. This may take a while. UTC." class="mdl-button mdl-js-button mdl-js-ripple-effect">
dd8621f8   Goutte   Play some accordi...
78
79
      </form>
    </details>
1754789b   Goutte   Decorate and clea...
80

1754789b   Goutte   Decorate and clea...
81
    <hr class="clear">
4900d232   Goutte   Add the time inte...
82

dd8621f8   Goutte   Play some accordi...
83
84
    <details open>
      <summary>
e2aefa78   hitier   Join planets and ...
85
        <span class="mdl-layout-title">{{ icon('rocket') }} Targets </span>
dd8621f8   Goutte   Play some accordi...
86
      </summary>
f6ed8d85   Goutte   Rework layout as ...
87

dd8621f8   Goutte   Play some accordi...
88
89
90
91
92
      <section class="targets-filters">
        {% for target in planets %}
          {{ target_button(target) }}
        {% endfor %}
      </section>
a79c5268   Goutte   Add probes and co...
93

a79c5268   Goutte   Add probes and co...
94

befd6269   Goutte   Add Chris' changes.
95
96
{# The probes and comets are not displayed in the ESA version. #}
{% if not is_esa %}
dd8621f8   Goutte   Play some accordi...
97
98
99
100
101
102
103
104
105

      <section class="targets-filters">
        {% for target in probes %}
          {{ target_button(target) }}
        {% endfor %}
        {% for target in comets %}
          {{ target_button(target) }}
        {% endfor %}
      </section>
e2aefa78   hitier   Join planets and ...
106
{% endif %}
dd8621f8   Goutte   Play some accordi...
107
    </details>
a79c5268   Goutte   Add probes and co...
108

575e380a   Goutte   Add disabled laye...
109
    <hr class="clear">
cdf79b23   Goutte   Give the future d...
110

707a9bdf   Goutte   Add some fixes fo...
111
    <details{{ ' open' if is_esa }}>
dd8621f8   Goutte   Play some accordi...
112
113
114
      <summary>
        <span class="mdl-layout-title">{{ icon('flask') }} Parameters</span>
      </summary>
b550c2b0   Goutte   Rework the home s...
115

dd8621f8   Goutte   Play some accordi...
116
117
118
119
120
121
      <nav id="parameters" class="mdl-navigation">
        {% for p in parameters %}
          <a class="mdl-navigation__link parameter{{ ' active' if p.active }}" data-ts-slug="{{ p.slug }}" href="#" title="{{ p.title }} ({{ p.units }})">{{ p.name }}</a>
        {% endfor %}
      </nav>
    </details>
b550c2b0   Goutte   Rework the home s...
122

1ab47144   Goutte   Add new menus, up...
123
124
    <hr class="clear">

befd6269   Goutte   Add Chris' changes.
125
126
{# The following sections are not displayed in the ESA version. #}
{% if not is_esa %}
1ab47144   Goutte   Add new menus, up...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

    <details>
      <summary>
        <span class="mdl-layout-title">{{ icon('database') }} Inputs</span>
      </summary>

      <section class="section-drawer">
{% for input in config.inputs %}
        <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-input-{{ input.slug }}" title="{{ input.desc }}">
          <input type="radio" id="option-input-{{ input.slug }}" class="mdl-radio__button" name="input_slug" value="{{ input.slug }}" {{ 'checked' if input.slug == input_slug }}>
          <span class="mdl-radio__label">{{ input.name }}</span>
        </label>
        <br />
{% endfor %}
        <br />
866991ff   Goutte   Add Jupiter's CME...
142
        <input type="button" id="apply_new_input" value="Reload for input" title="Reloading may take a while." class="mdl-button mdl-js-button mdl-js-ripple-effect">
1ab47144   Goutte   Add new menus, up...
143
144
145
      </section>
    </details>

befd6269   Goutte   Add Chris' changes.
146
147
{% endif %}{# not is_esa #}

a4a9ef03   Goutte   Cache generated C...
148
149
    <div class="mdl-layout-spacer"></div>

c42fea3a   Goutte   Rework the CSS wi...
150
  </div>
80352490   Goutte   Multi model suppo...
151

befd6269   Goutte   Add Chris' changes.
152
{#############################################################################}
80352490   Goutte   Multi model suppo...
153

b7fe650c   Goutte   Misc bundle of ol...
154
  <main id="plots_wrapper" class="mdl-layout__content">
9390ec89   Goutte   Initial experimen...
155

b550c2b0   Goutte   Rework the home s...
156
    <div class="mdl-grid">
707a9bdf   Goutte   Add some fixes fo...
157
      <div class="mdl-cell mdl-cell--4-col mdl-cell--12-col-tablet mdl-cell--12-col-phone">
b550c2b0   Goutte   Rework the home s...
158
        <section id="orbits"></section>
cad44b6d   Goutte   Finish adding the...
159
        <div class="plots-actions plots-buttons">
dfa1f66e   Goutte   Move the layers b...
160
161
          <button id="zoom_inner_heliosphere"
                  class="mdl-button mdl-button--raised mdl-button--primary"
3c2b15fc   Goutte   Make the Y-Axis o...
162
163
164
                  title="Zoom to the inner heliosphere.">
            Zoom in
          </button>
dfa1f66e   Goutte   Move the layers b...
165
166
          <button id="zoom_outer_heliosphere"
                  class="mdl-button mdl-button--raised mdl-button--primary"
3c2b15fc   Goutte   Make the Y-Axis o...
167
168
169
170
171
                  title="Zoom to the outer heliosphere.">
            Zoom out
          </button>
        </div>
        <div class="plots-actions plots-buttons">
dfa1f66e   Goutte   Move the layers b...
172
173
          <button id="download"
                  class="mdl-button mdl-button--raised mdl-button--primary"
dc0be992   Goutte   Support having no...
174
                  title="Download the raw data for each selected target and parameters.">
cad44b6d   Goutte   Finish adding the...
175
            Download
51d614e6   Goutte   Add a spinner to ...
176
            <div id="download_spinner" class="mdl-spinner mdl-js-spinner is-active"></div>
cad44b6d   Goutte   Finish adding the...
177
          </button>
befd6269   Goutte   Add Chris' changes.
178
{% if not is_esa %}
3e786bc9   hitier   Temporary comment...
179
{#
dfa1f66e   Goutte   Move the layers b...
180
181
          <button id="samp"
                  class="samp mdl-button mdl-button--raised mdl-button--primary mdl-button--disabled"
dd8621f8   Goutte   Play some accordi...
182
                  title="Send the data to a connected SAMP hub, such as TOPCAT.">
cad44b6d   Goutte   Finish adding the...
183
184
            SAMP
          </button>
3e786bc9   hitier   Temporary comment...
185
#}
ea45ebf9   Goutte   Add the mocks of ...
186
          <button id="email_alert"
dd8621f8   Goutte   Play some accordi...
187
188
189
                  class="mdl-button mdl-button--raised mdl-button--primary"
                  title="Set an alert to receive an email when the data validates pre-defined conditions."
                  data-href="http://alerts-psws.irap.omp.eu/tao">
ea45ebf9   Goutte   Add the mocks of ...
190
191
            Alert
          </button>
befd6269   Goutte   Add Chris' changes.
192
{% endif %}
11d86851   Goutte   Add support for s...
193

cad44b6d   Goutte   Finish adding the...
194
        </div>
11d86851   Goutte   Add support for s...
195
196
197
198
199
200
201
202
        <div>
          <div id="time_series_cursor_morebox" class="hidden">
            <a
                id="time_series_cursor_image_link"
                target="_blank"
                href="#">
              <img
                  id="time_series_cursor_image"
622d37d6   hitier   Remove voparis im...
203
204
                  src=""
{#               src="http://voparis-srv.obspm.fr/vo/planeto/apis/dataset/Bastet/Saturn_-_2017_14_Feb-09_Sept/od9u09rgq_proc_small.jpg"#}
11d86851   Goutte   Add support for s...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                  alt="Image Capture of Aurorae"
              >
            </a>
            <div id="time_series_cursor_image_extra">
              <a id="time_series_cursor_link" target="_blank">
                View details on APIS.
              </a>
              <p id="time_series_cursor_image_comment">
                Nothing to comment.
              </p>
            </div>
          </div>
        </div>

b550c2b0   Goutte   Rework the home s...
219
      </div>
707a9bdf   Goutte   Add some fixes fo...
220
      <div class="mdl-cell mdl-cell--8-col mdl-cell--12-col-tablet mdl-cell--12-col-phone">
9c0c4509   Goutte   Add a loader to t...
221
222
223
        <section id="time_series">
          <p id="zoom_controls_help" class="help mdl-cell--8-col">Drag to zoom in, double click to zoom out.</p>
        </section>
b550c2b0   Goutte   Rework the home s...
224
225
226
      </div>
    </div>

f6ed8d85   Goutte   Rework layout as ...
227
228
  </main>
</div>
9390ec89   Goutte   Initial experimen...
229
230
231
{% endblock %}


80352490   Goutte   Multi model suppo...
232
{#### CSS ####################################################################}
7d6dee0f   Goutte   Continue refacto ...
233

9390ec89   Goutte   Initial experimen...
234
{% block styles %}
11d86851   Goutte   Add support for s...
235
236
237
  <link rel="stylesheet" type="text/css" href="{{ static('css/home.css') }}">
{#  <style>#}
{#  </style>#}
9390ec89   Goutte   Initial experimen...
238
239
240
{% endblock %}


80352490   Goutte   Multi model suppo...
241
242
{#### JAVASCRIPT #############################################################}

9390ec89   Goutte   Initial experimen...
243
{% block scripts_footer %}
f7a10f28   Goutte   Make our custom m...
244
<script type="application/javascript" src="{{ static('js/vendor/d3-custom.js') }}"></script>
a4a9ef03   Goutte   Cache generated C...
245
<script type="application/javascript" src="{{ static('js/vendor/moment.min.js') }}"></script>
3e786bc9   hitier   Temporary comment...
246
{#
80352490   Goutte   Multi model suppo...
247
<script type="application/javascript" src="{{ static('js/vendor/samp.js') }}"></script>
3e786bc9   hitier   Temporary comment...
248
#}
db69e5a7   Goutte   Continue implemen...
249
<script type="application/javascript" src="{{ static('js/main.js') }}"></script>
9390ec89   Goutte   Initial experimen...
250
251
<script type="application/javascript">

11d86851   Goutte   Add support for s...
252
var sw_configuration = {
ae0aa7d2   Goutte   Add an x axis lab...
253
254
  time_series_container: '#time_series',
  orbits_container: '#orbits',
bde97e4d   Goutte   Add more changes ...
255
  api: {
11d86851   Goutte   Add support for s...
256
      'root':              "{{ request.url_root }}",
297a7dfc   Goutte   Add support for i...
257
258
      'data_for_interval': "{{ request.url_root }}<target>_{{ input_slug }}_<started_at>_<stopped_at>.csv",
      'download':          "{{ request.url_root }}<targets>_{{ input_slug }}_<started_at>_<stopped_at>.cdf",
3e786bc9   hitier   Temporary comment...
259
      {#
297a7dfc   Goutte   Add support for i...
260
      'samp':              "{{ request.url_root }}<targets>_{{ input_slug }}_<started_at>_<stopped_at>.cdf"
3e786bc9   hitier   Temporary comment...
261
      #}
f75faf5f   Goutte   WIP
262
  },
8bd715ad   Goutte   Use a pixel art i...
263
264
265
  sun: {
    img: '{{ static('img/sun_128.png') }}'
  },
bde97e4d   Goutte   Add more changes ...
266
  targets: {
0332f168   Goutte   Initial support f...
267
{% for target in targets %}
a21f81d9   Goutte   Enable Venus and ...
268
    '{{ target.slug }}': {
0332f168   Goutte   Initial support f...
269
270
      slug: "{{ target.slug | escapejs }}",
      name: "{{ target.name | escapejs }}",
1ab47144   Goutte   Add new menus, up...
271
      active: {{ 'true' if target.default else 'false' }},
25071e08   Goutte   Easy fix to suppo...
272
      orbit: { a: {{ target.orbit.semimajor or 0 }}, b: {{ target.orbit.semiminor or 0 }} },
0332f168   Goutte   Initial support f...
273
274
      img: '{{ static('img/target/'~target.slug~'_128.png') }}',
      layers: {
34e94ae3   hitier   Code reformating
275
{% for catalog_slug, catalog_intervals in target.catalog_layers.items() %}
0332f168   Goutte   Initial support f...
276
277
278
279
280
281
282
283
284
        "{{ catalog_slug }}": [
{% for interval in catalog_intervals %}
{#        { start: "2018-03-28T00:00:00Z", stop: "2018-03-29T00:00:00Z" },   #}
          {# /!. All datetimes here MUST be suffixed by Z #}
          { start: "{{ interval.start }}", stop: "{{ interval.stop }}" }{{ ',' if not loop.last }}
{% endfor %}
        ]
{% endfor %}
      }
a0e5bc71   Goutte   Keep trying to fi...
285
    }{{ ',' if not loop.last }}
a21f81d9   Goutte   Enable Venus and ...
286
{% endfor %}
aba70d3a   Goutte   Refactor time ser...
287
  },
bde97e4d   Goutte   Add more changes ...
288
289
  parameters: [
{% for p in parameters %}
aba70d3a   Goutte   Refactor time ser...
290
    {
bde97e4d   Goutte   Add more changes ...
291
292
293
294
295
296
      id: "{{ p.slug | escapejs }}",
      title: "{{ p.name | escapejs }} ({{ p.units | escapejs }})",
      active: {{ 'true' if p.active else 'false' }},
      unit: "{{ p.units | escapejs }}"
    }{{ ',' if not loop.last }}
{% endfor %}
aba70d3a   Goutte   Refactor time ser...
297
  ]
0332f168   Goutte   Initial support f...
298
299
300
301
302
303
304
305
306
307
308
309
{#    ,#}
{#  layers: [#}
{#{% for layer in config.layers %}#}
{#    {#}
{#      id: "{{ layer.slug | escapejs }}",#}
{#      data: [#}
{#        { start: "2018-03-08T00:00:00Z", end: "2018-03-20T17:00:00Z" },#}
{#        { start: "2018-03-28T00:00:00", end: "2018-03-29T00:00:00" }#}
{#      ]#}
{#    }{{ ',' if not loop.last }}#}
{#{% endfor %}#}
{#  ]#}
438929a4   Goutte   Rewrite the orbit...
310
};
9390ec89   Goutte   Initial experimen...
311

06a3a1f1   Goutte   Continue bug hunt...
312
var sw;
9390ec89   Goutte   Initial experimen...
313
jQuery().ready(function($){
a975b380   Goutte   Clean up.
314
  // Space Weather app itself, handling data downloads and plot draws.
11d86851   Goutte   Add support for s...
315
  sw = new SpaceWeather(sw_configuration);
2a5f0e9b   Goutte   Force UTC. A bit ...
316
  sw.init("{{ started_at }}Z", "{{ stopped_at }}Z");
ae0aa7d2   Goutte   Add an x axis lab...
317

a975b380   Goutte   Clean up.
318
319
320
321
322
323
324
325
  // User Interface (except plots' interactivity, such as mouse hovers)
  var parameters = $('#parameters');
  var isLastParameterEnabled = function(parameter_id) {
    var s = 0;
    parameters.find('.parameter[data-ts-slug]').each(function(i,p) {
      if ($(p).hasClass('active')) s++;
    });
    return s < 2;
6f9a3852   Goutte   Hide time series ...
326
  };
4cf497e0   Goutte   Make the targets ...
327
328
  var isLastTargetEnabled = function(target_slug) {
    var s = 0;
4900d232   Goutte   Add the time inte...
329
    $(".targets-filters .target:not(.locked)").each(function(i,p) {
fb6cfc7d   Goutte   Make sure we cann...
330
331
332
333
334
      if ($(p).hasClass('active')
          && ! $(p).hasClass('loading')
          && ! $(p).hasClass('empty')
          && ! $(p).hasClass('failed')
      ) { s++; }
4cf497e0   Goutte   Make the targets ...
335
336
337
    });
    return s < 2;
  };
866991ff   Goutte   Add Jupiter's CME...
338

0332f168   Goutte   Initial support f...
339
340
  $(".targets-filters .target:not(.locked)").on("click", function(e){
    if ($(this).hasClass('loading')) return false;
b7fe650c   Goutte   Misc bundle of ol...
341
    var switch_on = ! $(this).hasClass('active');
0332f168   Goutte   Initial support f...
342
    var target_slug = $(this).attr('data-target-slug');
b7fe650c   Goutte   Misc bundle of ol...
343
    if (switch_on) {
0332f168   Goutte   Initial support f...
344
      sw.enableTarget(target_slug);
a975b380   Goutte   Clean up.
345
      $(this).addClass('active');
0332f168   Goutte   Initial support f...
346
347
    } else if ( ! isLastTargetEnabled(target_slug)) {
      sw.disableTarget(target_slug);
a975b380   Goutte   Clean up.
348
      $(this).removeClass('active');
b7fe650c   Goutte   Misc bundle of ol...
349
    }
6f9a3852   Goutte   Hide time series ...
350
351
    return false;
  });
866991ff   Goutte   Add Jupiter's CME...
352

0332f168   Goutte   Initial support f...
353
  parameters.find(".parameter").click(function(e){
4cf497e0   Goutte   Make the targets ...
354
    var switch_on = ! $(this).hasClass('active');
0332f168   Goutte   Initial support f...
355
    var parameter_slug = $(this).attr('data-ts-slug');
4cf497e0   Goutte   Make the targets ...
356
    if (switch_on) {
0332f168   Goutte   Initial support f...
357
      sw.enableParameter(parameter_slug);
4cf497e0   Goutte   Make the targets ...
358
      $(this).addClass('active');
0332f168   Goutte   Initial support f...
359
360
    } else if ( ! isLastParameterEnabled(parameter_slug)) {
      sw.disableParameter(parameter_slug);
4cf497e0   Goutte   Make the targets ...
361
362
363
364
      $(this).removeClass('active');
    }
    return false;
  });
866991ff   Goutte   Add Jupiter's CME...
365

243cd8a4   Goutte   Timestamp party c...
366
367
368
369
370
  $('#apply_new_interval').on("click", function(e){
    var started_at = moment($("#started_at").val());
    var stopped_at = moment($("#stopped_at").val());
    sw.resizeDomain(started_at, stopped_at);
    return false;
6b149919   Goutte   Add a Download bu...
371
  });
866991ff   Goutte   Add Jupiter's CME...
372

297a7dfc   Goutte   Add support for i...
373
374
  $('#apply_new_input').on("click", function(e){
    var new_input_slug = $("input[name='input_slug']:checked").val();
866991ff   Goutte   Add Jupiter's CME...
375
376
377
378
379
    var started_at = $("#started_at").val();
    var stopped_at = $("#stopped_at").val();
    window.location = "?input_slug="+new_input_slug+
                      "&started_at="+started_at+
                      "&stopped_at="+stopped_at;
297a7dfc   Goutte   Add support for i...
380
381
    return false;
  });
0332f168   Goutte   Initial support f...
382

11d86851   Goutte   Add support for s...
383
  $('.option-layer-catalog').on("click", function(e){
0332f168   Goutte   Initial support f...
384
385
386
387
388
389
    var catalog_slug = $(this).attr('value');
    var checked = $(this).prop('checked');
    if (checked) { sw.showCatalogLayer(catalog_slug); }
    else         { sw.hideCatalogLayer(catalog_slug); }
  });

866991ff   Goutte   Add Jupiter's CME...
390
391
392
393
394
395
396
397
398
399
400
401
402
403
  $('#option-layer-hstjupiterobservations').on("click", function(e){
    var that = $(this);
    var catalog_slug = $(this).attr('value');
    var checked = $(this).prop('checked');
    if (checked) {
      $(this).addClass('loading');
      sw.showImagePreviewLayer("jupiter", catalog_slug).finally( function(){
        that.removeClass('loading');
      });
    } else {
      sw.hideImagePreviewLayer("jupiter", catalog_slug);
    }
  });

11d86851   Goutte   Add support for s...
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  $('#option-layer-hstsaturnobservations').on("click", function(e){
    var that = $(this);
    var catalog_slug = $(this).attr('value');
    var checked = $(this).prop('checked');
    if (checked) {
      $(this).addClass('loading');
      sw.showImagePreviewLayer("saturn", catalog_slug).finally( function(){
        that.removeClass('loading');
      });
    } else {
      sw.hideImagePreviewLayer("saturn", catalog_slug);
    }
  });

51d614e6   Goutte   Add a spinner to ...
418
419
  var download_spinner = $('#download_spinner');
  var waiting_for_download = false;
a0e5bc71   Goutte   Keep trying to fi...
420

6b149919   Goutte   Add a Download bu...
421
  $('#download').on("click", function(e){
51d614e6   Goutte   Add a spinner to ...
422
423
424
    if (waiting_for_download) return;
    download_spinner.css('display', 'inline-block');
    waiting_for_download = true;
6b149919   Goutte   Add a Download bu...
425
    var url = sw.buildDownloadUrl();
aa7247d6   Goutte   Generate a CDF fi...
426
    console.info("Downloading " + url);
6b149919   Goutte   Add a Download bu...
427
428
429
430
    $.ajax({
      type: 'GET',
      url: url,
      processData: false,
51d614e6   Goutte   Add a spinner to ...
431
432
433
434
435
      success: function (data) {
        download_spinner.css('display', 'none');
        waiting_for_download = false;
        window.location = url;
      },
6b149919   Goutte   Add a Download bu...
436
      error: function (xhr) {
51d614e6   Goutte   Add a spinner to ...
437
438
        download_spinner.css('display', 'none');
        waiting_for_download = false;
6b149919   Goutte   Add a Download bu...
439
440
441
442
443
444
        console.error('Cannot download.', xhr);
        alert("Our apologies, there was an error while downloading.");
      }
    });
    return false;
  });
3c2b15fc   Goutte   Make the Y-Axis o...
445
446
447
448
449
450
451
452
453
454
  $('#zoom_inner_heliosphere').on("click", function(e){
    console.info("Zooming to inner heliosphere…");
    sw.orbits.zoomToTarget('mars');
    return false;
  });
  $('#zoom_outer_heliosphere').on("click", function(e){
    console.info("Zooming to outer heliosphere…");
    sw.orbits.resize(true);
    return false;
  });
dd8621f8   Goutte   Play some accordi...
455
456
457
458
459
460
  $('#email_alert').on("click", function(e){
    console.info("Setting an alert…");
    var href = $(this).attr("data-href");
    window.open(href);
    return false;
  });
6f9a3852   Goutte   Hide time series ...
461

9390ec89   Goutte   Initial experimen...
462
463
});
</script>
cad44b6d   Goutte   Finish adding the...
464
465

{#### SAMP ###################################################################}
3e786bc9   hitier   Temporary comment...
466
{#
dd8621f8   Goutte   Play some accordi...
467
<script type="application/javascript">
cad44b6d   Goutte   Finish adding the...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
  jQuery().ready(function ($) {
    // Flag to know when a hub is connected or not
    var isConnected = false;

    // Show SAMP button(s) depending on whether the hub is available or not.
    var onHubAvailability = function (isHubRunning) {
      $(".samp").each(function (index, element) {
        if (isHubRunning) {
          isConnected = true;
          $(element).removeClass('disabled mdl-button--disabled');
        } else {
          isConnected = false;
          $(element).addClass('disabled mdl-button--disabled');
        }
      });
    };

03452084   Goutte   Make time series'...
485
    // Update the document about the presence of any SAMP hub every 7 sec.
ddd9e89c   Goutte   Add metadata to S...
486
487
488
    var connector = new samp.Connector("Sender", {
        "samp.name": "Heliopropa",
        "samp.description.text": "{{ config.meta.description }}",
11d86851   Goutte   Add support for s...
489
        // {{ request.url_root }} <- use this instead ?
ddd9e89c   Goutte   Add metadata to S...
490
491
        "samp.icon.url": "http://heliopropa.irap.omp.eu/static/img/target/earth_128.png",
    });
03452084   Goutte   Make time series'...
492
    connector.onHubAvailability(onHubAvailability, 7000);
cad44b6d   Goutte   Finish adding the...
493
494
495
496
497
498
499
500
501
502
503
    window.onunload = function () {
      connector.unregister();
    };

    // Clicking on a SAMP button sends the CDF file to the connected hub.
    $("#samp").click(function (event) {
      event.stopPropagation();
      if ($(this).hasClass('disabled')) { return; }
      // pitfall : connector.connection is ALWAYS undefined here
      if ( ! isConnected) {  // so we use a bool flag instead
        alert("We do not detect any connected SAMP hub.\n" +
03452084   Goutte   Make time series'...
504
              "Wait some more, or try refreshing this page?");
cad44b6d   Goutte   Finish adding the...
505
506
507
508
        return;
      }
      var name = sw.buildSampName();
      var url = sw.buildSampUrl();
aa7247d6   Goutte   Generate a CDF fi...
509
      console.info("Trying to activate SAMP…", name, url);
cad44b6d   Goutte   Finish adding the...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
      connector.runWithConnection(function (connection) {
        var msg = new samp.Message("table.load.cdf", {
          "name": name,
          "url": url // absolute URL required
        });
        connection.notifyAll([msg]);
      }, function (error) {
        var msg = 'Error: ' + error;
        console.error(msg);
        alert(msg);  // let's yell at the user as well
      });
    });
  });
</script>
3e786bc9   hitier   Temporary comment...
524
#}
9390ec89   Goutte   Initial experimen...
525
{% endblock %}