This commit is contained in:
Renato Gabriele 2017-03-18 18:09:06 +01:00
commit 9c29d24e87
5 changed files with 89 additions and 15 deletions

View file

@ -38,6 +38,8 @@
<script src="js/main.js"></script>
<script src="js/update.js"></script>
<script src="js/query.js"></script>
<script src="js/eventsCRUD.js"></script>
<script src="js/vendor/jquery.mobile-1.4.5.min.js"></script>
<script src="js/vendor/xml2json.js"></script>
<script src="js/vendor/toastr.js"></script>

View file

@ -22,11 +22,11 @@ var ai1ec = (function(){
},
getInitDate : function(event) {
return event.dtstart._ || "";
return event.dtstart && event.dtstart._ ? event.dtstart._ : "";
},
getEndDate : function(event) {
return event.dtend._ || "";
return event.dtend && event.dtend._ ? event.dtend._ : "";
},
getCats : function(event) {
@ -34,11 +34,11 @@ var ai1ec = (function(){
},
getTags : function(event) {
return event["x-tags"]._ || "";
return event["x-tags"] && event["x-tags"]._ ? event["x-tags"]._ : "";
},
getUrl : function(event) {
return event.url.$.uri || "";
return event.url && event.url.$ && event.url.$.uri ? event.url.$.uri : "";
},
getContact : function(event) {
@ -85,22 +85,18 @@ var ai1ec = (function(){
//post_ids
//Torna un array con tutti gli eventi organizzati da xm24, un array vuoto se errore.
getAllEvents : function(catId) {
getAllEvents : function(catId, callback) {
var url = getDefaultUrl(catId);
getXmlData(url, function(events){
return events;
});
getXmlData(url, callback);
},
//Torna un array con gli eventi tra -30 e +30 giorni da oggi, un array vuoto se errore.
getLastEvents : function(catId) {
getLastEvents : function(catId, callback) {
var url = getDefaultUrl(catId) + '&' + API.remote.win;
getXmlData(url, function(events){
return events;
});
getXmlData(url, callback);
},
}
return API;
})();
})();

72
www/js/eventsCRUD.js Normal file
View file

@ -0,0 +1,72 @@
var EVENTS = EVENTS || {};
EVENTS.querySingle = function () {
$.mobile.loading('show');
ai1ec.remote.getLastEvents(ai1ec.cats.single, function(events) {
for (var i = 0; i < events.length; i++) {
var event = events[i];
var evId = ai1ec.event.getId(event);
var evTitle = ai1ec.event.getTitle(event);
var evDesc = ai1ec.event.getDescription(event);
var evInitDate = ai1ec.event.getInitDate(event);
var evEndDate = ai1ec.event.getEndDate(event);
var evUrl = ai1ec.event.getUrl(event);
var evGeo = ai1ec.event.getGeo(event);
FONTE.dbHandler.executeSql('TRUNCATE TABLE xm24_events_single', [], function() {
FONTE.dbHandler.executeSql('INSERT INTO xm24_events_single VALUES (?,?,?,?,?,?,?)', [evId, evTitle, evDesc, evInitDate, evEndDate, evUrl, evGeo], function (resultSet) {
console.log('resultSet.insertId: ' + resultSet.insertId);
console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected);
$.mobile.loading('hide');
}, function (error) {
console.error("EVENTS.query() : ", error);
});
});
}
});
};
EVENTS.queryRepeat = function () {
$.mobile.loading('show');
ai1ec.remote.getLastEvents(ai1ec.cats.single, function(events) {
for (var i = 0; i < events.length; i++) {
var event = events[i];
var evId = ai1ec.event.getId(event);
var evTitle = ai1ec.event.getTitle(event);
var evDesc = ai1ec.event.getDescription(event);
var evInitDate = ai1ec.event.getInitDate(event);
var evEndDate = ai1ec.event.getEndDate(event);
var evUrl = ai1ec.event.getUrl(event);
var evGeo = ai1ec.event.getGeo(event);
FONTE.dbHandler.executeSql('TRUNCATE TABLE xm24_events_repeat', [], function() {
FONTE.dbHandler.executeSql('INSERT INTO xm24_events_repeat VALUES (?,?,?,?,?,?,?)', [evId, evTitle, evDesc, evInitDate, evEndDate, evUrl, evGeo], function (resultSet) {
console.log('resultSet.insertId: ' + resultSet.insertId);
console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected);
$.mobile.loading('hide');
}, function (error) {
console.error("EVENTS.query() : ", error);
});
});
}
});
};
EVENTS.loadFromDb = function (containerId) {
$.mobile.loading('show');
FONTE.dbHandler.executeSql("SELECT * FROM xm24_events_single ORDER BY initDate COLLATE NOCASE ASC;", [], function (resultSet) {
var items = [];
for (var i = 0; i < resultSet.rows.length; i++) {
var item = resultSet.rows.item(i);
items.push("<li><img src='./image/virgolette_1.png' class='epuntato'/><a href='#event' data-post='" + item.id + "' >" + item.title + "</a><br/></li>");
}
$(containerId).empty();
$("<ul/>", {
"class": "my-new-list"
, html: items.join("")
}).prependTo(containerId);
$.mobile.loading('hide');
}, function (error) {
console.log(error);
});
};

View file

@ -71,8 +71,9 @@ function alterContent(url) {
case '#events':
$("#navheader").removeClass("hide");
$("#navfooter").removeClass("hide");
ai1ec.remote.getAllEvents(ai1ec.cats.single);
ai1ec.remote.getLastEvents(ai1ec.cats.single);
EVENTS.loadFromDb('#mostralista');
// ai1ec.remote.getAllEvents(ai1ec.cats.single);
// ai1ec.remote.getLastEvents(ai1ec.cats.single);
break;
case '#aggiorna':
$("#navheader").removeClass("hide");

View file

@ -246,6 +246,9 @@ function createDB() {
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_tags (id INTEGER PRIMARY KEY, title, tag)');
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_tags_to_posts (id, tagid)');
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_pages (id INTEGER PRIMARY KEY, title, date, page)');
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_events_single (id PRIMARY KEY, title, description, initDate, endDate, url, geo)');
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_tags_to_events (id, tagid)');
FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_events_repeat (id PRIMARY KEY, title, description, initDate, endDate, url, geo)');
}, function () {
console.log('error');
console.log(arguments);