diff options
Diffstat (limited to 'apps/files_texteditor')
-rw-r--r-- | apps/files_texteditor/js/editor.js | 105 |
1 files changed, 54 insertions, 51 deletions
diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index a0629aa8c4e..e3581a16a6d 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -4,6 +4,7 @@ function setEditorSize(){ } function getFileExtension(file){ + // Extracts the file extension from the full filename var parts=file.split('.'); return parts[parts.length-1]; } @@ -11,7 +12,6 @@ function getFileExtension(file){ function setSyntaxMode(ext){ // Loads the syntax mode files and tells the editor var filetype = new Array(); - // Todo finish these filetype["h"] = "c_cpp"; filetype["c"] = "c_cpp"; filetype["cpp"] = "c_cpp"; @@ -63,19 +63,18 @@ function showControls(filename){ function bindControlEvents(){ $("#editor_save").live('click',function() { - doFileSave(); + if(is_editor_shown){ + doFileSave(); + } }); $('#editor_close').live('click',function() { - hideFileEditor(); + if(is_editor_shown){ + hideFileEditor(); + } }); } -function editorIsShown(){ - // Not working as intended. Always returns true. - return is_editor_shown; -} - function updateSessionFileHash(path){ $.get(OC.filePath('files_texteditor','ajax','loadfile.php'), { path: path }, @@ -86,56 +85,57 @@ function updateSessionFileHash(path){ }, "json");} function doFileSave(){ - if(editorIsShown()){ - $('#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').remove(); - }, 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(); }); - }, 2000); - } - }, 'json'); + if(is_editor_shown){ + $('#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').remove(); + }, 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(); }); + }, 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(); }); + }, 2000); + } } - else { - // Don't save! + 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(); }); }, 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(); }); - }, 2000); - } - }, 'json'); - giveEditorFocus(); + } + }, 'json'); + giveEditorFocus(); } else { + $('#editor').data('editor','false'); return; } }; @@ -145,7 +145,7 @@ function giveEditorFocus(){ }; function showFileEditor(dir,filename){ - if(!editorIsShown()){ + if(!is_editor_shown){ // Loads the file editor and display it. var data = $.ajax({ url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), @@ -175,6 +175,7 @@ function showFileEditor(dir,filename){ } function hideFileEditor(){ + $('#editor').attr('editorshown','false'); // Fade out controls $('#editor_close').fadeOut('slow'); // Fade out the save button @@ -198,6 +199,7 @@ $(window).resize(function() { setEditorSize(); }); var is_editor_shown = false; + $(document).ready(function(){ if(typeof FileActions!=='undefined'){ FileActions.register('text','Edit','',function(filename){ @@ -217,6 +219,7 @@ $(document).ready(function(){ a.click(function(){ var file=text.split('/').pop(); var dir=text.substr(0,text.length-file.length-1); + // TODO this will only work in the files app. showFileEditor(dir,file); }); } |