Fix title setter logic and separate it from UI

pull/1/head
Caleb James DeLisle 7 years ago
parent ec87f3f897
commit cf6d8c83b2

@ -16,6 +16,7 @@ define([], function () {
var dirty = true;
var changeHandlers = [];
var lazyChangeHandlers = [];
var titleChangeHandlers = [];
var rememberedTitle;
@ -50,13 +51,14 @@ define([], function () {
var lazyUserStr = JSON.stringify(metadataLazyObj.users[meta.user.netfluxId]);
dirty = false;
if (lazy || lazyUserStr !== JSON.stringify(meta.user)) {
metadataLazyObj.users = mdo;
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
lazyChangeHandlers.forEach(function (f) { f(); });
}
if (metadataObj.title !== rememberedTitle) {
console.log("Title update\n" + metadataObj.title + '\n');
rememberedTitle = metadataObj.title;
titleChangeHandlers.forEach(function (f) { f(metadataObj.title); });
}
changeHandlers.forEach(function (f) { f(); });
@ -113,6 +115,7 @@ define([], function () {
getMetadataLazy: function () {
return metadataLazyObj;
},
onTitleChange: function (f) { titleChangeHandlers.push(f); },
onChange: function (f) { changeHandlers.push(f); },
onChangeLazy: function (f) { lazyChangeHandlers.push(f); },
isConnected : function () {

@ -15,9 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define([
'/common/metadata-manager.js',
'/bower_components/chainpad/chainpad.dist.js'
], function (MetadataMgr) {
], function () {
var ChainPad = window.ChainPad;
var module = { exports: {} };
@ -39,14 +38,13 @@ define([
var logLevel = typeof(config.logLevel) !== 'undefined'? config.logLevel : 1;
var readOnly = config.readOnly || false;
var sframeChan = config.sframeChan;
var metadataMgr = config.metadataMgr;
config = undefined;
var chainpad;
var myID;
var isReady = false;
var metadataMgr = MetadataMgr.create(sframeChan);
sframeChan.on('EV_RT_DISCONNECT', function () {
isReady = false;
onConnectionChange({ state: false });

@ -50,19 +50,9 @@ define(['jquery'], function ($) {
cb = cb || $.noop;
if (newTitle === exp.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = exp.title;
Common.setPadTitleInDrive(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
updateLocalTitle(oldTitle);
return void cb(err);
}
metadataMgr.updateTitle(newTitle);
//onLocal();
cb(null, data);
if (!$title) { return; }
});
//var oldTitle = exp.title;
Common.updateTitle(newTitle, cb)
//cb(null, newTitle);
};
// TODO not needed?

@ -2,9 +2,10 @@ define([
'/bower_components/nthen/index.js',
'/common/sframe-chainpad-netflux-inner.js',
'/common/sframe-channel.js',
'/common/sframe-common-title.js'
'/common/sframe-common-title.js',
'/common/metadata-manager.js',
], function (nThen, CpNfInner, SFrameChannel, Title) {
], function (nThen, CpNfInner, SFrameChannel, Title, MetadataMgr) {
// Chainpad Netflux Inner
var funcs = {};
@ -13,6 +14,7 @@ define([
funcs.startRealtime = function (options) {
if (ctx.cpNfInner) { return ctx.cpNfInner; }
options.sframeChan = ctx.sframeChan;
options.metadataMgr = ctx.metadataMgr;
ctx.cpNfInner = CpNfInner.start(options);
ctx.cpNfInner.metadataMgr.onChangeLazy(options.onLocal);
return ctx.cpNfInner;
@ -23,10 +25,10 @@ define([
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
};
funcs.setPadTitleInDrive = function (title, cb) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (cb) { cb(err, title); }
});
var titleUpdated;
funcs.updateTitle = function (title, cb) {
ctx.metadataMgr.updateTitle(title);
titleUpdated = cb;
};
// Title module
@ -49,6 +51,13 @@ define([
SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; }));
// CpNfInner.start() should be here....
}).nThen(function () {
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
ctx.metadataMgr.onTitleChange(function (title) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (err) { return; }
if (titleUpdated) { titleUpdated(undefined, title); }
});
});
cb(funcs);
});
} };

@ -725,6 +725,7 @@ define([
realtimeOptions.onError = onConnectError;
var onLocal = realtimeOptions.onLocal = function () {
console.log('onlocal');
if (initializing) { return; }
if (isHistoryMode) { return; }
if (readOnly) { return; }

Loading…
Cancel
Save