6 'remoto!stdlib:js/include/utils.js',
50 for (var i in this._objects)
51 for (var j=0;j<this._objects[i].length;j++)
52 if (this._objects[i][j].
detach)
53 this._objects[i][j].detach();
74 console.log(
"objects", this._objects );
75 console.log(
"definitions", _definitions );
76 console.log(
"loaders", _loaders );
77 console.log(
"reads", this._reads );
78 console.log(
"metadata", this._metadatas );
98 var forceSubscribe =
false;
102 if (!this._objects[
id])
103 { this._objects[
id] = [];
107 if (!this._objects[
id].includes(o))
108 this._objects[
id].push(o);
115 if (!nosubscribe || forceSubscribe)
135 var forceUnsubscribe =
false;
139 if (!this._objects[
id])
142 console.warn(
"Registered object with id \""+
id+
"\" does not exist.",o);
146 var i = this._objects[
id].indexOf(o);
150 var b = this._objects[
id].splice(i,1);
156 if (this._objects[
id].length === 0)
157 {
delete this._objects[
id];
165 if (!nounsubscribe || forceUnsubscribe)
189 var requested =
true;
193 if (!this._reads[
id])
194 { this._reads[
id] = [];
198 this._reads[
id].push(o);
201 if (this.pathReadCallback)
202 this.pathReadCallback([
id]);
223 var requested =
true;
227 if (!this._reads[
id])
228 { this._reads[
id] = [];
232 this._reads[
id].push(o);
235 if (this.pathReadSingleCallback)
236 this.pathReadSingleCallback(
id,
metadata);
256 var requested =
true;
260 if (!this._metadatas[
id])
261 { this._metadatas[
id] = [];
265 this._metadatas[
id].push(o);
268 if (this.pathMetadataCallback)
269 this.pathMetadataCallback([
id]);
285 if (this._objects[
id])
286 if (this._objects[
id].indexOf(
object) > -1)
306 pathReadCallback:
null,
307 pathMetadataCallback:
null,
323 var l = Object.keys(this._objects);
355 var o = this._objects[
id];
356 o = o ? o.slice(0) :
null;
366 for (var i=0;i<o.length;i++)
367 if (
"applyDiff" in o[i])
372 if (diff !==
null && Object.keys(diff).length == 1 && (
"mounted" in diff))
374 if (
"mounted" in o[i])
375 o[i].mounted(diff.mounted)
380 o[i].applyDiff(diff,
user);
392 { console.error(
"Object in registry doesn't have an applyDiff function!",
id,o[i]);
434 var o1 = this._objects[
id];
435 var o = o1 ? o1.slice(0) :
null;
439 context.sourcepath =
id;
444 for (var i=0;i<o.length;i++)
446 if (
"applySubscription" in o[i])
449 o[i].applySubscription(data,
metadata);
453 else if (
"applyDiff" in o[i])
454 o[i].applyDiff(data,
null);
456 { console.error(
"Object in registry doesn't have an applySubscription or applyDiff function!");
465 console.error(
"Non-registered path: "+
id,arguments);
490 var o = this._reads[
id];
491 delete this._reads[
id];
495 for (var i=0;i<o.length;i++)
497 if (
"applyRead" in o[i])
502 { console.error(
"Object in registry doesn't have an applyRead function!");
511 console.error(
"Non-registered path: "+
id,arguments);
535 var o = this._metadatas[
id];
536 delete this._metadatas[
id];
540 for (var i=0;i<o.length;i++)
542 if (
"applyMetadata" in o[i])
547 { console.error(
"Object in registry doesn't have an applyMetadata function!");
556 console.error(
"Non-registered metadata path: "+
id,arguments,o);
561 console.trace(
"returning false");
579 var o = this._objects[
id];
583 for (var i=0;i<o.length;i++)
585 if (
"applyRequestLock" in o[i])
587 o[i].applyRequestLock(data);
590 { console.error(
"Object in registry doesn't have an applyRequestLock function!");
599 console.error(
"Non-registered path: "+
id,arguments);
621 var o = this._objects[
id];
625 for (var i=0;i<o.length;i++)
627 if (
"applyReleaseLock" in o[i])
629 o[i].applyReleaseLock(data);
632 { console.error(
"Object in registry doesn't have an applyReleaseLock function!");
641 console.error(
"Non-registered path: "+
id,arguments);
672 case "unsubscribe": o = this._objects[
id];
break;
674 case "read": o = this._reads[
id];
break;
676 case "metadata": o = this._metadatas[
id];
break;
678 default: console.error(
"unsupported applyRequestError command: "+command);
684 for (var i=0;i<o.length;i++)
686 if (
"applyRequestError" in o[i])
688 o[i].applyRequestError(command,
id,reason);
691 { console.error(
"Object '"+
id+
"' in registry doesn't have an applyRequestError function!",o[i]);
694 var commandUP = command.charAt(0).toUpperCase() + command.slice(1);
695 modal.alert( reason,
null, commandUP+
" Error" );
706 case "unsubscribe":
delete this._objects[
id];
break;
708 case "read":
delete this._reads[
id];
break;
710 case "metadata":
delete this._metadatas[
id];
break;
732 var o = this._objects[
id];
736 for (var i=0;i<o.length;i++)
738 if (
"applyRequestSuccess" in o[i])
740 o[i].applyRequestSuccess(command,
id,data,
metadata);
743 { console.error(
"Object '"+
id+
"' in registry doesn't have an applyRequestSuccess function!");
745 modal.alert(
"no applyRequestSuccess function!",
null, command+
" success error" );
755 console.error(
"applyRequestSuccess Non-registered path: "+
id,arguments);
756 console.log(this._objects);
778 var o = this._objects[
id];
786 for (var i=0;i<o.length;i++)
788 if (o[i] instanceof
type)
791 if (o[i]._object instanceof
type)
824 if (typeof base ==
"string")
828 if (!
utils.
isArray(extender) && typeof extender ==
'object' && extender !==
null)
833 if ((
'value' in base) && !(
'value' in extender))
842 for (var a in extender)
853 if (typeof base[a] ==
'object')
857 base[a] = extender[a];
861 {
if (
'value' in base)
862 base[
"value"] = extender;
870 var _definitions = {};
892 basePath = basePath ||
"";
895 this._strict = !!strict;
946 if (!(
path in _definitions))
972 if (!(
path in _loaders))
975 _loaders[
path].enqueue( data, callback );
993 _definitions[
path ] = data;
1030 if (definition ===
null)
1034 if (!
utils.
isArray(values) && typeof values ==
'object')
1035 {
for (var a in values)
1038 var aa = a.split(
'.');
1049 if (!(a in definition) && (
'value' in definition) && (typeof definition[
'value'] ==
'object'))
1051 if (a.split(
'.',2)[0] in definition[
'value'])
1054 definition[
'value'] = this.
applyValues( v, definition[
'value'] );
1056 else if (typeof definition[a] ==
'object')
1057 definition[a] = this.
applyValues( v, definition[a] );
1063 {
if (
'value' in definition)
1064 definition[
'value'] = values;
1096 this._factory = factory;
1098 this._callbacks = [ { data:data, callback:callback } ];
1099 this._subscribed =
false;
1105 _objectRegistry.readPath(
path,
this );
1107 this._timeout = setTimeout( this.
timeout.bind(
this), 60000 );
1127 { clearTimeout( this._timeout );
1128 this._timeout =
null;
1132 delete _loaders[this._path];
1134 this._factory =
null;
1135 this._callbacks = [];
1148 console.warn(
"Timeout on "+this._path );
1181 if (this._subscribed)
1182 { console.warn(
"already subscribed: "+this._path)
1186 this._subscribed =
true;
1188 if (!this._callbacks.length)
1189 { console.error(
"objectLoaderLoader has no callbacks... don't know what to do with the subscription!");
1193 var base = data.base;
1196 this._factory.fetchDefinition( base, data, this.
loaded.bind(
this) );
1211 enqueue:
function(data,callback)
1213 this._callbacks.push( { data:data, callback:callback } );
1227 this._factory.loadedDefinition( this._path, data );
1232 for (var i=0;i<this._callbacks.length;i++)
1233 { var c = this._callbacks[i];
1235 c.callback( this._factory.applyDefinition(
this._path, c.data) );
1259 if (this._callbacks.length)
1261 var c = this._callbacks.shift();
1263 c.callback( this._factory.applyDefinition(
this._path, c.data ) );
1266 if (this._callbacks.length)
1278 return _objectRegistry;
applySubscription(data, metadata)
getter id
returns the number of milliseconds since midnight January 1, 1970 UTC
extendDefinition(extender, base, strict)
setter type
a setter DOCME
loadDefinition(path, data, callback)
Create an objectLoaderLoader for a requested path.
applyValues(values, definition)
fetchDefinition(path, data, callback)
Read data from a VFS path, and apply the loaded contents to a JSON object as a diff.
objectLoader(basePath, strict)
loadedDefinition(path, data)
applyDefinition(path, data)
objectLoaderLoader(factory, path, data, callback)
metadataPath(id, o)
Request metadata for a given path.
find(id, type)
Find a registered object, optionally by type.
applyRequestError(command, id, reason)
readPath(id, o)
Request a read on a given path.
applyMetadata(id, metadata)
readSinglePath(id, o, metadata)
Request a read on a given path, and send metadata.
printRegistry()
Print the contents of the registry to the console.
applyReleaseLock(id, data)
applyRead(id, data, metadata)
registerObject(id, o, nosubscribe)
Register an object in the registry, and call the pathAddedCallback.
applyRequestLock(id, data)
unregisterObject(id, o, silent, nounsubscribe, now)
Unregister an object from the registry.
detach()
Detach the tab's children.
pathAddedCallback()
DOCME.
pathRemovedCallback()
DOCME.
getter path
a getter DOCME
applyRequestSuccess()
If an adminstrator has deleted his own preferences, this function will be called on success.
Utility functions for javascript clients.
cleanPath(path)
Clean and normalize a resource path.
fileNameFromPath(p, orDirIfNeeded)
Retrieve the last part of a file path.
copyObject(source, dest)
Create a deep copy of a JSON object, extending the destination object recursively.
isArray(a)
Determine if an object is a javascript array.
dirNameFromPath(p)
Retrieve the directory portion of a path.