From 85b972a4c3fe7f96f50546ec68c26c38c4f190df Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Sat, 10 Nov 2007 10:53:45 -0700
Subject: [PATCH] WUI: hook up an "overwrite" button on mutable files

---
 src/allmydata/web/directory.xhtml |  3 +++
 src/allmydata/webish.py           | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/src/allmydata/web/directory.xhtml b/src/allmydata/web/directory.xhtml
index 478f5bc8..27302b1f 100644
--- a/src/allmydata/web/directory.xhtml
+++ b/src/allmydata/web/directory.xhtml
@@ -31,6 +31,7 @@
     <td></td>
     <td></td>
     <td></td>
+    <td></td>
     <td>Checker Results</td>
   </tr>
   <tr n:pattern="item" n:render="row">
@@ -39,7 +40,9 @@
     <td><n:slot name="size"/></td>
     <td><n:slot name="data"/></td>
     <td><n:slot name="delete"/></td>
+	      <td><div n:render="overwrite"/></td>
     <td><n:slot name="rename"/></td>
+
     <td><n:slot name="check"/></td>
     <td><n:slot name="checker_results"/></td>
   </tr>
diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py
index a8e888a6..afd808f5 100644
--- a/src/allmydata/webish.py
+++ b/src/allmydata/webish.py
@@ -332,6 +332,25 @@ class Directory(rend.Page):
                 T.div(class_="freeform-form")[mount],
                 ]
 
+    def render_overwrite(self, ctx, data):
+        name, target = data
+        if IMutableFileNode.providedBy(target):
+            overwrite = T.form(action=".", method="post",
+                               enctype="multipart/form-data")[
+                T.fieldset[
+                T.input(type="hidden", name="t", value="overwrite"),
+                T.input(type='hidden', name='name', value=name),
+                T.input(type='hidden', name='when_done', value=url.here),
+                T.legend(class_="freeform-form-label")["Overwrite"],
+                "Choose new file: ",
+                T.input(type="file", name="file", class_="freeform-input-file"),
+                " ",
+                T.input(type="submit", value="Overwrite")
+                ]]
+            return [T.div(class_="freeform-form")[overwrite],]
+        else:
+            return []
+
     def render_results(self, ctx, data):
         req = inevow.IRequest(ctx)
         if "results" in req.args:
@@ -790,6 +809,17 @@ class POSTHandler(rend.Page):
                     return newnode.get_uri()
                 d.addCallback(_done)
 
+        elif t == "overwrite":
+            contents = req.fields["file"]
+            # SDMF: files are small, and we can only upload data.
+            contents.file.seek(0)
+            data = contents.file.read()
+            d = self._node.get(name)
+            def _got_child(child_node):
+                child_node.replace(data)
+                return child_node.get_uri()
+            d.addCallback(_got_child)
+
         elif t == "check":
             d = self._node.get(name)
             def _got_child(child_node):
-- 
2.45.2