summaryrefslogtreecommitdiff
path: root/app/views/downloads/select.html.erb
blob: 7f5cb86ee958a783efbd7cc511324961c9f94d46 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'application', 'responsive', :media => 'all' %>
<style type="text/css">
  #release-select-form           { width: 56em ; }

  #release-select-bwd-a          { -webkit-appearance: button ; -moz-appearance: button ; appearance: button ;
                                   display: block ; width: 5em ; height: 1.5em ; text-align: center ;
                                   font-size: 13px ; text-decoration: none ; }
  #release-select-bwd-a        ,
  #release-select-fwd-button     { background-color: #080 ; color: #FFF ; }
  #release-select-metadata-div   { margin-top: 1em ; }

  #release-select-inputs-table   { padding: 0em 2em 0em 1em ; }
  #release-select-inputs-table ,
  .release-select-input-table    { border: 1px solid #404060 ; border-radius: 2em ; }
  .release-select-input-table    { width: 100% ; margin: 1em ; padding: 1em ; white-space: nowrap ; }
  .release-select-prompt-td      { width: 13em ; }
  .release-select-input-td       { width: 8em ; }

  #hidden-table                  { display: none ; }
</style>


<% def inputs_table %>
  <% IMAGE_PARAMS.each do | param_id | %>
    <% param_data       = @image_options[param_id]           %>
    <% param_prompt     = param_data[:prompt  ]              %>
    <% param_selected   = param_data[:selected]              %>
    <% param_options    = param_data[:options ]              %>
    <% param_first_id   = param_options.first[:option_id]    %>
    <% param_is_visible = param_id == @nojs_current_param_id %>

<table class="release-select-input-table" <%=raw 'style="display: none ;"' unless param_is_visible %> >

    <% param_options.each do | param_option | %>
      <% option_id         = param_option[:option_id]                       %>
      <% option_label      = param_option[:label    ]                       %>
      <% option_desc       = param_option[:desc     ]                       %>
      <% option_is_checked = (option_id == param_selected) ? 'checked' : '' %>

  <tr>
      <% if option_id == param_first_id %>
    <td class="release-select-prompt-td" rowspan="<%= param_options.size %>"><%= param_prompt %>:</td>
      <% end %>
    <td class="release-select-input-td">
      <input  id="release-<%= param_id %>-<%= option_id %>-input" type="radio" name="<%= param_id %>" value="<%= option_id %>" <%= option_is_checked %> />
      <label for="release-<%= param_id %>-<%= option_id %>-input"><%= option_label %></label></td>
    <td>(<%= option_desc %>)</td>
    <% end %>
  </tr>
</table>
  <% end %>

<input id="release-nojs-input"     type="text" name="nojs"     value="true"                         style="display: none ;" />
<input id="release-download-input" type="text" name="download" value="<%= @all_params_satisfied %>" style="display: none ;" />
<% end %>

<% def metadata_span %>
  <% image_size    = @selected_image[:image_size   ] %>
  <% kernel_ver    = @selected_image[:kernel_ver   ] %>
  <% pkglist_url   = @selected_image[:pkglist_url  ] %>
  <% magnet_uri    = @selected_image[:magnet_uri   ] %>
  <% torrent_url   = @selected_image[:torrent_url  ] %>
  <% checksums_url = @selected_image[:checksums_url] %>
  <% signature_url = @selected_image[:signature_url] %>
  <% gpg_key_url   = @selected_image[:gpg_key_url  ] %>
        <div id="release-select-metadata-div">
          <span id="release-select-kernel-span">Kernel: <%= kernel_ver %></span><br />
          <span id="release-select-size-span"  >Size: <%=   image_size %></span><br />
          <span><a id="release-select-pkgs-a"    href="<%=  pkglist_url   %>">Packages</a   ></span><br />
          <span><a id="release-select-magnet-a"  href="<%=  magnet_uri    %>">Magnet</a     ></span><br />
          <span><a id="release-select-torrent-a" href="<%=  torrent_url   %>">Torrent</a    ></span><br />
          <span><a id="release-select-sums-a"    href="<%=  checksums_url %>">SHA512SUMS</a ></span><br />
          <span><a id="release-select-sig-a"     href="<%=  signature_url %>">Signature</a  ></span><br />
          <span><a id="release-select-gpg-a"     href="<%=  gpg_key_url   %>">Signing Key</a></span>
        </div>
<% end %>


<form id="release-select-form" action="/downloads/select" method="get">
  <table id="release-select-inputs-table">
    <tr>
<% if @nojs && ! @all_params_satisfied %>
      <td><a id="release-select-bwd-a" href="/downloads/select">Back</a><br />
          <button id="release-select-fwd-button" type="submit">Accept</button></td>
<% else %>
      <td><button id="release-select-fwd-button" type="submit">Download</button>
  <% metadata_span %></td>
<% end %>
      <td id="nojs-inputs-td"><% inputs_table %></td>
    </tr>
  </table>
</form>


<script type="text/javascript">
window.onload = ()=>
{
//   const IMAGE_PARAMS   = <%=raw IMAGE_PARAMS.to_json    %> ;
  const VALID_RELEASE_ARCHES   = <%=raw VALID_RELEASE_ARCHES.to_json   %> ;
  const VALID_RELEASE_INITS    = <%=raw VALID_RELEASE_INITS.to_json    %> ;
  const VALID_RELEASE_WMDES    = <%=raw VALID_RELEASE_WMDES.to_json    %> ;
  const VALID_RELEASE_INSTALLS = <%=raw VALID_RELEASE_INSTALLS.to_json %> ;
  const RELEASE_IMAGES_TREE    = <%=raw @release_images_tree.to_json   %> ;

  var select_form    = document.getElementById        ('release-select-form'       ) ;
  var input_tables   = document.getElementsByClassName('release-select-input-table') ;
  var download_input = document.getElementById        ('release-download-input'    ) ;
  var nojs_input     = document.getElementById        ('release-nojs-input'        ) ;
  var kernel_li      = document.getElementById        ('release-select-kernel-span') ;
  var size_li        = document.getElementById        ('release-select-size-span'  ) ;
  var pkgs_a         = document.getElementById        ('release-select-pkgs-a'     ) ;
  var magnet_a       = document.getElementById        ('release-select-magnet-a'   ) ;
  var torrent_a      = document.getElementById        ('release-select-torrent-a'  ) ;
  var sums_a         = document.getElementById        ('release-select-sums-a'     ) ;
  var sig_a          = document.getElementById        ('release-select-sig-a'      ) ;
  var gpg_a          = document.getElementById        ('release-select-gpg-a'      ) ;
//   var radios         = [ select_form.arch , select_form.init    ,
//                          select_form.wmde , select_form.install ] ;
  var radios         = { 'arch': {} , 'init': {} , 'wmde': {} , 'install': {} } ;
  function SetRadio(param_id , option_id)
  {
    var radio_id                = 'release-' + param_id + '-' + option_id + '-input' ;
    var radio                   = document.getElementById(radio_id) ;
    radios[param_id][option_id] = radio ;
    radio.onclick               = onClicked ;
  }
  VALID_RELEASE_ARCHES  .forEach((arch   )=> { SetRadio('arch'    , arch   ) ; }) ;
  VALID_RELEASE_INITS   .forEach((init   )=> { SetRadio('init'    , init   ) ; }) ;
  VALID_RELEASE_WMDES   .forEach((wmde   )=> { SetRadio('wmde'    , wmde   ) ; }) ;
  VALID_RELEASE_INSTALLS.forEach((install)=> { SetRadio('install' , install) ; }) ;

//   for (var radio_n = 0 ; radio_n < radios.length ; ++radio_n)
//     for (var input_n = 0 ; input_n < radios[radio_n].length ; ++input_n)
//       radios[radio_n][input_n].onclick = onClicked ;
//       radios.forEach((radio)=> { radio.onclick = onClicked ; }) ;
//       radios[radio_n][input_n].onclick = ()=> { download_input.value = false ; select_form.submit() ; } ;
  for (var table_n = 0 ; table_n < input_tables.length ; ++table_n)
    input_tables[table_n].style.display = 'block' ;
  download_input.value = true ;
  nojs_input.parentNode.removeChild(nojs_input) ;

  function onClicked(evt)
  {
console.log("onclicked() this=" + this.name) ;

// console.log("onclicked() RELEASE_IMAGES_TREE[" + Object.keys(RELEASE_IMAGES_TREE).length + "]=" + JSON.stringify(RELEASE_IMAGES_TREE)) ;
// console.log("onclicked() arch   =" + select_form.arch   .value) ; console.log("onclicked() init   =" + select_form.init   .value) ; console.log("onclicked() wmde   =" + select_form.wmde   .value) ; console.log("onclicked() install=" + select_form.install   .value) ;
/*
    image_data = RELEASE_IMAGES.find((image_data)=>
    {
console.log("onclicked() image_data['arch'   ]=" + image_data['arch']) ; console.log("onclicked() image_data['init'   ]=" + image_data['init']) ; console.log("onclicked() image_data['wmde'   ]=" + image_data['wmde']) ; console.log("onclicked() image_data['install']=" + image_data['install']) ;

      return image_data['arch'   ] == select_form.arch   .value &&
             image_data['init'   ] == select_form.init   .value &&
             image_data['wmde'   ] == select_form.wmde   .value &&
             image_data['install'] == select_form.install.value  ;
    }) ;
*/

    var arch       = select_form.arch   .value ;
    var init       = select_form.init   .value ;
    var wmde       = select_form.wmde   .value ;
    var install    = select_form.install.value ;
    var image_data = RELEASE_IMAGES_TREE[arch][init][wmde][install] ;

//     if (image_data !== undefined)
    if (!!image_data)
    {
console.log("onclicked() got image_data " + image_data['image_url'  ]) ;
// console.log("onclicked() image_data=" + JSON.stringify(image_data)) ;

      kernel_li.textContent = "Kernel: " + image_data['kernel_ver'   ] ;
      size_li  .textContent = "Size: "   + image_data['image_size'   ] ;
      pkgs_a   .href        =              image_data['pkglist_url'  ] ;
      magnet_a .href        =              image_data['magnet_uri'   ] ;
      torrent_a.href        =              image_data['torrent_url'  ] ;
      sums_a   .href        =              image_data['checksums_url'] ;
      sig_a    .href        =              image_data['signature_url'] ;
      gpg_a    .href        =              image_data['gpg_key_url'  ] ;
    }

//     var rs = [ select_form.arch   , select_form.init   , select_form.wmde   , select_form.install ] ;
//     var param   = this.name ;
//     var param_n = IMAGE_PARAMS.indexOf(this.name) ;
//     var param   = IMAGE_PARAMS[param_n] ;
//     var radio   = rs[param_n] ;
//     var image_tree = (param == 'arch'   ) ? RELEASE_IMAGES_TREE                   :
//                      (param == 'init'   ) ? RELEASE_IMAGES_TREE[arch]             :
//                      (param == 'wmde'   ) ? RELEASE_IMAGES_TREE[arch][init]       :
//                      (param == 'install') ? RELEASE_IMAGES_TREE[arch][init][wmde] ;

    function enableRadios(arch , init , wmde , install)
    {
      var has_image = !!RELEASE_IMAGES_TREE[arch][init][wmde][install] ;

      if (has_image)
      {
        radios['arch'][arch].enabled = true ; radios['init'   ][init   ].enabled = true ;
        radios['wmde'][wmde].enabled = true ; radios['install'][install].enabled = true ;
      }
    }
    VALID_RELEASE_ARCHES  .forEach((arch   )=> { radios['arch'   ][arch   ].enabled = false ;
    VALID_RELEASE_INITS   .forEach((init   )=> { radios['init'   ][init   ].enabled = false ;
    VALID_RELEASE_WMDES   .forEach((wmde   )=> { radios['wmde'   ][wmde   ].enabled = false ;
    VALID_RELEASE_INSTALLS.forEach((install)=> { radios['install'][install].enabled = false ;
      enableRadios(arch , init , wmde , install) ;
    }) ; }) ; }) ; }) ;


// VALID_RELEASE_INITS
// VALID_RELEASE_WMDES
// VALID_RELEASE_INSTALLS
"release-#{param_id}-#{option_id}-input"
//   for (var radio_n = 0 ; radio_n < radios.length ; ++radio_n)
//     for (var input_n = 0 ; input_n < radios[radio_n].length ; ++input_n)
//       radio[input_n].enabled

  }
}
</script>