some pending cosmetics
[webgit] / src / edit.c
1 /*
2     cehtehs git web frontend
3
4   Copyright (C)
5     2007, 2008,         Christian Thaeter <ct@pipapo.org>
6
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU Affero General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU Affero General Public License for more details.
16
17   You should have received a copy of the GNU Affero General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "edit.h"
22 #include "repo.h"
23 #include "actions.h"
24 #include "object.h"
25 #include "summary.h"
26
27 /*
28   Edit menu
29 */
30
31 static Html
32 webgit_edit_blob_menu_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
33 {
34   (void) sha1;
35   (void) buf;
36   (void) size;
37
38   struct webgit_query* query = repo->query;
39
40   return html (html_tag ("div"),
41                webgit_repo_logo (repo), "<br />",
42                webgit_object_tree_parent_link (query, "<<%s"),
43                webgit_summary_link (query, repo, html("Summary")), "<br />",
44                webgit_main_link (query, html ("Main"))
45                );
46 }
47
48 static Html
49 webgit_edit_blob_content_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
50 {
51   (void) sha1;
52   struct webgit_query* query = repo->query;
53
54   TRACE (webgit, "%.*s", size, buf);
55
56   return html (
57                html (html_tag ("form",
58                                html_attr ("name", "blob-edit"),
59                                html_attr ("enctype", "multipart/form-data"),
60                                html_attr ("method", "post"),
61                                html_attr ("action", query->request->script_name)
62                                ),
63                      html (html_tag ("p"), "File: (change this for renaming, copying or deleting)<br />",
64                            html_hidden ("repo", query->repo),
65                            html_hidden ("ref", query->head),
66                            html_hidden ("commit", query->commit),
67                            html_hidden ("oldpath", query->path),
68                            html (html_tag ("input",
69                                            html_attr ("name", "path"),
70                                            html_attr ("type", "text"),
71                                            html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
72                                            html_attr ("size", "60"),
73                                            html_attr ("value", query->path)
74                                            )
75                                  ),
76                            html (html_tag ("input",
77                                            html_attr ("name", "mode"),
78                                            html_attr ("type", "radio"),
79                                            html_attr ("value", "rename"),
80                                            html_attr ("checked", "checked")
81                                            )
82                                  ),
83                            "rename",
84                            html (html_tag ("input",
85                                            html_attr ("name", "mode"),
86                                            html_attr ("type", "radio"),
87                                            html_attr ("value", "copy")
88                                            )
89                                  ),
90                            "copy",
91                            html (html_tag ("input",
92                                            html_attr ("name", "mode"),
93                                            html_attr ("type", "radio"),
94                                            html_attr ("value", "delete")
95                                            )
96                                  ),
97                            "delete",
98                            !memchr(buf, 0, size>8192 ? 8192 : size) ?
99                            html (
100 #ifndef ENABLE_CODEPRESS
101                                  html (html_tag ("input",
102                                                  html_attr ("type", "reset"),
103                                                  html_attr ("value", "Undo all changes")
104                                                  )
105                                        ),
106 #endif
107                                  html (html_tag ("textarea",
108                                                  html_attr ("id", "blob"),
109                                                  html_attr ("name", "blob"),
110 #ifdef ENABLE_CODEPRESS
111                                                  html_attr ("class", "codepress generic"),
112 #endif
113                                                  html_attr ("wrap", "off"),
114                                                  html_attr ("style", "width:100%;height:600px")
115                                                  ),
116                                        html_strndup (buf, size)
117                                        )
118                                  ) : html ()
119                            ),
120                      html (html_tag ("p"), "Please add a brief summary of the changes you have made:",
121                            html (html_tag ("input",
122                                            html_attr ("name", "comment"),
123                                            html_attr ("type", "text"),
124                                            html_attr ("value", ""),
125                                            html_attr ("maxlen", "512"),
126                                            html_attr ("size", "80")
127                                            )
128                                  )
129                            ),
130                      html (html_tag ("p"), "Or"),
131                      html ( html_tag ("dl"),
132                             html ( html_tag ("dt"), "Upload File:"),
133                             html ( html_tag ("dt"),
134                                    html (html_tag ("input",
135                                                    html_attr ("name", "file"),
136                                                    html_attr ("size", "50"),
137                                                    html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
138                                                    html_attr ("type", "file")
139                                                    )
140                                          )
141                                    )
142                             ),
143                      html (html_tag ("p"),
144                            html (html_tag ("input",
145                                            html_attr ("name", "cancel"),
146                                            html_attr ("type", "submit"),
147                                            html_attr ("value", "Cancel")
148                                            )
149                                  ),
150                            html (html_tag ("input",
151                                            html_attr ("name", "stage"),
152                                            html_attr ("type", "submit"),
153                                            html_attr ("value", "Stage for commit")
154                                            )
155                                  ),
156                            html (html_tag ("input",
157                                            html_attr ("name", "docommit"),
158                                            html_attr ("type", "submit"),
159                                            html_attr ("value", "Commit ...")
160                                            )
161                                  )
162                            )
163                      )
164                );
165 }
166
167
168
169 Html
170 webgit_edit_blob_action (struct webgit_repo_info* repo, unsigned char* sha1)
171 {
172   void* buf;
173   unsigned long size;
174
175   buf = read_object_with_reference (sha1, "blob", &size, NULL);
176
177   return html (html (html_tag ("div", html_attr("id", "sub-menu")),
178                      webgit_edit_blob_menu_action (repo, sha1, buf, size)), html_nl (),
179                html (html_tag ("div", html_attr("id", "content")),
180                      webgit_edit_blob_content_action (repo, sha1, buf, size)), html_nl ()
181                );
182 }
183
184 /*
185 //      Local Variables:
186 //      mode: C
187 //      c-file-style: "gnu"
188 //      indent-tabs-mode: nil
189 //      End:
190 */