|
40 | 40 | <form method="post" id="new_file"> |
41 | 41 | <h4>/home/container/{{ $directory }} <input type="text" id="file_name" class="filename" value="newfile.txt" /></h4> |
42 | 42 | <div class="form-group"> |
43 | | - <div> |
44 | | - <textarea name="file_contents" id="fileContents" style="border: 1px solid #dddddd;" class="form-control console"></textarea> |
45 | | - </div> |
| 43 | + <div id="fileContents" style="height:500px;"></div> |
46 | 44 | </div> |
47 | 45 | <div class="form-group"> |
48 | | - <div> |
49 | | - <button class="btn btn-primary btn-sm" id="create_file">{{ trans('strings.save') }}</button> |
50 | | - <button class="btn btn-default btn-sm" onclick="window.location='/server/{{ $server->uuidShort }}/files?dir=/{{ $directory }}';return false;">{{ trans('server.files.back') }}</button> |
| 46 | + <div class="row"> |
| 47 | + <div class="col-md-8"> |
| 48 | + <button class="btn btn-primary btn-sm" id="create_file">{{ trans('strings.save') }}</button> |
| 49 | + <button class="btn btn-default btn-sm" onclick="window.location='/server/{{ $server->uuidShort }}/files?dir=/{{ $directory }}';return false;">{{ trans('server.files.back') }}</button> |
| 50 | + </div> |
| 51 | + <div class="col-md-4 pull-right"> |
| 52 | + <select name="aceMode" id="aceMode" class="form-control"> |
| 53 | + <option value="assembly_x86">Assembly x86</option> |
| 54 | + <option value="c_cpp">C/C++</option> |
| 55 | + <option value="coffee">CoffeeScript</option> |
| 56 | + <option value="csharp">C#</option> |
| 57 | + <option value="css">CSS</option> |
| 58 | + <option value="golang">Go</option> |
| 59 | + <option value="haml">HAML</option> |
| 60 | + <option value="html">HTML</option> |
| 61 | + <option value="ini">INI</option> |
| 62 | + <option value="java">Java</option> |
| 63 | + <option value="javascript">JavaScript</option> |
| 64 | + <option value="json">JSON</option> |
| 65 | + <option value="lua">Lua</option> |
| 66 | + <option value="markdown">Markdown</option> |
| 67 | + <option value="mysql">MySQL</option> |
| 68 | + <option value="objectivec">Objective-C</option> |
| 69 | + <option value="perl">Perl</option> |
| 70 | + <option value="php">PHP</option> |
| 71 | + <option value="properties">Properties</option> |
| 72 | + <option value="python">Python</option> |
| 73 | + <option value="ruby">Ruby</option> |
| 74 | + <option value="rust">Rust</option> |
| 75 | + <option value="smarty">Smarty</option> |
| 76 | + <option value="textile" selected="selected">Plain Text</option> |
| 77 | + <option value="xml">XML</option> |
| 78 | + <option value="yaml">YAML</option> |
| 79 | + </select> |
| 80 | + </div> |
51 | 81 | </div> |
52 | 82 | </div> |
53 | 83 | </form> |
|
66 | 96 | @endcan |
67 | 97 | </div> |
68 | 98 | </div> |
| 99 | +{!! Theme::js('js/vendor/ace/ace.js') !!} |
| 100 | +{!! Theme::js('js/vendor/ace/ext-modelist.js') !!} |
69 | 101 | <script> |
70 | 102 | $(window).load(function () { |
71 | 103 |
|
@@ -170,35 +202,54 @@ function doNothing (e){ |
170 | 202 | } |
171 | 203 | @endcan |
172 | 204 |
|
173 | | - $('textarea').keydown(function (e) { |
174 | | - if (e.keyCode === 9) { |
175 | | - var start = this.selectionStart; |
176 | | - var end = this.selectionEnd; |
177 | | - var value = $(this).val(); |
178 | | - $(this).val(value.substring(0, start) + '\t' + value.substring(end)); |
179 | | - this.selectionStart = this.selectionEnd = start + 1; |
180 | | - e.preventDefault(); |
181 | | - } |
| 205 | + const Editor = ace.edit('fileContents'); |
| 206 | +
|
| 207 | + Editor.setTheme('ace/theme/chrome'); |
| 208 | + Editor.getSession().setUseWrapMode(true); |
| 209 | + Editor.setShowPrintMargin(false); |
| 210 | +
|
| 211 | + $('#aceMode').on('change', event => { |
| 212 | + Editor.getSession().setMode(`ace/mode/${$('#aceMode').val()}`); |
| 213 | + }); |
| 214 | +
|
| 215 | + Editor.commands.addCommand({ |
| 216 | + name: 'save', |
| 217 | + bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, |
| 218 | + exec: function(editor) { |
| 219 | + save(); |
| 220 | + }, |
| 221 | + readOnly: false |
182 | 222 | }); |
183 | 223 |
|
184 | | - $("#create_file").click(function(e) { |
| 224 | + $('#create_file').on('click', function (e) { |
185 | 225 | e.preventDefault(); |
186 | | - $("#create_file").append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass("disabled"); |
| 226 | + save(); |
| 227 | + }); |
| 228 | +
|
| 229 | + function save() { |
| 230 | + var fileName = $('input[name="file"]').val(); |
| 231 | + $('#create_file').append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass('disabled'); |
187 | 232 | $.ajax({ |
188 | 233 | type: 'POST', |
189 | 234 | url: '{{ route('server.files.save', $server->uuidShort) }}', |
190 | 235 | headers: { 'X-CSRF-Token': '{{ csrf_token() }}' }, |
191 | 236 | data: { |
192 | 237 | file: '{{ $directory }}' + $('#file_name').val(), |
193 | | - contents: $('#fileContents').val() |
| 238 | + contents: Editor.getValue() |
194 | 239 | } |
195 | 240 | }).done(function (data) { |
196 | 241 | window.location.replace('/server/{{ $server->uuidShort }}/files/edit/{{ $directory }}' + $('#file_name').val()); |
197 | 242 | }).fail(function (jqXHR) { |
198 | | - $('#write_status').html('<div class="alert alert-danger">' + jqXHR.responseText + '</div>').show(); |
199 | | - $('#create_file').html('{{ trans('strings.save') }}').removeClass('disabled'); |
| 243 | + $.notify({ |
| 244 | + message: jqXHR.responseText |
| 245 | + }, { |
| 246 | + type: 'danger' |
| 247 | + }); |
| 248 | + }).always(function () { |
| 249 | + $('#save_file').html('{{ trans('strings.save') }}').removeClass('disabled'); |
200 | 250 | }); |
201 | | - }); |
| 251 | + } |
| 252 | +
|
202 | 253 |
|
203 | 254 | }); |
204 | 255 | </script> |
|
0 commit comments