diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-06-08 21:07:11 +0300 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-06-09 19:21:30 +0300 |
commit | 8440ecf4699ee6da2454cfd54f4eb70ffc88ff24 (patch) | |
tree | 06e21ce3a110c98746ea173e2139a7c5755840ad /js | |
parent | 8748910bf5f44a2687835bf4dd2be9782a8e4ce8 (diff) |
move load/save file to a controller and fix error response on failed load operation
Diffstat (limited to 'js')
-rw-r--r-- | js/editor.js | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/js/editor.js b/js/editor.js index 6585519..a635fcf 100644 --- a/js/editor.js +++ b/js/editor.js @@ -158,18 +158,18 @@ function doFileSave() { // Get the data var filecontents = window.aceEditor.getSession().getValue(); // Send the data - $.post(OC.filePath('files_texteditor', 'ajax', 'savefile.php'), { filecontents: filecontents, path: path, mtime: mtime }, function (jsondata) { - if (jsondata.status != 'success') { - // Save failed - $('#editor_save').text(t('files_texteditor', 'Save')); - $('#notification').text(jsondata.data.message); - $('#notification').fadeIn(); - $('#editor').attr('data-edited', 'true'); - $('#editor').attr('data-saving', 'false'); - } else { + $.ajax({ + type: 'PUT', + url: OC.generateUrl('/apps/files_texteditor/ajax/savefile'), + data: { + filecontents: filecontents, + path: path, + mtime: mtime + } + }).done(function(data) { // Save OK // Update mtime - $('#editor').attr('data-mtime', jsondata.data.mtime); + $('#editor').attr('data-mtime', data.mtime); $('#editor_save').text(t('files_texteditor', 'Save')); // Update titles if($('#editor').attr('data-edited') != 'true') { @@ -177,9 +177,17 @@ function doFileSave() { document.title = $('#editor').attr('data-filename') + ' - ownCloud'; } $('#editor').attr('data-saving', 'false'); + $('#editor_save').live('click', doFileSave); } - $('#editor_save').live('click', doFileSave); - }, 'json'); + ).fail(function(jqXHR) { + $('#editor_save').text(t('files_texteditor', 'Save')); + $('#notification').text(JSON.parse(jqXHR.responseText).message); + $('#notification').fadeIn(); + $('#editor').attr('data-edited', 'true'); + $('#editor').attr('data-saving', 'false'); + $('#editor_save').live('click', doFileSave); + } + ); } } giveEditorFocus(); @@ -210,14 +218,16 @@ function showFileEditor(dir, filename) { // bigger text for better readability document.getElementById('editor').style.fontSize = '16px'; - var data = $.ajax( + + $.get( + OC.generateUrl('/apps/files_texteditor/ajax/loadfile'), { - dataType: "json", - url: OC.filePath('files_texteditor', 'ajax', 'loadfile.php'), - data: {file: filename, dir: dir}, - success: function (result) { + filename: filename, + dir: dir + } + ).done(function (data) { // Save mtime - $('#editor').attr('data-mtime', result.data.mtime); + $('#editor').attr('data-mtime', data.mtime); $('#editor').attr('data-saving', 'false'); // Initialise the editor if (window.FileList){ @@ -226,21 +236,21 @@ function showFileEditor(dir, filename) { $('#fileList').on('changeDirectory.texteditor', textEditorOnChangeDirectory); } // Show the control bar - showControls(dir, filename, result.data.writeable); + showControls(dir, filename, data.writeable); // Update document title $('body').attr('old_title', document.title); document.title = filename + ' - ownCloud'; - $('#editor').text(result.data.filecontents); + $('#editor').text(data.filecontents); $('#editor').attr('data-dir', dir); $('#editor').attr('data-filename', filename); $('#editor').attr('data-edited', 'false'); window.aceEditor = ace.edit("editor"); aceEditor.setShowPrintMargin(false); aceEditor.getSession().setUseWrapMode(true); - if ( ! result.data.writeable ) { + if ( ! data.writeable ) { aceEditor.setReadOnly(true); } - if (result.data.mime && result.data.mime === 'text/html') { + if (data.mime && data.mime === 'text/html') { setSyntaxMode('html'); } else { setSyntaxMode(getFileExtension(filename)); @@ -272,17 +282,13 @@ function showFileEditor(dir, filename) { } }); giveEditorFocus(); - }, - error: function(result) { - // Failed to get the file. - OC.dialogs.alert('', t('files_texteditor', 'An error occurred!')); - hideFileEditor(); } - // End success + ).fail(function(jqXHR) { + // Failed to get the file. + OC.dialogs.alert(JSON.parse(jqXHR.responseText).message, t('files_texteditor', 'An error occurred!')); + hideFileEditor(); } - // End ajax ); - return data; } } } |