diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-01-08 23:30:50 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-01-08 23:30:50 +0000 |
commit | f7f19af8164aa78c3d1a143c40098e48f00145b8 (patch) | |
tree | 6dd334e2d93338ee7737eca0519636e84a4dcac2 /apps/files_texteditor/js | |
parent | 65c37abef9a9fb7d5c8abae644f3aedb41cbb0a0 (diff) | |
download | nextcloud-server-f7f19af8164aa78c3d1a143c40098e48f00145b8.tar.gz nextcloud-server-f7f19af8164aa78c3d1a143c40098e48f00145b8.zip |
Handles file permissions. Protect against overwriting changes.
Diffstat (limited to 'apps/files_texteditor/js')
-rw-r--r-- | apps/files_texteditor/js/editor.js | 145 |
1 files changed, 58 insertions, 87 deletions
diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index 63e67460a3b..060c76705a1 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -77,81 +77,42 @@ function editorIsShown(){ return is_editor_shown; } -function updateSessionFileHash(path){ - $.get(OC.filePath('files_texteditor','ajax','loadfile.php'), - { path: path }, - function(jsondata){ - if(jsondata.status=='failure'){ - alert('Failed to update session file hash.'); - } - }, "json");} - function doFileSave(){ if(editorIsShown()){ + // Get file path + var path = $('#editor').attr('data-dir')+'/'+$('#editor').attr('data-filename'); + // Get original mtime + var mtime = $('#editor').attr('data-mtime'); + // Show saving spinner $("#editor_save").die('click',doFileSave); $('#editor_save').after('<img id="saving_icon" src="'+OC.filePath('core','img','loading.gif')+'"></img>'); - var filecontents = window.aceEditor.getSession().getValue(); - var dir = $('#editor').attr('data-dir'); - var file = $('#editor').attr('data-filename'); - $.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, file: file, dir: dir },function(jsondata){ - - if(jsondata.status == 'failure'){ - var answer = confirm(jsondata.data.message); - if(answer){ - $.post(OC.filePath('files_texteditor','ajax','savefile.php'),{ filecontents: filecontents, file: file, dir: dir, force: 'true' },function(jsondata){ - if(jsondata.status =='success'){ - $('#saving_icon').remove(); - $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>') - setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - $("#editor_save").live('click',doFileSave); - }); - }, 2000); - } - else { - // Save error - $('#saving_icon').remove(); - $('#editor_save').after('<p id="save_result" style="float: left">Failed!</p>'); - setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - $("#editor_save").live('click',doFileSave); - }); - }, 2000); - } - }, 'json'); - } - else { - // Don't save! - $('#saving_icon').remove(); - // Temporary measure until we get a tick icon - $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>'); - setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - $("#editor_save").live('click',doFileSave); - }); - }, 2000); - } - } - else if(jsondata.status == 'success'){ - // Success - $('#saving_icon').remove(); - // Temporary measure until we get a tick icon - $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>'); - setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - $("#editor_save").live('click',doFileSave); - }); - }, 2000); - } - }, 'json'); - giveEditorFocus(); - } else { - return; - } + // 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 + $('#saving_icon').remove(); + $('#editor_save').after('<p id="save_result" style="float: left">Failed to save file</p>'); + setTimeout(function() { + $('#save_result').fadeOut('slow',function(){ + $(this).remove(); + $("#editor_save").live('click',doFileSave); + }); + }, 2000); + } else { + // Save OK + $('#saving_icon').remove(); + $('#editor_save').after('<p id="save_result" style="float: left">Saved</p>') + setTimeout(function() { + $('#save_result').fadeOut('slow',function(){ + $(this).remove(); + $("#editor_save").live('click',doFileSave); + }); + }, 2000); + } + },'json'); + } }; function giveEditorFocus(){ @@ -162,24 +123,34 @@ function showFileEditor(dir,filename){ if(!editorIsShown()){ // Loads the file editor and display it. var data = $.ajax({ - url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), + url: OC.filePath('files_texteditor','ajax','loadfile.php'), + data: 'file='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), complete: function(data){ - // Initialise the editor - updateSessionFileHash(dir+'/'+filename); - showControls(filename); - $('table').fadeOut('slow', function() { - $('#editor').text(data.responseText); - // encodeURIComponenet? - $('#editor').attr('data-dir', dir); - $('#editor').attr('data-filename', filename); - window.aceEditor = ace.edit("editor"); - aceEditor.setShowPrintMargin(false); - setEditorSize(); - setSyntaxMode(getFileExtension(filename)); - OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){ - window.aceEditor.setTheme("ace/theme/clouds"); + result = jQuery.parseJSON(data.responseText); + if(result.status == 'success'){ + // Save mtime + $('#editor').attr('data-mtime', result.data.mtime); + // Initialise the editor + showControls(filename); + $('table').fadeOut('slow', function() { + $('#editor').text(result.data.filecontents); + $('#editor').attr('data-dir', dir); + $('#editor').attr('data-filename', filename); + window.aceEditor = ace.edit("editor"); + aceEditor.setShowPrintMargin(false); + if(result.data.write=='false'){ + aceEditor.setReadOnly(true); + } + setEditorSize(); + setSyntaxMode(getFileExtension(filename)); + OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){ + window.aceEditor.setTheme("ace/theme/clouds"); + }); }); - }); + } else { + // Failed to get the file. + alert(result.data.message); + } // End success } // End ajax |