cherryext/orun/extjs/static/ext-6.2.0/packages/google/classic/google.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2018-08-17 12:14:11 +03:00
Ext.define("Ext.google.ux.Client",{extend:"Ext.Mixin",mixins:["Ext.mixin.Mashup"],requiredScripts:["//apis.google.com/js/client.js?onload=_ext_google_ux_client_initialize_"],statics:{getApiVersion:function(b){var a=this.libraries[b];return a&&a.state==2?a.version:null}},mixinConfig:{extended:function(c,a,b){this.load(b.googleApis)}},onClassMixedIn:function(a){this.load(a.prototype.googleApis)},privates:{statics:{initialized:false,blocked:false,loading:0,libraries:{},load:function(d){var c=this.libraries,a,b;if(!Ext.isObject(d)){return}Ext.Object.each(d,function(f,e){a=e.version||"v1";b=c[f];if(!Ext.isDefined(b)){c[f]={version:a,state:0}}else{if(b.version!==a){Ext.log.error('Google API: failed to load version "'+a+'" of the','"'+f+'" API: "'+b.version+'" already loaded.')}}});this.refresh()},refresh:function(){var a=this;if(!a.blocked){Ext.env.Ready.block();a.blocked=true}if(!a.initialized){return}Ext.Object.each(a.libraries,function(c,b){if(b.state==0){b.state=1;gapi.client.load(c,b.version,function(){b.state=2;if(!--a.loading){a.refresh()}})}if(b.state==1){a.loading++}});if(!a.loading&&a.blocked){Ext.env.Ready.unblock();a.blocked=false}},initialize:function(){this.initialized=true;this.refresh()}}}});_ext_google_ux_client_initialize_=function(){gapi.auth.init(function(){Ext.google.ux.Client.initialize()})};Ext.define("Ext.google.data.AbstractProxy",{extend:"Ext.data.proxy.Server",mixins:["Ext.google.ux.Client"],batchActions:false,reader:{type:"json",rootProperty:"items",messageProperty:"error"},doRequest:function(a){var d=this,c=d.buildRequest(a),e=d.getWriter(),b=false;if(e&&a.allowWrite()){c=e.write(c)}d.execute(d.buildApiRequests(c)).then(function(f){d.processApiResponse(a,c,f)});return c},buildUrl:function(a){return""},privates:{execute:function(b){b=[].concat(b);var a=[];return Ext.Array.reduce(b,function(d,c){return d.then(function(){return c.then(function(e){a.push(e)})})},Ext.Deferred.resolved()).then(function(){return{result:a}})},processApiResponse:function(a,d,e){var b=false,c=[];Ext.each(Object.keys(e.result),function(g){var f=e.result[g].result;if(f.error){b=f.error.message;return false}c.push(f)});this.processResponse(true,a,d,{results:b?[]:c,success:!b,error:b})},sanitizeItems:function(a){var b=[],c=[];Ext.Array.each(a,function(d){if(!Ext.Array.contains(c,d.id)){b.push(d);c.push(d.id)}},this,true);return b}}});Ext.define("Ext.google.data.EventsProxy",{extend:"Ext.google.data.AbstractProxy",alias:"proxy.google-events",googleApis:{calendar:{version:"v3"}},buildApiRequests:function(b){var a=this,c=b.getAction();switch(c){case"read":return a.buildReadApiRequests(b);case"create":return a.buildCreateApiRequests(b);case"update":return a.buildUpdateApiRequests(b);case"destroy":return a.buildDestroyApiRequests(b);default:Ext.raise("unsupported request: events."+c);return null}},extractResponseData:function(b){var c=this,d=c.callParent(arguments),a=[];Ext.each(d.results,function(e){switch(e.kind){case"calendar#events":a=a.concat(e.items.map(c.fromApiEvent.bind(c)));break;case"calendar#event":a.push(c.fromApiEvent(e));break;default:break}});return{items:c.sanitizeItems(a),success:d.success,error:d.error}},privates:{toApiEvent:function(c,b){var a={};Ext.Object.each(c,function(e,g){var f=null,d=null;switch(e){case"calendarId":case"description":a[e]=g;break;case"id":a.eventId=g;break;case"title":a.summary=g;break;case"startDate":case"endDate":if(b){d=new Date(g);d.setHours(0,-d.getTimezoneOffset());d=Ext.Date.format(d,"Y-m-d")}else{f=Ext.Date.format(new Date(g),"c")}a[e.slice(0,-4)]={date:d,dateTime:f};break;default:break}});return a},fromApiEvent:function(b){var a={allDay:true};Ext.Object.each(b,function(d,f){var c,g,e;switch(d){case"id":case"description":a[d]=f;break;case"summary":a.title=f;break;case"start":case"end":c=Ext.Date.parse(f.dateTime||f.date,"C");g=c.getTimezoneOffset();e=!!f.date;if(e&&g!==0){c.setHours(0,-g)}a[d+"Date"]=c;a.allDay=a.allDay&&e;break;default:break}});return a},buildReadApiRequests:function(d){var b=d.getParams(),f=new Date(b.startDate),a=new Date(b.endDate),e=[],c;while(f<a){c=Ext.Date.a