Offline calendars

pull/1/head
yflory 4 years ago
parent dd7746a2fd
commit 19ad5d90e8

@ -56,7 +56,7 @@ Messages.calendar_today = "Today";
Messages.calendar_deleteConfirm = "Are you sure you want to delete this calendar from your account?"; Messages.calendar_deleteConfirm = "Are you sure you want to delete this calendar from your account?";
Messages.calendar_deleteTeamConfirm = "Are you sure you want to delete this calendar from this team?"; Messages.calendar_deleteTeamConfirm = "Are you sure you want to delete this calendar from this team?";
Messages.calendar_deleteOwned = " It will still be visible for the users it has been shared with."; Messages.calendar_deleteOwned = " It will still be visible for the users it has been shared with.";
Messages.calendar_errorNoCalendar = "No calendar selected!"; Messages.calendar_errorNoCalendar = "No editable calendar selected!";
var onCalendarsUpdate = Util.mkEvent(); var onCalendarsUpdate = Util.mkEvent();
@ -125,7 +125,7 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
var getCalendars = function () { var getCalendars = function () {
return Object.keys(APP.calendars).map(function (id) { return Object.keys(APP.calendars).map(function (id) {
var c = APP.calendars[id]; var c = APP.calendars[id];
if (c.hidden) { return; } if (c.hidden || c.restricted) { return; }
var md = Util.find(c, ['content', 'metadata']); var md = Util.find(c, ['content', 'metadata']);
if (!md) { return void console.error('Ignore calendar without metadata'); } if (!md) { return void console.error('Ignore calendar without metadata'); }
return { return {
@ -142,12 +142,15 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
var s = []; var s = [];
Object.keys(APP.calendars).forEach(function (id) { Object.keys(APP.calendars).forEach(function (id) {
var c = APP.calendars[id]; var c = APP.calendars[id];
if (c.hidden) { return; } if (c.hidden || c.restricted) { return; }
var data = c.content || {}; var data = c.content || {};
Object.keys(data.content || {}).forEach(function (uid) { Object.keys(data.content || {}).forEach(function (uid) {
var obj = data.content[uid]; var obj = data.content[uid];
obj.title = Util.fixHTML(obj.title || ""); obj.title = Util.fixHTML(obj.title || "");
obj.location = Util.fixHTML(obj.location || ""); obj.location = Util.fixHTML(obj.location || "");
if (c.readOnly) {
obj.isReadOnly = true;
}
s.push(data.content[uid]); s.push(data.content[uid]);
}); });
}); });
@ -347,6 +350,7 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
return UIElements.createDropdown(dropdownConfig)[0]; return UIElements.createDropdown(dropdownConfig)[0];
}; };
var makeCalendarEntry = function (id, teamId) { var makeCalendarEntry = function (id, teamId) {
// XXX handle RESTRICTED calendars (data.restricted)
var data = APP.calendars[id]; var data = APP.calendars[id];
var edit; var edit;
if (!data.readOnly) { if (!data.readOnly) {
@ -523,6 +527,15 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
}); });
}); });
cal.on('clickSchedule', function (event) {
var id = event.calendar && event.calendar.id;
if (!id || !APP.calendars[id]) {
APP.lastClicked = false;
return;
}
APP.lastClicked = id;
});
renderCalendar(); renderCalendar();
}; };
@ -593,7 +606,20 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
$el.find('input').attr('autocomplete', 'off'); $el.find('input').attr('autocomplete', 'off');
$el.find('.tui-full-calendar-dropdown-button').addClass('btn btn-secondary'); $el.find('.tui-full-calendar-dropdown-button').addClass('btn btn-secondary');
$el.find('.tui-full-calendar-popup-close').addClass('btn btn-cancel fa fa-times cp-calendar-close').empty(); $el.find('.tui-full-calendar-popup-close').addClass('btn btn-cancel fa fa-times cp-calendar-close').empty();
if ($el.find('.tui-full-calendar-hide.tui-full-calendar-dropdown').length) {
var calendars = APP.calendars || {};
var show = false;
$el.find('.tui-full-calendar-dropdown-menu li').each(function (i, li) {
var $li = $(li);
var id = $li.attr('data-calendar-id');
var c = calendars[id];
if (!c || c.readOnly) {
return void $li.remove();
}
// If at least one calendar is editable, show the popup
show = true;
});
if ($el.find('.tui-full-calendar-hide.tui-full-calendar-dropdown').length || !show) {
$el.hide(); $el.hide();
UI.warn(Messages.calendar_errorNoCalendar); UI.warn(Messages.calendar_errorNoCalendar);
return; return;
@ -604,14 +630,24 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
$el.find('.tui-full-calendar-dropdown-menu').addClass('cp-forcehide'); $el.find('.tui-full-calendar-dropdown-menu').addClass('cp-forcehide');
} }
}; };
var onCalendarEditPopup = function (el) {
// TODO
};
var observer = new MutationObserver(function(mutations) { var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) { mutations.forEach(function(mutation) {
var node; var node;
for (var i = 0; i < mutation.addedNodes.length; i++) { for (var i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i]; var node = mutation.addedNodes[i];
if (node.classList && node.classList.contains('tui-full-calendar-popup')) { try {
onCalendarPopup(node); if (node.classList && node.classList.contains('tui-full-calendar-popup')
} && node.parentNode.classList.contains('tui-view-26')) {
onCalendarPopup(node);
}
if (node.classList && node.classList.contains('tui-full-calendar-popup')
&& node.parentNode.classList.contains('tui-view-29')) {
onCalendarEditPopup(node);
}
} catch (e) {}
} }
}); });
}); });
@ -637,7 +673,6 @@ Messages.calendar_errorNoCalendar = "No calendar selected!";
}); });
return; return;
} }
console.error('subscribed');
// XXX build UI // XXX build UI
makeCalendar(); makeCalendar();
UI.removeLoadingScreen(); UI.removeLoadingScreen();

@ -26,7 +26,8 @@ define([
//addRpc: addRpc, //addRpc: addRpc,
//addData: addData, //addData: addData,
//owned: true, //owned: true,
noRealtime: true noRealtime: true,
cache: true,
}); });
}); });
}); });

@ -1494,7 +1494,7 @@ define([
} }
}; };
// Teams support offline/cache mode // Teams support offline/cache mode
if (obj.type === "team") { return void todo(); } if (['team', 'calendar'].indexOf(obj.type) !== -1) { return void todo(); }
// If we're in "noDrive" mode // If we're in "noDrive" mode
if (!store.proxy) { return void todo(); } if (!store.proxy) { return void todo(); }
// Other modules should wait for the ready event // Other modules should wait for the ready event
@ -2652,6 +2652,7 @@ define([
}, true); }, true);
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
loadUniversal(Team, 'team', waitFor, clientId); loadUniversal(Team, 'team', waitFor, clientId);
loadUniversal(Calendar, 'calendar', waitFor);
}).nThen(function () { }).nThen(function () {
cb(); cb();
}); });

@ -3,12 +3,13 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-constants.js', '/common/common-constants.js',
'/common/common-realtime.js', '/common/common-realtime.js',
'/common/outer/cache-store.js',
'/customize/messages.js', '/customize/messages.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad/chainpad.dist.js', '/bower_components/chainpad/chainpad.dist.js',
], function (Util, Hash, Constants, Realtime, Messages, nThen, Listmap, Crypto, ChainPad) { ], function (Util, Hash, Constants, Realtime, Cache, Messages, nThen, Listmap, Crypto, ChainPad) {
var Calendar = {}; var Calendar = {};
@ -103,8 +104,9 @@ ctx.calendars[channel] = {
ctx.emit('UPDATE', { ctx.emit('UPDATE', {
teams: c.stores, teams: c.stores,
id: c.channel, id: c.channel,
readOnly: c.readOnly, readOnly: c.readOnly || (!c.ready && c.cacheready),
deleted: !c.stores.length, deleted: !c.stores.length,
restricted: c.restricted,
owned: false, // XXX XXX destroy owned: false, // XXX XXX destroy
content: Util.clone(c.proxy) content: Util.clone(c.proxy)
}, ctx.clients); }, ctx.clients);
@ -178,14 +180,16 @@ ctx.calendars[channel] = {
var config = { var config = {
data: {}, data: {},
network: ctx.store.network, // XXX offline network: ctx.store.network || ctx.store.networkPromise, // XXX offline
channel: secret.channel, channel: secret.channel,
crypto: crypto, crypto: crypto,
owners: [edPublic], owners: [edPublic],
ChainPad: ChainPad, ChainPad: ChainPad,
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
userName: 'calendar', userName: 'calendar',
classic: true Cache: Cache,
classic: true,
onRejected: ctx.Store && ctx.Store.onRejected
}; };
console.error(channel, config); console.error(channel, config);
@ -213,7 +217,12 @@ ctx.calendars[channel] = {
}); });
}; };
lm.proxy.on('ready', function () { lm.proxy.on('cacheready', function () {
if (!proxy.metadata) { return; }
c.cacheready = true;
setTimeout(update);
if (cb) { cb(null, lm.proxy); }
}).on('ready', function () {
c.ready = true; c.ready = true;
if (!proxy.metadata) { if (!proxy.metadata) {
if (!cfg.isNew) { if (!cfg.isNew) {
@ -240,6 +249,9 @@ ctx.calendars[channel] = {
if (info.error === "EDELETED" ) { if (info.error === "EDELETED" ) {
return void onDeleted(); return void onDeleted();
} }
if (info.error === "ERESTRICTED" ) {
c.restricted = true;
}
cb(info); cb(info);
}); });
}); });
@ -274,7 +286,7 @@ ctx.calendars[channel] = {
Object.keys(ctx.calendars).forEach(function (channel) { Object.keys(ctx.calendars).forEach(function (channel) {
var c = ctx.calendars[channel] || {}; var c = ctx.calendars[channel] || {};
console.log(channel, c); console.log(channel, c);
if (!c.ready) { return; } if (!c.ready && !c.cacheready) { return; }
sendUpdate(ctx, c); sendUpdate(ctx, c);
}); });
}; };

@ -186,7 +186,7 @@ define([
ChainPad: ChainPad, ChainPad: ChainPad,
classic: true, classic: true,
network: network, network: network,
Cache: Cache, // ICE shared-folder cache Cache: Cache, // shared-folder cache
metadata: { metadata: {
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
owners: owners owners: owners

Loading…
Cancel
Save