]> source.dussan.org Git - nextcloud-server.git/commitdiff
Updated copyright info and ajax responses
authorTom Needham <needham.thomas@gmail.com>
Wed, 28 Sep 2011 18:52:08 +0000 (19:52 +0100)
committerTom Needham <needham.thomas@gmail.com>
Wed, 28 Sep 2011 18:52:08 +0000 (19:52 +0100)
apps/editor/ajax/savefile.php
apps/editor/index.php
apps/editor/js/editor.js

index 536ea9a2f796d8a79abaf1ec9352cc8cc4648ff3..95afb4588379fd8abfebf3c4cf9bcd417e997eb9 100644 (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();
+}
\ No newline at end of file
index 7d94f135f256f05dabbec378ff5d850c89102116..437934b3e85760f641573aad50b76841c27b88bb 100644 (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;
index 2895468e0a36f7107ce3d9901dc87fa192ba32d0..86b0461c53db4db91434c241ccc6fd80da789eae 100644 (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();
        });