diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/classes/wizard_api.php | 92 | ||||
-rw-r--r-- | frontend/css/wlca.css (renamed from frontend/css/pkgs.css) | 4 | ||||
-rw-r--r-- | frontend/js/wlca.js | 18 | ||||
-rw-r--r-- | frontend/modules/gentoo/step2.php | 14 | ||||
-rw-r--r-- | frontend/pages/test.php | 20 | ||||
-rw-r--r-- | frontend/routing.csv | 1 |
6 files changed, 101 insertions, 48 deletions
diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php index b510fa3..b23b8a5 100644 --- a/frontend/classes/wizard_api.php +++ b/frontend/classes/wizard_api.php @@ -10,7 +10,7 @@ class wizard_step { } require($file); $this->title="Step $step".($title?" - $title":''); - $this->next=$next; + $this->next=isset($next)?$next:$step+1; } public function output() { echo "<h3>$this->title</h3>\n"; @@ -25,7 +25,7 @@ class wizard_step { } public function process() { global $request; - if (isset($request['wizard_submit_'.$this->step])) { + if (!isset($request['wizard_submit'][$this->step])) { return $this->step; } $result=$this->next; @@ -45,9 +45,21 @@ class wizard_step { private function select($optname, $htmlname, $label, $options) { $this->data[]=new wizard_select($optname, $htmlname, $label, $options); } + private function radio($optname, $htmlname, $label, $options) { + $this->data[]=new wizard_radio($optname, $htmlname, $label, $options); + } + private function checkbox_array($optname, $htmlname, $label, $array, $delim=' ') { + $this->data[]=new wizard_checkbox_array($optname, $htmlname, $label, $array, $delim=' '); + } + private function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) { + $this->data[]=new wizard_layered_checkbox_array($optname, $htmlname, $label, $array, $delim, $metadata); + } private function query($q) { return $GLOBALS['S']['pdo']->query($q); } + private function get_opt($opt) { + return wizard::get_opt($opt); + } } abstract class wizard { public $status=true; @@ -57,11 +69,12 @@ abstract class wizard { } abstract public function output(); abstract public function process(); - protected static function get_opt($name) { + public static function get_opt($name) { $opts=self::$configuration->get_opts(); return isset($opts[$name])?$opts[$name]:null; } protected static function set_opt($name, $val) { + debug('wizard', "$name=$val"); if (substr($name, 0, 1) == ':') { self::$configuration->$name=$val; self::$configuration->write(); @@ -184,47 +197,59 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array { } } public function output() { + if ($this->label) { + echo '<h4>'.htmlentities($this->label).'</h4>'; + } $this->r_output($this->array); } + public function process() { + self::set_opt($this->optname, implode($this->delim, $this->r_process($this->array))); + return true; + } 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++; - } + $search=$autosize=0; + for ($i=1; $i<count($this->metadata); $i++) { + $m=&$this->metadata[$i]; + if (isset($m['tag'])) { + $autosize++; } + if (isset($m['search'])) { + $search++; + } + } + if ($search) { + if (!isset($conf['id'])) { + $conf['id']=self::b36($uid++); + } + 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 '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"; + echo "<script type=\"text/javascript\">\n<!--\nwlca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\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"':'').'>'; + echo '<'.$meta['tag'].' class="wlcae'.(isset($meta['search'])?' wlcas':'').(isset($meta['collapsed'])?' wlca'.($meta['collapsed']?'c':'C'):'').(isset($meta['class'])?' '.$meta['class']:'').'" id="'.self::b36($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>'; + echo '<a href="javascript:wlcat(\''.self::b36($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++; + $hex=self::b36($ucid++); + echo '<input type="checkbox" id="-'.$hex.'" name="'.$this->htmlname.'['.$hex.']"'.(self::opt_has($this->optname, $this->format_label($array, $meta['checkbox'], $path, $name), $this->delim)?' checked="checked"':'').' /><label for="-'.$hex.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n"; } elseif (isset($meta['label'])) { - echo '<span class="wlcal">'.$this->format_label($array, $meta['label'], $path, $name)."</span><br/>\n"; + echo '<span class="wlcal">'.$this->format_label($array, $meta['label'], $path, $name)."</span>\n"; } - if ($depth + 1 <= $this->depth) { + if ($depth < $this->depth) { foreach ($array as $name => &$val) { - $uid++; + $uid++; $this->r_output($val, $depth+1, (isset($path)?($path.$meta['delim']):'').$name, $name); } } @@ -233,6 +258,30 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array { } } } + private function r_process(&$array, $depth=0, $path=null, $name=null) { + static $ucid=0, $r; + if ($depth == 0) { + $r=array(); + foreach ($array as $name => &$val) { + $this->r_process($val, $depth+1, $name, $name); + } + return $r; + } elseif ($depth <= $this->depth) { + $meta=$this->metadata[$depth]; + if (isset($meta['checkbox'])) { + global $request; + if (isset($request[$this->htmlname][self::b36($ucid)])) { + $r[]=$this->format_label($array, $meta['checkbox'], $path, $name); + } + $ucid++; + } + if ($depth + 1 <= $this->depth) { + foreach ($array as $name => &$val) { + $this->r_process($val, $depth+1, (isset($path)?($path.$meta['delim']):'').$name, $name); + } + } + } + } private function format_label(&$array, $label='%p', $path, $name) { $arg=$array; $label=str_replace(array('%p', '%n'), array($path, $name), $label); @@ -244,5 +293,8 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array { } return htmlentities($label); } + private static function b36($n) { + return base_convert($n, 10, 36); + } } ?> diff --git a/frontend/css/pkgs.css b/frontend/css/wlca.css index b115a4a..e090b89 100644 --- a/frontend/css/pkgs.css +++ b/frontend/css/wlca.css @@ -11,12 +11,12 @@ padding: 5px; border: 1px dotted black; } -#plist a { +.wlcae a { text-decoration: none; } #plist div.masked { color: red; } -.wlca label { +.wlcae label { cursor: pointer; } diff --git a/frontend/js/wlca.js b/frontend/js/wlca.js index 58e9f7c..942300c 100644 --- a/frontend/js/wlca.js +++ b/frontend/js/wlca.js @@ -1,4 +1,6 @@ var wlca_last_search; +var wlca_search_timeout; +var wlca_found_last; function wlcat(id, set) { // Short for 'toggle' tag=document.getElementById(id); for (var i=1; i<tag.childNodes.length; i++) { @@ -16,10 +18,20 @@ function wlca_expand(id) { function wlca_collapse(id) { wlcat(id, "none"); } -function wlca_search(q, el, depth, maxdepth) { +function wlca_search(q, el, depth, maxdepth, t) { + if (!t) { + clearTimeout(wlca_search_timeout); + wlca_search_timeout=setTimeout(function () {wlca_found_last=wlca_search(q, el, depth, maxdepth, true)}, 300); + return; + } if (depth == 0) { - if (q == wlca_last_search) return; + if (q == wlca_last_search) return wlca_found_last; + if (wlca_found_last == 0 && q.indexOf(wlca_last_search) != -1) { + debug('wlca', 'Already had no results, not searching "'+q+'"'); + return 0; + } wlca_last_search=q; + debug('wlca', 'Searching "'+q+'"'); } var found=0; for (var i=0; i<el.childNodes.length; i++) { @@ -31,7 +43,7 @@ function wlca_search(q, el, depth, maxdepth) { 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); + var lfound=wlca_search(q, el.childNodes[i], depth+1, maxdepth, true); found+=lfound; el.childNodes[i].style.display=(q.length == 0 || lfound > 0?"":"none"); } diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php index fce2d70..df8ecce 100644 --- a/frontend/modules/gentoo/step2.php +++ b/frontend/modules/gentoo/step2.php @@ -1,7 +1,17 @@ <?php $title='Choose Extra Packages'; $scripts='wlca'; -function gentoo_body_step2() { +$profile=new sql_gentoo_profile($this->get_opt('profile')); +$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) +); +$this->layered_checkbox_array('install_packages', 'p', null, $pkgs, ' ', $meta); +/*function gentoo_body_step2() { global $S; $configuration=&$S['wizard']['configuration']; $opts=$configuration->get_configopts(); @@ -37,5 +47,5 @@ function gentoo_process_step2() { $opt=new sql_configopt($S['wizard']['configuration']->id, 'install_packages', $packages); $opt->write(); } -} +}*/ ?> diff --git a/frontend/pages/test.php b/frontend/pages/test.php deleted file mode 100644 index 1f94178..0000000 --- a/frontend/pages/test.php +++ /dev/null @@ -1,20 +0,0 @@ -<?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 0329ba6..1455cf7 100644 --- a/frontend/routing.csv +++ b/frontend/routing.csv @@ -9,7 +9,6 @@ # Something like the following line should always be last to catch unrecognized URLs # ^ 404 -^test$ test # Home ^$ welcome # Logs |