##// END OF EJS Templates
forms: fix call for secure form
marcink -
r1987:58523759 default
parent child Browse files
Show More
@@ -1,238 +1,238 b''
1 <%inherit file="/base/base.mako"/>
1 <%inherit file="/base/base.mako"/>
2
2
3 <%def name="title()">
3 <%def name="title()">
4 ${_('%s Files Add') % c.repo_name}
4 ${_('%s Files Add') % c.repo_name}
5 %if c.rhodecode_name:
5 %if c.rhodecode_name:
6 &middot; ${h.branding(c.rhodecode_name)}
6 &middot; ${h.branding(c.rhodecode_name)}
7 %endif
7 %endif
8 </%def>
8 </%def>
9
9
10 <%def name="menu_bar_nav()">
10 <%def name="menu_bar_nav()">
11 ${self.menu_items(active='repositories')}
11 ${self.menu_items(active='repositories')}
12 </%def>
12 </%def>
13
13
14 <%def name="breadcrumbs_links()">
14 <%def name="breadcrumbs_links()">
15 ${_('Add new file')} @ ${h.show_id(c.commit)}
15 ${_('Add new file')} @ ${h.show_id(c.commit)}
16 </%def>
16 </%def>
17
17
18 <%def name="menu_bar_subnav()">
18 <%def name="menu_bar_subnav()">
19 ${self.repo_menu(active='files')}
19 ${self.repo_menu(active='files')}
20 </%def>
20 </%def>
21
21
22 <%def name="main()">
22 <%def name="main()">
23 <div class="box">
23 <div class="box">
24 <div class="title">
24 <div class="title">
25 ${self.repo_page_title(c.rhodecode_db_repo)}
25 ${self.repo_page_title(c.rhodecode_db_repo)}
26 </div>
26 </div>
27 <div class="edit-file-title">
27 <div class="edit-file-title">
28 ${self.breadcrumbs()}
28 ${self.breadcrumbs()}
29 </div>
29 </div>
30 ${h.secure_form(h.route_path('repo_files_create_file', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path), id='eform', method='POST', enctype="multipart/form-data", class_="form-horizontal")}
30 ${h.secure_form(h.route_path('repo_files_create_file', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path), id='eform', method='POST', enctype="multipart/form-data", class_="form-horizontal", request=request)}
31 <div class="edit-file-fieldset">
31 <div class="edit-file-fieldset">
32 <div class="fieldset">
32 <div class="fieldset">
33 <div id="destination-label" class="left-label">
33 <div id="destination-label" class="left-label">
34 ${_('Path')}:
34 ${_('Path')}:
35 </div>
35 </div>
36 <div class="right-content">
36 <div class="right-content">
37 <div id="specify-custom-path-container">
37 <div id="specify-custom-path-container">
38 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path)}</span>
38 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path)}</span>
39 <a class="custom-path-link" id="specify-custom-path" href="#">${_('Specify Custom Path')}</a>
39 <a class="custom-path-link" id="specify-custom-path" href="#">${_('Specify Custom Path')}</a>
40 </div>
40 </div>
41 <div id="remove-custom-path-container" style="display: none;">
41 <div id="remove-custom-path-container" style="display: none;">
42 ${c.repo_name}/
42 ${c.repo_name}/
43 <input type="input-small" value="${c.f_path}" size="46" name="location" id="location">
43 <input type="input-small" value="${c.f_path}" size="46" name="location" id="location">
44 <a class="custom-path-link" id="remove-custom-path" href="#">${_('Remove Custom Path')}</a>
44 <a class="custom-path-link" id="remove-custom-path" href="#">${_('Remove Custom Path')}</a>
45 </div>
45 </div>
46 </div>
46 </div>
47 </div>
47 </div>
48 <div id="filename_container" class="fieldset">
48 <div id="filename_container" class="fieldset">
49 <div class="filename-label left-label">
49 <div class="filename-label left-label">
50 ${_('Filename')}:
50 ${_('Filename')}:
51 </div>
51 </div>
52 <div class="right-content">
52 <div class="right-content">
53 <input class="input-small" type="text" value="" size="46" name="filename" id="filename">
53 <input class="input-small" type="text" value="" size="46" name="filename" id="filename">
54 <p>${_('or')} <a id="upload_file_enable" href="#">${_('Upload File')}</a></p>
54 <p>${_('or')} <a id="upload_file_enable" href="#">${_('Upload File')}</a></p>
55 </div>
55 </div>
56 </div>
56 </div>
57 <div id="upload_file_container" class="fieldset" style="display: none;">
57 <div id="upload_file_container" class="fieldset" style="display: none;">
58 <div class="filename-label left-label">
58 <div class="filename-label left-label">
59 ${_('Filename')}:
59 ${_('Filename')}:
60 </div>
60 </div>
61 <div class="right-content">
61 <div class="right-content">
62 <input class="input-small" type="text" value="" size="46" name="filename_upload" id="filename_upload" placeholder="${_('No file selected')}">
62 <input class="input-small" type="text" value="" size="46" name="filename_upload" id="filename_upload" placeholder="${_('No file selected')}">
63 </div>
63 </div>
64 <div class="filename-label left-label file-upload-label">
64 <div class="filename-label left-label file-upload-label">
65 ${_('Upload file')}:
65 ${_('Upload file')}:
66 </div>
66 </div>
67 <div class="right-content file-upload-input">
67 <div class="right-content file-upload-input">
68 <label for="upload_file" class="btn btn-default">Browse</label>
68 <label for="upload_file" class="btn btn-default">Browse</label>
69
69
70 <input type="file" name="upload_file" id="upload_file">
70 <input type="file" name="upload_file" id="upload_file">
71 <p>${_('or')} <a id="file_enable" href="#">${_('Create New File')}</a></p>
71 <p>${_('or')} <a id="file_enable" href="#">${_('Create New File')}</a></p>
72 </div>
72 </div>
73 </div>
73 </div>
74 </div>
74 </div>
75 <div class="table">
75 <div class="table">
76 <div id="files_data">
76 <div id="files_data">
77 <div id="codeblock" class="codeblock">
77 <div id="codeblock" class="codeblock">
78 <div class="code-header form" id="set_mode_header">
78 <div class="code-header form" id="set_mode_header">
79 <div class="fields">
79 <div class="fields">
80 ${h.dropdownmenu('set_mode','plain',[('plain',_('plain'))],enable_filter=True)}
80 ${h.dropdownmenu('set_mode','plain',[('plain',_('plain'))],enable_filter=True)}
81 <label for="line_wrap">${_('line wraps')}</label>
81 <label for="line_wrap">${_('line wraps')}</label>
82 ${h.dropdownmenu('line_wrap', 'off', [('on', _('on')), ('off', _('off')),])}
82 ${h.dropdownmenu('line_wrap', 'off', [('on', _('on')), ('off', _('off')),])}
83
83
84 <div id="render_preview" class="btn btn-small preview hidden" >${_('Preview')}</div>
84 <div id="render_preview" class="btn btn-small preview hidden" >${_('Preview')}</div>
85 </div>
85 </div>
86 </div>
86 </div>
87 <div id="editor_container">
87 <div id="editor_container">
88 <pre id="editor_pre"></pre>
88 <pre id="editor_pre"></pre>
89 <textarea id="editor" name="content" ></textarea>
89 <textarea id="editor" name="content" ></textarea>
90 <div id="editor_preview"></div>
90 <div id="editor_preview"></div>
91 </div>
91 </div>
92 </div>
92 </div>
93 </div>
93 </div>
94 </div>
94 </div>
95
95
96 <div class="edit-file-fieldset">
96 <div class="edit-file-fieldset">
97 <div class="fieldset">
97 <div class="fieldset">
98 <div id="commit-message-label" class="commit-message-label left-label">
98 <div id="commit-message-label" class="commit-message-label left-label">
99 ${_('Commit Message')}:
99 ${_('Commit Message')}:
100 </div>
100 </div>
101 <div class="right-content">
101 <div class="right-content">
102 <div class="message">
102 <div class="message">
103 <textarea id="commit" name="message" placeholder="${c.default_message}"></textarea>
103 <textarea id="commit" name="message" placeholder="${c.default_message}"></textarea>
104 </div>
104 </div>
105 </div>
105 </div>
106 </div>
106 </div>
107 <div class="pull-right">
107 <div class="pull-right">
108 ${h.reset('reset',_('Cancel'),class_="btn btn-small")}
108 ${h.reset('reset',_('Cancel'),class_="btn btn-small")}
109 ${h.submit('commit_btn',_('Commit changes'),class_="btn btn-small btn-success")}
109 ${h.submit('commit_btn',_('Commit changes'),class_="btn btn-small btn-success")}
110 </div>
110 </div>
111 </div>
111 </div>
112 ${h.end_form()}
112 ${h.end_form()}
113 </div>
113 </div>
114 <script type="text/javascript">
114 <script type="text/javascript">
115
115
116 $('#commit_btn').on('click', function() {
116 $('#commit_btn').on('click', function() {
117 var button = $(this);
117 var button = $(this);
118 if (button.hasClass('clicked')) {
118 if (button.hasClass('clicked')) {
119 button.attr('disabled', true);
119 button.attr('disabled', true);
120 } else {
120 } else {
121 button.addClass('clicked');
121 button.addClass('clicked');
122 }
122 }
123 });
123 });
124
124
125 $('#specify-custom-path').on('click', function(e){
125 $('#specify-custom-path').on('click', function(e){
126 e.preventDefault();
126 e.preventDefault();
127 $('#specify-custom-path-container').hide();
127 $('#specify-custom-path-container').hide();
128 $('#remove-custom-path-container').show();
128 $('#remove-custom-path-container').show();
129 $('#destination-label').css('margin-top', '13px');
129 $('#destination-label').css('margin-top', '13px');
130 });
130 });
131
131
132 $('#remove-custom-path').on('click', function(e){
132 $('#remove-custom-path').on('click', function(e){
133 e.preventDefault();
133 e.preventDefault();
134 $('#specify-custom-path-container').show();
134 $('#specify-custom-path-container').show();
135 $('#remove-custom-path-container').hide();
135 $('#remove-custom-path-container').hide();
136 $('#location').val('${c.f_path}');
136 $('#location').val('${c.f_path}');
137 $('#destination-label').css('margin-top', '0');
137 $('#destination-label').css('margin-top', '0');
138 });
138 });
139
139
140 var hide_upload = function(){
140 var hide_upload = function(){
141 $('#files_data').show();
141 $('#files_data').show();
142 $('#upload_file_container').hide();
142 $('#upload_file_container').hide();
143 $('#filename_container').show();
143 $('#filename_container').show();
144 };
144 };
145
145
146 $('#file_enable').on('click', function(e){
146 $('#file_enable').on('click', function(e){
147 e.preventDefault();
147 e.preventDefault();
148 hide_upload();
148 hide_upload();
149 });
149 });
150
150
151 $('#upload_file_enable').on('click', function(e){
151 $('#upload_file_enable').on('click', function(e){
152 e.preventDefault();
152 e.preventDefault();
153 $('#files_data').hide();
153 $('#files_data').hide();
154 $('#upload_file_container').show();
154 $('#upload_file_container').show();
155 $('#filename_container').hide();
155 $('#filename_container').hide();
156 if (detectIE() && detectIE() <= 9) {
156 if (detectIE() && detectIE() <= 9) {
157 $('#upload_file_container .file-upload-input label').hide();
157 $('#upload_file_container .file-upload-input label').hide();
158 $('#upload_file_container .file-upload-input span').hide();
158 $('#upload_file_container .file-upload-input span').hide();
159 $('#upload_file_container .file-upload-input input').show();
159 $('#upload_file_container .file-upload-input input').show();
160 }
160 }
161 });
161 });
162
162
163 $('#upload_file').on('change', function() {
163 $('#upload_file').on('change', function() {
164 if (this.files && this.files[0]) {
164 if (this.files && this.files[0]) {
165 $('#filename_upload').val(this.files[0].name);
165 $('#filename_upload').val(this.files[0].name);
166 }
166 }
167 });
167 });
168
168
169 hide_upload();
169 hide_upload();
170
170
171 var renderer = "";
171 var renderer = "";
172 var reset_url = "${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path)}";
172 var reset_url = "${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path)}";
173 var myCodeMirror = initCodeMirror('editor', reset_url, false);
173 var myCodeMirror = initCodeMirror('editor', reset_url, false);
174
174
175 var modes_select = $('#set_mode');
175 var modes_select = $('#set_mode');
176 fillCodeMirrorOptions(modes_select);
176 fillCodeMirrorOptions(modes_select);
177
177
178 var filename_selector = '#filename';
178 var filename_selector = '#filename';
179 var callback = function(filename, mimetype, mode){
179 var callback = function(filename, mimetype, mode){
180 CodeMirrorPreviewEnable(mode);
180 CodeMirrorPreviewEnable(mode);
181 };
181 };
182 // on change of select field set mode
182 // on change of select field set mode
183 setCodeMirrorModeFromSelect(
183 setCodeMirrorModeFromSelect(
184 modes_select, filename_selector, myCodeMirror, callback);
184 modes_select, filename_selector, myCodeMirror, callback);
185
185
186 // on entering the new filename set mode, from given extension
186 // on entering the new filename set mode, from given extension
187 setCodeMirrorModeFromInput(
187 setCodeMirrorModeFromInput(
188 modes_select, filename_selector, myCodeMirror, callback);
188 modes_select, filename_selector, myCodeMirror, callback);
189
189
190 // if the file is renderable set line wraps automatically
190 // if the file is renderable set line wraps automatically
191 if (renderer !== ""){
191 if (renderer !== ""){
192 var line_wrap = 'on';
192 var line_wrap = 'on';
193 $($('#line_wrap option[value="'+line_wrap+'"]')[0]).attr("selected", "selected");
193 $($('#line_wrap option[value="'+line_wrap+'"]')[0]).attr("selected", "selected");
194 setCodeMirrorLineWrap(myCodeMirror, true);
194 setCodeMirrorLineWrap(myCodeMirror, true);
195 }
195 }
196
196
197 // on select line wraps change the editor
197 // on select line wraps change the editor
198 $('#line_wrap').on('change', function(e){
198 $('#line_wrap').on('change', function(e){
199 var selected = e.currentTarget;
199 var selected = e.currentTarget;
200 var line_wraps = {'on': true, 'off': false}[selected.value];
200 var line_wraps = {'on': true, 'off': false}[selected.value];
201 setCodeMirrorLineWrap(myCodeMirror, line_wraps)
201 setCodeMirrorLineWrap(myCodeMirror, line_wraps)
202 });
202 });
203
203
204 // render preview/edit button
204 // render preview/edit button
205 $('#render_preview').on('click', function(e){
205 $('#render_preview').on('click', function(e){
206 if($(this).hasClass('preview')){
206 if($(this).hasClass('preview')){
207 $(this).removeClass('preview');
207 $(this).removeClass('preview');
208 $(this).html("${_('Edit')}");
208 $(this).html("${_('Edit')}");
209 $('#editor_preview').show();
209 $('#editor_preview').show();
210 $(myCodeMirror.getWrapperElement()).hide();
210 $(myCodeMirror.getWrapperElement()).hide();
211
211
212 var possible_renderer = {
212 var possible_renderer = {
213 'rst':'rst',
213 'rst':'rst',
214 'markdown':'markdown',
214 'markdown':'markdown',
215 'gfm': 'markdown'}[myCodeMirror.getMode().name];
215 'gfm': 'markdown'}[myCodeMirror.getMode().name];
216 var _text = myCodeMirror.getValue();
216 var _text = myCodeMirror.getValue();
217 var _renderer = possible_renderer || DEFAULT_RENDERER;
217 var _renderer = possible_renderer || DEFAULT_RENDERER;
218 var post_data = {'text': _text, 'renderer': _renderer, 'csrf_token': CSRF_TOKEN};
218 var post_data = {'text': _text, 'renderer': _renderer, 'csrf_token': CSRF_TOKEN};
219 $('#editor_preview').html(_gettext('Loading ...'));
219 $('#editor_preview').html(_gettext('Loading ...'));
220 var url = pyroutes.url('repo_commit_comment_preview',
220 var url = pyroutes.url('repo_commit_comment_preview',
221 {'repo_name': '${c.repo_name}',
221 {'repo_name': '${c.repo_name}',
222 'commit_id': '${c.commit.raw_id}'});
222 'commit_id': '${c.commit.raw_id}'});
223
223
224 ajaxPOST(url, post_data, function(o){
224 ajaxPOST(url, post_data, function(o){
225 $('#editor_preview').html(o);
225 $('#editor_preview').html(o);
226 })
226 })
227 }
227 }
228 else{
228 else{
229 $(this).addClass('preview');
229 $(this).addClass('preview');
230 $(this).html("${_('Preview')}");
230 $(this).html("${_('Preview')}");
231 $('#editor_preview').hide();
231 $('#editor_preview').hide();
232 $(myCodeMirror.getWrapperElement()).show();
232 $(myCodeMirror.getWrapperElement()).show();
233 }
233 }
234 });
234 });
235 $('#filename').focus();
235 $('#filename').focus();
236
236
237 </script>
237 </script>
238 </%def>
238 </%def>
General Comments 0
You need to be logged in to leave comments. Login now