summaryrefslogtreecommitdiff
path: root/httemplate/elements/tr-tower_sectors.html
blob: 5351becd8183eaca14096c2505e270a11ec8cc13 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<%init>
my %opt = @_;
my $tower = $opt{'object'};
my $towernum = $tower->towernum;
my $cgi = $opt{'cgi'};

my $tabcounter = 0;

my @fields = qw(
  sectorname ip_addr height freq_mhz direction width tilt v_width db_high
  db_low sector_range
);

my @sectors;
if ( $cgi->param('error') ) {
  foreach my $k ($cgi->param) {
    if ($k =~ /^sectornum\d+$/) {
      my $sectornum = $cgi->param($k);
      my $sector = FS::tower_sector->new({
        'sectornum' => $sectornum,
        'towernum'  => $towernum,
        map { $_ => scalar($cgi->param($k.'_'.$_)) } @fields,
      });
      push @sectors, $sector if length($sector->sectorname);
    }
  }
} elsif ( $towernum ) {
  @sectors = $tower->tower_sector;
} # else new mode, no sectors yet

my $id = $opt{id} || $opt{field} || 'sectornum';

</%init>
<& tablebreak-tr-title.html, %opt &>

<style>
  .ui-tabs-nav a {
    padding: 6px 9px;
    font-weight: bold;
  }
  .ui-tabs-nav li {
    border-top-left-radius: 0.5em;
    border-top-right-radius: 0.5em;
  }
  .ui-tabs-active li {
    border-bottom-color: #fff;
  }
  .ui-tabs {
    font-weight: bold;
  }
  .ui-tabs label {
    padding-top: 3px;
    width: 140px;
    display: inline-block;
    text-align: right;
  }
  .ui-tabs input, .ui-spinner {
    border: 1px solid #666;
    border-radius: 2px;
    font-size: 13.3px;
    text-align: right;
    font-weight: normal;
    padding: 1px;
  }
  .ui-tabs input { /* but not spinner, messes it up */
    margin-left: 1px;
    margin-right: 1px;
  }
  .ui-tabs input:focus {
    border-color: #7e0079;
    background-color: #ffffdd;
  }
  .ui-spinner input { /* use the spinner's border and padding */
    border: none;
    text-align: left;
  }
</style>


<tr>
  <td colspan=2>
%# prototypes
    <div style="display: none">
<& .tab, id => $id . '_P' &>
<& .panel, id => $id . '_P' &>
    </div>

%# main container
    <div id="<% $id %>_tabs">
      <ul>
% foreach my $sector (@sectors) {
<& .tab, sector => $sector, id => $id . $tabcounter &>
%   $tabcounter++;
% }
      </ul>

% $tabcounter = 0;
% foreach my $sector (@sectors) {
<& .panel, sector => $sector, id => $id . $tabcounter &>
%   $tabcounter++;
% }
    </div>
  </td>
</tr>
<script>
$(function() {
  var tabcounter = <% $tabcounter %>;
  var id = <% $id |js_string %>;
  //create tab bar
  var tabs = $( '#'+id+'_tabs' ).tabs();

  function changedSectorName() {
    var this_panel = $(this).parent();
    var this_tab = tabs.find('#' + this_panel.prop('id') + '_tab');
    // if this is the last panel, make a new one
    if (this_panel.next().length == 0) {
      addSector(this_panel);
    }
    // and update the current tab's text with the sector name
    this_tab.find('a').text($(this).val());
  }

  var tab_proto = $('#'+id+'_P_tab');
  var panel_proto = $('#'+id+'_P');

  function addSector() {
    var new_tab = tab_proto.clone();
    var new_panel = panel_proto.clone();
    // replace proto placeholder with the counter value, in all id and
    // name properties in new_panel and its children
    new_panel.add( new_panel.find('*') ).each(function() {
      this.id = this.id.replace('_P', tabcounter);
      if (this.name) {
        this.name = this.name.replace('_P', tabcounter);
      }
    });
    tabcounter++;
    // and set the handler up on it
    new_panel.find('.input-sectorname').on('change', changedSectorName);
    
    // also update the tab itself
    new_tab.find('a').prop('href', '#' + new_panel.prop('id'));
    new_tab.prop('id', new_panel.prop('id') + '_tab');

    tabs.append(new_panel);
    tabs.children('ul:first').append(new_tab);

    tabs.tabs('refresh');
  }

  $('.dbspinner').spinner({ step: 5 });

  $('.input-sectorname').on('change', changedSectorName);
  addSector();

});
</script>
<%def .tab>
% my %opt = @_;
% my $sector = $opt{sector};
% my $id = $opt{id};
% my $title = $sector ? $sector->sectorname : mt('Add new');
      <li id="<% $id %>_tab">
        <a href="#<% $id %>"><% $title |h %></a>
      </li>
</%def>
<%def .panel>
% my %opt = @_;
% my $sector = $opt{sector} || FS::tower_sector->new({});
% my $id = $opt{id}; # sectornumX
<div id="<% $id %>">
% # no id on this one, the panel gets the "sectornumX" id
  <input type="hidden" name="<% $id %>" value="<% $sector->sectornum |h %>">
  <p>
    <label><% emt('Sector name') %></label>
    <input style="text-align: left"
           class="input-sectorname"
           id="<% $id %>_sectorname"
           name="<% $id %>_sectorname"
           value="<% $sector->sectorname |h %>">

    <label><% emt('IP address') %></label>
    <input style="text-align: left"
           id="<% $id %>_ip_addr"
           name="<% $id %>_ip_addr"
           value="<% $sector->ip_addr |h %>">
  </p>
  <p>
    <label for="<% $id %>_height"><% emt('Antenna height') %></label>
    <input size="3"
           id="<% $id %>_height"
           name="<% $id %>_height"
           value="<% $sector->height |h %>">
    <% emt('feet above ground') %>
  </p>
  <p>
    <label for="<% $id %>_direction"><% emt('Azimuth') %></label>
    <input size="3"
           id="<% $id %>_direction"
           name="<% $id %>_direction"
           value="<% $sector->direction |h %>">&deg;
    <label for="<% $id %>_downtilt"><% emt('Down tilt') %></label>
    <input size="2"
           id="<% $id %>_downtilt"
           name="<% $id %>_downtilt"
           value="<% $sector->downtilt |h %>">&deg;
  </p>

  <p>
    <label for="<% $id %>_freq_mhz"><% emt('Frequency') %></label>
    <input size="4"
           id="<% $id %>_freq_mhz"
           name="<% $id %>_freq_mhz"
           value="<% $sector->freq_mhz |h %>">
    <% emt('MHz') %>
  </p>

  <p>
    <label for="<% $id %>_width"><% emt('Horizontal beam') %></label>
    <input size="3"
           id="<% $id %>_width"
           name="<% $id %>_width"
           value="<% $sector->width |h %>">&deg;
    <label for="<% $id %>_v_width"><% emt('Vertical beam') %></label>
    <input size="2"
           id="<% $id %>_v_width"
           name="<% $id %>_v_width"
           value="<% $sector->v_width |h %>">&deg;
  </p>

  <label><% emt('Signal margin') %></label>
      <div style="display: inline-block; vertical-align: top">
      <input class="dbspinner"
             size="4"
             id="<% $id %>_db_high"
             name="<% $id %>_db_high"
             value="<% $sector->db_high |h %>">
      <% emt('dB (high quality)') %>
      <br>

      <input class="dbspinner"
             size="4"
             id="<% $id %>_db_low"
             name="<% $id %>_db_low"
             value="<% $sector->db_low |h %>">
      <% emt('dB (low quality)') %>
      </div>

</div>
</%def>