From 327fee0f6d1d8a286fa583e0d6a2a92a4471a205 Mon Sep 17 00:00:00 2001 From: Charles du Jeu Date: Sun, 7 Jul 2013 20:37:21 +0200 Subject: [PATCH] Create pads either on a text file, or a "free" pad --- .../editor.etherpad/class.EtherpadClient.php | 58 +++++++++++--- .../editor.etherpad/class.EtherpadLauncher.js | 79 ++++++++++++++++++- core/src/plugins/editor.etherpad/i18n/en.php | 3 +- core/src/plugins/editor.etherpad/manifest.xml | 38 +++++---- 4 files changed, 147 insertions(+), 31 deletions(-) diff --git a/core/src/plugins/editor.etherpad/class.EtherpadClient.php b/core/src/plugins/editor.etherpad/class.EtherpadClient.php index bda7f9b488..af9e8e3fc1 100644 --- a/core/src/plugins/editor.etherpad/class.EtherpadClient.php +++ b/core/src/plugins/editor.etherpad/class.EtherpadClient.php @@ -24,6 +24,11 @@ public function switchAction($actionName, $httpVars, $fileVars){ require_once("etherpad-client/etherpad-lite-client.php"); $client = new EtherpadLiteClient("nl8VJIWXZMHNj7aWj6rWy4CLct1mu97v",$this->baseURL."/api"); + $userName = AuthService::getLoggedUser()->getId(); + $res = $client->createAuthorIfNotExistsFor($userName, $userName); + $authorID = $res->authorID; + $res2 = $client->createGroupIfNotExistsFor("ajaxplorer"); + $groupID = $res2->groupID; if($actionName == "etherpad_create"){ @@ -31,27 +36,41 @@ public function switchAction($actionName, $httpVars, $fileVars){ $padID = $httpVars["pad_name"]; $startContent = ""; + if($httpVars["pad_type"] && $httpVars["pad_type"] == 'free'){ + $padID = "FREEPAD__".$padID; + } }else if(isSet($httpVars["file"])){ $startContent = file_get_contents($filename); + if(strtolower(pathinfo($filename, PATHINFO_EXTENSION)) == "html"){ + $startContentHTML = $startContent; + } $padID = AJXP_Utils::slugify($httpVars["file"]); } - $userName = AuthService::getLoggedUser()->getId(); - - $res = $client->createAuthorIfNotExistsFor($userName, $userName); - $authorID = $res->authorID; - - $res2 = $client->createGroupIfNotExistsFor("ajaxplorer"); - $groupID = $res2->groupID; $resP = $client->listPads($res2->groupID); $pads = $resP->padIDs; if(!in_array($groupID.'$'.$padID, $pads)){ - $res3 = $client->createGroupPad($groupID, $padID, $startContent); + $res3 = $client->createGroupPad($groupID, $padID, null); + if(isSet($startContentHTML)){ + $client->setHTML($groupID.'$'.$padID, $startContentHTML); + }else if(!empty($startContent)){ + $client->setText($groupID.'$'.$padID, $startContent); + } + }else{ + // Check if content needs relaunch! + $test = $client->getText($groupID.'$'.$padID); + if(!empty($startContent) && $test->text != $startContent){ + if(isSet($startContentHTML)){ + $client->setHTML($groupID.'$'.$padID, $startContentHTML); + }else{ + $client->setText($groupID.'$'.$padID, $startContent); + } + } } $res4 = $client->createSession($groupID, $authorID, time()+14400); @@ -72,15 +91,34 @@ public function switchAction($actionName, $httpVars, $fileVars){ }else if ($actionName == "etherpad_save"){ + $node = new AJXP_Node($filename); + $padID = $httpVars["pad_id"]; - $res = $client->getText($padID); + if(isSet($startContentHTML)){ + $res = $client->getHTML($padID); + }else{ + $res = $client->getText($padID); + } + + AJXP_Controller::applyHook("node.before_change", array($node, strlen($res->text))); file_put_contents($filename, $res->text); + AJXP_Controller::applyHook("node.change", array($node, $node)); }else if ($actionName == "etherpad_close"){ // WE SHOULD DETECT IF THERE IS NOBODY CONNECTED ANYMORE, AND DELETE THE PAD. $sessionID = $httpVars["session_id"]; - $i = $client->getSessionInfo($sessionID); + $client->deleteSession($sessionID); + + }else if($actionName == "etherpad_proxy_api"){ + + if($httpVars["api_action"] == "list_pads"){ + $res = $client->listPads($groupID); + }else if($httpVars["api_action"] == "list_authors_for_pad"){ + $res = $client->listAuthorsOfPad($httpVars["pad_id"]); + } + HTMLWriter::charsetHeader("application/json"); + echo(json_encode($res)); } diff --git a/core/src/plugins/editor.etherpad/class.EtherpadLauncher.js b/core/src/plugins/editor.etherpad/class.EtherpadLauncher.js index 937b8f917e..c6879e2458 100644 --- a/core/src/plugins/editor.etherpad/class.EtherpadLauncher.js +++ b/core/src/plugins/editor.etherpad/class.EtherpadLauncher.js @@ -42,7 +42,69 @@ Class.create("EtherpadLauncher", AbstractEditor, { return false; }.bind(this)); }, - + + initEmptyPadPane : function(form){ + + var selector = form.down('[name="pad_list"]'); + var textInput = form.down('[name="new_pad_name"]'); + var joinButton = form.down('#join_pad'); + fitHeightToBottom(form.down("#ether_frame"), null, null, true); + + var con = new Connexion(); + con.setParameters(new Hash({ + get_action: 'etherpad_proxy_api', + api_action: 'list_pads' + })); + con.onComplete = function(transport){ + var pads = $A(transport.responseJSON.padIDs); + var frees = $A(); + var files = $A(); + pads.each(function(el){ + var label = el.split('$').pop(); + if(label.startsWith('FREEPAD__')){ + frees.push(label); + }else{ + files.push(label); + } + }); + selector.insert(new Element('optgroup',{label:'Free boards'})); + frees.each(function(e){ + selector.insert(new Element('option', {value:e}).update(e.replace('FREEPAD__', ''))); + }); + selector.insert(new Element('option', {value:-1}).update('Create new pad')); + + if(files.size()){ + selector.insert(new Element('optgroup', {label:'Files'})); + files.each(function(e){ + selector.insert(new Element('option', {value:e}).update(e)); + }); + } + + selector.observe("change", function(){ + textInput[(selector.getValue() == -1)?'show':'hide'](); + }); + textInput[(selector.getValue() == -1)?'show':'hide'](); + }; + con.sendAsync(); + + joinButton.observe("click", function(){ + + var conn = new Connexion(); + conn.addParameter("get_action", "etherpad_create"); + if(selector.getValue() == -1){ + conn.addParameter("pad_name", textInput.getValue()); + conn.addParameter("pad_type", 'free'); + }else{ + conn.addParameter("pad_name", selector.getValue()); + } + conn.onComplete = function(transport){ + var data = transport.responseJSON; + $("etherpad_container").down("#ether_frame").src = data.url; + } + conn.sendAsync(); + }); + + }, open : function($super, nodeOrNodes){ $super(nodeOrNodes); @@ -64,6 +126,17 @@ Class.create("EtherpadLauncher", AbstractEditor, { this.setFullScreen(); attachMobileScroll(this.textarea, "vertical"); } + + this.element.observe("editor:enterFSend", function(){ + fitHeightToBottom($("ether_box").down("#ether_box_frame")); + }); + this.element.observe("editor:resize", function(){ + fitHeightToBottom($("ether_box").down("#ether_box_frame")); + }); + this.element.observe("editor:exitFSend", function(){ + fitHeightToBottom($("ether_box").down("#ether_box_frame")); + }); + this.element.observeOnce("editor:close", function(){ var conn = new Connexion(); conn.addParameter("get_action", "etherpad_close"); @@ -71,12 +144,12 @@ Class.create("EtherpadLauncher", AbstractEditor, { conn.addParameter("pad_id", this.padID); conn.addParameter("session_id", this.sessionID); conn.sendAsync(); - }); + }.bind(this)); }, saveFile : function(){ - if(!this.padID) return; + if(!this.padID || !this.node) return; var conn = new Connexion(); conn.addParameter("get_action", "etherpad_save"); conn.addParameter("file", this.node.getPath()); diff --git a/core/src/plugins/editor.etherpad/i18n/en.php b/core/src/plugins/editor.etherpad/i18n/en.php index 06f9750f04..9d3aabe9d4 100644 --- a/core/src/plugins/editor.etherpad/i18n/en.php +++ b/core/src/plugins/editor.etherpad/i18n/en.php @@ -1,6 +1,7 @@ "Create an empty Pad", + "1" => "Collaboration board", + "1b"=> "Create an empty collaboration pad", "2" => "Collaborative Editor", "3" => "Real-time collaborative edition" ); \ No newline at end of file diff --git a/core/src/plugins/editor.etherpad/manifest.xml b/core/src/plugins/editor.etherpad/manifest.xml index bc14b3b3d0..09c309c870 100644 --- a/core/src/plugins/editor.etherpad/manifest.xml +++ b/core/src/plugins/editor.etherpad/manifest.xml @@ -1,8 +1,11 @@ - + - + @@ -22,30 +25,26 @@ - - + + + EtherpadLauncher.prototype.initEmptyPadPane(modal.getForm()); + ]]> + $("etherpad_container").down("#ether_frame").remove(); + hideLightBox(); + ]]> +
+ Join an existing board or create a new one: + Join +
]]>
@@ -62,6 +61,11 @@
+ + + + +