Code deduplication
This commit is contained in:
parent
db2b876132
commit
ab9ceaf3f4
@ -67,6 +67,22 @@ class Controller {
|
|||||||
\OCP\JSON::error();
|
\OCP\JSON::error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function listSessions(){
|
||||||
|
self::getUser();
|
||||||
|
$sessions = Session::getAll();
|
||||||
|
if (!is_array($sessions)){
|
||||||
|
$sessions = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$preparedSessions = array_map(
|
||||||
|
function($x){return ($x['es_id']);},
|
||||||
|
$sessions
|
||||||
|
);
|
||||||
|
\OCP\JSON::success(array(
|
||||||
|
"session_list" => $preparedSessions
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
protected static function getUser(){
|
protected static function getUser(){
|
||||||
\OCP\JSON::checkLoggedIn();
|
\OCP\JSON::checkLoggedIn();
|
||||||
return \OCP\User::getUser();
|
return \OCP\User::getUser();
|
||||||
|
@ -34,9 +34,10 @@
|
|||||||
* @source: http://www.webodf.org/
|
* @source: http://www.webodf.org/
|
||||||
* @source: http://gitorious.org/webodf/webodf/
|
* @source: http://gitorious.org/webodf/webodf/
|
||||||
*/
|
*/
|
||||||
// OCP\JSON::checkLoggedIn();
|
|
||||||
// OCP\JSON::checkAppEnabled('office');
|
OCP\JSON::checkLoggedIn();
|
||||||
// session_write_close();
|
OCP\JSON::checkAppEnabled('office');
|
||||||
|
// session_write_close();
|
||||||
|
|
||||||
$response = array();
|
$response = array();
|
||||||
try{
|
try{
|
||||||
@ -44,15 +45,8 @@ try{
|
|||||||
$command = $request->getParam('command');
|
$command = $request->getParam('command');
|
||||||
switch ($command){
|
switch ($command){
|
||||||
case 'session-list':
|
case 'session-list':
|
||||||
$sessions = OCA\Office\Session::getAll();
|
OCA\Office\Controller::listSessions();
|
||||||
if (!is_array($sessions)){
|
exit();
|
||||||
$sessions = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response["session_list"] = array_map(
|
|
||||||
function($x){return ($x['es_id']);},
|
|
||||||
$sessions
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case 'join-session':
|
case 'join-session':
|
||||||
$response = "true"; // should fail when session is non-existent
|
$response = "true"; // should fail when session is non-existent
|
||||||
|
@ -27,6 +27,15 @@ $this->create('office_session_start', 'ajax/session/start')
|
|||||||
->action('\OCA\Office\Controller', 'startSession')
|
->action('\OCA\Office\Controller', 'startSession')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$this->create('office_session_list', 'ajax/session/list')
|
||||||
|
->get()
|
||||||
|
->action('\OCA\Office\Controller', 'listSessions')
|
||||||
|
;
|
||||||
|
$this->create('office_session_list', 'ajax/session/list')
|
||||||
|
->post()
|
||||||
|
->action('\OCA\Office\Controller', 'listSessions')
|
||||||
|
;
|
||||||
|
|
||||||
$this->create('office_session_join', 'ajax/session/join/{es_id}')
|
$this->create('office_session_join', 'ajax/session/join/{es_id}')
|
||||||
->get()
|
->get()
|
||||||
->action('\OCA\Office\Controller', 'joinSession')
|
->action('\OCA\Office\Controller', 'joinSession')
|
||||||
|
10
js/office.js
10
js/office.js
@ -23,7 +23,7 @@ var officeMain = {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
OC.addScript('office', 'editor/boot_editor').done(function() {
|
OC.addScript('office', 'editor/boot_editor').done(function() {
|
||||||
var doclocation = response.genesis_url;
|
var doclocation = response.es_id;
|
||||||
|
|
||||||
// fade out files menu and add odf menu
|
// fade out files menu and add odf menu
|
||||||
$('.documentslist, #emptyfolder').fadeOut('slow').promise().done(function() {
|
$('.documentslist, #emptyfolder').fadeOut('slow').promise().done(function() {
|
||||||
@ -97,18 +97,18 @@ var officeMain = {
|
|||||||
$.post(OC.Router.generate('office_session_list'), {}, officeMain.onSessions);
|
$.post(OC.Router.generate('office_session_list'), {}, officeMain.onSessions);
|
||||||
},
|
},
|
||||||
onSessions : function(response){
|
onSessions : function(response){
|
||||||
if (response && response.sessions){
|
if (response && response.session_list){
|
||||||
$(response.sessions).each( function(i, s){ officeMain.addSession(s) } );
|
$(response.session_list).each( function(i, s){ officeMain.addSession(s) } );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addSession : function(s){
|
addSession : function(s){
|
||||||
if (!$('#allsessions').length){
|
if (!$('#allsessions').length){
|
||||||
$(document.body).append('<div id="allsessions"></div>');
|
$(document.body).append('<div id="allsessions"></div>');
|
||||||
}
|
}
|
||||||
$('<div><a href="">'+s.es_id+ '</a></div>').appendTo('#allsessions').click(
|
$('<div><a href="">'+s+ '</a></div>').appendTo('#allsessions').click(
|
||||||
function(event){
|
function(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
officeMain.joinSession(s);
|
officeMain.joinSession({es_id : s});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user