1 | internalUrl = /^([A-z0-9-_]+)(:[A-z0-9-_]+)?$/;
|
---|
2 | internalUri = /^([a-zA-Z0-9-_]+)\(([a-zA-Z0-9-_]+)\):\/\/(.*)|([a-zA-Z0-9-_]+):\/\/(.*)$/;
|
---|
3 | isGeneratedId = /^\d+\(javascript\)$/;
|
---|
4 | arrayName = /^([A-z0-9-_]+)\[\]$/;
|
---|
5 | startsDoubleDot = /^:/;
|
---|
6 | // cached_urls = {};
|
---|
7 |
|
---|
8 | $.ajaxPrefilter(function( options, originalOptions, jqXHR ){
|
---|
9 |
|
---|
10 | if( options.url != 'undefined' && internalUrl.test( options.url ) ){
|
---|
11 |
|
---|
12 | // if( !cached_urls[options.url] )
|
---|
13 | // return;
|
---|
14 | // alert( options.url + " dentro" );
|
---|
15 | jqXHR.abort();
|
---|
16 |
|
---|
17 | var callback = ( options.success || options.complete || $.noop );
|
---|
18 |
|
---|
19 | switch( options.type.toUpperCase() )
|
---|
20 | {
|
---|
21 | case 'GET':
|
---|
22 | return callback( DataLayer.get( options.url, /*false,*/ options.data ) );
|
---|
23 |
|
---|
24 | case 'POST':
|
---|
25 | return callback( DataLayer.put( options.url, options.data ) );
|
---|
26 | }
|
---|
27 |
|
---|
28 | //return( false );
|
---|
29 |
|
---|
30 | // options.url = params[1];
|
---|
31 | // options.data = ( options.data || "" ) + "&" + params[2];
|
---|
32 | }
|
---|
33 |
|
---|
34 | });
|
---|
35 |
|
---|
36 | // $("a").live("click", function( event ){
|
---|
37 | //
|
---|
38 | // event.preventDefault();
|
---|
39 | //
|
---|
40 | // $.ajax({
|
---|
41 | //
|
---|
42 | //
|
---|
43 | //
|
---|
44 | // });
|
---|
45 | //
|
---|
46 | // });
|
---|
47 |
|
---|
48 | $("form").live( "submit", function( event ){
|
---|
49 |
|
---|
50 | var action = $(this).attr("action"), res = false;
|
---|
51 |
|
---|
52 | if( res = internalUrl.exec( action ) )
|
---|
53 | {
|
---|
54 | event.preventDefault();
|
---|
55 |
|
---|
56 | var data = DataLayer.form( this );
|
---|
57 | DataLayer.put( res[1], data );
|
---|
58 |
|
---|
59 | return( false );
|
---|
60 | }
|
---|
61 |
|
---|
62 | return( true );
|
---|
63 | });
|
---|
64 |
|
---|
65 | $.storage = new $.store();
|
---|
66 |
|
---|
67 | DataLayer = {
|
---|
68 |
|
---|
69 | links: {},
|
---|
70 | concepts: {},
|
---|
71 | listeners: {},
|
---|
72 | encoders: {},
|
---|
73 | decoders: {},
|
---|
74 | templates: {},
|
---|
75 | criterias: {},
|
---|
76 | tasks: [],
|
---|
77 |
|
---|
78 | render: function( templateName, data, filter, formatter, force ){
|
---|
79 |
|
---|
80 | if( $.isFunction( filter ) )
|
---|
81 | {
|
---|
82 | force = formatter;
|
---|
83 | formatter = filter;
|
---|
84 | filter = false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | if( typeof data === "string" )
|
---|
88 | {
|
---|
89 | data = this.get( data, filter, force ) || {};
|
---|
90 | }
|
---|
91 |
|
---|
92 | var formatting = function( template ){
|
---|
93 |
|
---|
94 | if( template === false ) return( false );
|
---|
95 |
|
---|
96 | if( template )
|
---|
97 | DataLayer.templates[ templateName ] = new EJS({ text: template, cache: false });
|
---|
98 |
|
---|
99 | var html = DataLayer.templates[ templateName ].render( { data: data } );
|
---|
100 |
|
---|
101 | if( !formatter )
|
---|
102 | return( html );
|
---|
103 |
|
---|
104 | return formatter( html );
|
---|
105 | }
|
---|
106 |
|
---|
107 | if( this.templates[ templateName ] )
|
---|
108 | {
|
---|
109 | return formatting();
|
---|
110 | }
|
---|
111 |
|
---|
112 | return this.send( DataLayer.templatePath + templateName, 'get', false, formatting, !!!formatter );
|
---|
113 | },
|
---|
114 |
|
---|
115 | send: function( url, type, data, callback, sync ){
|
---|
116 |
|
---|
117 | var result = false, fired = false;
|
---|
118 |
|
---|
119 | var envelope = {
|
---|
120 |
|
---|
121 | 'async': ( typeof sync !== "undefined" ? !sync : !!callback ),
|
---|
122 | 'url': url,
|
---|
123 | 'success': function( dt, textStatus, jqXHR ){
|
---|
124 |
|
---|
125 | if( callback )
|
---|
126 | {
|
---|
127 | fired = true;
|
---|
128 | result = callback( dt, textStatus, jqXHR );
|
---|
129 | }
|
---|
130 | else
|
---|
131 | result = dt;
|
---|
132 |
|
---|
133 | },
|
---|
134 | 'complete': function( jqXHR, textStatus ){
|
---|
135 |
|
---|
136 | if( !fired && callback )
|
---|
137 | result = callback( false, textStatus, jqXHR );
|
---|
138 |
|
---|
139 | },
|
---|
140 |
|
---|
141 | 'type': $.isArray( type ) ? type[0] : type,
|
---|
142 | 'data': data
|
---|
143 |
|
---|
144 | };
|
---|
145 |
|
---|
146 | if( $.isArray( type ) && type[1] )
|
---|
147 | envelope['dataType'] = type[1];
|
---|
148 |
|
---|
149 | $.ajax( envelope );
|
---|
150 |
|
---|
151 | return( result );
|
---|
152 | },
|
---|
153 |
|
---|
154 | dispatch: function( dispatcher, data, callback, isPost ){
|
---|
155 |
|
---|
156 | return this.send( this.dispatchPath + dispatcher + ".php",
|
---|
157 | [ ( isPost ? 'post' : 'get' ), 'json' ],
|
---|
158 | data,
|
---|
159 | callback );
|
---|
160 |
|
---|
161 | // $.ajax({
|
---|
162 | // 'async': !!callback,
|
---|
163 | // 'url': this.dispatchPath + dispatcher + ".php",
|
---|
164 | // 'type': ( isPost ? 'post' : 'get' ),
|
---|
165 | // 'dataType': 'json',
|
---|
166 | // 'data': data,
|
---|
167 | // 'success': function( dt, textStatus, jqXHR ){
|
---|
168 | //
|
---|
169 | // if( callback )
|
---|
170 | // {
|
---|
171 | // fired = true;
|
---|
172 | // callback( dt, textStatus, jqXHR );
|
---|
173 | // }
|
---|
174 | // else
|
---|
175 | // result = dt;
|
---|
176 | //
|
---|
177 | // },
|
---|
178 | // 'complete': function( jqXHR, textStatus ){
|
---|
179 | //
|
---|
180 | // if( !fired && callback )
|
---|
181 | // callback( false, textStatus, jqXHR );
|
---|
182 | //
|
---|
183 | // }/*,
|
---|
184 | // 'processData': false*/
|
---|
185 | // });
|
---|
186 |
|
---|
187 | //return( result );
|
---|
188 | },
|
---|
189 |
|
---|
190 | form: function( target ){
|
---|
191 |
|
---|
192 | var params = {}, $this = $(target);
|
---|
193 |
|
---|
194 | if( !$this.is( "form" ) )
|
---|
195 | $this = $this.parents( "form" );
|
---|
196 |
|
---|
197 | $.each( $this.serializeArray(), function( i, el ){
|
---|
198 |
|
---|
199 | if( newName = arrayName.exec( el.name ) )
|
---|
200 | el.name = newName[1];
|
---|
201 | else if( !params[ el.name ] )
|
---|
202 | return( params[ el.name ] = el.value );
|
---|
203 |
|
---|
204 | params[ el.name ] = params[ el.name ] || [];
|
---|
205 |
|
---|
206 | if( $.type(params[ el.name ]) !== "array" )
|
---|
207 | params[ el.name ] = [ params[ el.name ] ];
|
---|
208 |
|
---|
209 | params[ el.name ].push( el.value );
|
---|
210 | });
|
---|
211 |
|
---|
212 | // alert(dump(params));
|
---|
213 |
|
---|
214 | return this.decode( $this.attr( "action" ), params );
|
---|
215 | },
|
---|
216 |
|
---|
217 | blend: function( action, data ){
|
---|
218 |
|
---|
219 | // if( notArray = (!$.isArray(data)) )
|
---|
220 | // data = [ data ];
|
---|
221 |
|
---|
222 | var form = $('form[action="'+action+'"]');
|
---|
223 |
|
---|
224 | form.get(0).reset();
|
---|
225 |
|
---|
226 | var named = form.find( 'input[name]' );
|
---|
227 |
|
---|
228 | for( var name in data )
|
---|
229 | {
|
---|
230 | named.filter( '[name="'+name+'"]' ).val( data[name] );
|
---|
231 | }
|
---|
232 | },
|
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|
236 | put: function( concept, filter, data, oneSide ){
|
---|
237 |
|
---|
238 | ///////////////////////////// normalize ////////////////////////////////
|
---|
239 | if( arguments.length == 2 )
|
---|
240 | {
|
---|
241 | data = filter;
|
---|
242 | filter = false;
|
---|
243 | }
|
---|
244 | if( typeof data === "undefined" ||
|
---|
245 | $.type(data) === "boolean" )
|
---|
246 | {
|
---|
247 | oneSide = data;
|
---|
248 | data = filter;
|
---|
249 | filter = false;
|
---|
250 | }
|
---|
251 |
|
---|
252 | if( !concept || !data )
|
---|
253 | return( false );
|
---|
254 |
|
---|
255 | var decoder = "", id = false, bothSides = (typeof oneSide === "undefined"), notArray, res;
|
---|
256 |
|
---|
257 | if( $.type(filter) === "string" )
|
---|
258 | {
|
---|
259 | id = filter;
|
---|
260 | filter = false;
|
---|
261 | }
|
---|
262 |
|
---|
263 | if( id )
|
---|
264 | data.id = id;
|
---|
265 |
|
---|
266 | if( notArray = ( $.type( data ) !== "array" ) )
|
---|
267 | data = [ data ];
|
---|
268 |
|
---|
269 | if( res = internalUrl.exec( concept ) )
|
---|
270 | {
|
---|
271 | //TODO: verificar se a decodificaçao deve ser feita em cada item do array
|
---|
272 | data = this.decode( concept, data );
|
---|
273 | concept = res[1];
|
---|
274 | decoder = res[2];
|
---|
275 | }
|
---|
276 |
|
---|
277 | ////////////////////////////////////////////////////////////////////////
|
---|
278 |
|
---|
279 | if( bothSides || !oneSide )
|
---|
280 | {
|
---|
281 | var result = false, links = this.links( concept ),
|
---|
282 | current = this.check( concept ) || {}, ids = [];
|
---|
283 |
|
---|
284 | for( var i = 0; i < data.length; i++ )
|
---|
285 | {
|
---|
286 | var key = ids[ ids.length ] = data[i].id || this.generateId( concept ), updateSet = {};
|
---|
287 |
|
---|
288 | ////////////////////////////// linkage /////////////////////////////////
|
---|
289 | for( var link in links )
|
---|
290 | {
|
---|
291 | if( data[i][link] )
|
---|
292 | {
|
---|
293 | var isConcept = false;
|
---|
294 |
|
---|
295 | if( isConcept = this.isConcept( concept, link ) )
|
---|
296 | data[i][link] = [ data[i][link] ];
|
---|
297 |
|
---|
298 | var _this = this;
|
---|
299 |
|
---|
300 | $.each( data[i][link], function( ii, el ){
|
---|
301 |
|
---|
302 | var isRef = false
|
---|
303 |
|
---|
304 | if( isRef = ($.type(el) === "string") )
|
---|
305 | el = { id: el };
|
---|
306 |
|
---|
307 | var nestedLinks = _this.links( links[link], true );
|
---|
308 |
|
---|
309 | if( isConcept )
|
---|
310 | {
|
---|
311 | el[ nestedLinks[concept] ] = el[ nestedLinks[concept] ] || [];
|
---|
312 | el[ nestedLinks[concept] ].push( key );
|
---|
313 | }
|
---|
314 | else
|
---|
315 | el[ nestedLinks[concept] ] = key;
|
---|
316 |
|
---|
317 | if( isRef && ( !current[ key ] || !current[ key ][ link ] ||
|
---|
318 | (isConcept ? current[ key ][ link ] !== el.id : !$.inArray( el.id, current[ key ][ link ] )) ) )
|
---|
319 | {
|
---|
320 | updateSet[ links[link] ] = updateSet[ links[link] ] || [];
|
---|
321 | updateSet[ links[link] ].push( el );
|
---|
322 | }
|
---|
323 | else if( !isRef )
|
---|
324 | data[i][link][ii] = _this.put( links[link], el, oneSide );
|
---|
325 | });
|
---|
326 |
|
---|
327 | if( isConcept )
|
---|
328 | data[i][link] = data[i][link][0];
|
---|
329 | }
|
---|
330 | }
|
---|
331 | //////////////////////////////////////////////////////////////////////////
|
---|
332 |
|
---|
333 | if( data[i].id )
|
---|
334 | data[i] = this.merge( concept, current[ data[i].id ], data[i] );
|
---|
335 |
|
---|
336 | current[ key ] = data[i];
|
---|
337 |
|
---|
338 | if( bothSides )
|
---|
339 | this.report( concept, key, data[i] );
|
---|
340 | }
|
---|
341 |
|
---|
342 | this.store( concept, current );
|
---|
343 |
|
---|
344 | for( var setKey in updateSet )
|
---|
345 | {
|
---|
346 | DataLayer.put( setKey, updateSet[ setKey ], false );
|
---|
347 |
|
---|
348 | if( bothSides )
|
---|
349 | for( var i = 0; i < updateSet[ setKey ].length; i++ )
|
---|
350 | this.report( setKey, updateSet[ setKey ][i].id, updateSet[ setKey ][i] );
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | if( oneSide )
|
---|
355 | this.commit( concept, ids/*, true */);
|
---|
356 |
|
---|
357 | this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', true );
|
---|
358 |
|
---|
359 | return( notArray ? ids[0] : ids );
|
---|
360 |
|
---|
361 | },
|
---|
362 |
|
---|
363 | remove: function( concept, id, oneSide ){
|
---|
364 |
|
---|
365 | var bothSides = (typeof oneSide === "undefined");
|
---|
366 |
|
---|
367 | if( bothSides || !oneSide )
|
---|
368 | this.del( concept, id );
|
---|
369 |
|
---|
370 | if( bothSides )
|
---|
371 | this.report( concept, id, false );
|
---|
372 | if( oneSide )
|
---|
373 | this.commit( concept, id );
|
---|
374 |
|
---|
375 | this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false );
|
---|
376 | },
|
---|
377 |
|
---|
378 | report: function( concept, id, data )
|
---|
379 | {
|
---|
380 | var current = this.check( ':current', concept ) || {};
|
---|
381 |
|
---|
382 | if( !current[ id ] )
|
---|
383 | current[ id ] = this.check( concept, id ) || {};
|
---|
384 |
|
---|
385 | this.store( ':current', concept, current );
|
---|
386 |
|
---|
387 | var diff = this.diff( current[ id ], data );
|
---|
388 |
|
---|
389 | var diffs = this.check( ':diff', concept ) || {};
|
---|
390 |
|
---|
391 | diffs[ id ] = diff;
|
---|
392 |
|
---|
393 | this.store( ':diff', concept, diffs );
|
---|
394 | },
|
---|
395 |
|
---|
396 | // enqueue: function( queueName, concept, id, data ){
|
---|
397 | //
|
---|
398 | // var queue = this.check( ':' + queueName, concept ) || {};
|
---|
399 | //
|
---|
400 | //
|
---|
401 | // },
|
---|
402 | //
|
---|
403 | // dequeue: function( queueName, concept, id ){
|
---|
404 | //
|
---|
405 | //
|
---|
406 | //
|
---|
407 | // },
|
---|
408 |
|
---|
409 |
|
---|
410 |
|
---|
411 | rollback: function( concept, ids ){
|
---|
412 |
|
---|
413 | var queue = this.prepareQ( 'current', concept, ids );
|
---|
414 |
|
---|
415 | ids = [];
|
---|
416 |
|
---|
417 | for( var id in queue )
|
---|
418 | {
|
---|
419 | this.put( concept, id, queue[id], false );
|
---|
420 |
|
---|
421 | ids[ ids.length ] = id;
|
---|
422 | }
|
---|
423 |
|
---|
424 | this.clearQ( concept, ( ids.length ? ids : false ) );
|
---|
425 |
|
---|
426 | this.broadcast( concept, 'revert' );
|
---|
427 |
|
---|
428 | },
|
---|
429 |
|
---|
430 | prepareQ: function( queueName, concept, ids ){
|
---|
431 |
|
---|
432 | if( notArray = ($.type(concept) !== "array") )
|
---|
433 | concept = [ concept ];
|
---|
434 |
|
---|
435 | for( var i = 0; i < concept.length; i++ )
|
---|
436 | {
|
---|
437 | var queue = this.check( ':' + queueName, concept[i] || false );
|
---|
438 |
|
---|
439 | if( ids )
|
---|
440 | {
|
---|
441 | if( $.type(ids) !== "array" )
|
---|
442 | ids = [ ids ];
|
---|
443 |
|
---|
444 | var filtered = {};
|
---|
445 |
|
---|
446 | for( var ii = 0; ii < ids.length; ii++ )
|
---|
447 | {
|
---|
448 | filtered[ ids[ii] ] = queue[ ids[ii] ];
|
---|
449 | }
|
---|
450 |
|
---|
451 | queue = filtered;
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | return( queue );
|
---|
456 | },
|
---|
457 |
|
---|
458 | clearQ: function( concept, ids ){
|
---|
459 |
|
---|
460 | var current = this.check( ':current', concept || false );
|
---|
461 | var diffs = this.check( ':diff', concept || false );
|
---|
462 |
|
---|
463 | if( !ids )
|
---|
464 | current = diffs = {};
|
---|
465 | else
|
---|
466 | {
|
---|
467 | if( notArray = ($.type(ids) !== "array") )
|
---|
468 | ids = [ ids ];
|
---|
469 |
|
---|
470 | for( var i = 0; i < ids.length; i++ )
|
---|
471 | {
|
---|
472 | delete current[ ids[i] ];
|
---|
473 | delete diffs[ ids[i] ];
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | this.store( ':current', concept, current );
|
---|
478 | this.store( ':diff', concept, diffs );
|
---|
479 | },
|
---|
480 |
|
---|
481 | commit: function( concept, ids, callback ){
|
---|
482 |
|
---|
483 | var queue = this.prepareQ( 'diff', concept, ids );
|
---|
484 |
|
---|
485 | this.sync( queue, concept || false, callback );
|
---|
486 | },
|
---|
487 |
|
---|
488 | sync: function( queue, concept, callback ){
|
---|
489 |
|
---|
490 | if( !queue || $.isEmptyObject( queue ) )
|
---|
491 | return;
|
---|
492 |
|
---|
493 | if( concept )
|
---|
494 | {
|
---|
495 | var helper = {};
|
---|
496 | helper[concept] = queue;
|
---|
497 | queue = helper;
|
---|
498 | }
|
---|
499 |
|
---|
500 | var data = {}, URIs = {};
|
---|
501 |
|
---|
502 | for( var concept in queue )
|
---|
503 | for( var id in queue[concept] )
|
---|
504 | {
|
---|
505 | data[ this.URI( concept, id ) ] = queue[concept][id];
|
---|
506 | URIs[ this.URI( concept, id ) ] = { concept: concept, id: id };
|
---|
507 | }
|
---|
508 |
|
---|
509 | if( $.isEmptyObject( data ) )
|
---|
510 | return;
|
---|
511 |
|
---|
512 | this.dispatch( "Sync", data, function( data, status, jqXHR ){
|
---|
513 |
|
---|
514 | // switch( status )
|
---|
515 | // {
|
---|
516 | // case "error":
|
---|
517 | // case "parsererror":
|
---|
518 | // return DataLayer.rollback( concept, URI );
|
---|
519 | // case "success":
|
---|
520 | // return DataLayer.commit();
|
---|
521 | // case "timeout":
|
---|
522 | // case "notmodified":
|
---|
523 | // }
|
---|
524 |
|
---|
525 | for( var URI in data )
|
---|
526 | {
|
---|
527 | var parsed = DataLayer.parseURI( URI ),
|
---|
528 |
|
---|
529 | concept = parsed[1], id = parsed[3];
|
---|
530 |
|
---|
531 | if( $.type(data[URI]) === "string" )
|
---|
532 | {
|
---|
533 | //TODO:threat the exception thrown
|
---|
534 | DataLayer.rollback( concept, id );
|
---|
535 | delete URIs[ URI ];
|
---|
536 | continue;
|
---|
537 | }
|
---|
538 |
|
---|
539 | if( data[URI] === false ){
|
---|
540 | DataLayer.remove( concept, id, false );
|
---|
541 | continue;
|
---|
542 | }
|
---|
543 |
|
---|
544 | if( id !== data[URI].id )
|
---|
545 | DataLayer.move( concept, id, data[URI].id );
|
---|
546 |
|
---|
547 | DataLayer.put( concept, id, data[URI], false );
|
---|
548 | }
|
---|
549 |
|
---|
550 | for( var URI in URIs )
|
---|
551 | DataLayer.clearQ( URIs[URI].concept, URIs[URI].id );
|
---|
552 |
|
---|
553 | if( callback )
|
---|
554 | callback();
|
---|
555 |
|
---|
556 | }, true );
|
---|
557 |
|
---|
558 | },
|
---|
559 |
|
---|
560 | receive: function( concept, data ){
|
---|
561 |
|
---|
562 | this.put( concept, data, false );
|
---|
563 |
|
---|
564 | // if( typeof data.URI === "undefined" )
|
---|
565 | // {
|
---|
566 | // URI = this.add( concept, data, oneSide );
|
---|
567 | // }
|
---|
568 | // else if( data.URI === false )
|
---|
569 | // {
|
---|
570 | // status = this.remove( concept, URI, oneSide );
|
---|
571 | // }
|
---|
572 | // else
|
---|
573 | // {
|
---|
574 | // status = this.set( concept, URI, data, oneSide );
|
---|
575 | // }
|
---|
576 | //
|
---|
577 | // if( URI && data.URI && URI !== data.URI )
|
---|
578 | // this.move( concept, URI, data.URI );
|
---|
579 |
|
---|
580 |
|
---|
581 | },
|
---|
582 |
|
---|
583 |
|
---|
584 |
|
---|
585 | merge: function( concept, current, data ){
|
---|
586 |
|
---|
587 | return $.extend( current, data );
|
---|
588 |
|
---|
589 | },
|
---|
590 |
|
---|
591 | diff: function( base, toDiff ){
|
---|
592 |
|
---|
593 | // var df = toDiff;
|
---|
594 | //
|
---|
595 | // for( var key in base ){
|
---|
596 | //
|
---|
597 | // if( base[key] === df[key] )
|
---|
598 | // delete df[key];
|
---|
599 | //
|
---|
600 | //
|
---|
601 | // }
|
---|
602 | if( toDiff === false )
|
---|
603 | return( false );
|
---|
604 |
|
---|
605 | var toDiff = $.extend( {}, toDiff );
|
---|
606 |
|
---|
607 | if( isGeneratedId.test( toDiff.id ) )
|
---|
608 | delete toDiff['id'];
|
---|
609 |
|
---|
610 | return( toDiff );
|
---|
611 |
|
---|
612 | },
|
---|
613 |
|
---|
614 | links: function( concept, reverse ){
|
---|
615 |
|
---|
616 | if( !this.links[ concept ] )
|
---|
617 | {
|
---|
618 | var result = this.dispatch( "links", { concept: concept } ) || false;
|
---|
619 |
|
---|
620 | if( !result )
|
---|
621 | return( false );
|
---|
622 |
|
---|
623 | this.concepts[ concept ] = $.extend( this.concepts[ concept ] || {},
|
---|
624 | result['concepts'] || {} );
|
---|
625 |
|
---|
626 | this.links[ concept ] = result['links'] || {};
|
---|
627 | }
|
---|
628 |
|
---|
629 | if( reverse )
|
---|
630 | {
|
---|
631 | var reverted = {}, llinks = this.links[ concept ];
|
---|
632 |
|
---|
633 | for( var key in llinks )
|
---|
634 | reverted[ llinks[key] ] = key;
|
---|
635 |
|
---|
636 | return( reverted );
|
---|
637 | }
|
---|
638 |
|
---|
639 | return( this.links[ concept ] );
|
---|
640 |
|
---|
641 | },
|
---|
642 |
|
---|
643 | isConcept: function( concept, attr ){
|
---|
644 |
|
---|
645 | if( typeof this.concepts[concept] === "undefined" )
|
---|
646 | {
|
---|
647 | this.links( concept );
|
---|
648 | }
|
---|
649 |
|
---|
650 | return !!this.concepts[ concept ][ attr ];
|
---|
651 | },
|
---|
652 |
|
---|
653 | URI: function( concept, URI, context ){
|
---|
654 |
|
---|
655 | if( res = internalUrl.exec( concept ) )
|
---|
656 | concept = res[1];
|
---|
657 |
|
---|
658 | context = context ? "(" + context + ")" : "";
|
---|
659 |
|
---|
660 | if( URI )
|
---|
661 | return( concept + context + "://" + URI );
|
---|
662 | else
|
---|
663 | return( concept );
|
---|
664 |
|
---|
665 | },
|
---|
666 |
|
---|
667 | parseURI: function( URI ){
|
---|
668 |
|
---|
669 | return internalUri.exec( URI ) || false;
|
---|
670 |
|
---|
671 | },
|
---|
672 |
|
---|
673 |
|
---|
674 |
|
---|
675 |
|
---|
676 | generateId: function( concept ){
|
---|
677 |
|
---|
678 | var newId = this.counter + "(javascript)";
|
---|
679 |
|
---|
680 | this.store( ":counter", (this.counter++) + "" );
|
---|
681 |
|
---|
682 | return( newId );
|
---|
683 | },
|
---|
684 |
|
---|
685 |
|
---|
686 |
|
---|
687 |
|
---|
688 | get: function( concept, /*URI, */filter, oneSide ){
|
---|
689 |
|
---|
690 | ///////////////////////////// normalize ////////////////////////////////
|
---|
691 | if( arguments.length == 2 && $.type(filter) === "boolean" )
|
---|
692 | {
|
---|
693 | oneSide = filter;
|
---|
694 | filter = false;
|
---|
695 | }
|
---|
696 |
|
---|
697 | var encoder = false, id = false, bothSides = (typeof oneSide === 'undefined'), res;
|
---|
698 |
|
---|
699 | if( $.type(filter) === "string" )
|
---|
700 | {
|
---|
701 | id = filter;
|
---|
702 | filter = false;
|
---|
703 | }
|
---|
704 |
|
---|
705 | filter = filter || false;
|
---|
706 |
|
---|
707 | if( !concept )
|
---|
708 | return( false );
|
---|
709 |
|
---|
710 | if( res = internalUrl.exec( concept ) )
|
---|
711 | {
|
---|
712 | encoder = concept;
|
---|
713 | concept = res[1];
|
---|
714 |
|
---|
715 | if( filter )
|
---|
716 | filter = this.criteria( encoder, filter );
|
---|
717 | }
|
---|
718 |
|
---|
719 | if ( $.type(filter) === "array" )
|
---|
720 | {
|
---|
721 | filter = { filter: filter, criteria: false };
|
---|
722 | }
|
---|
723 |
|
---|
724 | //////////////////////////////////////////////////////////////////////////
|
---|
725 |
|
---|
726 | var result = false;
|
---|
727 |
|
---|
728 | if( bothSides || !oneSide )
|
---|
729 | result = this.check( concept, id || filter );
|
---|
730 |
|
---|
731 | if( !result && (bothSides || oneSide) )
|
---|
732 | {
|
---|
733 | result = this.request( concept, id || filter.filter, filter.criteria );
|
---|
734 |
|
---|
735 | if( result && bothSides )
|
---|
736 | {
|
---|
737 | var newResult = [];
|
---|
738 |
|
---|
739 | for( var i = 0; i < result.length; i++ )
|
---|
740 | newResult[i] = $.extend( {}, result[i] );
|
---|
741 |
|
---|
742 | this.put( concept, id, newResult, false );
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | if( /*result &&*/ encoder )
|
---|
747 | result = this.encode( encoder, result, filter ); //TODO: retirar o filtro no método encode
|
---|
748 |
|
---|
749 | return( result );
|
---|
750 | },
|
---|
751 |
|
---|
752 |
|
---|
753 | filter: function( base, filter ){
|
---|
754 |
|
---|
755 | var filtered = [];
|
---|
756 |
|
---|
757 | // var operator = filter.shift();
|
---|
758 |
|
---|
759 | /*for( var key in base )
|
---|
760 | {
|
---|
761 | switch( operator )
|
---|
762 | {
|
---|
763 | case 'AND':
|
---|
764 | for( var i = 0, current = true; i < filter.length && current; i++ )
|
---|
765 | current = this.compare( '&', current, this.compare( base[key], filter[i] ) );
|
---|
766 | break;
|
---|
767 | case 'OR':
|
---|
768 | for( var i = 0, current = false; i < filter.length && !current; i++ )
|
---|
769 | current = this.compare( '|', current, this.compare( base[key], filter[i] ) );
|
---|
770 | break;
|
---|
771 | case 'IN':
|
---|
772 | for( var i = 0, current = false; i < filter[1].length && !current; i++ )
|
---|
773 | current = this.compare( '|', current, this.compare( base[key], [ '=', filter[0], filter[1][i] ] ) );
|
---|
774 | break;
|
---|
775 | default : current = this.compare( operator, base[key], );
|
---|
776 | }
|
---|
777 | */
|
---|
778 | // if( !noGroup )
|
---|
779 | // for( var i = 0, current = original; i < filter.length && ( current === original ); i++ )
|
---|
780 | // current = this.compare( operator, current, this.compare( base[key], filter[i] ) );
|
---|
781 |
|
---|
782 | // if( current )
|
---|
783 | // filtered[ filtered.length ] = key;
|
---|
784 | // }
|
---|
785 |
|
---|
786 | return( filtered );
|
---|
787 | },
|
---|
788 |
|
---|
789 | compare: function( operator, base, test ){
|
---|
790 |
|
---|
791 | switch( operator )
|
---|
792 | {
|
---|
793 | case '*': return RegExp( "*" + base + "*" ).test( test );
|
---|
794 | case '^': return RegExp( "^" + base + "" ).test( test );
|
---|
795 | case '$': return RegExp( "" + base + "$" ).test( test );
|
---|
796 |
|
---|
797 | case '&': return ( base && test );
|
---|
798 | case '|': return ( base || test );
|
---|
799 |
|
---|
800 | case '=': return ( base == test );
|
---|
801 | case '<=': return ( base <= test );
|
---|
802 | case '>=': return ( base >= test );
|
---|
803 | case '>': return ( base < test );
|
---|
804 | case '<': return ( base > test );
|
---|
805 | }
|
---|
806 |
|
---|
807 | },
|
---|
808 |
|
---|
809 |
|
---|
810 | check: function( namespace, keys ){
|
---|
811 |
|
---|
812 | if( !namespace )
|
---|
813 | return( false );
|
---|
814 |
|
---|
815 | var result = $.storage.get( namespace );
|
---|
816 |
|
---|
817 | if( !keys || !result )
|
---|
818 | return( result || false );
|
---|
819 |
|
---|
820 | if( notArray = $.type(keys) === "string" )
|
---|
821 | keys = [ keys ];
|
---|
822 | else if( $.type(keys) !== "array" )
|
---|
823 | keys = this.filter( result, keys.filter );
|
---|
824 |
|
---|
825 | var res = [];
|
---|
826 |
|
---|
827 | for( var i = 0; i < keys.length; i++ )
|
---|
828 | res[ res.length ] = result[keys[i]];
|
---|
829 |
|
---|
830 | return( notArray ? res[0] || false : res.length ? res : false );
|
---|
831 | },
|
---|
832 |
|
---|
833 | store: function( namespace, key, data ){
|
---|
834 |
|
---|
835 | if( !data )
|
---|
836 | return $.storage.set( namespace, key );
|
---|
837 |
|
---|
838 | var res = this.check( namespace ) || {};
|
---|
839 |
|
---|
840 | res[key] = data;
|
---|
841 |
|
---|
842 | return $.storage.set( namespace, res );
|
---|
843 | },
|
---|
844 |
|
---|
845 | del: function( namespace, key ){
|
---|
846 |
|
---|
847 | if( !key )
|
---|
848 | return $.storage.del( namespace );
|
---|
849 |
|
---|
850 | var res = this.check( namespace ) || {};
|
---|
851 |
|
---|
852 | delete res[key];
|
---|
853 |
|
---|
854 | return $.storage.set( namespace, res );
|
---|
855 |
|
---|
856 | },
|
---|
857 |
|
---|
858 | move: function( concept, oldId, newId ){
|
---|
859 |
|
---|
860 | this.store( concept, newId, this.check( concept, oldId ) );
|
---|
861 |
|
---|
862 | this.del( concept, oldId );
|
---|
863 | },
|
---|
864 |
|
---|
865 |
|
---|
866 |
|
---|
867 |
|
---|
868 |
|
---|
869 | request: function( concept, filter, criteria ){
|
---|
870 |
|
---|
871 | var id = false, criteria = criteria || {};
|
---|
872 |
|
---|
873 | if( $.type(filter) === "string" )
|
---|
874 | {
|
---|
875 | id = filter;
|
---|
876 | filter = false;
|
---|
877 | }
|
---|
878 |
|
---|
879 | return this.dispatch( "request", {
|
---|
880 |
|
---|
881 | concept: concept || '',
|
---|
882 | id: id || '',
|
---|
883 | filter: filter || '',
|
---|
884 | criteria: criteria || '',
|
---|
885 | service: criteria.service || '',
|
---|
886 | properties: criteria.properties || ''
|
---|
887 |
|
---|
888 | } );
|
---|
889 | },
|
---|
890 |
|
---|
891 |
|
---|
892 | // sync: function( data, callback ){
|
---|
893 | //
|
---|
894 | // if( !data || $.isEmptyObject( data ) )
|
---|
895 | // return;
|
---|
896 | //
|
---|
897 | // this.send( "Sync", data, function( data, status, jqXHR ){
|
---|
898 | //
|
---|
899 | // // switch( status )
|
---|
900 | // // {
|
---|
901 | // // case "error":
|
---|
902 | // // case "parsererror":
|
---|
903 | // // return DataLayer.rollback( concept, URI );
|
---|
904 | // // case "success":
|
---|
905 | // // return DataLayer.commit();
|
---|
906 | // // case "timeout":
|
---|
907 | // // case "notmodified":
|
---|
908 | // // }
|
---|
909 | //
|
---|
910 | // if( callback )
|
---|
911 | // {
|
---|
912 | // var result = callback( data, status, jqXHR );
|
---|
913 | //
|
---|
914 | // if( result === false )
|
---|
915 | // return;
|
---|
916 | // else if( typeof result != "undefined" )
|
---|
917 | // data = result;
|
---|
918 | // }
|
---|
919 | //
|
---|
920 | // for( var URI in data )
|
---|
921 | // {
|
---|
922 | // var parsed = DataLayer.parseURI( URI ),
|
---|
923 | //
|
---|
924 | // concept = parsed[1], /*URI = parsed[3],*/
|
---|
925 | //
|
---|
926 | // links = DataLayer.links( concept );
|
---|
927 | //
|
---|
928 | // for( var linkName in links )
|
---|
929 | // {
|
---|
930 | // var subURI = data[URI][linkName];
|
---|
931 | //
|
---|
932 | // if( subURI && data[subURI] )
|
---|
933 | // {
|
---|
934 | // data[URI][linkName] = DataLayer.put( linkName, subURI, data[subURI], false );
|
---|
935 | //
|
---|
936 | // delete( data[subURI] );
|
---|
937 | // }
|
---|
938 | // }
|
---|
939 | //
|
---|
940 | // DataLayer.put( concept, URI, data[URI], false );
|
---|
941 | // }
|
---|
942 | // }, true );
|
---|
943 | //
|
---|
944 | // },
|
---|
945 |
|
---|
946 | // report: function( concept, URI, data, sync )
|
---|
947 | // {
|
---|
948 | // var current = this.dequeue( 'current', concept, URI );
|
---|
949 | //
|
---|
950 | // if( !current )
|
---|
951 | // this.enqueue( 'current', concept, URI, ( current = this.check( concept, URI ) || {} ) );
|
---|
952 | //
|
---|
953 | // var diff = this.diff( current, data );
|
---|
954 | //
|
---|
955 | // if( !diff )
|
---|
956 | // this.dequeue( 'current', concept, URI, true );
|
---|
957 | // else
|
---|
958 | // this.enqueue( 'diff', concept, URI, diff );
|
---|
959 | //
|
---|
960 | // if( sync )
|
---|
961 | // this.commit( concept, URI, function(){
|
---|
962 | //
|
---|
963 | // DataLayer.set( concept, URI, data, false );
|
---|
964 | //
|
---|
965 | // });
|
---|
966 | // },
|
---|
967 |
|
---|
968 | // enqueue: function( type, concept, URI, obj ){
|
---|
969 | //
|
---|
970 | // //var newURI = this.URI( concept, URI );
|
---|
971 | //
|
---|
972 | // if( !this.queue[type] )
|
---|
973 | // this.queue[type] = {};
|
---|
974 | //
|
---|
975 | // if( !this.queue['all'] )
|
---|
976 | // this.queue['all'] = {};
|
---|
977 | //
|
---|
978 | // if( !this.queue[type][concept] )
|
---|
979 | // this.queue[type][concept] = {};
|
---|
980 | //
|
---|
981 | // if( !this.queue['all'][type] )
|
---|
982 | // this.queue['all'][type] = {};
|
---|
983 | //
|
---|
984 | // if( !this.queue['all'][type][/*new*/URI] )
|
---|
985 | // this.queue[type][concept][URI] = this.queue['all'][type][/*new*/URI] = obj;
|
---|
986 | //
|
---|
987 | // this.store( ':queue', this.queue );
|
---|
988 | // },
|
---|
989 | //
|
---|
990 | // dequeue: function( type, concept, URI, remove ){
|
---|
991 | //
|
---|
992 | // ///////////////////////////// normalize ////////////////////////////////
|
---|
993 | // if( arguments.length < 4 && $.type(URI) === 'boolean' )
|
---|
994 | // {
|
---|
995 | // remove = URI;
|
---|
996 | // URI = false;
|
---|
997 | // }
|
---|
998 | // if( arguments.length < 3 && $.type(concept) === 'boolean' )
|
---|
999 | // {
|
---|
1000 | // remove = concept;
|
---|
1001 | // concept = false;
|
---|
1002 | // }
|
---|
1003 | // //////////////////////////////////////////////////////////////////////////
|
---|
1004 | //
|
---|
1005 | // if( !this.queue[type] || !this.queue['all'] )
|
---|
1006 | // return( false );
|
---|
1007 | //
|
---|
1008 | // if( !concept )
|
---|
1009 | // {
|
---|
1010 | // var obj = this.queue['all'][type];
|
---|
1011 | //
|
---|
1012 | // if( remove )
|
---|
1013 | // {
|
---|
1014 | // delete this.queue['all'][type];
|
---|
1015 | // delete this.queue[type];
|
---|
1016 | // }
|
---|
1017 | //
|
---|
1018 | // this.store( ':queue', this.queue );
|
---|
1019 | // return( obj );
|
---|
1020 | // }
|
---|
1021 | //
|
---|
1022 | // if( !this.queue[type][concept] )
|
---|
1023 | // return( false );
|
---|
1024 | //
|
---|
1025 | // if( !URI )
|
---|
1026 | // {
|
---|
1027 | // var obj = this.queue[type][concept];
|
---|
1028 | //
|
---|
1029 | // if( remove )
|
---|
1030 | // {
|
---|
1031 | // var URIs = this.queue[type][concept];
|
---|
1032 | //
|
---|
1033 | // for( var subURI in URIs )
|
---|
1034 | // delete this.queue['all'][type][subURI];
|
---|
1035 | //
|
---|
1036 | // delete this.queue[type][concept];
|
---|
1037 | // }
|
---|
1038 | //
|
---|
1039 | // this.store( ':queue', this.queue );
|
---|
1040 | // return( obj );
|
---|
1041 | // }
|
---|
1042 | //
|
---|
1043 | // // var newURI = URI ? this.URI( concept, URI ) : concept;
|
---|
1044 | //
|
---|
1045 | // var obj = this.queue['all'][type][/*new*/URI];
|
---|
1046 | //
|
---|
1047 | // if( remove )
|
---|
1048 | // {
|
---|
1049 | // delete this.queue['all'][type][/*new*/URI];
|
---|
1050 | // delete this.queue[type][concept][URI];
|
---|
1051 | // }
|
---|
1052 | //
|
---|
1053 | // this.store( ':queue', this.queue );
|
---|
1054 | // return( obj );
|
---|
1055 | // },
|
---|
1056 |
|
---|
1057 | //TODO: definir a 'usage' desta função e refatora-la
|
---|
1058 | // set: function( concept, filter, data, oneSide ){
|
---|
1059 | //
|
---|
1060 | // ///////////////////////////// normalize ////////////////////////////////
|
---|
1061 | // if( arguments.length == 2 )
|
---|
1062 | // {
|
---|
1063 | // data = filter;
|
---|
1064 | // filter = false;
|
---|
1065 | // }
|
---|
1066 | // if( $.type(data) === "boolean" )
|
---|
1067 | // {
|
---|
1068 | // oneSide = data;
|
---|
1069 | // data = filter;
|
---|
1070 | // filter = false;
|
---|
1071 | // }
|
---|
1072 | //
|
---|
1073 | // if( !concept || !data )
|
---|
1074 | // return( false );
|
---|
1075 | //
|
---|
1076 | // var decoder = "", URI = false, bothSides = (typeof oneSide === "undefined");
|
---|
1077 | //
|
---|
1078 | // if( $.type(filter) === "string" )
|
---|
1079 | // {
|
---|
1080 | // URI = filter;
|
---|
1081 | // filter = false;
|
---|
1082 | // }
|
---|
1083 | //
|
---|
1084 | // if( res = internalUrl.exec( concept ) )
|
---|
1085 | // {
|
---|
1086 | // //TODO: verificar se a decodificaçao deve ser feita em cada item do array
|
---|
1087 | // data = this.decode( concept, data );
|
---|
1088 | // concept = res[1];
|
---|
1089 | // decoder = res[2];
|
---|
1090 | // }
|
---|
1091 | // ///////////////////////////////////////////////////////////////////////////
|
---|
1092 | //
|
---|
1093 | // if( bothSides || oneSide )
|
---|
1094 | // this.report( concept, URI, data, !bothSides );
|
---|
1095 | //
|
---|
1096 | // if( bothSides || !oneSide )
|
---|
1097 | // {
|
---|
1098 | // if( URI )
|
---|
1099 | // {
|
---|
1100 | // var helper = {};
|
---|
1101 | // helper[URI] = data;
|
---|
1102 | // data = helper;
|
---|
1103 | // }
|
---|
1104 | //
|
---|
1105 | // for( var URI in data )
|
---|
1106 | // {
|
---|
1107 | // var current = this.check( concept, URI ) || {};
|
---|
1108 | //
|
---|
1109 | // data[URI] = this.merge( current, data[URI] );
|
---|
1110 | //
|
---|
1111 | // this.store( concept, URI, data[URI] );
|
---|
1112 | // }
|
---|
1113 | //
|
---|
1114 | // }
|
---|
1115 | //
|
---|
1116 | // this.broadcast( concept, oneSide ? 'client' : 'server' );
|
---|
1117 | //
|
---|
1118 | // return( true );
|
---|
1119 | // },
|
---|
1120 | // put: function( concept, URI, data, oneSide ){
|
---|
1121 | //
|
---|
1122 | // ///////////////////////////// normalize ////////////////////////////////
|
---|
1123 | // if( $.type(URI) !== "string" && arguments.length < 4 )
|
---|
1124 | // {
|
---|
1125 | // oneSide = data;
|
---|
1126 | // data = URI;
|
---|
1127 | // URI = false;
|
---|
1128 | // }
|
---|
1129 | // ////////////////////////////////////////////////////////////////////////
|
---|
1130 | //
|
---|
1131 | // ////////////////////////////// linkage /////////////////////////////////
|
---|
1132 | // var result = false, links = this.links( concept );
|
---|
1133 | //
|
---|
1134 | // for( var link in links )
|
---|
1135 | // {
|
---|
1136 | // if( data[link] )
|
---|
1137 | // {
|
---|
1138 | // if( $.isArray( data[link] ) )
|
---|
1139 | // {
|
---|
1140 | // data[link] = this.put( links[link], data[link].URI, data[link], oneSide );
|
---|
1141 | // }
|
---|
1142 | // else if( $.isObject( data[link] ) )
|
---|
1143 | // {
|
---|
1144 | // $.each( data[link], function( i, el ){
|
---|
1145 | //
|
---|
1146 | // data[link][i] = this.put( links[link], el.URI, el, oneSide );
|
---|
1147 | //
|
---|
1148 | // });
|
---|
1149 | // }
|
---|
1150 | // }
|
---|
1151 | // }
|
---|
1152 | // //////////////////////////////////////////////////////////////////////////
|
---|
1153 | //
|
---|
1154 | // if( typeof data.URI === "undefined" )
|
---|
1155 | // {
|
---|
1156 | // URI = this.add( concept, data, oneSide );
|
---|
1157 | // }
|
---|
1158 | // else if( data.URI === false )
|
---|
1159 | // {
|
---|
1160 | // status = this.remove( concept, URI, oneSide );
|
---|
1161 | // }
|
---|
1162 | // else
|
---|
1163 | // {
|
---|
1164 | // status = this.set( concept, URI, data, oneSide );
|
---|
1165 | // }
|
---|
1166 | //
|
---|
1167 | // if( URI && data.URI && URI !== data.URI )
|
---|
1168 | // this.move( concept, URI, data.URI );
|
---|
1169 | //
|
---|
1170 | // return( data.URI || URI );
|
---|
1171 | //
|
---|
1172 | // },
|
---|
1173 |
|
---|
1174 | // add: function( concept, data, oneSide ){
|
---|
1175 | //
|
---|
1176 | // ///////////////////////////// normalize ////////////////////////////////
|
---|
1177 | // if( !concept || !data )
|
---|
1178 | // return( false );
|
---|
1179 | //
|
---|
1180 | // if( res = internalUrl.exec( concept ) )
|
---|
1181 | // {
|
---|
1182 | // //TODO: verificar se a decodificaï¿Åï¿Åo deve ser feita em cada item do array
|
---|
1183 | // data = this.decode( concept, data );
|
---|
1184 | // concept = res[1];
|
---|
1185 | // decoder = res[2];
|
---|
1186 | // }
|
---|
1187 | //
|
---|
1188 | // var bothSides = (typeof oneSide === "undefined"), uris = [];
|
---|
1189 | //
|
---|
1190 | // if( notArray = $.type(data) !== "array" )
|
---|
1191 | // data = [ data ];
|
---|
1192 | // //////////////////////////////////////////////////////////////////////////
|
---|
1193 | //
|
---|
1194 | // for( var i = 0; i < data.length; i++ )
|
---|
1195 | // {
|
---|
1196 | // var URI = uris[i] = this.generateURI( concept );
|
---|
1197 | //
|
---|
1198 | // this.set( concept, URI, data[i], oneSide );
|
---|
1199 | // }
|
---|
1200 | //
|
---|
1201 | // return( notArray ? uris[0] : uris );
|
---|
1202 | // },
|
---|
1203 | // put: function( concept, data ){
|
---|
1204 | //
|
---|
1205 | // var decoder = "";
|
---|
1206 | //
|
---|
1207 | // if( res = internalUrl.exec( concept ) )
|
---|
1208 | // {
|
---|
1209 | // data = this.decode( concept, data );
|
---|
1210 | // concept = res[1];
|
---|
1211 | // decoder = res[2];
|
---|
1212 | // }
|
---|
1213 | //
|
---|
1214 | // var New = [], Update = [], uris = [];
|
---|
1215 | //
|
---|
1216 | // if( notArray = $.type(data) !== "array" )
|
---|
1217 | // data = [ data ];
|
---|
1218 | //
|
---|
1219 | // for( var i = 0; i < data.length; i++ )
|
---|
1220 | // {
|
---|
1221 | // if( !data[i].URI )
|
---|
1222 | // {
|
---|
1223 | // uris[ uris.length ] = data[i].URI = this.create( concept, data[i] );
|
---|
1224 | // New[ New.length ] = data[i];
|
---|
1225 | // continue;
|
---|
1226 | // }
|
---|
1227 | //
|
---|
1228 | // for( var key in data[i] )
|
---|
1229 | // if( klass = this.isReference( concept, key, data[i][key] ) )
|
---|
1230 | // data[i][key] = this.put( klass + decoder, data[i][key] );
|
---|
1231 | //
|
---|
1232 | // Update[ Update.length ] = this.update( concept, data[i].URI, data[i] );
|
---|
1233 | // }
|
---|
1234 | //
|
---|
1235 | // this.report( concept, { "created": New, "updated": Update });
|
---|
1236 | //
|
---|
1237 | // return( notArray ? uris[0] : uris );
|
---|
1238 | // },
|
---|
1239 | // merge: function( concept, current, data ){
|
---|
1240 | //
|
---|
1241 | // current = current || {};
|
---|
1242 | //
|
---|
1243 | // for( var key in data )
|
---|
1244 | // current[key] = (klass = this.isReference( concept, key, data[key] )) ?
|
---|
1245 | // this.merge( klass, current[key], data[key] ) : data[key];
|
---|
1246 | //
|
---|
1247 | // return( current );
|
---|
1248 | // },
|
---|
1249 | //
|
---|
1250 | // isReference: function( concept, key, value ){
|
---|
1251 | //
|
---|
1252 | // return( ($.type(value) === "object" ||
|
---|
1253 | // $.type(value) === "array" )? this.links[concept][key] : false );
|
---|
1254 | //
|
---|
1255 | // },
|
---|
1256 | //
|
---|
1257 | // set: function( concept, data, URI, mergeable ){
|
---|
1258 | //
|
---|
1259 | // if( URI )
|
---|
1260 | // {
|
---|
1261 | // var res = this.get( concept, true ) || {};
|
---|
1262 | //
|
---|
1263 | // if( mergeable )
|
---|
1264 | // data = this.merge( res[URI] || {}, data );
|
---|
1265 | //
|
---|
1266 | // res[URI] = data;
|
---|
1267 | //
|
---|
1268 | // data = res;
|
---|
1269 | // }
|
---|
1270 | //
|
---|
1271 | // return this.store( concept, data );
|
---|
1272 | // },
|
---|
1273 | //
|
---|
1274 | // create: function( concept, data ){
|
---|
1275 | //
|
---|
1276 | // if( notArray = ($.type(data) !== "array") )
|
---|
1277 | // data = [ data ];
|
---|
1278 | //
|
---|
1279 | // var uris = [];
|
---|
1280 | //
|
---|
1281 | // for( var i = 0; i < data.length; i++ )
|
---|
1282 | // {
|
---|
1283 | // uris[ uris.length ] = data[i].URI = "javascript://" + (this.counter + i);
|
---|
1284 | //
|
---|
1285 | // this.set( concept, data[i], data[i].URI );
|
---|
1286 | // }
|
---|
1287 | //
|
---|
1288 | // this.set( ":counter", (this.counter += data.length) );
|
---|
1289 | //
|
---|
1290 | // return notArray ? uris[0] : uris;
|
---|
1291 | // },
|
---|
1292 | //
|
---|
1293 | // update: function( concept, URI, data )
|
---|
1294 | // {
|
---|
1295 | // var target = this.check( concept, URI ) || {};
|
---|
1296 | //
|
---|
1297 | // target = this.merge( concept, target, data );
|
---|
1298 | //
|
---|
1299 | // if( target.URI !== URI )
|
---|
1300 | // this.remove( concept, URI );
|
---|
1301 | //
|
---|
1302 | // this.set( concept, target, target.URI );
|
---|
1303 | //
|
---|
1304 | // return( target );
|
---|
1305 | // },
|
---|
1306 | //
|
---|
1307 | // remove: function( concept, URI ){
|
---|
1308 | //
|
---|
1309 | // if( !URI )
|
---|
1310 | // return $.storage.del( concept );
|
---|
1311 | //
|
---|
1312 | // var res = this.check( concept );
|
---|
1313 | //
|
---|
1314 | // delete res[URI];
|
---|
1315 | //
|
---|
1316 | // this.set( concept, res );
|
---|
1317 | // },
|
---|
1318 | //
|
---|
1319 | // del: function( concept, URI ){
|
---|
1320 | //
|
---|
1321 | // this.remove( concept, URI );
|
---|
1322 | //
|
---|
1323 | // this.report( concept, { "deleted": { 'URI': URI } });
|
---|
1324 | // },
|
---|
1325 | //
|
---|
1326 | // report: function( concept, changes ){
|
---|
1327 | //
|
---|
1328 | // this.broadcast( concept, changes.created, changes.updated, changes.deleted );
|
---|
1329 | //
|
---|
1330 | // if( changes.created )
|
---|
1331 | // this.sync( concept, changes.created, 'create' );
|
---|
1332 | // if( changes.updated )
|
---|
1333 | // this.sync( concept, changes.updated, 'update' );
|
---|
1334 | // if( changes.deleted )
|
---|
1335 | // this.sync( concept, changes.deleted, 'delete' );
|
---|
1336 | //
|
---|
1337 | // },
|
---|
1338 | //
|
---|
1339 | //
|
---|
1340 | // sync: function( concept, data, type ){
|
---|
1341 | //
|
---|
1342 | // if( $.type(data) !== "array" )
|
---|
1343 | // data = [ data ];
|
---|
1344 | //
|
---|
1345 | // $.each( data, function( i, el ){
|
---|
1346 | //
|
---|
1347 | // DataLayer.send( concept, el, type );
|
---|
1348 | //
|
---|
1349 | // });
|
---|
1350 | //
|
---|
1351 | // },
|
---|
1352 | //
|
---|
1353 | //
|
---|
1354 | //
|
---|
1355 | //
|
---|
1356 | //
|
---|
1357 | // request: function( concept, URI, filter ){
|
---|
1358 | //
|
---|
1359 | // // if( startsDoubleDot.test(concept) )
|
---|
1360 | // // return( false );
|
---|
1361 | //
|
---|
1362 | // filter = filter || {};
|
---|
1363 | //
|
---|
1364 | // if( URI )
|
---|
1365 | // filter.URI = URI;
|
---|
1366 | //
|
---|
1367 | // return this.send( concept, filter, "read", true );
|
---|
1368 | //
|
---|
1369 | // },
|
---|
1370 | //
|
---|
1371 | // send: function( concept, data, type, wait ){
|
---|
1372 | //
|
---|
1373 | // switch( type )
|
---|
1374 | // {
|
---|
1375 | // case "create": type = "POST"; break;
|
---|
1376 | // case "update": type = "PUT"; break;
|
---|
1377 | // case "delete": type = "DELETE"; break;
|
---|
1378 | // case "read": type = "GET"; break;
|
---|
1379 | // }
|
---|
1380 | //
|
---|
1381 | // var url = this.basePath + concept;
|
---|
1382 | //
|
---|
1383 | // var result = [], notArray = false;
|
---|
1384 | //
|
---|
1385 | // // alert( data.URI );
|
---|
1386 | //
|
---|
1387 | // if( data.URI && data.URI.indexOf("javascript://") !== 0 )
|
---|
1388 | // url += "/" + data.URI;
|
---|
1389 | //
|
---|
1390 | // var callback = function( dt, textStatus, jqXHR ){
|
---|
1391 | //
|
---|
1392 | // if( notArray = (!$.isArray( dt )) )
|
---|
1393 | // dt = [ dt ];
|
---|
1394 | //
|
---|
1395 | // $.each( dt, function( i, el ){
|
---|
1396 | //
|
---|
1397 | // if( !el || !el.URI )
|
---|
1398 | // return;
|
---|
1399 | //
|
---|
1400 | // if( data.URI )
|
---|
1401 | // el = DataLayer.update( concept, data.URI, el );
|
---|
1402 | // else
|
---|
1403 | // DataLayer.set( concept, el, el.URI );
|
---|
1404 | //
|
---|
1405 | // result[ result.length ] = el;
|
---|
1406 | // DataLayer.broadcast( concept );
|
---|
1407 | // });
|
---|
1408 | // };
|
---|
1409 | //
|
---|
1410 | // $.ajax({
|
---|
1411 | // 'async': ( !wait ),
|
---|
1412 | // 'url': url,
|
---|
1413 | // 'type': type,
|
---|
1414 | // 'success': callback,
|
---|
1415 | // 'dataType': 'json',
|
---|
1416 | // 'data': data/*,
|
---|
1417 | // 'processData': false*/
|
---|
1418 | // });
|
---|
1419 | //
|
---|
1420 | // return( notArray ? result[0] || false : result );
|
---|
1421 | // },
|
---|
1422 |
|
---|
1423 |
|
---|
1424 | generateURI: function( concept ){
|
---|
1425 |
|
---|
1426 | return this.URI( concept, this.generateId( concept ), "javascript" );
|
---|
1427 |
|
---|
1428 | },
|
---|
1429 |
|
---|
1430 |
|
---|
1431 | broadcast: function( concept, status, diff ){
|
---|
1432 |
|
---|
1433 | if( this.listeners[ concept ] )
|
---|
1434 | for( var i = 0;
|
---|
1435 | i < this.listeners[ concept ].length;
|
---|
1436 | this.listeners[ concept ][ i++ ]( status, diff ) );
|
---|
1437 | },
|
---|
1438 |
|
---|
1439 | listen: function( concept, listener ){
|
---|
1440 |
|
---|
1441 | this.register( "listeners", concept, listener );
|
---|
1442 |
|
---|
1443 | },
|
---|
1444 |
|
---|
1445 | codec: function( concept, namespace, codec ){
|
---|
1446 |
|
---|
1447 | if( codec.encoder )
|
---|
1448 | this.encoder( concept, namespace, codec.encoder );
|
---|
1449 | if( codec.decoder )
|
---|
1450 | this.decoder( concept, namespace, codec.decoder );
|
---|
1451 | if( codec.criteria )
|
---|
1452 | this.register( "criterias", concept + ":" + namespace, codec.criteria );
|
---|
1453 |
|
---|
1454 | },
|
---|
1455 |
|
---|
1456 | encoder: function( concept, namespace, encoder ){
|
---|
1457 |
|
---|
1458 | this.register( "encoders", concept + ":" + namespace, encoder );
|
---|
1459 |
|
---|
1460 | },
|
---|
1461 |
|
---|
1462 | encode: function( encoder, data, filter ){
|
---|
1463 |
|
---|
1464 | if( this.encoders[ encoder ] )
|
---|
1465 | for( var i = 0;
|
---|
1466 | i < this.encoders[ encoder ].length;
|
---|
1467 | data = this.encoders[ encoder ][ i++ ]( data, filter ) );
|
---|
1468 |
|
---|
1469 | return( data );
|
---|
1470 | },
|
---|
1471 |
|
---|
1472 | decoder: function( concept, namespace, decoder ){
|
---|
1473 |
|
---|
1474 | this.register( "decoders", concept + ":" + namespace, decoder );
|
---|
1475 |
|
---|
1476 | },
|
---|
1477 |
|
---|
1478 | decode: function( decoder, data ){
|
---|
1479 |
|
---|
1480 | if( this.decoders[ decoder ] )
|
---|
1481 | for( var i = 0;
|
---|
1482 | i < this.decoders[ decoder ].length;
|
---|
1483 | data = this.decoders[ decoder ][ i++ ]( data ) );
|
---|
1484 |
|
---|
1485 | return( data );
|
---|
1486 | },
|
---|
1487 |
|
---|
1488 | criteria: function( codec, filter ){
|
---|
1489 |
|
---|
1490 | if( this.criterias[ codec ] )
|
---|
1491 | for( var i = 0;
|
---|
1492 | i < this.criterias[ codec ].length;
|
---|
1493 | filter = this.criterias[ codec ][ i++ ]( filter ) );
|
---|
1494 |
|
---|
1495 | return( filter );
|
---|
1496 |
|
---|
1497 | },
|
---|
1498 |
|
---|
1499 | register: function( kind, concept, deployable ){
|
---|
1500 |
|
---|
1501 | if( !this[ kind ][ concept ] )
|
---|
1502 | this[ kind ][ concept ] = [];
|
---|
1503 |
|
---|
1504 | this[ kind ][ concept ][ this[ kind ][ concept ].length ] = deployable;
|
---|
1505 |
|
---|
1506 | },
|
---|
1507 |
|
---|
1508 | start: function(){
|
---|
1509 |
|
---|
1510 | var timer = function(){
|
---|
1511 |
|
---|
1512 | setTimeout( timer, 1 );
|
---|
1513 |
|
---|
1514 | var now = parseInt( $.now() / 1000 );
|
---|
1515 |
|
---|
1516 | var tasks = DataLayer.tasks[ now ];
|
---|
1517 |
|
---|
1518 | if( !tasks ) return;
|
---|
1519 |
|
---|
1520 | for( var i = 0; i < tasks.length; i++ )
|
---|
1521 | {
|
---|
1522 | var result = tasks[i].task( now );
|
---|
1523 |
|
---|
1524 | DataLayer.schedule( tasks[i].task, tasks[i].factor );
|
---|
1525 | }
|
---|
1526 |
|
---|
1527 | delete DataLayer.tasks[ now ];
|
---|
1528 | };
|
---|
1529 |
|
---|
1530 | setTimeout( timer, 1 );
|
---|
1531 | },
|
---|
1532 |
|
---|
1533 | schedule: function( task, time ){
|
---|
1534 |
|
---|
1535 | time = time || 1;
|
---|
1536 |
|
---|
1537 | var index = parseInt( $.now() / 1000 ) + time;
|
---|
1538 |
|
---|
1539 | if( !this.tasks[ index ] )
|
---|
1540 | this.tasks[ index ] = [];
|
---|
1541 |
|
---|
1542 | this.tasks[ index ][ this.tasks[ index ].length ] = { task: task, factor: time };
|
---|
1543 | },
|
---|
1544 |
|
---|
1545 | poll: function( concept, time ){
|
---|
1546 |
|
---|
1547 | this.schedule( function( now ){
|
---|
1548 |
|
---|
1549 | DataLayer.commit( concept );
|
---|
1550 |
|
---|
1551 | }, time || 5 );
|
---|
1552 | },
|
---|
1553 |
|
---|
1554 | init: function(){
|
---|
1555 |
|
---|
1556 | this.counter = parseInt( this.get( ":counter", false ) ) || 0;
|
---|
1557 |
|
---|
1558 | if( !this.dispatchPath )
|
---|
1559 | this.dispatchPath = "../../";
|
---|
1560 |
|
---|
1561 | if( !this.templatePath )
|
---|
1562 | this.templatePath = "";
|
---|
1563 |
|
---|
1564 | if( !this.basePath )
|
---|
1565 | this.basePath = this.dispatchPath + "REST.php?q=";
|
---|
1566 |
|
---|
1567 | this.start();
|
---|
1568 | }
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | DataLayer.init();
|
---|
1572 |
|
---|
1573 | // setTimeout(function(){
|
---|
1574 | //
|
---|
1575 | //
|
---|
1576 | //
|
---|
1577 | // }, 1000 );
|
---|
1578 |
|
---|
1579 | // var DataLayer = {
|
---|
1580 | //
|
---|
1581 | // get: function( concept, filter ){
|
---|
1582 | //
|
---|
1583 | // var data = $.storage.get( concept );
|
---|
1584 | //
|
---|
1585 | // if( !filter )
|
---|
1586 | // return( data );
|
---|
1587 | //
|
---|
1588 | // return this.filter( data, filter );
|
---|
1589 | // },
|
---|
1590 | //
|
---|
1591 | // filter:function( data, filter ){
|
---|
1592 | //
|
---|
1593 | // if( filter.charAt )
|
---|
1594 | // filter = { URI: filter };
|
---|
1595 | //
|
---|
1596 | // var filtered = [];
|
---|
1597 | //
|
---|
1598 | // $.each(data, function(i, obj){
|
---|
1599 | //
|
---|
1600 | // for( var attr in filter )
|
---|
1601 | // if( filter[attr] !== obj[attr] )
|
---|
1602 | // return( true );
|
---|
1603 | //
|
---|
1604 | // filtered[i] = obj;
|
---|
1605 | // });
|
---|
1606 | //
|
---|
1607 | // return( filtered );
|
---|
1608 | // },
|
---|
1609 | //
|
---|
1610 | // find: function( concept, filter, callback ){
|
---|
1611 | //
|
---|
1612 | // var data = this.get( concept, filter );
|
---|
1613 | //
|
---|
1614 | // if( data )
|
---|
1615 | // return callback( data );
|
---|
1616 | //
|
---|
1617 | // //TODO: register callback like a weak listener
|
---|
1618 | //
|
---|
1619 | // // $.ajax({
|
---|
1620 | // // type: 'GET',
|
---|
1621 | // // data: $.param( filter ),
|
---|
1622 | // // success: callback,
|
---|
1623 | // // url: BASE_PATH + filter.URI || concept
|
---|
1624 | // // });
|
---|
1625 | // this.report( concept, filter );
|
---|
1626 | // },
|
---|
1627 | //
|
---|
1628 | // put: function( concept, data, filter ){
|
---|
1629 | //
|
---|
1630 | // var beforeDiff = this.store( concept, $.extend({},data) );
|
---|
1631 | //
|
---|
1632 | // this.report( concept, data, filter, beforeDiff );
|
---|
1633 | // },
|
---|
1634 | //
|
---|
1635 | //
|
---|
1636 | // /*var data = {
|
---|
1637 | // startTime: $.now(),
|
---|
1638 | // endTime: $.now() + 1800000,
|
---|
1639 | // summary: "meu querido evento",
|
---|
1640 | // description: "desc do evento",
|
---|
1641 | // location: "prognus software livre",
|
---|
1642 | // class: 1,
|
---|
1643 | // calendar: 1,
|
---|
1644 | // category: 1,
|
---|
1645 | // participants: [ {
|
---|
1646 | // user: { isExternal: true, mail: "user7@prognus.org", name: "user7" }
|
---|
1647 | // },{
|
---|
1648 | // user: "1003"
|
---|
1649 | // } ]
|
---|
1650 | //
|
---|
1651 | // };*/
|
---|
1652 | //
|
---|
1653 | //
|
---|
1654 | // merge:function( data, target ){
|
---|
1655 | //
|
---|
1656 | // var diff = { New: {}, Update:{}, Delete: {} };
|
---|
1657 | //
|
---|
1658 | // for( var key in data )
|
---|
1659 | // {
|
---|
1660 | // if( !target[ key ] )
|
---|
1661 | // diff.New[ key ] = target[ key ] = data[ key ];
|
---|
1662 | //
|
---|
1663 | //
|
---|
1664 | //
|
---|
1665 | // }
|
---|
1666 | //
|
---|
1667 | // }
|
---|
1668 | //
|
---|
1669 | // store: function( concept, data, filter ){
|
---|
1670 | //
|
---|
1671 | // if( !data.spline )
|
---|
1672 | // data = [ data ];
|
---|
1673 | //
|
---|
1674 | // var target = $.storage.get( concept );
|
---|
1675 | //
|
---|
1676 | // var diff = { New: {}, Update:{}, Delete: {} };
|
---|
1677 | //
|
---|
1678 | // for( var i = 0; i < data.length; i++ )
|
---|
1679 | // {
|
---|
1680 | // if( data[i].URI && target[ data[i].URI ] )
|
---|
1681 | // {
|
---|
1682 | // diff.Update[ data[i].URI ] = this.merge( target[ data[i].URI ], data[i] );
|
---|
1683 | // }
|
---|
1684 | // else
|
---|
1685 | // {
|
---|
1686 | // diff.New[] = data[i];
|
---|
1687 | // }
|
---|
1688 | // }
|
---|
1689 | //
|
---|
1690 | //
|
---|
1691 | //
|
---|
1692 | // this.broadcast( concept, data );
|
---|
1693 | //
|
---|
1694 | // if( filter )
|
---|
1695 | // target = this.filter( target, filter );
|
---|
1696 | //
|
---|
1697 | // if( target )
|
---|
1698 | // data = $.extend( target, data );
|
---|
1699 | //
|
---|
1700 | // $.storage.set( concept, data );
|
---|
1701 | //
|
---|
1702 | // // return;
|
---|
1703 | // },
|
---|
1704 | //
|
---|
1705 | // set: function( concept, data, filter ){
|
---|
1706 | //
|
---|
1707 | //
|
---|
1708 | //
|
---|
1709 | // },
|
---|
1710 | //
|
---|
1711 | // post: function( concept, data, filter, isNew ){
|
---|
1712 | //
|
---|
1713 | // var callback = function( ){ DataLayer.store( concept, data, filter ) };
|
---|
1714 | //
|
---|
1715 | // //TODO: register callback like a weak listener
|
---|
1716 | //
|
---|
1717 | // this.report( concept, data, filter, isNew );
|
---|
1718 | // },
|
---|
1719 | //
|
---|
1720 | // report: function( concept, filter, postData, isNew ){
|
---|
1721 | //
|
---|
1722 | // $.ajax({
|
---|
1723 | // type: postData ? isNew ? 'POST' : 'PUT' : 'GET',
|
---|
1724 | // data: postData || $.param( filter ),
|
---|
1725 | // success: function( data ){ DataLayer.broadcast( concept ) },
|
---|
1726 | // url: BASE_PATH + filter.URI || concept
|
---|
1727 | // });
|
---|
1728 | // },
|
---|
1729 | //
|
---|
1730 | // del:function( concept, filter ){
|
---|
1731 | //
|
---|
1732 | //
|
---|
1733 | //
|
---|
1734 | // }
|
---|
1735 | //
|
---|
1736 | // broadcast: function( concept, data ){
|
---|
1737 | //
|
---|
1738 | //
|
---|
1739 | //
|
---|
1740 | // },
|
---|
1741 | //
|
---|
1742 | // pool: function(){
|
---|
1743 | //
|
---|
1744 | // },
|
---|
1745 | //
|
---|
1746 | // refresh: function(){
|
---|
1747 | //
|
---|
1748 | // }
|
---|
1749 | // };
|
---|
1750 |
|
---|
1751 | //
|
---|
1752 | // DataLayer = {
|
---|
1753 | //
|
---|
1754 | // get: function( concept, filter ){
|
---|
1755 | //
|
---|
1756 | // var data = $.storage.get( concept );
|
---|
1757 | //
|
---|
1758 | // if( !filter )
|
---|
1759 | // return( data );
|
---|
1760 | //
|
---|
1761 | // if( filter.charAt )
|
---|
1762 | // filter = { URI: filter };
|
---|
1763 | //
|
---|
1764 | // var filtered = [];
|
---|
1765 | //
|
---|
1766 | // $.each(data, function(i, obj){
|
---|
1767 | //
|
---|
1768 | // for( var attr in filter )
|
---|
1769 | // if( filter[attr] !== obj[attr] )
|
---|
1770 | // return( true );
|
---|
1771 | //
|
---|
1772 | // filtered[i] = obj;
|
---|
1773 | // });
|
---|
1774 | //
|
---|
1775 | // return( filtered );
|
---|
1776 | // },
|
---|
1777 | //
|
---|
1778 | // find: function( concept, filter, callback ){
|
---|
1779 | //
|
---|
1780 | // var data = this.get( concept, filter );
|
---|
1781 | //
|
---|
1782 | // if( data )
|
---|
1783 | // return callback( data );
|
---|
1784 | //
|
---|
1785 | // $.ajax({
|
---|
1786 | // type: 'GET',
|
---|
1787 | // data: $.param( filter ),
|
---|
1788 | // success: callback,
|
---|
1789 | // url: filter.URI || concept
|
---|
1790 | // });
|
---|
1791 | // },
|
---|
1792 | //
|
---|
1793 | // put: function( concept, data, filter ){
|
---|
1794 | //
|
---|
1795 | // var target = this.get( concept, filter );
|
---|
1796 | //
|
---|
1797 | // if( target )
|
---|
1798 | // data = $.extend( target, data );
|
---|
1799 | //
|
---|
1800 | // $.storage.set( concept, data );
|
---|
1801 | //
|
---|
1802 | // //diff
|
---|
1803 | // },
|
---|
1804 | //
|
---|
1805 | // post: function( concept, data, filter ){
|
---|
1806 | //
|
---|
1807 | //
|
---|
1808 | //
|
---|
1809 | // },
|
---|
1810 | //
|
---|
1811 | // pool: function(){
|
---|
1812 | //
|
---|
1813 | // },
|
---|
1814 | //
|
---|
1815 | // queue: function(){
|
---|
1816 | //
|
---|
1817 | // },
|
---|
1818 | //
|
---|
1819 | // dequeue: function(){
|
---|
1820 | //
|
---|
1821 | // },
|
---|
1822 | //
|
---|
1823 | // refresh: function(){
|
---|
1824 | //
|
---|
1825 | // }
|
---|
1826 | // }
|
---|
1827 |
|
---|
1828 | // var DataLayer = {
|
---|
1829 |
|
---|
1830 | // cache: {},
|
---|
1831 |
|
---|
1832 | // get: function( concept, location ){
|
---|
1833 |
|
---|
1834 | /* if( location )
|
---|
1835 | {*/
|
---|
1836 | // var schema = $.data( this.cache, concept + ':schema' );
|
---|
1837 | // var uri = [];
|
---|
1838 | //
|
---|
1839 | // $.each( schema, function( i, addrs ){
|
---|
1840 | // uri[ uri.length ] = location[addrs];
|
---|
1841 | // });
|
---|
1842 |
|
---|
1843 | /*var filter = [], result = false;
|
---|
1844 |
|
---|
1845 | while( !(result = $.data( this.cache, uri.join( '.' ) )) || !(uri = uri.join('.')) )
|
---|
1846 | filter[ filter.length ] = uri.pop();
|
---|
1847 |
|
---|
1848 | if( !filter.length )
|
---|
1849 | {
|
---|
1850 | var indexes = $.data( this.cache, uri + ':indexes' );
|
---|
1851 |
|
---|
1852 | if( indexes )
|
---|
1853 | Array.prototype.concat.apply( result, indexes );
|
---|
1854 |
|
---|
1855 | return( result );
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 | for( var i = 0; i < result.length; i++ )
|
---|
1859 | {
|
---|
1860 |
|
---|
1861 | }
|
---|
1862 |
|
---|
1863 | if( result.length )
|
---|
1864 | return( result );
|
---|
1865 | }*/
|
---|
1866 |
|
---|
1867 | // var data = $.data( this.cache, concept );
|
---|
1868 |
|
---|
1869 | // if( !data )
|
---|
1870 | // $.ajax( );
|
---|
1871 |
|
---|
1872 | // return( data );
|
---|
1873 | // },
|
---|
1874 |
|
---|
1875 | // data: function(){
|
---|
1876 | //
|
---|
1877 | //
|
---|
1878 | //
|
---|
1879 | // }
|
---|
1880 | //
|
---|
1881 | // search: function( concept, filter ){
|
---|
1882 | //
|
---|
1883 | // var schema = $.data( this.cache, concept + ':schema' );
|
---|
1884 | // var uri = [];
|
---|
1885 | //
|
---|
1886 | // $.each( schema, function( i, addrs ){
|
---|
1887 | // uri[ uri.length ] = location[addrs];
|
---|
1888 | // });
|
---|
1889 | // }
|
---|
1890 | // put: function( concept, data, location ){
|
---|
1891 |
|
---|
1892 | // if( location )
|
---|
1893 | // {
|
---|
1894 | // var schema = $.data( this.cache, concept + ':schema');
|
---|
1895 | // var uri = [];
|
---|
1896 |
|
---|
1897 | // $.each( schema, function( i, addrs ){
|
---|
1898 | // uri[ uri.length ] = location[addrs];
|
---|
1899 | // });
|
---|
1900 |
|
---|
1901 | // var result = false, filter = [];
|
---|
1902 |
|
---|
1903 | // while( !(result = $.data( this.cache, uri.join('.')) )
|
---|
1904 | // filter[ filter.length ] = uri.pop();
|
---|
1905 |
|
---|
1906 | // $.data( this.cache, '
|
---|
1907 |
|
---|
1908 | // }
|
---|
1909 |
|
---|
1910 | // var model = $.storage.get( concept );
|
---|
1911 | //
|
---|
1912 | // $.each( model, function( i, o ){
|
---|
1913 | // $.each( location, function( ii, attr ){
|
---|
1914 | // if( o[ii] === attr )
|
---|
1915 | // return( false );
|
---|
1916 | // });
|
---|
1917 | // });
|
---|
1918 |
|
---|
1919 | // return $.data( this.cache, concept, data );
|
---|
1920 |
|
---|
1921 | // },
|
---|
1922 | // del: function( concept, location ){
|
---|
1923 | //
|
---|
1924 | // if( location )
|
---|
1925 | // {
|
---|
1926 | // var schema = $.data( this.cache, 'concepts', concept );
|
---|
1927 | // var uri = [];
|
---|
1928 | //
|
---|
1929 | // $.each( schema, function( i, addrs ){
|
---|
1930 | // uri[ uri.length ] = location[addrs];
|
---|
1931 | // });
|
---|
1932 | //
|
---|
1933 | // concept = uri.join( '.' );
|
---|
1934 |
|
---|
1935 | // var model = $.storage.get( concept );
|
---|
1936 | //
|
---|
1937 | // $.each( model, function( i, o ){
|
---|
1938 | // $.each( location, function( ii, attr ){
|
---|
1939 | // if( o[ii] === attr )
|
---|
1940 | // return( false );
|
---|
1941 | // });
|
---|
1942 | // });
|
---|
1943 | // }
|
---|
1944 | //
|
---|
1945 | //
|
---|
1946 | // $.removeData( this.cache, concept );
|
---|
1947 | // }
|
---|
1948 | // }
|
---|