move documents.php functionality to controller, add route
This commit is contained in:
Родитель
d62e723304
Коммит
e62bae00b4
|
@ -96,7 +96,7 @@ class Controller {
|
|||
exit();
|
||||
} catch (\Exception $e){
|
||||
Helper::warnLog('Joining a session failed. Reason:' . $e->getMessage());
|
||||
\OCP\JSON::error();
|
||||
\OCP\JSON::error(array('message'=>$e->getMessage()));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,30 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* lists the documents the user has access to (including shared files, once the code in core has been fixed)
|
||||
* also adds session and member info for these files
|
||||
*/
|
||||
public static function listDocuments(){
|
||||
self::preDispatch();
|
||||
|
||||
$documents = Storage::getDocuments();
|
||||
|
||||
$fileIds = array();
|
||||
foreach ($documents as $document) {
|
||||
$fileIds[] = $document['fileid'];
|
||||
}
|
||||
|
||||
$sessions = Session::getSessionsByFileIds($fileIds);
|
||||
|
||||
$members = array();
|
||||
foreach ($sessions as $session) {
|
||||
$members[$session['es_id']] = Member::getMembersByEsId($session['es_id']);
|
||||
}
|
||||
|
||||
\OCP\JSON::success(array('documents' => $documents,'sessions' => $sessions,'members' => $members));
|
||||
}
|
||||
|
||||
public static function listSessions(){
|
||||
self::preDispatch();
|
||||
$sessions = Session::getAll();
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* returns the list of documents the user has access to
|
||||
*/
|
||||
|
||||
// Init owncloud
|
||||
|
||||
namespace OCA\Documents;
|
||||
|
||||
\OCP\User::checkLoggedIn();
|
||||
\OCP\JSON::checkAppEnabled('documents');
|
||||
|
||||
$documents = Storage::getDocuments();
|
||||
|
||||
$fileIds = array();
|
||||
foreach ($documents as $document) {
|
||||
$fileIds[] = $document['fileid'];
|
||||
}
|
||||
|
||||
$sessions = Session::getSessionsByFileIds($fileIds);
|
||||
|
||||
$members = array();
|
||||
foreach ($sessions as $session) {
|
||||
$members[$session['es_id']] = Member::getMembersByEsId($session['es_id']);
|
||||
}
|
||||
|
||||
\OCP\JSON::success(array('documents' => $documents,'sessions' => $sessions,'members' => $members));
|
|
@ -27,6 +27,11 @@ $this->create('documents_session_start', 'ajax/session/start')
|
|||
->action('\OCA\Documents\Controller', 'startSession')
|
||||
;
|
||||
|
||||
$this->create('documents_documents_list', 'ajax/documents/list')
|
||||
->get()
|
||||
->action('\OCA\Documents\Controller', 'listDocuments')
|
||||
;
|
||||
|
||||
$this->create('documents_session_list', 'ajax/session/list')
|
||||
->get()
|
||||
->action('\OCA\Documents\Controller', 'listSessions')
|
||||
|
|
|
@ -155,6 +155,11 @@ var documentsMain = {
|
|||
onClose: function() {
|
||||
"use strict";
|
||||
|
||||
var saveSessionRoute = OC.Router.generate('documents_session_save');
|
||||
//auto save document
|
||||
documentsMain.webodfEditorInstance.saveDocument(saveSessionRoute, function(){});
|
||||
|
||||
//close editor
|
||||
documentsMain.webodfEditorInstance.shutdown(function() {
|
||||
// successfull shutdown - all is good.
|
||||
|
||||
|
@ -173,16 +178,18 @@ var documentsMain = {
|
|||
loadDocuments: function () {
|
||||
var self = this;
|
||||
var def = new $.Deferred();
|
||||
jQuery.getJSON(OC.filePath('documents', 'ajax', 'documents.php'))
|
||||
.done(function (data) {
|
||||
self._documents = data.documents;
|
||||
self._sessions = data.sessions;
|
||||
self._members = data.members;
|
||||
def.resolve();
|
||||
})
|
||||
.fail(function(data){
|
||||
console.log(t('documents','Failed to load documents.'));
|
||||
});
|
||||
OC.Router.registerLoadedCallback(function () {
|
||||
jQuery.getJSON(OC.Router.generate('documents_documents_list'))
|
||||
.done(function (data) {
|
||||
self._documents = data.documents;
|
||||
self._sessions = data.sessions;
|
||||
self._members = data.members;
|
||||
def.resolve();
|
||||
})
|
||||
.fail(function(data){
|
||||
console.log(t('documents','Failed to load documents.'));
|
||||
});
|
||||
});
|
||||
return def;
|
||||
},
|
||||
renderDocuments: function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче