diff --git a/apps/editor/ajax/savefile.php b/apps/editor/ajax/savefile.php index 536ea9a2f7..95afb45883 100644 --- a/apps/editor/ajax/savefile.php +++ b/apps/editor/ajax/savefile.php @@ -54,17 +54,17 @@ if(isset($_SESSION[$sessionname])){ // Force save? if($force){ do_save($path, $filecontents); - echo '1'; + OC_JSON::success(); } else { // No force // Show error - echo '2'; + OC_JSON::faliure(); } } else { // No body has edited it whilst you were, so save the file // Update the session hash. do_save($path,$filecontents); - echo '1'; + OC_JSON::success(); } @@ -72,8 +72,5 @@ if(isset($_SESSION[$sessionname])){ } else { // No session value set for soem reason, just save the file. do_save($path,$filecontents); - echo '1'; -} - - -//OC_JSON::success(array('data' => array( 'success' => 'true' ))); + OC_JSON::success(); +} \ No newline at end of file diff --git a/apps/editor/index.php b/apps/editor/index.php index 7d94f135f2..437934b3e8 100644 --- a/apps/editor/index.php +++ b/apps/editor/index.php @@ -2,8 +2,8 @@ /** * ownCloud - Addressbook * - * @author Jakob Sack - * @copyright 2011 Jakob Sack mail@jakobsack.de + * @author Tom Needham + * @copyright 2011 Tom Needham contact@tomneedham.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -33,11 +33,12 @@ $file = $_GET['file']; $dir = $_GET['dir']; $path = $dir.'/'.$file; +// Add scripts OC_UTIL::addStyle('editor', 'styles'); OC_UTIL::addScript('editor','editor'); OC_UTIL::addScript('editor','aceeditor/ace'); -//Get file type +// Get file type if(substr_count($file,'.')!=0){ // Find extension $parts = explode(".",$file); @@ -56,11 +57,11 @@ if(substr_count($file,'.')!=0){ } +// Add theme OC_UTIL::addScript('editor','aceeditor/theme-cobalt'); OC_App::setActiveNavigationEntry( 'editor_index' ); - // Save a hash of the file for later $sessionname = md5('oc_file_hash_'.$path); $_SESSION[$sessionname] = $filehash; diff --git a/apps/editor/js/editor.js b/apps/editor/js/editor.js index 2895468e0a..86b0461c53 100644 --- a/apps/editor/js/editor.js +++ b/apps/editor/js/editor.js @@ -23,27 +23,33 @@ $(document).ready(function(){ var filecontents = window.aceEditor.getSession().getValue(); var dir = $('#editor').attr('data-dir'); var file = $('#editor').attr('data-file'); - $.post('ajax/savefile.php',{ filecontents: filecontents, file: file, dir: dir },function(data){ - if(data=='2'){ + $.post('ajax/savefile.php',{ filecontents: filecontents, file: file, dir: dir },function(jsondata){ + if(jsondata.satus == 'failure'){ var answer = confirm('The file has been modified after you opened it. Do you want to overwrite the file with your changes?'); - if(answer){ - $.post('ajax/savefile.php',{ filecontents: filecontents, file: file, dir: dir, force: 'true' },function(data){ - if(data=='1'){ - $('#editor_save').val('Save'); - $('#editor_save').effect("highlight", {color:'#4BFF8D'}, 3000); - } - }); - } else { - // Don't save! - $('#editor_save').effect("highlight", {color:'#FF5757'}, 3000); - $('#editor_save').val('Save'); - } - } else if(data=='1'){ + if(answer){ + $.post('ajax/savefile.php',{ filecontents: filecontents, file: file, dir: dir, force: 'true' },function(jsondata){ + if(jsondata.status =='success'){ + $('#editor_save').val('Save'); + $('#editor_save').effect("highlight", {color:'#4BFF8D'}, 3000); + } + else { + // Save error + alert('Error saving the file. Please report this!'); + } + }, 'json'); + } + else { + // Don't save! + $('#editor_save').effect("highlight", {color:'#FF5757'}, 3000); + $('#editor_save').val('Save'); + } + } + else if(jsondata.status == 'success'){ // Success $('#editor_save').val('Save'); $('#editor_save').effect("highlight", {color:'#4BFF8D'}, 3000); } - }); + }, 'json'); // TODO give focus back to the editor // window.aceEditor.focus(); });