Updated copyright info and ajax responses

This commit is contained in:
Tom Needham 2011-09-28 19:52:08 +01:00
parent 3ab8739809
commit 3886a749fb
3 changed files with 32 additions and 28 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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();
});