Gestione della visualizzazione di eventi singoli

This commit is contained in:
gine 2017-03-19 15:14:05 +01:00
parent bdfe57965a
commit 96deb48283
4 changed files with 72 additions and 27 deletions

View file

@ -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) {

View file

@ -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 = "<li>" +
//"<img src='./image/virgolette_1.png' class='epuntato'/>" +
"<a href='#event' data-post='" + item.id + "' >"
"<a class='event-"+type+"' href='#event' data-post='" + item.id + "' >"
+ item.title +
"</a>" +
"<br/>" +

View file

@ -273,10 +273,11 @@ function postInList() {
$("body").on('click', '.listevoci li > a', function (event) {
// console.log("HUU_post in list");
var idOra = $(this).attr("data-post");
var _class = $(this).attr("class");
$("#titolosingle").empty();
$("#mostracontentsingle").empty();
//console.log(idOra);
myJsonPost(idOra, "#titolosingle", "#mostracontentsingle");
myJsonPost(idOra, "#titolosingle", "#mostracontentsingle", _class);
// Prevent the usual navigation behavior
event.preventDefault();
/*se serve idTAg, mettiamolo nell'url!! e anche nella page!*/

View file

@ -104,20 +104,51 @@ function myJsonCategoryPaginated(Qcategory, div, pageNumber) {
$.mobile.loading('hide');
};
function myJsonPost(Qid, div_title, div_content) {
FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts WHERE id = ?;", [Qid], function (resultSet) {
for (var i = 0; i < resultSet.rows.length; i++) {
var val = JSON.parse(resultSet.rows.item(i).post);
var id = val.id;
var time = val.modified;
var title = val.title.rendered;
var url = val.guid.rendered;
var content = val.content.rendered;
content = findImg(content);
function drawPost(div_title, div_content, resultSet){
for (var i = 0; i < resultSet.rows.length; i++) {
var val = JSON.parse(resultSet.rows.item(i).post);
var id = val.id;
var time = val.modified;
var title = val.title.rendered;
var url = val.guid.rendered;
var content = val.content.rendered;
content = findImg(content);
$(div_title).html(title);
//key mi dice l'indice'
$(div_content).html("<p>" + content + "</p>");
$(div_title).html(title);
//key mi dice l'indice'
$(div_content).html("<p>" + content + "</p>");
}
}
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("<p>" + content + "</p>");
}
}
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);