Code deduplication

pull/1/head
Victor Dubiniuk 11 years ago committed by Tobias Hintze
parent db2b876132
commit ab9ceaf3f4

@ -67,6 +67,22 @@ class Controller {
\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(){
\OCP\JSON::checkLoggedIn();
return \OCP\User::getUser();

@ -34,9 +34,10 @@
* @source: http://www.webodf.org/
* @source: http://gitorious.org/webodf/webodf/
*/
// OCP\JSON::checkLoggedIn();
// OCP\JSON::checkAppEnabled('office');
// session_write_close();
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('office');
// session_write_close();
$response = array();
try{
@ -44,15 +45,8 @@ try{
$command = $request->getParam('command');
switch ($command){
case 'session-list':
$sessions = OCA\Office\Session::getAll();
if (!is_array($sessions)){
$sessions = array();
}
$response["session_list"] = array_map(
function($x){return ($x['es_id']);},
$sessions
);
OCA\Office\Controller::listSessions();
exit();
break;
case 'join-session':
$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')
;
$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}')
->get()
->action('\OCA\Office\Controller', 'joinSession')

@ -23,7 +23,7 @@ var officeMain = {
"use strict";
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
$('.documentslist, #emptyfolder').fadeOut('slow').promise().done(function() {
@ -97,18 +97,18 @@ var officeMain = {
$.post(OC.Router.generate('office_session_list'), {}, officeMain.onSessions);
},
onSessions : function(response){
if (response && response.sessions){
$(response.sessions).each( function(i, s){ officeMain.addSession(s) } );
if (response && response.session_list){
$(response.session_list).each( function(i, s){ officeMain.addSession(s) } );
}
},
addSession : function(s){
if (!$('#allsessions').length){
$(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){
event.preventDefault();
officeMain.joinSession(s);
officeMain.joinSession({es_id : s});
}
);
},

Loading…
Cancel
Save