+<& /elements/select-table.html,
+ 'table' => 'part_pkg',
+ 'agent_virt' => 1,
+ 'agent_null' => 1,
+ 'name_col' => 'pkg',
+ 'empty_label' => 'Select package', #should this be the default?
+ 'label_callback' => $opt{'label_callback'} || sub { shift->pkg_comment_only },
+ 'hashref' => \%hash,
+ %opt,
+&>
+
+% if ($opt{'toggle_disabled'}) {
+% unless ($toggle_disabled_init) {
+% $toggle_disabled_init = 1;
+
+<% include('/elements/xmlhttp.html',
+ 'url' => $fsurl.'misc/xmlhttp-part_pkg.cgi',
+ 'subs' => [ 'load_part_pkg' ],
+ ) %>
+
+<SCRIPT>
+var toggle_disabled_part_pkg_list = undefined;
+function toggle_disabled_part_pkg (id,showdisabled,noload) {
+ // remove link text, only put it back if this works
+ var trigger = document.getElementById(id+'_switch');
+ trigger.innerHTML = '';
+ // if needed, load pkg_list before trying again
+ var pkg_list = toggle_disabled_part_pkg_list;
+ if (!pkg_list && !noload) {
+ load_part_pkg(
+ function (result) {
+ result = JSON.parse(result);
+ if (result) {
+ toggle_disabled_part_pkg_list = result;
+ toggle_disabled_part_pkg(id,showdisabled,true);
+ } else {
+ console.log('Error loading pkg list');
+ }
+ }
+ );
+ return;
+ }
+ if (!(pkg_list && pkg_list.length)) {
+ console.log('Cannot load pkg list, or pkg list empty');
+ return;
+ }
+ // remove all existing options, tracking which are selected
+ var selectbox = document.getElementById(id);
+ var selected = {};
+ for (var i = selectbox.length - 1; i >= 0; i--) {
+ var nextopt = selectbox.options[i];
+ selected[nextopt.value] = nextopt.selected;
+ nextopt.parentNode.removeChild(nextopt);
+ }
+ // regenerate options list from pkg list
+ for (var i = 0; i < pkg_list.length; i++) {
+ var pkginfo = pkg_list[i];
+ if (showdisabled || selected[pkginfo.pkgpart] || !pkginfo.disabled) {
+ var newopt = document.createElement('option');
+ newopt.value = pkginfo.pkgpart;
+ newopt.text = pkginfo.label;
+ newopt.selected = selected[newopt.value] ? true : false;
+ selectbox.appendChild(newopt);
+ }
+ }
+ trigger.innerHTML = showdisabled ? '<% $hidetext %>' : '<% $showtext %>';
+ trigger.onclick = function () { toggle_disabled_part_pkg(id,(showdisabled ? 0 : 1)) };
+}
+</SCRIPT>
+
+% } # unless $toggle_disabled_init
+
+<BR><A
+ HREF="javascript:void(0)"
+ STYLE="font-size: smaller"
+ ONCLICK="toggle_disabled_part_pkg('<% $opt{'id'} %>',<% $showdisabled ? '0' : '1' %>)"
+ ID="<% $opt{'id'} %>_switch"><% $showdisabled ? $hidetext : $showtext %></A>
+
+% } # if $opt{'toggle_disabled'}
+
+<%shared>
+my $toggle_disabled_init = 0;
+</%shared>