W.I.P collab editor:

- Fix error second cursor inserted
- Fix close button does not close the session
This commit is contained in:
Hadi Nategh 2016-08-15 17:16:09 +02:00
parent afafc8ccba
commit 3755f9d0c2
2 changed files with 49 additions and 7 deletions

View File

@ -117,11 +117,10 @@ class filemanager_collab_bo
*/ */
protected function OP_addMember($es_id, $member_id, $full_name, $user_id, $color='', $imageUrl='') protected function OP_addMember($es_id, $member_id, $full_name, $user_id, $color='', $imageUrl='')
{ {
$date = new DateTime();
$op = array( $op = array(
'optype' => 'AddMember', 'optype' => 'AddMember',
'memberid' => (string) $member_id, 'memberid' => (string) $member_id,
'timestamp' => $date->getTimestamp(), 'timestamp' => self::getTimeStamp(),
'setProperties' => array( 'setProperties' => array(
'fullName' => $full_name, 'fullName' => $full_name,
'color' => $color, 'color' => $color,
@ -132,6 +131,24 @@ class filemanager_collab_bo
$this->OP_add2Db($op, $es_id); $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 * Function to get top head seq for a given session
* *
@ -297,4 +314,14 @@ class filemanager_collab_bo
$last_row = $query->fetchRow(); $last_row = $query->fetchRow();
return is_array($last_row)? $last_row['collab_member_id']: 0; 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();
}
} }

View File

@ -120,6 +120,8 @@ app.classes.filemanager = AppJS.extend(
{ {
// need to make body rock solid to avoid extra scrollbars // need to make body rock solid to avoid extra scrollbars
jQuery('body').css({overflow:'hidden'}); jQuery('body').css({overflow:'hidden'});
var self = this;
jQuery(window).on('unload', function(){self.editor.leaveSession()});
this._init_odf_collab_editor (); this._init_odf_collab_editor ();
} }
}, },
@ -1077,8 +1079,7 @@ app.classes.filemanager = AppJS.extend(
{ {
var widgetFilePath = this.et2.getWidgetById('file_path'), var widgetFilePath = this.et2.getWidgetById('file_path'),
file_path = widgetFilePath.value, file_path = widgetFilePath.value;
base64 = new core.Base64();
var serverOptions = { var serverOptions = {
@ -1088,7 +1089,7 @@ app.classes.filemanager = AppJS.extend(
}), }),
genesisUrl:egw.webserverUrl+file_path genesisUrl:egw.webserverUrl+file_path
}, },
"sessionId": egw.webserverUrl+file_path, "sessionId": this.editor_getSessionId(),
editorOptions: { editorOptions: {
allFeaturesEnabled: true, allFeaturesEnabled: true,
userData: { userData: {
@ -1119,10 +1120,9 @@ app.classes.filemanager = AppJS.extend(
{ {
var closeFn = function () var closeFn = function ()
{ {
self.editor.closeDocument(function(){}); self.editor.leaveSession(function(){});
if (action != 'new') if (action != 'new')
{ {
self.editor.destroy(function(){});
window.close(); window.close();
} }
callback.call(this); callback.call(this);
@ -1238,7 +1238,9 @@ app.classes.filemanager = AppJS.extend(
// Add odt extension if not exist // Add odt extension if not exist
if (!file_path.match(/\.odt$/,'ig')) file_path += '.odt'; if (!file_path.match(/\.odt$/,'ig')) file_path += '.odt';
widgetFilePath.set_value(file_path); widgetFilePath.set_value(file_path);
self.editor.leaveSession(function(){});
self.editor.getDocumentAsByteArray(saveByteArrayLocally); self.editor.getDocumentAsByteArray(saveByteArrayLocally);
self._init_odf_collab_editor();
egw.refresh('','filemanager'); egw.refresh('','filemanager');
} }
}); });
@ -1322,6 +1324,19 @@ app.classes.filemanager = AppJS.extend(
return data.data.mime.match(mime.mime_odf_regex)?true:false; 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 * Function to create collab editor
* *