From 3755f9d0c2f83cc2e07563092f88af4eb97087b4 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 15 Aug 2016 17:16:09 +0200 Subject: [PATCH] W.I.P collab editor: - Fix error second cursor inserted - Fix close button does not close the session --- .../inc/class.filemanager_collab_bo.inc.php | 31 +++++++++++++++++-- filemanager/js/app.js | 25 ++++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/filemanager/inc/class.filemanager_collab_bo.inc.php b/filemanager/inc/class.filemanager_collab_bo.inc.php index 0d0c7e859b..e51700c527 100644 --- a/filemanager/inc/class.filemanager_collab_bo.inc.php +++ b/filemanager/inc/class.filemanager_collab_bo.inc.php @@ -117,11 +117,10 @@ class filemanager_collab_bo */ protected function OP_addMember($es_id, $member_id, $full_name, $user_id, $color='', $imageUrl='') { - $date = new DateTime(); $op = array( 'optype' => 'AddMember', 'memberid' => (string) $member_id, - 'timestamp' => $date->getTimestamp(), + 'timestamp' => self::getTimeStamp(), 'setProperties' => array( 'fullName' => $full_name, 'color' => $color, @@ -132,6 +131,24 @@ class filemanager_collab_bo $this->OP_add2Db($op, $es_id); } + /** + * Function to remove cursor for a member + * + * @param string $es_id session id + * @param string $member_id member id + */ + protected function OP_removeCursor ($es_id, $member_id) + { + $op = array( + 'optype' => 'RemoveCursor', + 'memberid' => (string) $member_id, + 'reason' => 'server-idle', + 'timestamp' => self::getTimeStamp() + ); + + $this->OP_add2Db($op, $es_id); + } + /** * Function to get top head seq for a given session * @@ -297,4 +314,14 @@ class filemanager_collab_bo $last_row = $query->fetchRow(); return is_array($last_row)? $last_row['collab_member_id']: 0; } + + /** + * Get timestamp + * @return int returns current time as timestamp + */ + static function getTimeStamp () + { + $date = new DateTime(); + return $date->getTimestamp(); + } } \ No newline at end of file diff --git a/filemanager/js/app.js b/filemanager/js/app.js index 998aa55fa2..3e11d471ce 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -120,6 +120,8 @@ app.classes.filemanager = AppJS.extend( { // need to make body rock solid to avoid extra scrollbars jQuery('body').css({overflow:'hidden'}); + var self = this; + jQuery(window).on('unload', function(){self.editor.leaveSession()}); this._init_odf_collab_editor (); } }, @@ -1077,8 +1079,7 @@ app.classes.filemanager = AppJS.extend( { var widgetFilePath = this.et2.getWidgetById('file_path'), - file_path = widgetFilePath.value, - base64 = new core.Base64(); + file_path = widgetFilePath.value; var serverOptions = { @@ -1088,7 +1089,7 @@ app.classes.filemanager = AppJS.extend( }), genesisUrl:egw.webserverUrl+file_path }, - "sessionId": egw.webserverUrl+file_path, + "sessionId": this.editor_getSessionId(), editorOptions: { allFeaturesEnabled: true, userData: { @@ -1119,10 +1120,9 @@ app.classes.filemanager = AppJS.extend( { var closeFn = function () { - self.editor.closeDocument(function(){}); + self.editor.leaveSession(function(){}); if (action != 'new') { - self.editor.destroy(function(){}); window.close(); } callback.call(this); @@ -1238,7 +1238,9 @@ app.classes.filemanager = AppJS.extend( // Add odt extension if not exist if (!file_path.match(/\.odt$/,'ig')) file_path += '.odt'; widgetFilePath.set_value(file_path); + self.editor.leaveSession(function(){}); self.editor.getDocumentAsByteArray(saveByteArrayLocally); + self._init_odf_collab_editor(); egw.refresh('','filemanager'); } }); @@ -1322,6 +1324,19 @@ app.classes.filemanager = AppJS.extend( return data.data.mime.match(mime.mime_odf_regex)?true:false; }, + /** + * Function to generate session id + * + * @returns {String} retruns session id + */ + editor_getSessionId: function () + { + var widgetFilePath = this.et2.getWidgetById('file_path'), + file_path = widgetFilePath.value, + es_id = egw.webserverUrl+file_path; + return es_id; + }, + /** * Function to create collab editor *