Commit af1dc370 authored by Thomas Marrinan's avatar Thomas Marrinan

state synced with server - pdf implemented


Former-commit-id: 2e75a113e2b2178ca83551aa23129e8e23851eff
parent 7a175f1a
......@@ -310,7 +310,6 @@ appLoader.prototype.loadPdfFromFile = function(file, mime_type, url, external_ur
url: external_url,
data: {
src: external_url,
type: "application/pdf",
page: 1,
numPagesShown: 1
},
......
......@@ -357,15 +357,15 @@
}, false);
js.addEventListener('load', function(event) {
var app = new window[data.application];
app.init(data.id, data.width, data.height, data.url, date);
Object.observe(app.state, function(changes) {
var updatedState = JSON.parse(JSON.stringify(app.state));
console.log(data.id + ": ");
console.log(updatedState);
wsio.emit('updateAppState', {id: data.id, state: updatedState});
});
app.init(data.id, data.width, data.height, data.url, date);
//app.init(data.id, data.width, data.height, data.url, date);
app.load(data.data, date);
app.draw(date);
......@@ -380,15 +380,15 @@
// load existing app
else {
var app = new window[data.application];
app.init(data.id, data.width, data.height, data.url, date);
Object.observe(app.state, function(changes) {
var updatedState = JSON.parse(JSON.stringify(app.state));
console.log(data.id + ": ");
console.log(updatedState);
wsio.emit('updateAppState', {id: data.id, state: updatedState});
});
app.init(data.id, data.width, data.height, data.url, date);
//app.init(data.id, data.width, data.height, data.url, date);
app.load(data.data, date);
app.draw(date);
......
......@@ -35,8 +35,8 @@ var pdf_viewer = SAGE2_App.extend( {
// *** DO NOT OVERWRITE this.state, ALWAYS EDIT ITS PROPERTIES
// this.state = {srcPDF: null, pageNum: null, numPagesShown: null}; // BAD
this.state.srcPDF = null;
this.state.pageNum = null;
this.state.src = null;
this.state.page = null;
this.state.numPagesShown = null;
},
......@@ -49,8 +49,8 @@ var pdf_viewer = SAGE2_App.extend( {
_this.loaded = true;
_this.pdfDoc = _pdfDoc;
_this.state.srcPDF = state.src;
_this.state.pageNum = state.page;
_this.state.src = state.src;
_this.state.page = state.page;
_this.state.numPagesShown = state.numPagesShown;
_this.draw(date);
......@@ -58,7 +58,7 @@ var pdf_viewer = SAGE2_App.extend( {
}
// load new state of same document
else {
this.state.pageNum = state.page;
this.state.page = state.page;
this.state.numPagesShown = state.numPagesShown;
this.draw(date);
......@@ -73,7 +73,7 @@ var pdf_viewer = SAGE2_App.extend( {
if(this.loaded === false) return;
var _this = this;
this.pdfDoc.getPage(this.state.pageNum).then(function(page) {
this.pdfDoc.getPage(this.state.page).then(function(page) {
// set the scale to match the canvas
var viewport = page.getViewport(_this.canvas.width / page.getViewport(1.0).width);
viewport.height = _this.canvas.height;
......@@ -103,14 +103,14 @@ var pdf_viewer = SAGE2_App.extend( {
if(eventType === "specialKey"){
if(data.code === 37 && data.state === "up"){ // Left Arrow
if(this.state.pageNum <= 1) return;
this.state.pageNum = this.state.pageNum - 1;
if(this.state.page <= 1) return;
this.state.page = this.state.page - 1;
this.draw(date);
}
if(data.code === 39 && data.state === "up"){ // Right Arrow
if(this.state.pageNum >= this.pdfDoc.numPages) return;
this.state.pageNum = this.state.pageNum + 1;
if(this.state.page >= this.pdfDoc.numPages) return;
this.state.page = this.state.page + 1;
this.draw(date);
}
......
......@@ -216,6 +216,7 @@ function initializeWSClient(wsio) {
}
if(wsio.messages.requiresFullApps){
wsio.on('finishedRenderingAppFrame', wsFinishedRenderingAppFrame);
wsio.on('updateAppState', wsUpdateAppState);
}
if(wsio.messages.requestsServerFiles){
wsio.on('requestStoredFiles', wsRequestStoredFiles);
......@@ -628,6 +629,12 @@ function wsFinishedRenderingAppFrame(wsio, data) {
}
}
function wsUpdateAppState(wsio, data) {
var app = findAppById(data.id);
app.data = data.state;
}
/******************** Server File Functions ********************/
function wsRequestStoredFiles(wsio, data) {
var savedFiles = getSavedFilesList();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment