r8999@llin: dpavlin | 2005-11-20 22:46:22 +0100
[webpac2] / web / browse.cgi
index a10d175..bc9340f 100755 (executable)
@@ -75,6 +75,23 @@ sub get_file_in_html($) {
        return $content;
 }
 
+sub template_list_html($) {
+       my $current = shift || die;
+
+       my $html = qq{ Template\n<ul> };
+
+       foreach my $t (sort @templates) {
+               if ($t eq $current) {
+                       $html .= qq{ <li><b>$t</b></li> };
+               } else {
+                       $html .= qq{ <li><a href="#" onClick="load_template('$t'); return false;">$t</a></li> };
+               }
+       }
+
+       $html .= qq{ </ul> };
+       return $html;
+}
+
 ##----
 
 if ($q->path_info =~ m#xml#) {
@@ -118,6 +135,17 @@ if ($q->path_info =~ m#xml#) {
                exit;
        }
 
+} elsif ($q->path_info =~ m#template_list#) {
+
+               print qq{<response>
+<action type='html' target='div_template_list' errorCode='' errorMessage='' >
+<div>} . template_list_html($template_filename) . qq{</div>
+</action>
+</response>
+               };
+
+               exit;
+
 } elsif ($q->path_info =~ m#template#) {
 
                my $template_path = $out->{'include_path'} . '/' . $template_filename;
@@ -167,6 +195,7 @@ $tmpl
 </action>
 <action type='js'>
 <!--
+iwfOpacity('div_template', 100);
 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
 -->
 </action>
@@ -231,20 +260,7 @@ iwfLog('loaded CSS template');
 
 } else {
 
-       my $template_form = qq{
-               <form action="$self" method="get" style="display: inline;">
-               <select name="template">
-       };
-       foreach my $t (@templates) {
-               my $s = '';
-               $s = ' selected' if ($t eq $template_filename);
-               $template_form .= qq{<option$s>$t</option>};
-       }
-       $template_form .= qq{
-               </select>
-               <input type="submit" name="ch_template" value="Switch"/>
-               </form>
-       };
+       my $template_list_html = template_list_html($template_filename);
 
        print <<"_END_OF_HEAD_";
 <html>
@@ -313,6 +329,18 @@ function edit_css() {
        return false;
 }
 
+function load_template(name) {
+       iwfLog('changing template to '+name);
+       iwfOpacity('div_template', 30);
+       template_filename = name;
+       // load template editor
+       iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
+       load_rec(rec);
+
+       // refresh template list
+       iwfRequest( url+'/template_list/?template='+template_filename, 'div_template_list' );
+}
+
 function init_page() {
        iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
        iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
@@ -322,10 +350,9 @@ function init_page() {
 
        iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
 
-       load_rec(rec);
+       // load template editor and record
+       load_template(template_filename);
 
-       // load template editor
-       iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
        // load css editor
        iwfRequest( url+'/css/', 'div_css' );
 }
@@ -339,7 +366,6 @@ function init_page() {
 </div>
 
 db_path = <tt>$db_path</tt><br/>
-template = $template_form<br/>
 css = <tt>$css_file</tt>
 
 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
@@ -352,13 +378,20 @@ css = <tt>$css_file</tt>
 
 </div>
 
+
+<div id="div_template_list" style="display: inline; border: 2px solid #ffcc88; float: right; z-index: 10;">
+$template_list_html
+</div>
+
 <div>
 
-<div style="display: block;">
+<div style="border: 2px solid #ffff80;">
+
 Editor
 <a id="a_template" href="#" onClick="return edit_template();">template</a>
 <a id="a_css" href="#" onClick="return edit_css();">css</a>
 
+
 <div id="div_template">
 <span style="color: #808080;"> no template loaded yet. </span>
 </div>