Info e comunicati
+News
- + + Non è stato attalmente caricato alcun contenuto +
+ +Info e comunicati
+News
- + + Non è stato attalmente caricato alcun contenuto +
+ +I love Xm24
++ + Non è stato attalmente caricato alcun contenuto + +
+ + +IO AMO XM
-- -
-- - + + Non è stato attalmente caricato alcun contenuto +
- -" + content + "
"); -// } -// }, function (error) { -// console.log(error); -// }); -//}; -// -//function myJsonPage(Qid, div_title, div_content) { -// $.mobile.loading('show'); -// var pageId = parseInt(Qid); -// FONTE.dbHandler.executeSql("SELECT * FROM xm24_pages WHERE id = ?;", [pageId], function (resultSet) { -// for (var i = 0; i < resultSet.rows.length; i++) { -// var data = resultSet.rows.item(i); -// var id = data.id; -// var time = data.time; -// var title = data.title; -// var content = data.page; -// content = findImg(content); -// $(div_title).html(title); -// //key mi dice l'indice' -// $(div_content).html("" + content + "
"); -// } -// }); -// $.mobile.loading('hide'); -//}; -// -//function myJsonRandomPost(div_title, div_content) { -// $.mobile.loading('show'); -// FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts ORDER BY RANDOM() LIMIT 1;", [], 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); -// $(div_title).html(title); -// //key mi dice l'indice' -// $(div_content).html("" + content + "
"); -// } -// }); -// $.mobile.loading('hide'); -//}; -// -//function myJsonPostByTagList(idTag, div) { -// $.mobile.loading('show'); -// var tagid = parseInt(idTag); -// FONTE.dbHandler.executeSql("SELECT * FROM xm24_tags_to_posts WHERE tagid = ?;", [tagid], function (resultSet) { -// var items = []; -// var finishCounter = 0; -// for (var i = 0; i < resultSet.rows.length; i++) { -// var val = resultSet.rows.item(i); -// FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts WHERE id = ? ORDER BY title COLLATE NOCASE ASC;", [val.id], function (resultSetPost) { -// finishCounter++; -// for (var n = 0; n < resultSetPost.rows.length; n++) { -// var val = JSON.parse(resultSetPost.rows.item(n).post); -// var id = val.id; -// var time = val.modified; -// var title = val.title.rendered; -// var url = val.guid.rendered; -// var splitTime = time.split("T"); -// var cleanTime = splitTime[0]; -// //key mi dice l'indice' -// items.push({ -// item: "" + 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); @@ -242,19 +395,34 @@ function createDB() { name: FONTE.dbName , location: 'default' }, function () { - FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_posts (id INTEGER PRIMARY KEY, title, date, category, post)'); + FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_posts (id INTEGER PRIMARY KEY, title, date, post)'); + + FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_cats (catid INTEGER PRIMARY KEY, title, cat)'); + FONTE.dbHandler.executeSql('CREATE TABLE IF NOT EXISTS xm24_cats_to_posts (id, catid, PRIMARY KEY (id, catid))'); + 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); }); }; +function insertOrUpdateCatToPost(id, catId) { + FONTE.dbHandler.executeSql('INSERT OR REPLACE INTO xm24_cats_to_posts VALUES (?,?)', [id, catId], function (resultSet) { + console.log('resultSet.insertId: ' + resultSet.insertId); + console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected); + }, function (error) { + console.log('INSERT error: ' + error.message); + //feedback + $("#aggiorna").attr("src", "./image/aggiorna.png"); + }); +} + function deleteDB() { window.sqlitePlugin.deleteDatabase({ name: FONTE.dbName @@ -299,7 +467,7 @@ function getSinglePageRecur(url, category, pagenum) { FONTE.updatedPostsCount += 1; console.log('Voci aggiornate: ' + FONTE.updatedPostsCount); if (FONTE.updatedCategoriesCount >= FONTE.categoriesList.length && FONTE.updatedPostsCount >= FONTE.neededPostsCount) { - window.localStorage.setItem('has_run', 'true'); + //window.localStorage.setItem('has_run', 'true'); var date = new Date(); var currentUpdate = date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2); @@ -314,7 +482,7 @@ function getSinglePageRecur(url, category, pagenum) { //feedback $("#aggiorna").attr("src", "./image/aggiorna.png"); - ultimoAggiornamento(); + displayLastUpdateDate(); } //manca il caso in cui sono stati cancellati dei post online, vanno cancellati anche dall'app. }, function (error) { FONTE.updatedPostsCount += 1; diff --git a/www/js/tag.update.js b/www/js/tag.update.js new file mode 100644 index 0000000..0e2235b --- /dev/null +++ b/www/js/tag.update.js @@ -0,0 +1,36 @@ +function aggiornaTagsToPosts(id, tagId) { + FONTE.dbHandler.executeSql('INSERT INTO xm24_tags_to_posts VALUES (?,?)', [id, tagId], function (resultSet) { + console.log('resultSet.insertId: ' + resultSet.insertId); + console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected); + }, function (error) { + console.log('INSERT error: ' + error.message); + //feedback + $("#aggiorna").attr("src", "./image/aggiorna.png"); + }); +} + +function aggiornaTags(pagenum) { + var jsonurl = weburl + "wp-json/wp/v2/tags?per_page=100&page=" + pagenum; + $.ajax({ + dataType: "json" + , url: jsonurl + , success: function (data, status, xhr) { + var totalPages = parseInt(xhr.getResponseHeader("X-WP-TotalPages")); + $.each(data, function (key, val) { + var name = val.name; + var slug = val.slug; + var id = val.id; + var blob = JSON.stringify(val); + FONTE.dbHandler.executeSql('INSERT INTO xm24_tags VALUES (?,?,?)', [id, slug, blob], function (resultSet) { + console.log('resultSet.insertId: ' + resultSet.insertId); + console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected); + }, function (error) { + console.log('INSERT error: ' + error.message); + }); + }); + pagenum += 1 + if (pagenum <= totalPages) aggiornaTags(pagenum) + } + , error: JSONErrorHandler + }); +}; \ No newline at end of file diff --git a/www/js/update.js b/www/js/update.js index 561359d..fbb8df7 100644 --- a/www/js/update.js +++ b/www/js/update.js @@ -1,3 +1,7 @@ +var REST_PARAMS = REST_PARAMS || {}; +REST_PARAMS.max_page = 10; +REST_PARAMS.per_page = 'per_page=' + REST_PARAMS.max_page; + function aggiornaPages() { var jsonurl = weburl + "wp-json/wp/v2/pages/"; $.ajax({ @@ -25,7 +29,7 @@ function aggiornaSingleCategory(category) { //resetta la variabile d'errore per le chiamate ajax asincrone FONTE.ajaxError = false; - var jsonurl = weburl + "wp-json/wp/v2/posts?per_page=100"; + var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page; var storage = window.localStorage; var lastUpdate = storage.getItem('db_update_date'); @@ -34,43 +38,6 @@ function aggiornaSingleCategory(category) { getSinglePageRecur(jsonurl, category, 1) }; -function aggiornaTagsToPosts(id, tagId) { - FONTE.dbHandler.executeSql('INSERT INTO xm24_tags_to_posts VALUES (?,?)', [id, tagId], function (resultSet) { - console.log('resultSet.insertId: ' + resultSet.insertId); - console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected); - }, function (error) { - console.log('INSERT error: ' + error.message); - //feedback - $("#aggiorna").attr("src", "./image/aggiorna.png"); - }); -} - -function aggiornaTags(pagenum) { - var jsonurl = weburl + "wp-json/wp/v2/tags?per_page=100&page=" + pagenum; - $.ajax({ - dataType: "json" - , url: jsonurl - , success: function (data, status, xhr) { - var totalPages = parseInt(xhr.getResponseHeader("X-WP-TotalPages")); - $.each(data, function (key, val) { - var name = val.name; - var slug = val.slug; - var id = val.id; - var blob = JSON.stringify(val); - FONTE.dbHandler.executeSql('INSERT INTO xm24_tags VALUES (?,?,?)', [id, slug, blob], function (resultSet) { - console.log('resultSet.insertId: ' + resultSet.insertId); - console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected); - }, function (error) { - console.log('INSERT error: ' + error.message); - }); - }); - pagenum += 1 - if (pagenum <= totalPages) aggiornaTags(pagenum) - } - , error: JSONErrorHandler - }); -}; - function aggiornaora() { $("#aggiornaora").popup("open"); }; @@ -95,52 +62,193 @@ function update() { }); } -function partialUpdate() { - //feedback - $("#aggiorna").attr("src", "./image/icona_aggiorna.gif"); - var storage = window.localStorage; - var jsonurl = weburl + "wp-json/wp/v2/posts?per_page=100&categories="; +var getObjKey = function(obj, val){ + var key = null; + for(var k in obj){ + if(obj[k] == val){ + key = k; + break; + } + } + + return key; +} +function partialUpdate(categories) { + var storage = window.localStorage; + var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page + "&categories=" + categories.join(','); + FONTE.updatedCategoriesCount = 0; FONTE.updatedPostsCount = 0; FONTE.neededPostsCount = 0; - for (var index in FONTE.categoriesList) { - aggiornaSingleCategory(FONTE.categoriesList[index]) - } - FONTE.dbHandler.executeSql('DROP TABLE IF EXISTS xm24_tags;'); - // FONTE.dbHandler.executeSql('DROP TABLE IF EXISTS xm24_tags_to_posts;'); - FONTE.dbHandler.executeSql('DROP TABLE IF EXISTS xm24_pages;'); - 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)'); - aggiornaTags(1); - aggiornaPages(); - + + FONTE.ajaxError = false; + + var lastUpdate = storage.getItem('db_update_date'); + if (lastUpdate) + jsonurl += "&after=" + lastUpdate; + //jsonurl += "&filter[date_query][column]=post_modified_gmt&filter[date_query][after]=" + lastUpdate; + var firstTime = storage.getItem('db_lastnews_firsttime'); if (firstTime == null) storage.setItem('db_lastnews_firsttime', 'yes'); if (firstTime == 'yes') storage.setItem('db_lastnews_firsttime', 'no'); - $("#benvenuta").popup("close"); - checkloader(); - + + getLastSinglePageRecur(jsonurl, 1, categories); }; -/* - * data ultimo aggiornamento - */ -function ultimoAggiornamento() { - var lastUpdate = window.localStorage.getItem('db_update_date'); - if (lastUpdate) { - var data = lastUpdate.split('T'); - var datagiorno = data[0]; - var dataora = data[1]; - $("#datadiritti").empty(); - $("#datadirittiora").empty(); - display_results("#datadiritti", datagiorno) - display_results("#datadirittiora", dataora) - if (data) { - $("#boxdata").css("display", "block"); +var updateLocalStorageDate = function(){ + var date = new Date(); + + var currentUpdate = date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2); + currentUpdate += 'T' + ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2) + ':' + ('0' + date.getSeconds()).slice(-2); + + var lastUpdate = window.localStorage.getItem('db_update_date') + + window.localStorage.setItem('db_update_date', currentUpdate); + window.localStorage.setItem('db_lastnews_date', lastUpdate); +} + +var getPrevNews = function(div, categories, page) { + var storage = window.localStorage; + var type = getObjKey(FONTE.categories, categories); + var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page + "&categories=" + FONTE.categories[type].join(','); + + FONTE.updatedCategoriesCount = 0; + FONTE.updatedPostsCount = 0; + FONTE.neededPostsCount = 0; + + var oldest_date = window.localStorage.getItem('db_oldest_' + type + '_date'); + if (oldest_date) + jsonurl += "&before=" + oldest_date; + + getPrevSinglePageRecur(jsonurl, 1, FONTE.categories[type]); +} + +function loadMore(type) { + var categories = FONTE.categories[type]; + + renderPrevNews(FONTE.contentListId, categories, FONTE.page_loaded[type], function(){ + getPrevNews(FONTE.contentListId, categories, FONTE.page_loaded[type]) + }); +} + +function getPrevSinglePageRecur(url, pagenum, categories) { + var type = getObjKey(FONTE.categories, categories); + + console.log('url:'+url); + $.ajax({ + dataType: "json" + , url: url + "&page=" + pagenum + , success: function (data, textStatus, jqXHR) { + var totalPages = jqXHR.getResponseHeader('X-WP-TotalPages'); + + FONTE.neededPostsCount += data.length; + if (FONTE.neededPostsCount == 0) { + toastr.info('Non ci sono altri alticoli da visualizzare in questa sezione'); + updateLocalStorageDate(); + } + + var n_error = 0 + var oldest_date = window.localStorage.getItem('db_oldest_' + type + '_date'); + $.each(data, function (key, val) { + var id = val.id; + var time = val.modified; + var title = val.title.rendered; + var tags = val.tags; + var postCategories = val.categories; + var blob = JSON.stringify(val); + + FONTE.dbHandler.executeSql('INSERT OR REPLACE INTO xm24_posts VALUES (?,?,?,?)', [id, title, time, blob], function (resultSet) { + FONTE.updatedPostsCount++; + oldest_date = time; + if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount) { + updateLocalStorageDate(); + window.localStorage.setItem('db_oldest_' + type + '_date', oldest_date); + toastr.info('Caricati altri ' + FONTE.updatedPostsCount + ' articoli.'); + loadMore(type); + } //manca il caso in cui sono stati cancellati dei post online, vanno cancellati anche dall'app. + }, function (error) { + n_error++; + if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount && FONTE.updatedPostsCount > 0 ) { + updateLocalStorageDate(); + window.localStorage.setItem('db_oldest_' + type + '_date', oldest_date); + toastr.info('Caricati altri ' + FONTE.updatedPostsCount + ' articoli.'); + loadMore(type); + } + }); + + $.each(postCategories, function (key, val) { + insertOrUpdateCatToPost(id, val); + }); + }); } - } else { - toastr.warning('Warn: manca la data del tuo ultimo aggiornamento. Aggiorna al più presto.'); - } + , error: JSONErrorHandler + }); }; + +function getLastSinglePageRecur(url, pagenum, categories) { + var type = getObjKey(FONTE.categories, categories); + + console.log('url:'+url); + $.ajax({ + dataType: "json" + , url: url + "&page=" + pagenum + , success: function (data, textStatus, jqXHR) { + var totalPages = jqXHR.getResponseHeader('X-WP-TotalPages'); + + FONTE.neededPostsCount += data.length; + if (FONTE.neededPostsCount == 0) { + toastr.info('Nessun nuovo articolo.'); + updateLocalStorageDate(); + if(FONTE.page_loaded[type] == 0) { + renderLastNews(FONTE.contentListId, categories); + } + } + + var n_error = 0 + var oldest_date = window.localStorage.getItem('db_oldest_' + type + '_date'); + var older_date = null; + $.each(data, function (key, val) { + var id = val.id; + var time = val.modified; + var title = val.title.rendered; + var tags = val.tags; + var postCategories = val.categories; + var blob = JSON.stringify(val); + + FONTE.dbHandler.executeSql('INSERT OR REPLACE INTO xm24_posts VALUES (?,?,?,?)', [id, title, time, blob], function (resultSet) { + FONTE.updatedPostsCount++; + console.log('Voci aggiornate: ' + FONTE.updatedPostsCount); + older_date = time; + if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount) { + updateLocalStorageDate(); + if(! oldest_date) + window.localStorage.setItem('db_oldest_' + type + '_date', older_date); + + toastr.info('Ci sono ' + FONTE.updatedPostsCount + ' nuovi articoli.'); + renderLastNews(FONTE.contentListId, categories); + } //manca il caso in cui sono stati cancellati dei post online, vanno cancellati anche dall'app. + }, function (error) { + n_error++; + if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount && FONTE.updatedPostsCount > 0 ) { + updateLocalStorageDate(); + if(! oldest_date) + window.localStorage.setItem('db_oldest_' + type + '_date', older_date); + + toastr.info('Aggiornati ' + FONTE.updatedPostsCount + ' nuovi articoli.'); + renderLastNews(FONTE.contentListId, categories); + } + }); + + // $.each(tags, function (key, val) { + // aggiornaTagsToPosts(id, val); + // }); + + $.each(postCategories, function (key, val) { + insertOrUpdateCatToPost(id, val); + }); + }); + } + , error: JSONErrorHandler + }); +}; \ No newline at end of file diff --git a/www/js/vendor/moment.min.js b/www/js/vendor/moment.min.js new file mode 100644 index 0000000..8c70671 --- /dev/null +++ b/www/js/vendor/moment.min.js @@ -0,0 +1,551 @@ +//! moment.js +//! version : 2.17.1 +//! authors : Tim Wood, Iskren Chernev, Moment.js contributors +//! license : MIT +//! momentjs.com +!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.moment=b()}(this,function(){"use strict";function a(){return od.apply(null,arguments)} +// This is done to register the method called with moment() +// without creating circular dependencies. +function b(a){od=a}function c(a){return a instanceof Array||"[object Array]"===Object.prototype.toString.call(a)}function d(a){ +// IE8 will treat undefined and null as object if it wasn't for +// input != null +return null!=a&&"[object Object]"===Object.prototype.toString.call(a)}function e(a){var b;for(b in a) +// even if its not own property I'd still call it non-empty +return!1;return!0}function f(a){return"number"==typeof a||"[object Number]"===Object.prototype.toString.call(a)}function g(a){return a instanceof Date||"[object Date]"===Object.prototype.toString.call(a)}function h(a,b){var c,d=[];for(c=0;c