Changeset 6523 for sandbox/2.4.1-3/prototype/api/datalayer.js
- Timestamp:
- 06/15/12 14:49:24 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.4.1-3/prototype/api/datalayer.js
r6514 r6523 1 internalUrl = /^([A-z0-9-_]+)(:[A-z0-9-_]+)?$/; 1 2 (function($){$.parseQuery=function(options){var config={query:window.location.search||""},params={};if(typeof options==='string'){options={query:options};} 3 $.extend(config,$.parseQuery,options);config.query=config.query.replace(/^\?/,'');$.each(config.query.split(config.separator),function(i,param){var pair=param.split('='),key=config.decode(pair.shift(),null).toString(),value=config.decode(pair.length?pair.join('='):null,key);if(config.array_keys(key)){params[key]=params[key]||[];params[key].push(value);}else{params[key]=value;}});return params;};$.parseQuery.decode=$.parseQuery.default_decode=function(string){return decodeURIComponent((string||"").replace('+',' '));};$.parseQuery.array_keys=function(){return false;};$.parseQuery.separator="&";}(jQuery)); 4 5 internalUrl = /^([A-z0-9-_]+)(:[A-z0-9-_]+)?$/; 2 6 internalUri = /^([a-zA-Z0-9-_]+)\(([a-zA-Z0-9-_]+)\):\/\/(.*)|([a-zA-Z0-9-_]+):\/\/(.*)$/; 3 7 isGeneratedId = /^\d+\(javascript\)$/; … … 57 61 58 62 jqXHR.abort(); 63 64 if( typeof options.data === "string" ) 65 options.data = $.parseQuery( options.data ); 59 66 60 67 switch( options.type.toUpperCase() ) … … 195 202 196 203 send: function( url, type, data, callback, sync, extraOptions ){ 197 204 198 205 var result = false, fired = false; 199 206 … … 213 220 214 221 }, 215 'error': function( dt, textStatus, jqXHR ){216 217 if( callback )218 {219 fired = true;220 result = callback( $.parseJSON(dt.responseText), textStatus, jqXHR );221 }222 else223 result = $.parseJSON(dt.responseText);224 225 },226 222 'complete': function( jqXHR, textStatus ){ 227 223 … … 243 239 244 240 $.ajax( envelope ); 241 245 242 return( result ); 246 },247 248 /**249 * This method is used to read resources from the server.250 *251 * @param uri Uri of the resource that gonna be readed.252 * @param callback A function that is called when the resource is loaded successfully. When the parameter is ignored the request is made synchrounsly.253 * @param accept The attribute accept that is used to ask the target format to the server254 * @return The target resource when the callback is ommitted ( made it synchronous )255 */256 257 read: function( uri, data, callback, accept ){258 //return this.send( this.dispatchPath + 'rest' + uri, [ 'get', accept || 'json' ], false, callback );259 //http://expressodev.prognus.com.br/cristiano/expresso-api/rest/maillast260 //return this.send( ('rest' + uri), [ 'get', accept || 'json' ], data, callback, !!!callback,261 console.log(this.dispatchPath+'../rest'+uri);262 return this.send( (this.dispatchPath + '../rest' + uri), [ 'get', accept || 'json' ], data, callback, !!!callback,263 {'beforeSend' : function (xhr){264 xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}265 });266 267 },268 269 /**270 * This method is used to create resources from the server.271 *272 * @param uri Uri of the resource that gonna be readed.273 * @param callback A function that is called when the resource is created on the server successfully. When the parameter is ignored the request is made synchrounsly.274 * @param accept The attribute accept that is used to ask the target format to the server.275 * @return The result response of the create from the server when the callback is ommitted ( made it synchronous )276 */277 278 create: function( uri, data, callback, accept ){279 //return this.send( 'rest' + uri, [ 'post', accept || 'json' ], data, callback, !!!callback,280 return this.send( (this.dispatchPath + '../rest' + uri), [ 'post', accept || 'json' ], data, callback, !!!callback,281 {'beforeSend' : function (xhr){282 //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}283 xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}284 });285 },286 287 /**288 * This method is used to update resources from the server.289 *290 * @param uri Uri of the resource that gonna be readed.291 * @param callback A function that is called when the resource is update on the server successfully. When the parameter is ignored the request is made synchrounsly.292 * @param accept The attribute accept that is used to ask the target format to the server293 * @return The result response of the update from the server when the callback is ommitted ( made it synchronous )294 */295 296 update: function( uri, data, callback, accept ){297 298 //return this.send( 'rest' + uri, [ 'put', accept || 'json' ], data, callback, !!!callback,299 return this.send( (this.dispatchPath + '../rest' + uri), [ 'put', accept || 'json' ], data, callback, !!!callback,300 {'beforeSend' : function (xhr){301 //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}302 xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}303 });304 305 },306 307 /**308 * This method is used to delete resources from the server.309 *310 * @param uri Uri of the resource that gonna be readed.311 * @param callback A function that is called when the resource is deleted successfully in the server. When the parameter is ignored the request is made synchrounsly.312 * @param accept The attribute accept that is used to ask the target format to the server313 * @return The result response of the delete from the server when the callback is ommitted ( made it synchronous )314 */315 316 delete: function( uri, callback, accept ){317 //return this.send( 'rest' + uri, [ 'delete', accept || 'json' ], false, callback, !!!callback,318 return this.send( (this.dispatchPath + '../rest' + uri), [ 'delete', accept || 'json' ], false, callback, !!!callback,319 {'beforeSend' : function (xhr){320 //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}321 xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}322 });323 324 243 }, 325 244 … … 646 565 }, 647 566 567 /* 568 * RemoveFilter = método para remoção de objetos por critério, funcionalidade não implementada no método remove 569 * TODO - A remoção é feira em tempo real, onde ainda o mesmo não suporta remoção apenas na camada do cliente 570 * caso necessária tao funcionalidade a mesma será implementada no futuro 571 **/ 572 removeFilter: function( concept, filter, oneSide ){ 573 //remover 574 oneSide = true; 575 576 if(filter) 577 filter = this.criteria(concept, filter); 578 else 579 return; 580 581 if ( $.type(filter) === "array" ) 582 filter = { filter: filter, criteria: false }; 583 584 var toRemove = {}; 585 586 toRemove[concept] = []; 587 588 toRemove[concept][toRemove[concept].length] = {filter: filter.filter, criteria: filter.criteria, method: 'delete'}; 589 590 this.dispatch( 'call', toRemove, false, true ); 591 592 this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false ); 593 }, 594 648 595 report: function( concept, id, data ) 649 596 { … … 684 631 685 632 rollback: function( concept, ids ){ 686 687 var queue = this.prepareQ( 'current', concept, ids ); 688 689 ids = []; 690 691 for( var id in queue ) 692 { 693 this.put( concept, id, queue[id], false ); 694 695 ids[ ids.length ] = id; 633 if(!DataLayer.storage.cache[':diff']) 634 return false; 635 if(concept){ 636 if(ids){ 637 ids = !$.isArray(ids) ? [ids] : ids; 638 for (var i in ids) 639 delete DataLayer.storage.cache[':diff'][concept][ids[i]]; 640 }else 641 delete DataLayer.storage.cache[':diff'][concept]; 642 }else{ 643 644 var queue = this.prepareQ( 'current', concept, ids ); 645 646 ids = []; 647 648 for( var id in queue ) 649 { 650 this.put( concept, id, queue[id], false ); 651 652 ids[ ids.length ] = id; 653 } 654 655 for(var link in ids) 656 delete DataLayer.storage.cache[':diff'][ids[link]]; 657 696 658 } 697 698 this.clearQ( concept, ( ids.length ? ids : false ) );699 700 this.broadcast( concept, 'revert' );701 702 659 }, 703 660 … … 1443 1400 properties: criteria.properties || '' 1444 1401 1445 } );1402 }, false, true ); 1446 1403 }, 1447 1404 … … 2127 2084 2128 2085 if( !this.dispatchPath ) 2129 this.dispatchPath = " prototype/";2086 this.dispatchPath = "../../"; 2130 2087 2131 2088 if( !this.templatePath ) … … 2142 2099 2143 2100 this.start(); 2144 this.me = this.dispatch( "me" );2145 2101 } 2146 2102 }
Note: See TracChangeset
for help on using the changeset viewer.