mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:07 +01:00
W.I.P. collab editor:
- Implement create new empty document
This commit is contained in:
parent
6a4c89d61a
commit
d622af8c44
@ -23,6 +23,11 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
'poll' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* session identification for an empty new file
|
||||
*/
|
||||
const NEW_FILE_ES_ID = 'new';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -35,12 +40,24 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
/**
|
||||
* Join session, initialises edit session for opened file by user
|
||||
*
|
||||
* @param type $es_id session id
|
||||
* @param type $es_id session id, 'new' session id means it's an empty
|
||||
* template opened as new file, and should not be store in DB.
|
||||
*
|
||||
* @return array returns an array consists of session data
|
||||
*/
|
||||
function join_session ($es_id)
|
||||
{
|
||||
if ($es_id === self::NEW_FILE_ES_ID)
|
||||
{
|
||||
$response = array(
|
||||
'member_id' => '0',
|
||||
'es_id' => self::NEW_FILE_ES_ID
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = $this->initSession($es_id);
|
||||
}
|
||||
$response += array (
|
||||
'id' => $GLOBALS['egw_info']['user']['account_id'],
|
||||
'full_name' => $GLOBALS['egw_info']['user']['account_fullname'],
|
||||
@ -87,11 +104,33 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
$response = $this->join_session($params['args']['es_id'],$params['args']['user_id']);
|
||||
break;
|
||||
case 'leave_session':
|
||||
if ($params['args']['es_id'] === self::NEW_FILE_ES_ID)
|
||||
{
|
||||
$response = array ('success' => true,'memberid' => '0','session_id'=>self::NEW_FILE_ES_ID);
|
||||
break;
|
||||
}
|
||||
$response = $this->leave_session($params['args']['es_id'],$params['args']['member_id']);
|
||||
break;
|
||||
case 'sync_ops':
|
||||
try
|
||||
{
|
||||
// handle new file operation
|
||||
if ($params['args']['es_id'] === self::NEW_FILE_ES_ID)
|
||||
{
|
||||
if (!$params['args']['client_ops'] && !$params['args']['seq_head'])
|
||||
{
|
||||
$response = $this->prepare_newFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = array(
|
||||
'result' => 'added',
|
||||
'seq_head' => 1
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$memberid = $params['args']['member_id']? $params['args']['member_id']: '';
|
||||
$es_id = $params['args']['es_id'];
|
||||
$seq_head = (string) isset($params['args']['seq_head'])? $params['args']['seq_head']: null;
|
||||
@ -157,6 +196,37 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function prepare an op structure for new file operation
|
||||
* as new file is not saved yet in database we need to satisfy the
|
||||
* client in order to be able to edit an empty document.
|
||||
*
|
||||
* @return array return op structure
|
||||
*/
|
||||
function prepare_newFile()
|
||||
{
|
||||
$date = new Api\DateTime();
|
||||
$use_id = $GLOBALS['egw_info']['user']['account_id'];
|
||||
$response = array (
|
||||
'result' => 'new_ops',
|
||||
'ops'=> array (
|
||||
0 => array (
|
||||
'optype' => 'AddMember',
|
||||
'memberid' => '0',
|
||||
'timestamp' => $date->getTimestamp(),
|
||||
'setProperties' => array(
|
||||
'fullName' => $GLOBALS['egw_info']['user']['account_fullname'],
|
||||
'color' => $GLOBALS['egw_info']['user']['preferences']['filemanager']['collab_user_color'],
|
||||
'imageUrl' => $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=addressbook.addressbook_ui.photo&account_id='.$use_id,
|
||||
'uid' => $use_id
|
||||
)
|
||||
)
|
||||
),
|
||||
'head_seq' => '1'
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a new head sequence
|
||||
*
|
||||
@ -249,10 +319,12 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
* client.
|
||||
*
|
||||
* @param type $file_path file path
|
||||
*
|
||||
* @param boolean $_isNew true means this is an empty doc opened as new file
|
||||
* in client-side and not stored yet therefore no genesis file should get generated for it.
|
||||
*/
|
||||
function ajax_getGenesisUrl ($file_path)
|
||||
function ajax_getGenesisUrl ($file_path, $_isNew)
|
||||
{
|
||||
|
||||
$result = array();
|
||||
$es_id = md5($file_path);
|
||||
$paths = explode('/webdav.php', $file_path);
|
||||
@ -260,6 +332,15 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
array_pop($dir_parts);
|
||||
$dir = join('/', $dir_parts);
|
||||
$response = Api\Json\Response::get();
|
||||
// handle new empty file
|
||||
if ($_isNew)
|
||||
{
|
||||
$response->data(array (
|
||||
'es_id' => self::NEW_FILE_ES_ID,
|
||||
'genesis_url' => $GLOBALS['egw_info']['server']['webserver_url'].'/api/js/webodf/template.odt'
|
||||
));
|
||||
return;
|
||||
}
|
||||
$session = $this->SESSION_Get($es_id);
|
||||
|
||||
if ($session && $session['genesis_url'] !== '')
|
||||
|
@ -1499,6 +1499,10 @@ class filemanager_ui
|
||||
$content['es_id'] = md5 ($file_path);
|
||||
$content['file_path'] = $paths[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$content = array();
|
||||
}
|
||||
}
|
||||
|
||||
$actions = self::getActions_edit();
|
||||
|
@ -1020,7 +1020,6 @@ app.classes.filemanager = AppJS.extend(
|
||||
var template_url = '/api/js/webodf/template.odt';
|
||||
egw.open_link(egw.link('/index.php', {
|
||||
menuaction: 'filemanager.filemanager_ui.editor',
|
||||
path: template_url
|
||||
}), '', egw.link_get_registry('filemanager','view_popup'));
|
||||
},
|
||||
|
||||
|
@ -73,46 +73,6 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initiate odf editor popup & load given file_path
|
||||
*
|
||||
*/
|
||||
_init_odf_editor: function ()
|
||||
{
|
||||
var widgetFilePath = this.et2.getWidgetById('file_path'),
|
||||
file_path = widgetFilePath.value,
|
||||
isNew = file_path == '/api/js/webodf/template.odt'? true: false,
|
||||
self = this;
|
||||
|
||||
var onEditorCreated = function (err ,editor)
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
console.log('Something went wrong whilst loading editor.'+ err);
|
||||
return;
|
||||
}
|
||||
self.editor = editor;
|
||||
self.editor.openDocumentFromUrl(egw.webserverUrl+file_path);
|
||||
if (isNew) {
|
||||
widgetFilePath.set_value('');
|
||||
}
|
||||
};
|
||||
|
||||
var editorOptions = {
|
||||
allFeaturesEnabled: true,
|
||||
userData: {
|
||||
fullName: egw.user('account_fullName'),
|
||||
color: 'blue'
|
||||
}
|
||||
};
|
||||
|
||||
var editor = this.et2.getWidgetById('odfEditor');
|
||||
if (editor)
|
||||
{
|
||||
Wodo.createTextEditor('filemanager-editor_odfEditor', editorOptions, onEditorCreated);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initiate odf collab editor popup & load given file_path as active session
|
||||
* editors options:
|
||||
@ -129,9 +89,9 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
*/
|
||||
_init_odf_collab_editor: function ()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
egw.json('filemanager.filemanager_collab.ajax_getGenesisUrl',[this.editor_getFilePath()], function (_data){
|
||||
var self = this,
|
||||
isNew = window.location.href.search(/&path=/) == -1?true:false;
|
||||
egw.json('filemanager.filemanager_collab.ajax_getGenesisUrl',[this.editor_getFilePath(), isNew], function (_data){
|
||||
var serverOptions = {
|
||||
serverParams: {
|
||||
url:egw.link('/index.php?', {
|
||||
@ -188,7 +148,8 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
editor_close: function (_egwAction, _callback) {
|
||||
var self = this,
|
||||
action = _egwAction.id,
|
||||
callback = _callback;
|
||||
callback = _callback,
|
||||
file_path = this.et2.getWidgetById('file_path');
|
||||
|
||||
if (this.editor)
|
||||
{
|
||||
@ -202,8 +163,8 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
callback.call(this);
|
||||
};
|
||||
|
||||
// warn user about unsaved changes
|
||||
if (this.editor.isDocumentModified())
|
||||
// it's an unsaved new file try to warn user about unsaved changes
|
||||
if (file_path.value == '')
|
||||
{
|
||||
et2_dialog.show_dialog(
|
||||
function(_btn)
|
||||
|
Loading…
Reference in New Issue
Block a user