From 267901aa0bea5dd1b968a2500f4155c09344e5c1 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Sat, 10 Aug 2013 01:49:20 +0300 Subject: [PATCH] More on joining session --- ajax/otpoll.php | 17 +++++++++-------- js/office.js | 17 +++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ajax/otpoll.php b/ajax/otpoll.php index f9638cf8..f066616d 100644 --- a/ajax/otpoll.php +++ b/ajax/otpoll.php @@ -59,22 +59,23 @@ try{ ); break; - case 'session-list': + case 'session_list': OCA\Office\Controller::listSessions(); exit(); break; - case 'join-session': + case 'join_session': + // should fail when session is non-existent + break; OCA\Office\Controller::joinSession(array( 'es_id' => $request->getParam('args/es_id') )); exit(); break; - case 'user-list': + case 'user_list': $members = OCA\Office\Member::getMembersByEsId( $request->getParam('args/es_id') ); break; - case 'sync-ops': case 'sync_ops': $seqHead = $request->getParam('args/seq_head'); if (!is_null($seqHead)){ @@ -93,16 +94,16 @@ try{ // Add incoming ops, respond with a new head $newHead = OCA\Office\Op::addOpsArray($esId, $memberId, $ops); $response["result"] = 'added'; - $response["headSeq"] = $newHead ? $newHead : $currentHead; + $response["head_seq"] = $newHead ? $newHead : $currentHead; } else { // no incoming ops (just checking for new ops...) - $response["result"] = 'newOps'; + $response["result"] = 'new_ops'; $response["ops"] = array(); - $response["headSeq"] = $currentHead; + $response["head_seq"] = $currentHead; } } else { // HEADs do not match $response["ops"] = OCA\Office\Op::getOpsAfterJson($esId, $seqHead); - $response["headSeq"] = $currentHead; + $response["head_seq"] = $currentHead; $response["result"] = $hasOps ? 'conflict' : 'newOps'; } } else { diff --git a/js/office.js b/js/office.js index 1962830c..1b480fff 100644 --- a/js/office.js +++ b/js/office.js @@ -19,7 +19,7 @@ var officeMain = { }); }); }, - joinSession: function(response) { + initSession: function(response) { "use strict"; OC.addScript('office', 'editor/boot_editor').done(function() { @@ -69,7 +69,7 @@ var officeMain = { loginProcedure: function(cb) { cb(response.es_id, OC.currentUser, "token"); }, - joinSession: function(userId, sessionId, cb) { + initSession: function(userId, sessionId, cb) { cb(memberId); }, callback: function() { @@ -89,10 +89,15 @@ var officeMain = { $.post(OC.Router.generate('office_session_start'), { 'path' : filepath }, - officeMain.joinSession + officeMain.initSession + ); + }, + joinSession : function (esId){ + $.post(OC.Router.generate('office_session_join') + '/' + esId, + {}, + officeMain.initSession ); }, - showSessions : function(){ if ($('#allsessions').length){ $('#allsessions').remove(); @@ -102,7 +107,7 @@ var officeMain = { }, onSessions : function(response){ if (response && response.session_list){ - $(response.session_list).each( function(i, s){ officeMain.addSession(s) } ); + $(response.session_list).each( function(i, s){ officeMain.addSession(s); } ); } }, addSession : function(s){ @@ -112,7 +117,7 @@ var officeMain = { $('
'+s+ '
').appendTo('#allsessions').click( function(event){ event.preventDefault(); - officeMain.joinSession({es_id : s}); + officeMain.joinSession(s); } ); },