add * to filename when changes have been made

This commit is contained in:
Tom Needham 2012-04-02 17:27:06 +00:00
parent d0cb99e347
commit dc499c5b4e
1 changed files with 42 additions and 26 deletions

View File

@ -141,31 +141,38 @@ function doSearch(){
// Tries to save the file. // Tries to save the file.
function doFileSave(){ function doFileSave(){
if(editorIsShown()){ if(editorIsShown()){
// Get file path // Changed contents?
var path = $('#editor').attr('data-dir')+'/'+$('#editor').attr('data-filename'); if($('#editor').attr('data-edited')=='true'){
// Get original mtime // Get file path
var mtime = $('#editor').attr('data-mtime'); var path = $('#editor').attr('data-dir')+'/'+$('#editor').attr('data-filename');
// Show saving spinner // Get original mtime
$("#editor_save").die('click',doFileSave); var mtime = $('#editor').attr('data-mtime');
$('#save_result').remove(); // Show saving spinner
$('#editor_save').text(t('files_texteditor','Saving...')); $("#editor_save").die('click',doFileSave);
// Get the data $('#save_result').remove();
var filecontents = window.aceEditor.getSession().getValue(); $('#editor_save').text(t('files_texteditor','Saving...'));
// Send the data // Get the data
$.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, path: path, mtime: mtime },function(jsondata){ var filecontents = window.aceEditor.getSession().getValue();
if(jsondata.status!='success'){ // Send the data
// Save failed $.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, path: path, mtime: mtime },function(jsondata){
$('#editor_save').text(t('files_texteditor','Save')); if(jsondata.status!='success'){
$('#editor_save').after('<p id="save_result" style="float: left">Failed to save file</p>'); // Save failed
$("#editor_save").live('click',doFileSave); $('#editor_save').text(t('files_texteditor','Save'));
} else { $('#editor_save').after('<p id="save_result" style="float: left">Failed to save file</p>');
// Save OK $("#editor_save").live('click',doFileSave);
// Update mtime } else {
$('#editor').attr('data-mtime',jsondata.data.mtime); // Save OK
$('#editor_save').text(t('files_texteditor','Save')); // Update mtime
$("#editor_save").live('click',doFileSave); $('#editor').attr('data-mtime',jsondata.data.mtime);
} $('#editor_save').text(t('files_texteditor','Save'));
},'json'); $("#editor_save").live('click',doFileSave);
// Update titles
$('#editor').attr('data-edited', 'false');
$('#breadcrumb_file').text($('#editor').attr('data-filename'));
document.title = $('#editor').attr('data-filename')+' - ownCloud';
}
},'json');
}
} }
}; };
@ -192,10 +199,11 @@ function showFileEditor(dir,filename){
// Show the control bar // Show the control bar
showControls(filename,result.data.write); showControls(filename,result.data.write);
// Update document title // Update document title
document.title = filename; document.title = filename+' - ownCloud';
$('#editor').text(result.data.filecontents); $('#editor').text(result.data.filecontents);
$('#editor').attr('data-dir', dir); $('#editor').attr('data-dir', dir);
$('#editor').attr('data-filename', filename); $('#editor').attr('data-filename', filename);
$('#editor').attr('data-edited', 'false');
window.aceEditor = ace.edit("editor"); window.aceEditor = ace.edit("editor");
aceEditor.setShowPrintMargin(false); aceEditor.setShowPrintMargin(false);
aceEditor.getSession().setUseWrapMode(true); aceEditor.getSession().setUseWrapMode(true);
@ -207,6 +215,13 @@ function showFileEditor(dir,filename){
OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){ OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){
window.aceEditor.setTheme("ace/theme/clouds"); window.aceEditor.setTheme("ace/theme/clouds");
}); });
window.aceEditor.getSession().on('change', function(){
if($('#editor').attr('data-edited')!='true'){
$('#editor').attr('data-edited', 'true');
$('#breadcrumb_file').text($('#breadcrumb_file').text()+' *');
document.title = $('#editor').attr('data-filename')+' * - ownCloud';
}
});
}); });
} else { } else {
// Failed to get the file. // Failed to get the file.
@ -287,4 +302,5 @@ $(document).ready(function(){
$('#editor').remove(); $('#editor').remove();
// Binds the save keyboard shortcut events // Binds the save keyboard shortcut events
//$(document).unbind('keydown').bind('keydown',checkForSaveKeyPress); //$(document).unbind('keydown').bind('keydown',checkForSaveKeyPress);
}); });