772040c50085914c5ba48610a6d8cac8797c1c61
[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
53   struct webgit_query* query = repo->query;
54
55   return html (
56                html (html_tag ("form",
57                                html_attr ("name", "blob-edit"),
58                                html_attr ("enctype", "multipart/form-data"),
59                                html_attr ("method", "post"),
60                                html_attr ("action", query->request->script_name)
61                                ),
62                      html (html_tag ("p"), "File: (change this for renaming, copying or deleting)<br />",
63                            html_hidden ("repo", query->repo),
64                            html_hidden ("ref", query->head),
65                            html_hidden ("commit", query->commit),
66                            html_hidden ("path", query->path),
67                            html_hidden ("action", "edit"),
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 ("value", ""),
139                                                    html_attr ("type", "file")
140                                                    )
141                                          )
142                                    )
143                             ),
144                      html (html_tag ("p"),
145                            html (html_tag ("input",
146                                            html_attr ("name", "cancel"),
147                                            html_attr ("type", "submit"),
148                                            html_attr ("value", "Cancel")
149                                            )
150                                  ),
151                            html (html_tag ("input",
152                                            html_attr ("name", "stage"),
153                                            html_attr ("type", "submit"),
154                                            html_attr ("value", "Stage for commit")
155                                            )
156                                  ),
157                            html (html_tag ("input",
158                                            html_attr ("name", "commit"),
159                                            html_attr ("type", "submit"),
160                                            html_attr ("value", "Commit ...")
161                                            )
162                                  )
163                            )
164                      )
165                );
166 }
167
168
169
170 Html
171 webgit_edit_blob_action (struct webgit_repo_info* repo, unsigned char* sha1)
172 {
173   void* buf;
174   unsigned long size;
175
176   buf = read_object_with_reference (sha1, "blob", &size, NULL);
177
178   return html(
179               html(html_tag("div", html_attr("id", "sub-menu")),
180                    webgit_edit_blob_menu_action (repo, sha1, buf, size)), html_nl (),
181               html(html_tag("div", html_attr("id", "content")),
182                    webgit_edit_blob_content_action (repo, sha1, buf, size)), html_nl ()
183               );
184 }
185
186 /*
187 //      Local Variables:
188 //      mode: C
189 //      c-file-style: "gnu"
190 //      indent-tabs-mode: nil
191 //      End:
192 */