Permalink
Browse files

Change put_content api: throw exceptions instead of plain-text error …

…codes. Add method in JS api, and update editors using this method.

Fix modal positioning when "messageBoxReference" is not visible or dimension 0, find visible parent, update css transition it's too slow.
  • Loading branch information...
1 parent 2059e8a commit 14737f0d92f4ff89c9f0276ddbfd8c0ce0beb9e4 @cdujeu cdujeu committed Sep 23, 2016
@@ -29,6 +29,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Pydio\Access\Core\AbstractAccessDriver;
+use Pydio\Access\Core\Exception\FileNotWriteableException;
use Pydio\Access\Core\MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider;
@@ -867,23 +868,17 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
} else {
$code=str_replace("&lt;","<", InputFilter::magicDequote($code));
}
- $response = $response->withHeader("Content-Type", "text/plain");
- try {
- Controller::applyHook("node.before_change", [&$currentNode, strlen($code)]);
- } catch (\Exception $e) {
- $response->getBody()->write($e->getMessage());
- break;
- }
+ Controller::applyHook("node.before_change", [&$currentNode, strlen($code)]);
if (!is_file($fileName) || !$this->isWriteable($currentNode)) {
- $response->getBody()->write((!$this->isWriteable($currentNode)?"1001":"1002"));
- break;
+ throw new FileNotWriteableException($currentNode);
}
$fp=fopen($fileName,"w");
fputs ($fp,$code);
fclose($fp);
clearstatcache(true, $fileName);
Controller::applyHook("node.change", [$currentNode, $currentNode, false]);
- $response->getBody()->write($mess[115]);
+ $logMessage = new UserMessage($mess[115]);
+ $nodesDiffs->update([$currentNode]);
break;
@@ -0,0 +1,42 @@
+<?php
+/*
+ * Copyright 2007-2016 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <https://pydio.com/>.
+ */
+namespace Pydio\Access\Core\Exception;
+
+use Pydio\Access\Core\Model\AJXP_Node;
+use Pydio\Core\Exception\PydioException;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+/**
+ * Class FileNotWriteableException
+ * @package Pydio\Access\Core\Exception
+ */
+class FileNotWriteableException extends PydioException
+{
+ /**
+ * FileNotWriteableException constructor.
+ * @param AJXP_Node $node
+ */
+ public function __construct($node)
+ {
+ parent::__construct("File ".$node->getPath()." is not writeable");
+ }
+}
@@ -124,7 +124,7 @@ Class.create("AjxpCkEditor", TextEditor, {
if(window.ajxpMobile){
this.setFullScreen();
}
-
+ this.element.down('.action_bar').removeClassName('full_width_action_bar');
},
bindCkEditorEvents : function(){
@@ -181,11 +181,15 @@ Class.create("AjxpCkEditor", TextEditor, {
},
saveFile : function(){
- var connexion = this.prepareSaveConnexion();
- var value = CKEDITOR.instances[this.editorInstanceId].getData();
- this.textarea.value = value;
- connexion.addParameter('content', value);
- connexion.sendAsync();
+
+ var value = CKEDITOR.instances[this.editorInstanceId].getData();
+ this.textarea.value = value;
+ PydioApi.getClient().postPlainTextContent(this.inputNode.getPath(), this.textarea.value, function(success){
+ if(success){
+ this.setModified(false);
+ }
+ }.bind(this));
+
},
parseTxt : function(transport){
@@ -302,46 +302,25 @@ Class.create("CodeMirrorEditor", AbstractEditor, {
loadFileContent : function(fileName){
this.currentFile = fileName;
- var connexion = new Connexion();
- connexion.addParameter('get_action', 'get_content');
- connexion.addParameter('file', fileName);
- connexion.onComplete = function(transp){
- this.parseTxt(transp);
+ PydioApi.getClient().request({
+ get_action: 'get_content',
+ file: fileName
+ }, function(transport){
+ this.parseTxt(transport);
this.updateTitle(getBaseName(fileName));
- }.bind(this);
- this.setModified(false);
- this.setOnLoad(this.contentMainContainer);
- connexion.sendAsync();
- },
-
- prepareSaveConnexion : function(){
- var connexion = new Connexion();
- connexion.addParameter('get_action', 'put_content');
- connexion.addParameter('file', this.inputNode.getPath());
- connexion.onComplete = function(transp){
- this.parseXml(transp);
- ajaxplorer.fireNodeRefresh(this.inputNode);
- }.bind(this);
- this.setOnLoad(this.contentMainContainer);
- connexion.setMethod('put');
- return connexion;
+ }.bind(this));
},
saveFile : function(){
- var connexion = this.prepareSaveConnexion();
- connexion.addParameter('content', this.codeMirror.getCode());
- connexion.sendAsync();
- },
-
- parseXml : function(transport){
- if(parseInt(transport.responseText).toString() == transport.responseText){
- alert("Cannot write the file to disk (Error code : "+transport.responseText+")");
- }else{
- this.setModified(false);
- }
- this.removeOnLoad(this.contentMainContainer);
+ this.setOnLoad(this.contentMainContainer);
+ PydioApi.getClient().postPlainTextContent(this.inputNode.getPath(), this.codeMirror.getCode(), function(success){
+ if(success){
+ this.setModified(false);
+ }
+ this.removeOnLoad(this.contentMainContainer)
+ }.bind(this));
},
-
+
parseTxt : function(transport){
this.codeMirror.setCode(transport.responseText);
this.setModified(false);
@@ -39,15 +39,16 @@ Class.create("TextEditor", AbstractEditor, {
$super(nodeOrNodes);
var fileName = nodeOrNodes.getPath();
var textarea;
- this.textareaContainer = document.createElement('div');
- this.textarea = $(document.createElement('textarea'));
- this.textarea.name = this.textarea.id = 'content';
- this.textarea.addClassName('dialogFocus');
- this.textarea.addClassName('editor');
+ this.textareaContainer = new Element('div');
+ this.textarea = new Element('textarea', {
+ id:'content',
+ name:'content',
+ style:'margin:0; border:0; width: 100%;',
+ className:'dialogFocus editor',
+ wrap: 'off'
+ });
this.currentUseCp = false;
this.contentMainContainer = this.textarea;
- this.textarea.setStyle({width:'100%'});
- this.textarea.setAttribute('wrap', 'off');
if(!this.canWrite){
this.textarea.readOnly = true;
}
@@ -69,6 +70,7 @@ Class.create("TextEditor", AbstractEditor, {
this.textarea.observe("blur", function(){
pydio.UI.enableAllKeyBindings()
});
+ this.element.down('.action_bar').addClassName('full_width_action_bar');
},
loadFileContent : function(fileName){
@@ -85,33 +87,18 @@ Class.create("TextEditor", AbstractEditor, {
connexion.sendAsync();
},
- prepareSaveConnexion : function(){
- var connexion = new Connexion();
- connexion.addParameter('get_action', 'put_content');
- connexion.addParameter('file', this.inputNode.getPath());
- connexion.onComplete = function(transp){
- this.parseXml(transp);
- }.bind(this);
- this.setOnLoad(this.textareaContainer);
- connexion.setMethod('put');
- return connexion;
- },
-
saveFile : function(){
- var connexion = this.prepareSaveConnexion();
- connexion.addParameter('content', this.textarea.value);
- connexion.sendAsync();
+
+ this.setOnLoad(this.textareaContainer);
+ PydioApi.getClient().postPlainTextContent(this.inputNode.getPath(), this.textarea.value, function(success){
+ if(success){
+ this.setModified(false);
+ }
+ this.removeOnLoad(this.textareaContainer)
+ }.bind(this));
+
},
-
- parseXml : function(transport){
- if(parseInt(transport.responseText).toString() == transport.responseText){
- alert("Cannot write the file to disk (Error code : "+transport.responseText+")");
- }else{
- this.setModified(false);
- }
- this.removeOnLoad(this.textareaContainer);
- },
-
+
parseTxt : function(transport){
this.textarea.value = transport.responseText;
if(this.canWrite){
@@ -179,6 +179,22 @@ class PydioApi{
}
+ postPlainTextContent(filePath, content, finishedCallback){
+
+ this.request({
+ get_action:'put_content',
+ file: filePath,
+ content: content
+ }, function(transport){
+ var success = this.parseXmlMessage(transport.responseXML);
+ finishedCallback(success);
+ }.bind(this), function(){
+ finishedCallback(false);
+ });
+
+
+ }
+
/**
* Detect a minisite_session parameter in the URL
* @param serverAccess
@@ -732,14 +732,11 @@ Class.create("Modal", {
}else {
container = $(ajxpBootstrap.parameters.get("MAIN_ELEMENT"));
}
- var containerOffset = Position.cumulativeOffset(container);
- var containerDimensions = container.getDimensions();
- var boxWidth = parseInt(containerDimensions.width * 90/100);
- var leftPosition = containerOffset[0] + parseInt(containerDimensions.width*5/100);
+ var boxPosition = this.computeMessageBoxPosition(container);
this.messageBox.setStyle({
bottom:'20px',
- left:leftPosition+'px',
- width:boxWidth+'px'
+ left:boxPosition.left+'px',
+ width:boxPosition.width+'px'
});
new Effect.MessageAppear(this.messageBox);
if(window.console){
@@ -748,6 +745,25 @@ Class.create("Modal", {
}
this.tempoMessageDivClosing();
},
+
+ computeMessageBoxPosition(container){
+ var dim = container.getDimensions();
+ if(!container.visible()) dim = {width:0, height: 0};
+ while((!dim.width || !dim.height) && container.parentNode){
+ container = container.parentNode;
+ if(!container.visible()) continue;
+ if(container === window.document) {
+ dim = document.viewport.getDimensions();
+ } else {
+ dim = container.getDimensions();
+ }
+ }
+ var offset = Position.cumulativeOffset(container);
+ var boxWidth = parseInt(dim.width * 90/100);
+ var leftPosition = offset[0] + parseInt(dim.width*5/100);
+ return {left: leftPosition, width: boxWidth};
+ },
+
/**
* Bootloader helper. Sets total steps
* @param count Integer
@@ -11,8 +11,8 @@
}
.animated.long {
- -webkit-animation-duration: 2s;
- animation-duration: 2s;
+ -webkit-animation-duration: 0.5s;
+ animation-duration: 0.5s;
}
@-webkit-keyframes fadeIn {
@@ -97,7 +97,7 @@
@-webkit-keyframes fadeInUpBig {
0% {
opacity: 0;
- -webkit-transform: translateY(2000px);
+ -webkit-transform: translateY(400px);
}
100% {
@@ -109,7 +109,7 @@
@-moz-keyframes fadeInUpBig {
0% {
opacity: 0;
- -moz-transform: translateY(2000px);
+ -moz-transform: translateY(400px);
}
100% {
@@ -121,7 +121,7 @@
@-o-keyframes fadeInUpBig {
0% {
opacity: 0;
- -o-transform: translateY(2000px);
+ -o-transform: translateY(400px);
}
100% {
@@ -133,7 +133,7 @@
@keyframes fadeInUpBig {
0% {
opacity: 0;
- transform: translateY(2000px);
+ transform: translateY(400px);
}
100% {
@@ -156,7 +156,7 @@
100% {
opacity: 0;
- -webkit-transform: translateY(2000px);
+ -webkit-transform: translateY(400px);
}
}
@@ -168,7 +168,7 @@
100% {
opacity: 0;
- -moz-transform: translateY(2000px);
+ -moz-transform: translateY(400px);
}
}
@@ -180,7 +180,7 @@
100% {
opacity: 0;
- -o-transform: translateY(2000px);
+ -o-transform: translateY(400px);
}
}
@@ -192,7 +192,7 @@
100% {
opacity: 0;
- transform: translateY(2000px);
+ transform: translateY(400px);
}
}

0 comments on commit 14737f0

Please sign in to comment.