olqv_infosblock.ejs 3.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Modal -->
<div class="modal fade" id="ModalInfosBlock" tabindex="-1" role="dialog" aria-labelledby="ModalInfosBlockTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ModalInfosBlockTitle">Infos</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" id="ModalInfosBlockBody">
      </div>
13
14
      <textarea id="ModalHiddenInfosBlock" style="height:0px;width:0px;opacity:0">
      </textarea>
15
      <div class="modal-footer">
16
17
18
        <button type="button" id="verbatimCopy" class="btn btn-primary btn-sm fas fa-files-o" data-tooltip="tooltip" title="Copy verbatim"></button>
        <button type="button" id="jsonCopy" class="btn btn-primary btn-sm">Copy as JSON</button>
        <button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">Close</button>
19
20
21
22
      </div>
    </div>
  </div>
</div>
23
24
25
26

<script>
class InfosBlock {
  constructor (sliceViewer) {
27
28
29
30
31
32
    this.infosLine        = document.getElementById('infos-line');
    this.infosBlock       = document.getElementById('ModalInfosBlockBody');
    this.hiddenInfosBlock = document.getElementById('ModalHiddenInfosBlock');
    this.verbatimCopyBtn  = document.getElementById('verbatimCopy');
    this.jsonCopyBtn      = document.getElementById('jsonCopy');

33
34
    this.sliceViewer      = sliceViewer;

35
    $(sliceViewer.getMap().getTargetElement()).append($("#ModalInfosBlock"));
36
37
38
39
    this.verbatimCopyBtn.onclick = this.verbatimCopy.bind(this);
    this.jsonCopyBtn.onclick = this.jsonCopy.bind(this);
  }

40
41
42
43
44
45
46
47
48
  format(floatValue) {
    let result = floatValue;
    if (typeof result === "number" && !Number.isInteger(result)){
      result = result.toExponential(4);
    }
    return result;
  };


49
50
51
52
53
54
55
56
57
58
59
  headline(title) {
    this.infosLine.innerHTML = title;
    this.infosLine.innerHTML += ' <button type="button" class="btn btn-outline-link btn-sm" data-toggle="modal" data-target="#ModalInfosBlock">etc.</button>';
  }

  populate(title, collection) {
    console.log("populate: entering");
    this.title = title;
    this.collection = collection;
    this.infosBlock.innerHTML = "<b>"+title+" <br><br>";
    for (var k in collection) {
60
      this.infosBlock.innerHTML += k + ":" + this.format(collection[k]["value"]) + " " + collection[k]["unit"] + "<br>";
61
62
63
64
65
66
67
    }
    console.log("populate: exiting");
  }

  verbatimCopy() {
    console.log("verbatimCopy : entering");
    this.hiddenInfosBlock.value = this.title + "\r\n\r\n";
68
69
70
71
    this.hiddenInfosBlock.value += "file:"+this.sliceViewer.getRelFITSFilePath()+"\r\n";
    if (sliceViewer.is3D()) {
      this.hiddenInfosBlock.value += "slice index:"+this.sliceViewer.getSliceIndex()+"\r\n";
    }
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    for (var k in this.collection) {
      this.hiddenInfosBlock.value += k + ":" + format(this.collection[k]["value"]) + " " + this.collection[k]["unit"] + "\r\n";
    }
    this.hiddenInfosBlock.select();
    try {
      var success = document.execCommand('copy');
    }
    catch (err){
      alert("Copy failed. " + err);
    }
    console.log("verbatimCopy : exiting");
  }

  jsonCopy() {
    console.log("jsonCopy : entering");
87
88
89
90
91
92
    let context = {};
    context["file"]=this.sliceViewer.getRelFITSFilePath();
    if (sliceViewer.is3D()) {
      context["slice index"]=this.sliceViewer.getSliceIndex();
    }
    this.hiddenInfosBlock.value = JSON.stringify($.extend(context, this.collection));
93
94
95
96
97
98
99
100
    this.hiddenInfosBlock.select();
    try {
      var success = document.execCommand('copy');
    }
    catch (err){
      alert("Copy failed. " + err);
    }
    console.log("jsonCopy : exiting");
101
102
103
  }
}
</script>