Lock the UI when someone is editing
This commit is contained in:
parent
d12e5da1b7
commit
a9d01ac864
@ -154,6 +154,7 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
var list = members.slice().filter(function (m) { return m.length === 32; });
|
var list = members.slice().filter(function (m) { return m.length === 32; });
|
||||||
return list.length - Object.keys(metadataObj.users).length;
|
return list.length - Object.keys(metadataObj.users).length;
|
||||||
},
|
},
|
||||||
|
getChannelMembers: function () { return members.slice(); },
|
||||||
getPrivateData : function () {
|
getPrivateData : function () {
|
||||||
return priv;
|
return priv;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -48,26 +48,29 @@ define([
|
|||||||
var toolbar;
|
var toolbar;
|
||||||
|
|
||||||
var andThen = function (common) {
|
var andThen = function (common) {
|
||||||
|
var readOnly = false;
|
||||||
|
var locked = false;
|
||||||
var config = {};
|
var config = {};
|
||||||
var hashes = [];
|
var hashes = [];
|
||||||
|
|
||||||
var getFileType = function () {
|
var getFileType = function () {
|
||||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||||
|
var title = common.getMetadataMgr().getMetadataLazy().title;
|
||||||
var file = {};
|
var file = {};
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case 'oodoc':
|
case 'oodoc':
|
||||||
file.type = 'docx';
|
file.type = 'docx';
|
||||||
file.title = 'test.docx';
|
file.title = title + '.docx' || 'document.docx';
|
||||||
file.doc = 'text';
|
file.doc = 'text';
|
||||||
break;
|
break;
|
||||||
case 'oocell':
|
case 'oocell':
|
||||||
file.type = 'xlsx';
|
file.type = 'xlsx';
|
||||||
file.title = 'test.xlsx';
|
file.title = title + '.xlsx' || 'spreadsheet.xlsx';
|
||||||
file.doc = 'spreadsheet';
|
file.doc = 'spreadsheet';
|
||||||
break;
|
break;
|
||||||
case 'ooslide':
|
case 'ooslide':
|
||||||
file.type = 'pptx';
|
file.type = 'pptx';
|
||||||
file.title = 'test.pptx';
|
file.title = titl + '.pptx' || 'presentation.pptx';
|
||||||
file.doc = 'presentation';
|
file.doc = 'presentation';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -77,12 +80,19 @@ define([
|
|||||||
var startOO = function (blob, file) {
|
var startOO = function (blob, file) {
|
||||||
if (APP.ooconfig) { return void console.error('already started'); }
|
if (APP.ooconfig) { return void console.error('already started'); }
|
||||||
var url = URL.createObjectURL(blob);
|
var url = URL.createObjectURL(blob);
|
||||||
|
var lock = locked !== common.getMetadataMgr().getNetfluxId();
|
||||||
|
|
||||||
|
// Config
|
||||||
APP.ooconfig = {
|
APP.ooconfig = {
|
||||||
"document": {
|
"document": {
|
||||||
"fileType": file.type,
|
"fileType": file.type,
|
||||||
"key": "fresh",
|
"key": "fresh",
|
||||||
"title": file.title,
|
"title": file.title,
|
||||||
"url": url
|
"url": url,
|
||||||
|
"permissions": {
|
||||||
|
"download": false, // FIXME: download/export is not working, so we use false
|
||||||
|
// to remove the button
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"documentType": file.doc,
|
"documentType": file.doc,
|
||||||
"editorConfig": {
|
"editorConfig": {
|
||||||
@ -95,7 +105,8 @@ define([
|
|||||||
"user": {
|
"user": {
|
||||||
"id": "", //"c0c3bf82-20d7-4663-bf6d-7fa39c598b1d",
|
"id": "", //"c0c3bf82-20d7-4663-bf6d-7fa39c598b1d",
|
||||||
"name": "", //"John Smith"
|
"name": "", //"John Smith"
|
||||||
}
|
},
|
||||||
|
"mode": readOnly || lock ? "view" : "edit"
|
||||||
},
|
},
|
||||||
"events": {
|
"events": {
|
||||||
"onDocumentStateChange": function (evt) {
|
"onDocumentStateChange": function (evt) {
|
||||||
@ -105,7 +116,19 @@ define([
|
|||||||
}
|
}
|
||||||
console.log("in change (remote)");
|
console.log("in change (remote)");
|
||||||
},
|
},
|
||||||
"onReady": function(/*evt*/) { console.log("in onReady"); },
|
"onReady": function(/*evt*/) {
|
||||||
|
var $tb = $('iframe[name="frameEditor"]').contents().find('head');
|
||||||
|
var css = '#id-toolbar-full .toolbar-group:nth-child(2), #id-toolbar-full .separator:nth-child(3) { display: none; }' +
|
||||||
|
'#fm-btn-save { display: none !important; }' +
|
||||||
|
'#header { display: none !important; }';
|
||||||
|
$('<style>').text(css).appendTo($tb);
|
||||||
|
console.log($('iframe[name="frameEditor"]'));
|
||||||
|
console.log($tb);
|
||||||
|
return;
|
||||||
|
$tb.find('> .toolbar-group:visible').first().hide();
|
||||||
|
$tb.find('> .separator').first().hide();
|
||||||
|
console.log($tb.find('> .toolbar-group:visible'));
|
||||||
|
},
|
||||||
"onAppReady": function(/*evt*/) { console.log("in onAppReady"); },
|
"onAppReady": function(/*evt*/) { console.log("in onAppReady"); },
|
||||||
"onDownloadAs": function (evt) { console.log("in onDownloadAs", evt); }
|
"onDownloadAs": function (evt) { console.log("in onDownloadAs", evt); }
|
||||||
}
|
}
|
||||||
@ -179,12 +202,6 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
/** TODO
|
|
||||||
* get hashes
|
|
||||||
* setPadAttribute the latest version + unpin/pin if necessary
|
|
||||||
* download & decrypt
|
|
||||||
* load OO
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
var loadDocument = function (newPad) {
|
var loadDocument = function (newPad) {
|
||||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||||
@ -211,7 +228,6 @@ define([
|
|||||||
startOO(blob, file);
|
startOO(blob, file);
|
||||||
};
|
};
|
||||||
|
|
||||||
var readOnly = false;
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
var $bar = $('#cp-toolbar');
|
var $bar = $('#cp-toolbar');
|
||||||
var Title;
|
var Title;
|
||||||
@ -219,7 +235,6 @@ define([
|
|||||||
var metadataMgr = common.getMetadataMgr();
|
var metadataMgr = common.getMetadataMgr();
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
readOnly: readOnly,
|
|
||||||
patchTransformer: ChainPad.NaiveJSONTransformer,
|
patchTransformer: ChainPad.NaiveJSONTransformer,
|
||||||
// cryptpad debug logging (default is 1)
|
// cryptpad debug logging (default is 1)
|
||||||
// logLevel: 0,
|
// logLevel: 0,
|
||||||
@ -240,7 +255,10 @@ define([
|
|||||||
|
|
||||||
var stringifyInner = function () {
|
var stringifyInner = function () {
|
||||||
var obj = {
|
var obj = {
|
||||||
content: hashes || [],
|
content: {
|
||||||
|
hashes: hashes || [],
|
||||||
|
locked: locked
|
||||||
|
},
|
||||||
metadata: metadataMgr.getMetadataLazy()
|
metadata: metadataMgr.getMetadataLazy()
|
||||||
};
|
};
|
||||||
// stringify the json and send it into chainpad
|
// stringify the json and send it into chainpad
|
||||||
@ -324,12 +342,28 @@ define([
|
|||||||
UI.errorLoadingScreen(errorText);
|
UI.errorLoadingScreen(errorText);
|
||||||
throw new Error(errorText);
|
throw new Error(errorText);
|
||||||
}
|
}
|
||||||
hashes = hjson.content;
|
hashes = hjson.content && hjson.content.hashes;
|
||||||
|
locked = hjson.content && hjson.content.locked;
|
||||||
newDoc = !hashes || hashes.length === 0;
|
newDoc = !hashes || hashes.length === 0;
|
||||||
} else {
|
} else {
|
||||||
Title.updateTitle(Title.defaultTitle);
|
Title.updateTitle(Title.defaultTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!readOnly) {
|
||||||
|
// Check if the editor has left
|
||||||
|
var me = common.getMetadataMgr().getNetfluxId();
|
||||||
|
var members = common.getMetadataMgr().getChannelMembers();
|
||||||
|
if (locked) {
|
||||||
|
if (members.indexOf(locked) === -1) {
|
||||||
|
locked = me;
|
||||||
|
APP.onLocal();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
locked = me;
|
||||||
|
APP.onLocal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadDocument(newDoc);
|
loadDocument(newDoc);
|
||||||
|
|
||||||
initializing = false;
|
initializing = false;
|
||||||
@ -337,6 +371,7 @@ define([
|
|||||||
UI.removeLoadingScreen();
|
UI.removeLoadingScreen();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var reloadDisplayed = false;
|
||||||
config.onRemote = function () {
|
config.onRemote = function () {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
var userDoc = APP.realtime.getUserDoc();
|
var userDoc = APP.realtime.getUserDoc();
|
||||||
@ -344,6 +379,18 @@ define([
|
|||||||
if (json.metadata) {
|
if (json.metadata) {
|
||||||
metadataMgr.updateMetadata(json.metadata);
|
metadataMgr.updateMetadata(json.metadata);
|
||||||
}
|
}
|
||||||
|
var newHashes = (json.content && json.content.hashes) || [];
|
||||||
|
if (newHashes.length !== hashes.length ||
|
||||||
|
stringify(newHashes) !== stringify(hashes)) {
|
||||||
|
hashes = newHashes;
|
||||||
|
if (reloadDisplayed) { return; }
|
||||||
|
reloadDisplayed = true;
|
||||||
|
UI.confirm('TODO new version available. Press OK to reload.', function (yes) {
|
||||||
|
reloadDisplayed = false;
|
||||||
|
if (!yes) { return; }
|
||||||
|
common.gotoURL();
|
||||||
|
}); // XXX
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
config.onAbort = function () {
|
config.onAbort = function () {
|
||||||
|
|||||||
@ -115,6 +115,7 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (fd.lastVersion) { toClean.push(Hash.hrefToHexChannelId(fd.lastVersion)); }
|
||||||
if (channelId) { toClean.push(channelId); }
|
if (channelId) { toClean.push(channelId); }
|
||||||
spliceFileData(id);
|
spliceFileData(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user