// 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();
}
} 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
/**
* 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
$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);
}
+// 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;
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();
});