diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-07-08 20:02:45 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-07-08 20:02:45 -0400 |
commit | a7d2b59581360701c5f1a146449ca8e15189f7a9 (patch) | |
tree | 24acad8f6d06f2239d2fac4d41a06e29b5178955 | |
parent | Got rid of ugly hacks for abstract classes and used ReflectionClass instead (diff) | |
download | ingenue-a7d2b59581360701c5f1a146449ca8e15189f7a9.tar.gz ingenue-a7d2b59581360701c5f1a146449ca8e15189f7a9.tar.bz2 ingenue-a7d2b59581360701c5f1a146449ca8e15189f7a9.zip |
Did most of the work to convert package adding to a very configurable class for the new wizard
-rw-r--r-- | frontend/classes/wizard_api.php | 89 | ||||
-rw-r--r-- | frontend/css/pkgs.css | 22 | ||||
-rw-r--r-- | frontend/js/pkgsearch.js | 75 | ||||
-rw-r--r-- | frontend/js/wlca.js | 43 | ||||
-rw-r--r-- | frontend/modules/gentoo/step2.php | 2 | ||||
-rw-r--r-- | frontend/pages/test.php | 20 | ||||
-rw-r--r-- | frontend/routing.csv | 1 |
7 files changed, 159 insertions, 93 deletions
diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php index 95ed57a..b510fa3 100644 --- a/frontend/classes/wizard_api.php +++ b/frontend/classes/wizard_api.php @@ -140,16 +140,16 @@ class wizard_radio extends wizard_select { } } class wizard_checkbox_array extends wizard_input { - private $boxes; - function __construct($optname, $htmlname, $label, $boxes, $delim=' ') { + protected $array; + function __construct($optname, $htmlname, $label, $array, $delim=' ') { parent::__construct($optname, $htmlname, $label); - $this->boxes=$boxes; + $this->array=$array; $this->delim=$delim; } public function output() { echo "$this->label:<br/>\n"; $i=0; - foreach ($this->boxes as $val => $label) { + foreach ($this->array as $val => $label) { echo "\t<input type=\"checkbox\" id=\"$this->htmlname-$i\" name=\"$this->htmlname[$i]\"".(self::opt_has($this->optname, $val, $this->delim)?' checked="checked"':'')." /><label for=\"$this->htmlname-$i\">$label</label><br/>\n"; $i++; } @@ -158,14 +158,91 @@ class wizard_checkbox_array extends wizard_input { global $request; $val=array(); // FIXME we're assuming that array_keys order is determinate and the same as the foreach in output() - $vals=array_keys($this->boxes); + $vals=array_keys($this->array); foreach ($request[$this->htmlname] as $i) { $val[]=$vals[$i]; } self::set_opt($this->optname, implode($this->delim, $vals)); } + private static $opt_cache; protected static function opt_has($name, $val, $delim=' ') { - return (array_search($val, explode($delim, self::get_opt($name))) !== false); + if (!isset(self::$opt_cache[$name][$delim])) { + self::$opt_cache[$name][$delim]=explode($delim, self::get_opt($name)); + } + return in_array($val, self::$opt_cache[$name][$delim]); + } +} +class wizard_layered_checkbox_array extends wizard_checkbox_array { + private $depth=0, $path_delims=array('', '/', '-'); + function __construct($optname, $htmlname, $label, &$array, $delim=' ', $metadata) { + parent::__construct($optname, $htmlname, $label, &$array, $delim); + $this->metadata=$metadata; + for ($i=current(&$array); is_array($i); $i=current($i)) $this->depth++; + global $S; + if (!in_array('wlca', $S['scripts'])) { + $S['scripts'][]='wlca'; + } + } + public function output() { + $this->r_output($this->array); + } + private function r_output(&$array, $depth=0, $path=null, $name=null) { + static $uid=0, $ucid=0; + $conf=&$this->metadata[0]; + if ($depth == 0) { + if (isset($conf['autosize'])) { + $autosize=0; + for ($i=1; $i<count($this->metadata); $i++) { + $m=&$this->metadata[$i]; + if (isset($m['tag'])) { + $autosize++; + } + } + } + echo 'Search: <input id="'.$conf['id'].'-q" onkeyup="wlca_search(this.value, document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$conf['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a><br/>'."\n"; + echo '<div class="wlca'.(isset($conf['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$conf['id'].'">'."\n"; + foreach ($array as $name => &$val) { + $this->r_output($val, $depth+1, $name, $name); + $uid++; + } + echo '</div>'; + $last=$uid-1; + echo "<script type=\"text/javascript\">\n<!--\nwlca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, 4);\n-->\n</script>\n"; + } elseif ($depth <= $this->depth) { + $meta=$this->metadata[$depth]; + if (isset($meta['tag'])) { + echo '<'.$meta['tag'].' class="wlcae'.(isset($meta['search'])?' wlcas':'').(isset($meta['collapsed'])?' wlca'.($meta['collapsed']?'c':'C'):'').(isset($meta['class'])?' '.$meta['class']:'').'" id="'.$uid.'"'.($depth > 1 && isset($this->metadata[$depth-1]['collapsed']) && $this->metadata[$depth-1]['collapsed'] && false?' style="display: none"':'').'>'; + if (isset($meta['collapsed']) && $depth < $this->depth) { + echo '<a href="javascript:wlcat(\''.$uid.'\')">±</a>'; + } + } + if (isset($meta['checkbox'])) { + echo '<input type="checkbox" id="c'.$ucid.'" name="'.$this->htmlname.'['.$ucid.']" /><label for="c'.$ucid.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n"; + $ucid++; + } elseif (isset($meta['label'])) { + echo '<span class="wlcal">'.$this->format_label($array, $meta['label'], $path, $name)."</span><br/>\n"; + } + if ($depth + 1 <= $this->depth) { + foreach ($array as $name => &$val) { + $uid++; + $this->r_output($val, $depth+1, (isset($path)?($path.$meta['delim']):'').$name, $name); + } + } + if (isset($meta['tag'])) { + echo '</'.$meta['tag'].">\n"; + } + } + } + private function format_label(&$array, $label='%p', $path, $name) { + $arg=$array; + $label=str_replace(array('%p', '%n'), array($path, $name), $label); + if (strpos($label, '$')) { + while (is_array(current($arg))) { + $arg=current($arg); + } + $label=eval("extract(\$arg, EXTR_PREFIX_INVALID, 'var_');\nreturn <<<_XQ1\n$label\n_XQ1;\n"); + } + return htmlentities($label); } } ?> diff --git a/frontend/css/pkgs.css b/frontend/css/pkgs.css index f9251da..b115a4a 100644 --- a/frontend/css/pkgs.css +++ b/frontend/css/pkgs.css @@ -1,6 +1,15 @@ +.wlca.autosize .wlcae { + font-size: 87%; +} +.wlca.autosize .wlcae .wlcae { + padding-left: 2em; +} #plist { - height: 25em; + height: 400px; overflow: auto; + margin: 10px; + padding: 5px; + border: 1px dotted black; } #plist a { text-decoration: none; @@ -8,15 +17,6 @@ #plist div.masked { color: red; } -#plist div.bct { - font-size: 125%; -} -#plist div.lct { - font-size: 110%; -} -#plist div.bc, div.lc { - padding-left: 2em; -} -#plist .pd { +.wlca label { cursor: pointer; } diff --git a/frontend/js/pkgsearch.js b/frontend/js/pkgsearch.js deleted file mode 100644 index 86dc1c3..0000000 --- a/frontend/js/pkgsearch.js +++ /dev/null @@ -1,75 +0,0 @@ -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':''); -} diff --git a/frontend/js/wlca.js b/frontend/js/wlca.js new file mode 100644 index 0000000..58e9f7c --- /dev/null +++ b/frontend/js/wlca.js @@ -0,0 +1,43 @@ +var wlca_last_search; +function wlcat(id, set) { // Short for 'toggle' + tag=document.getElementById(id); + for (var i=1; i<tag.childNodes.length; i++) { + if (tag.childNodes[i].className && tag.childNodes[i].className.match(/wlcae/)) { + if (typeof(set) == 'undefined') { + set=tag.childNodes[i].style.display=="none"?"":"none"; + } + tag.childNodes[i].style.display=set; + } + } +} +function wlca_expand(id) { + wlcat(id, ""); +} +function wlca_collapse(id) { + wlcat(id, "none"); +} +function wlca_search(q, el, depth, maxdepth) { + if (depth == 0) { + if (q == wlca_last_search) return; + wlca_last_search=q; + } + var found=0; + for (var i=0; i<el.childNodes.length; i++) { + if (el.childNodes[i].nodeName == "LABEL" || (el.childNodes[i].className && el.childNodes[i].className.match(/wlcal/))) { + found+=(el.childNodes[i].innerHTML.indexOf(q) == -1?0:1); + break; + } + } + if (depth < maxdepth) { + for (var i=0; i<el.childNodes.length; i++) { + if (!(el.childNodes[i].className && el.childNodes[i].className.match(/wlcae/))) continue; + var lfound=wlca_search(q, el.childNodes[i], depth+1, maxdepth); + found+=lfound; + el.childNodes[i].style.display=(q.length == 0 || lfound > 0?"":"none"); + } + if (q.length == 0 && el.className.match(/wlcac/)) { + wlca_collapse(el.id); + } + } + return found; +} diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php index 9ca5ee7..fce2d70 100644 --- a/frontend/modules/gentoo/step2.php +++ b/frontend/modules/gentoo/step2.php @@ -1,6 +1,6 @@ <?php $title='Choose Extra Packages'; -$scripts='pkgsearch'; +$scripts='wlca'; function gentoo_body_step2() { global $S; $configuration=&$S['wizard']['configuration']; diff --git a/frontend/pages/test.php b/frontend/pages/test.php new file mode 100644 index 0000000..1f94178 --- /dev/null +++ b/frontend/pages/test.php @@ -0,0 +1,20 @@ +<?php +function init_test() { + return array('title' => 'Test', 'scripts' => array('wlca')); +} +function body_test() { + $profile=new sql_gentoo_profile(1); + $pkgs=$profile->get_packages(); + $meta=array( + array('id' => 'plist', 'autosize'=> true), + array('delim' => '', 'tag' => 'div', 'label' => '%n', 'collapsed' => true), + array('delim' => '/', 'tag' => 'div', 'label' => '%p', 'collapsed' => true), + array('delim' => '-', 'tag' => 'div', 'label' => '%p: $desc', 'checkbox' => '%p', 'collapsed' => true, 'search' => true), + array('tag' => 'div', 'label' => '=%p', 'checkbox' => '%p', 'search' => true) + ); + $a=new wizard_layered_checkbox_array('x', 'x', 'x', $pkgs, ' ', $meta); + echo '<h3>Step 2: Package Selection</h3><form action="'.url('test').'" method="post">'; + $a->output(); + echo '<input type="submit" value="Continue" /></form>'; +} +?> diff --git a/frontend/routing.csv b/frontend/routing.csv index 1455cf7..0329ba6 100644 --- a/frontend/routing.csv +++ b/frontend/routing.csv @@ -9,6 +9,7 @@ # Something like the following line should always be last to catch unrecognized URLs # ^ 404 +^test$ test # Home ^$ welcome # Logs |