diff --git a/www/js/events.js b/www/js/events.js index 6bcc692..cc723cf 100644 --- a/www/js/events.js +++ b/www/js/events.js @@ -7,10 +7,17 @@ var ai1ec = (function(){ repeat: 25 }; + var getCleanId = function(uid){ + var initChar = uid.indexOf('-'), + endChar = uid.indexOf('@') + + return uid.substr(initChar+1, uid.length - uid.substr(endChar -1).length - initChar ); + } + //Parser di un evento dell'array tornato da getXmlData API.event = { getId : function(event) { - return event.uid || null; + return event.uid ? getCleanId(event.uid) : null; }, getTitle : function(event) { diff --git a/www/js/eventsCRUD.js b/www/js/eventsCRUD.js index 49c33c8..1606890 100644 --- a/www/js/eventsCRUD.js +++ b/www/js/eventsCRUD.js @@ -1,5 +1,10 @@ var EVENTS = EVENTS || {}; +EVENTS.table = { + single : 'xm24_events_single', + repeat : 'xm24_events_repeat', +} + EVENTS.dateFormat = { store : { date: "YYYY-MM-DD", @@ -13,14 +18,6 @@ EVENTS.dateFormat = { EVENTS.storeDateFormat = EVENTS.dateFormat.store.date + " " + EVENTS.dateFormat.store.hour; EVENTS.displayDateFormat = EVENTS.dateFormat.display.date + " " + EVENTS.dateFormat.display.hour; -EVENTS.render = function() { - var ret = checkConnection('ERR_EVENT'); - if (ret) { - EVENTS.query(ai1ec.cats.single); - } else { - EVENTS.loadFromDb('#mostralista', ai1ec.cats.single); - } -} EVENTS.formatDate = function(date, format) { var mdate = moment(date); @@ -28,7 +25,16 @@ EVENTS.formatDate = function(date, format) { return mdate.isValid() ? mdate.format(format) : ""; } -EVENTS.query = function (type) { +EVENTS.render = function() { + var ret = checkConnection('ERR_EVENT'); + if (ret) { + EVENTS.getDataAndLoad(ai1ec.cats.single); + } else { + EVENTS.loadFromDb('#mostralista', ai1ec.cats.single); + } +} + +EVENTS.getDataAndLoad = function (type) { type = type || ai1ec.cats.single; var table = type == ai1ec.cats.repeat ? 'xm24_events_repeat' : 'xm24_events_single'; @@ -105,7 +111,7 @@ EVENTS.loadFromDb = function (containerId, type) { var li = "
" + content + "
"); + $(div_title).html(title); + //key mi dice l'indice' + $(div_content).html("" + content + "
"); + } +} + +function drawEvent(div_title, div_content, resultSet){ + for (var i = 0; i < resultSet.rows.length; i++) { + var val = resultSet.rows.item(i); + var evInitDate = EVENTS.formatDate(val.initDate, EVENTS.displayDateFormat); + var evEndDate = EVENTS.formatDate(val.endDate, EVENTS.displayDateFormat); + + var id = val.id; + var title = val.title; + var url = val.url; + var content = val.description; + var geo = val.geo; + + $(div_title).html(title); + //key mi dice l'indice' + $(div_content).html("" + content + "
"); + } +} + +function myJsonPost(Qid, div_title, div_content, _class) { + var table = "xm24_posts"; + if(_class){ + table = EVENTS.table.single; + } + + FONTE.dbHandler.executeSql("SELECT * FROM " + table + " WHERE id = ?;", [Qid], function(resultSet) { + if(!_class){ + drawPost(div_title, div_content, resultSet); + } else { + drawEvent(div_title, div_content, resultSet); } }, function (error) { console.log(error); @@ -246,9 +277,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_events_single (id INTEGER 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)'); + FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_events_repeat (id INTEGER PRIMARY KEY, title, description, initDate, endDate, url, geo)'); }, function () { console.log('error'); console.log(arguments);