102 خطوط
3 KiB
JavaScript
102 خطوط
3 KiB
JavaScript
var ai1ec = (function(){
|
|
var API = {}, json = null, events = [];
|
|
|
|
//Categorie di eventi
|
|
API.cats = {
|
|
single: 34,
|
|
repeat: 25
|
|
};
|
|
|
|
//Parser di un evento dell'array tornato da getXmlData
|
|
API.event = {
|
|
getId : function(event) {
|
|
return event.uid || null;
|
|
},
|
|
|
|
getTitle : function(event) {
|
|
return event.summary || null;
|
|
},
|
|
|
|
getDescription : function(event) {
|
|
return event.description || "";
|
|
},
|
|
|
|
getInitDate : function(event) {
|
|
return event.dtstart && event.dtstart._ ? event.dtstart._ : "";
|
|
},
|
|
|
|
getEndDate : function(event) {
|
|
return event.dtend && event.dtend._ ? event.dtend._ : "";
|
|
},
|
|
|
|
getCats : function(event) {
|
|
return event.categories || "";
|
|
},
|
|
|
|
getTags : function(event) {
|
|
return event["x-tags"] && event["x-tags"]._ ? event["x-tags"]._ : "";
|
|
},
|
|
|
|
getUrl : function(event) {
|
|
return event.url && event.url.$ && event.url.$.uri ? event.url.$.uri : "";
|
|
},
|
|
|
|
getContact : function(event) {
|
|
return event.contact || "";
|
|
},
|
|
|
|
getGeo : function(event) {
|
|
return event.geo || "";
|
|
},
|
|
};
|
|
|
|
var getXmlData = function(url, callback) {
|
|
$.ajax({
|
|
url: url,
|
|
dataType: 'xml',
|
|
method: 'GET',
|
|
success: function(res) {
|
|
json = $.xml2json(res);
|
|
events = json["#document"].vcalendar.vevent;
|
|
console.log(events);
|
|
return callback(events);
|
|
},
|
|
error: function(err){
|
|
console.log("Err: status ", err.status);
|
|
return callback(events);
|
|
}
|
|
});
|
|
};
|
|
|
|
var getDefaultUrl = function(catId){
|
|
catId = catId || API.cats.single;
|
|
|
|
return API.remote.site + API.remote.q + "&" + API.remote.catq + catId + "&" + API.remote.xmlq;
|
|
}
|
|
|
|
//Oggetto che gestisce attività remote
|
|
API.remote = {
|
|
site : 'http://www.ecn.org/xm24',
|
|
q : '/?plugin=all-in-one-event-calendar&controller=ai1ec_exporter_controller&action=export_events',
|
|
post: 'ai1ec_post_ids=',
|
|
catq : 'ai1ec_cat_ids=',
|
|
xmlq : 'xml=true',
|
|
win : 'window=true',
|
|
//post_ids
|
|
|
|
//Torna un array con tutti gli eventi organizzati da xm24, un array vuoto se errore.
|
|
getAllEvents : function(catId, callback) {
|
|
var url = getDefaultUrl(catId);
|
|
getXmlData(url, callback);
|
|
},
|
|
|
|
//Torna un array con gli eventi tra -30 e +30 giorni da oggi, un array vuoto se errore.
|
|
getLastEvents : function(catId, callback) {
|
|
var url = getDefaultUrl(catId) + '&' + API.remote.win;
|
|
getXmlData(url, callback);
|
|
},
|
|
|
|
}
|
|
|
|
return API;
|
|
})();
|