From 74cdafd0760530566ed580d2a2cee5ee58fe0a84 Mon Sep 17 00:00:00 2001 From: "cek@posta.indivia.net" Date: Sat, 18 Mar 2017 18:01:35 +0100 Subject: [PATCH] aggiunto in parte la gestione degli eventi --- www/index.html | 2 ++ www/js/events.js | 22 ++++++-------- www/js/eventsCRUD.js | 72 ++++++++++++++++++++++++++++++++++++++++++++ www/js/main.js | 5 +-- www/js/query.js | 3 ++ 5 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 www/js/eventsCRUD.js diff --git a/www/index.html b/www/index.html index 66564fd..8a25afe 100644 --- a/www/index.html +++ b/www/index.html @@ -38,6 +38,8 @@ + + diff --git a/www/js/events.js b/www/js/events.js index f669346..6bcc692 100644 --- a/www/js/events.js +++ b/www/js/events.js @@ -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; -})(); \ No newline at end of file +})(); diff --git a/www/js/eventsCRUD.js b/www/js/eventsCRUD.js new file mode 100644 index 0000000..654a5bd --- /dev/null +++ b/www/js/eventsCRUD.js @@ -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("
  • " + item.title + "
  • "); + } + $(containerId).empty(); + $("