Add a whole lore of new query parameters for handling edits
[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   return html (
55                html (html_tag ("form",
56                                html_attr ("name", "blob-edit"),
57                                html_attr ("enctype", "multipart/form-data"),
58                                html_attr ("method", "post"),
59                                html_attr ("action", query->request->script_name)
60                                ),
61                      html (html_tag ("p"), "File: (change this for renaming, copying or deleting)<br />",
62                            html_hidden ("repo", query->repo),
63                            html_hidden ("ref", query->head),
64                            html_hidden ("commit", query->commit),
65                            html_hidden ("oldpath", query->path),
66                            html (html_tag ("input",
67                                            html_attr ("name", "path"),
68                                            html_attr ("type", "text"),
69                                            html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
70                                            html_attr ("size", "60"),
71                                            html_attr ("value", query->path)
72                                            )
73                                  ),
74                            html (html_tag ("input",
75                                            html_attr ("name", "mode"),
76                                            html_attr ("type", "radio"),
77                                            html_attr ("value", "rename"),
78                                            html_attr ("checked", "checked")
79                                            )
80                                  ),
81                            "rename",
82                            html (html_tag ("input",
83                                            html_attr ("name", "mode"),
84                                            html_attr ("type", "radio"),
85                                            html_attr ("value", "copy")
86                                            )
87                                  ),
88                            "copy",
89                            html (html_tag ("input",
90                                            html_attr ("name", "mode"),
91                                            html_attr ("type", "radio"),
92                                            html_attr ("value", "delete")
93                                            )
94                                  ),
95                            "delete",
96                            !memchr(buf, 0, size>8192 ? 8192 : size) ?
97                            html (
98 #ifndef ENABLE_CODEPRESS
99                                  html (html_tag ("input",
100                                                  html_attr ("type", "reset"),
101                                                  html_attr ("value", "Undo all changes")
102                                                  )
103                                        ),
104 #endif
105                                  html (html_tag ("textarea",
106                                                  html_attr ("id", "blob"),
107                                                  html_attr ("name", "blob"),
108 #ifdef ENABLE_CODEPRESS
109                                                  html_attr ("class", "codepress generic"),
110 #endif
111                                                  html_attr ("wrap", "off"),
112                                                  html_attr ("style", "width:100%;height:600px")
113                                                  ),
114                                        html_strndup (buf, size)
115                                        )
116                                  ) : html ()
117                            ),
118                      html (html_tag ("p"), "Please add a brief summary of the changes you have made:",
119                            html (html_tag ("input",
120                                            html_attr ("name", "comment"),
121                                            html_attr ("type", "text"),
122                                            html_attr ("value", ""),
123                                            html_attr ("maxlen", "512"),
124                                            html_attr ("size", "80")
125                                            )
126                                  )
127                            ),
128                      html (html_tag ("p"), "Or"),
129                      html ( html_tag ("dl"),
130                             html ( html_tag ("dt"), "Upload File:"),
131                             html ( html_tag ("dt"),
132                                    html (html_tag ("input",
133                                                    html_attr ("name", "file"),
134                                                    html_attr ("size", "50"),
135                                                    html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
136                                                    html_attr ("type", "file")
137                                                    )
138                                          )
139                                    )
140                             ),
141                      html (html_tag ("p"),
142                            html (html_tag ("input",
143                                            html_attr ("name", "cancel"),
144                                            html_attr ("type", "submit"),
145                                            html_attr ("value", "Cancel")
146                                            )
147                                  ),
148                            html (html_tag ("input",
149                                            html_attr ("name", "stage"),
150                                            html_attr ("type", "submit"),
151                                            html_attr ("value", "Stage for commit")
152                                            )
153                                  ),
154                            html (html_tag ("input",
155                                            html_attr ("name", "docommit"),
156                                            html_attr ("type", "submit"),
157                                            html_attr ("value", "Commit ...")
158                                            )
159                                  )
160                            )
161                      )
162                );
163 }
164
165
166
167 Html
168 webgit_edit_blob_action (struct webgit_repo_info* repo, unsigned char* sha1)
169 {
170   void* buf;
171   unsigned long size;
172
173   buf = read_object_with_reference (sha1, "blob", &size, NULL);
174
175   return html (html (html_tag ("div", html_attr("id", "sub-menu")),
176                      webgit_edit_blob_menu_action (repo, sha1, buf, size)), html_nl (),
177                html (html_tag ("div", html_attr("id", "content")),
178                      webgit_edit_blob_content_action (repo, sha1, buf, size)), html_nl ()
179                );
180 }
181
182 /*
183 //      Local Variables:
184 //      mode: C
185 //      c-file-style: "gnu"
186 //      indent-tabs-mode: nil
187 //      End:
188 */