summaryrefslogtreecommitdiff
blob: c800a5d437bc0ccc0ada2d79ff4fc94d1ba64293 (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
<?php
function gentoo_init_step2() {
	$js=<<<JS
function tog_show_pkgs(lc) {
	var div=document.getElementById('lc-'+lc);
	if (div.style.display == "none") {
		div.style.display="";
	} else {
		div.style.display="none";
	}
}
var oldq=null;
function packagesearch(entry) {
	var q=entry.value;
	if (q !== oldq) {
		filter_packages_by(q);
	}
	oldq=q;
}
function filter_packages_by(q) {
	var plist=document.getElementById('plist');
	var tfound=0;
	for (i=0; i<plist.childNodes.length; i++) {
		var bc=plist.childNodes[i];
		if (bc.className !== 'bc') {
			continue;
		}
		var bcid=bc.id.substr(3);
		var bfound=0;
		for (j=0; j<bc.childNodes.length; j++) {
			var lc=bc.childNodes[j];
			if (lc.className !== 'lc') {
				continue;
			}
			var lcid=lc.id.substr(3, lc.id.length-3);
			var found=0;
			for (k=0; k<lc.childNodes.length; k++) {
				var p=lc.childNodes[k];
				if (!p.className || p.className.substr(0,3) !== 'pkg') {
					continue;
				}
				if (q == '') {
					p.style.display="";
				} else {
					var name='';
					for (l=0; l<p.childNodes.length; l++) {
						var d=p.childNodes[l];
						if (d.className == 'pd') {
							name=d.innerHTML;
							break;
						}
					}
					if (name && name.toLowerCase().indexOf(q.toLowerCase()) != -1) {
						p.style.display="";
						found++;
					} else {
						p.style.display="none";
					}
				}
			}
			if (q == "" || found == 0) {
				lc.style.display="none";
				document.getElementById('lct-'+lcid).style.display=(q == ''?"":"none");
			} else {
				bfound+=found;
				lc.style.display="";
				document.getElementById('lct-'+lcid).style.display="";
			}
		}
		if (q=="" || bfound > 0) {
			document.getElementById('bct-'+bcid).style.display="";
		} else {
			document.getElementById('bct-'+bcid).style.display="none";
		}
		tfound+=bfound;
	}
	document.getElementById('zero').style.display=(tfound || !q.length?'none':'');
}
JS;
	$css=<<<CSS
#plist {
	height: 25em;
	overflow: auto;
}
#plist a {
	text-decoration: none;
}
div.masked {
	color: red;
}
div.bct {
	font-size: 125%;
}
div.lct {
	font-size: 110%;
}
div.bc, div.lc {
	padding-left: 2em;
}
.pd {
	cursor: pointer;
}
CSS;
	return array('title' => 'Step 2 - Choose Extra Packages', 'head_scripts' => array($js), 'head_css' => array($css));
}
function gentoo_body_step2() {
	global $S;
	$configuration=&$S['wizard.configuration'];
	$opts=$configuration->get_configopts();
	$profile=new sql_gentoo_profile($opts['profile']);
	$bcs=$profile->get_packages();
	echo 'Search packages: <input id="psearch" onkeyup="packagesearch(this)" /> <a href="javascript:var e=document.getElementById(\'psearch\'); e.value=\'\'; e.onkeyup()">Clear</a>';
	echo '<div id="plist"><div id="zero" style="display: none">'.print_error('No results found.').'</div>';
	$i=0;
	foreach ($bcs as $bc => $lcs) {
		echo '<div class="bct" id="bct-'.$bc.'">'.htmlentities($bc).'</div><div class="bc" id="bc-'.$bc.'">'."\n";
		foreach ($lcs as $lc => $packages) {
			echo '<div class="lct" id="lct-'.$bc.$lc.'"><a href="javascript:tog_show_pkgs(\''.$bc.$lc.'\')">&plusmn;</a> '.htmlentities("$bc$lc").'</div><div class="lc" id="lc-'.$bc.$lc.'" style="display: none">'."\n";
			foreach ($packages as $name => $vers) {
				foreach ($vers as $ver => $attrs) {
					$safename=htmlentities("$bc$lc/$name-$ver");
					echo '<div class="pkg'.($attrs['masked']?' masked':'').'"><input id="p'.$i.'" type="checkbox" name="expkgs['.$safename.']" /><label class="pd" for="p'.$i++.'">'.htmlentities("$name-$ver").' - '.htmlentities($attrs['desc']).($attrs['masked']?' [MASKED]':'').'</label></div>'."\n";
				}
			}
			echo '</div>'."\n";
		}
		echo '</div>'."\n";
	}
	echo '</div>';
}
function gentoo_process_step2() {
	global $S, $request;
	if (isset($request['expkgs'])) {
		$packages=array();
		foreach ($request['expkgs'] as $name => $null) {
			$packages[]='='.$name;
		}
		$packages=implode(' ', $packages);
		$opt=new sql_configopt($S['wizard.configuration']->id, 'install_packages', $packages);
		$opt->write();
	}
}
?>