logo       
Google Custom Search
    AddThis Social Bookmark Button

r9967 - trunk/libraries/koala/sources/examples/buddha: msg#00028

Subject: r9967 - trunk/libraries/koala/sources/examples/buddha
Author: hannes
Date: Sat Sep 17 23:56:09 2005
New Revision: 9967

Added:
   trunk/libraries/koala/sources/examples/buddha/class-editor.dylan
Modified:
   trunk/libraries/koala/sources/examples/buddha/TODO
   trunk/libraries/koala/sources/examples/buddha/buddha.dylan
   trunk/libraries/koala/sources/examples/buddha/buddha.lid
   trunk/libraries/koala/sources/examples/buddha/network.dylan
   trunk/libraries/koala/sources/examples/buddha/subnet.dylan
   trunk/libraries/koala/sources/examples/buddha/vlan.dylan
Log:
Bug: 7257
*implemented class-editor (generating html-forms for objects)


Modified: trunk/libraries/koala/sources/examples/buddha/TODO
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/TODO  (original)
+++ trunk/libraries/koala/sources/examples/buddha/TODO  Sat Sep 17 23:56:09 2005
@@ -13,3 +13,5 @@
 prevent cross-site scripting (escape <> in all input data)
 
 interface to get the next /XX subnet (or the next subnet with at least Y ips)
+
+with-xml:collect only works for elements, not for lists of elements
\ No newline at end of file

Modified: trunk/libraries/koala/sources/examples/buddha/buddha.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/buddha.dylan  (original)
+++ trunk/libraries/koala/sources/examples/buddha/buddha.dylan  Sat Sep 17 
23:56:09 2005
@@ -48,7 +48,7 @@
 define page save end;
 define page restore end;
 define page browse end;
-
+define page edit end;
 
 define macro with-buddha-template
   { with-buddha-template(?stream:variable, ?title:expression)
@@ -72,6 +72,7 @@
         a("Save to disk", href => "/save"),
         a("Restore from disk", href => "/restore"),
         a("Class browser", href => "/browse"),
+        a("Edit", href => "/edit"),
         a("Shutdown", href => "/koala/shutdown")
       }
     },
@@ -92,6 +93,26 @@
 
 define class <buddha-form-error> (<error>)
   constant slot error-string :: <string>, required-init-keyword: error:;
+end;
+
+define method respond-to-get
+    (page == #"edit",
+     request :: <request>,
+     response :: <response>,
+     #key errors)
+  let out = output-stream(response);
+  let obj-string = get-query-value("obj");
+  unless (obj-string)
+    obj-string := "";
+  end;
+  let obj = element($obj-table, obj-string, default: *config*);
+  with-buddha-template(out, "Edit")
+    with-xml()
+      div(id => "content") {
+        do(edit(obj))
+      }
+    end;
+  end;
 end;
 
 define method respond-to-get

Modified: trunk/libraries/koala/sources/examples/buddha/buddha.lid
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/buddha.lid    (original)
+++ trunk/libraries/koala/sources/examples/buddha/buddha.lid    Sat Sep 17 
23:56:09 2005
@@ -14,4 +14,5 @@
        mac
        cisco-telnet
        class-browser
+       class-editor
        buddha

Added: trunk/libraries/koala/sources/examples/buddha/class-editor.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/koala/sources/examples/buddha/class-editor.dylan    Sat Sep 
17 23:56:09 2005
@@ -0,0 +1,111 @@
+module: buddha
+
+
+define method edit (object :: <object>) => (res)
+  let class = object.object-class;
+  with-xml()
+    form(action => "/edit", \method => "post")
+    { div(class => "edit")
+      { do(for (slot in class.slot-descriptors)
+             let name = slot.slot-getter.debug-name;
+             collect(with-xml() text(concatenate(name, ": ")) end);
+             if (slot-initialized?(object, slot))
+               let slot-object = slot.slot-getter(object);
+               collect(edit-slot(slot-object, name));
+             else
+               //slot not initialized...
+               collect(with-xml() input(type => "text", name => name) end)
+             end if;
+             //if (subtype?(type, <sequence>) | subtype?(type, <table>))
+             //add-form-foobar (also when not initialized)
+             //else
+             collect(with-xml() br end);
+             //end if
+           end),
+        input(type => "submit", name => "save-button", value => "Save")
+      }
+    }
+  end;
+end;
+
+
+define generic edit-slot (object :: <object>, slot-name :: <string>);
+
+define method edit-slot (object :: <object>, slot-name :: <string>)
+  with-xml()
+    input(type => "text",
+          name => slot-name,
+          value => as(<string>, object))
+  end;
+end;
+
+define method edit-slot (object :: <ip-address>, slot-name :: <string>)
+  with-xml()
+    input(type => "text",
+          name => slot-name,
+          value => as(<string>, object))
+  end;
+end;
+
+define method edit-slot (object :: <string>, slot-name :: <string>)
+  with-xml()
+    input(type => "text",
+          name => slot-name,
+          value => object)
+  end;
+end;
+
+define method edit-slot (object :: type-union(<sequence>, <table>),
+                         slot-name :: <string>)
+  with-xml()
+    ul
+    { do(if (object.size > 0)
+           for (ele in object)
+             collect(with-xml()
+                       li { do(let reference = get-reference(ele);
+                               collect(with-xml()
+                                         a(as(<string>, ele),
+                                           href => concatenate("/edit?obj=",
+                                                               reference))
+                                       end);
+                               collect(with-xml()
+                                         input(type => "submit",
+                                               name => concatenate("remove-", 
reference),
+                                               value => "Remove")
+                                       end))
+                             }
+                     end);
+           end;
+         else
+           collect(with-xml() li("empty list") end);
+         end if)
+    }
+  end;
+end;
+
+define method edit-slot (object :: <integer>, slot-name :: <string>)
+  with-xml()
+    input(type => "text",
+          name => slot-name,
+          value => integer-to-string(object))
+  end;
+end;
+
+define method edit-slot (object :: <boolean>, slot-name :: <string>)
+  if (object)
+    with-xml()
+      input(type => "checkbox",
+            name => slot-name,
+            value => slot-name,
+            checked => "checked")
+    end;
+  else
+    with-xml()
+      input(type => "checkbox",
+            name => slot-name,
+            value => slot-name)
+    end;
+  end;
+end;
+
+               
\ No newline at end of file

Modified: trunk/libraries/koala/sources/examples/buddha/network.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/network.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/network.dylan Sat Sep 17 
23:56:09 2005
@@ -35,6 +35,11 @@
   a.network-cidr < b.network-cidr;
 end;
 
+define method as (class == <string>, network :: <network>)
+ => (res :: <string>)
+  as(<string>, network.network-cidr)
+end;
+  
 define method fits? (network :: <network>, cidr :: <cidr>)
  => (res :: <boolean>)
   //checks whether cidr is not used in network yet.

Modified: trunk/libraries/koala/sources/examples/buddha/subnet.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/subnet.dylan  (original)
+++ trunk/libraries/koala/sources/examples/buddha/subnet.dylan  Sat Sep 17 
23:56:09 2005
@@ -62,6 +62,11 @@
   end;
 end;
 
+define method as (class == <string>, subnet :: <subnet>)
+ => (res :: <string>)
+  as(<string>, subnet.network-cidr);
+end;
+
 define method gen-xml (subnet :: <subnet>)
   with-xml()
     tr { td(as(<string>, subnet.network-cidr)),

Modified: trunk/libraries/koala/sources/examples/buddha/vlan.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/vlan.dylan    (original)
+++ trunk/libraries/koala/sources/examples/buddha/vlan.dylan    Sat Sep 17 
23:56:09 2005
@@ -36,8 +36,13 @@
                    end);
   res;
 end;
-              
+
+define method as (class == <string>, vlan :: <vlan>)
+ => (res :: <string>)
+  concatenate(integer-to-string(vlan.vlan-number), " ", vlan.vlan-name);
+end;
+
 define method \< (a :: <vlan>, b :: <vlan>)
-  => (res :: <boolean>)
+ => (res :: <boolean>)
   a.vlan-number < b.vlan-number
 end;
-- 
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
https://gauss.gwydiondylan.org/mailman/listinfo/gd-chatter




Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>