2017-03-18 15:43:44 +01:00
function myJsonCategory ( Qcategory , div , addTagCategory ) {
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;" , [ Qcategory ] , function ( resultSet ) {
2017-03-18 15:43:44 +01:00
var items = [ ] ;
for ( var i = 0 ; i < resultSet . rows . length ; i ++ ) {
var val = JSON . parse ( resultSet . rows . item ( i ) . post ) ;
var id = val . id ;
2017-03-26 17:40:41 +02:00
var date = val . date ;
2017-03-18 15:43:44 +01:00
var title = val . title . rendered ;
var url = val . guid . rendered ;
2017-03-26 17:40:41 +02:00
var cleanTime = EVENTS . formatDate ( date , EVENTS . dateFormat . display . date ) ;
2017-03-18 15:43:44 +01:00
var tag = '' ;
var cattag = '' ;
/ * i f ( a d d T a g C a t e g o r y ) {
$ . each ( val . tags , function ( index , value ) {
if ( value == 43 ) {
}
if ( value == 36 ) {
}
} ) ;
//key mi dice l'indice'
2017-03-18 17:54:19 +01:00
items . push ( "<li class='" + cattag + "'><a href='#singleQpost' data-post='" + id + "'>" + title + "</a><br/><small>" + cleanTime + "</small><span>" + tag + "</span>|</li>" ) ;
2017-03-18 15:43:44 +01:00
}
else { * /
2017-03-26 17:40:41 +02:00
items . push ( getLiPost ( id , title , cleanTime ) ) ;
2017-03-18 15:43:44 +01:00
}
$ ( "<ul/>" , {
2017-03-25 16:32:18 +01:00
"class" : "my-new-list" ,
html : items . join ( "" )
2017-03-18 15:43:44 +01:00
} ) . prependTo ( div ) ;
2017-03-26 17:40:41 +02:00
$ . mobile . loading ( 'hide' ) ;
2017-03-18 15:43:44 +01:00
} ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
2017-03-26 17:40:41 +02:00
var getLiPostNotPresent = function ( id , title , cleanTime , url , style ) {
//TODO:var onclick = " onclick='"+getWpPost()+ "' ";
var li = "<li>" +
"<a style='" + style + "' href='" + url + "' rel='external'>" +
title +
"</a>" +
"<br/>" +
"<small>" + cleanTime + "</small>" +
"<hr class='post-divider'>" +
"</li>" ;
return li ;
} ;
var getLiPost = function ( id , title , cleanTime ) {
var li = "<li>" +
"<a href='#singleQpost' data-post='" + id + "'>" +
title +
"</a>" +
"<br/>" +
"<small>" + cleanTime + "</small>" +
"<hr class='post-divider'>" +
"</li>" ;
return li ;
} ;
2017-03-24 02:51:21 +01:00
var drawListPost = function ( div , resultSet , position ) {
2017-03-23 19:51:21 +01:00
var items = [ ] ;
2017-03-24 02:51:21 +01:00
for ( var i = 0 ; i < resultSet . rows . length ; i ++ ) {
var val = JSON . parse ( resultSet . rows . item ( i ) . post ) ;
var id = val . id ;
2017-03-25 17:13:16 +01:00
var date = val . date ;
2017-03-24 02:51:21 +01:00
var title = val . title . rendered ;
var url = val . guid . rendered ;
var cleanTime = EVENTS . formatDate ( date , EVENTS . dateFormat . display . date ) ;
2017-03-25 17:01:38 +01:00
2017-03-26 17:40:41 +02:00
items . push ( getLiPost ( id , title , cleanTime ) ) ;
2017-03-24 02:51:21 +01:00
}
2017-03-25 17:01:38 +01:00
2017-03-24 02:51:21 +01:00
var ul = $ ( "<ul/>" , {
html : items . join ( "" )
2017-03-25 16:32:18 +01:00
} ) ;
2017-03-25 17:01:38 +01:00
2017-03-24 02:51:21 +01:00
if ( position == 'append' ) {
ul . appendTo ( div ) ;
} else if ( position == 'prepend' ) {
ul . prependTo ( div ) ;
}
2017-04-19 17:42:11 +02:00
setTimeout ( function ( ) {
$ . mobile . loading ( 'hide' ) ;
} , 1000 ) ;
2017-03-25 16:32:18 +01:00
} ;
2017-03-24 02:51:21 +01:00
var appendPostList = function ( div , resultSet , categories , fallback ) {
var type = getObjKey ( FONTE . categories , categories ) ;
if ( resultSet . rows . length > 0 ) {
FONTE . page _loaded [ type ] ++ ;
drawListPost ( div , resultSet , 'append' ) ;
} else if ( fallback ) {
fallback ( ) ;
} else {
2017-03-26 19:03:01 +02:00
$ . mobile . loading ( 'hide' ) ;
2017-03-24 02:51:21 +01:00
toastr . info ( "Non ci sono altri articoli da visualizzare" ) ;
}
} ;
var prependPostsList = function ( div , resultSet , categories , fallback ) {
var type = getObjKey ( FONTE . categories , categories ) ;
2017-03-29 22:29:15 +02:00
//$(div).empty();
2017-03-23 19:51:21 +01:00
if ( resultSet . rows . length > 0 ) {
2017-03-24 02:51:21 +01:00
FONTE . page _loaded [ type ] ++ ;
drawListPost ( div , resultSet , 'prepend' ) ;
2017-03-23 19:51:21 +01:00
} else if ( fallback ) {
fallback ( div , categories ) ;
} else {
drawNoPostsFound ( div ) ;
}
} ;
function drawNoPostsFound ( div ) {
$ ( div ) . empty ( ) ;
2017-03-25 16:32:18 +01:00
$ ( div ) . append ( '<span>Non ci sono nuovi contenuti.</span>' ) ;
2017-03-26 19:03:01 +02:00
$ . mobile . loading ( 'hide' ) ;
2017-03-23 19:51:21 +01:00
}
function sqlErrHandler ( error ) {
2017-03-26 17:40:41 +02:00
$ . mobile . loading ( 'hide' ) ;
2017-03-23 19:51:21 +01:00
console . log ( error . message ) ;
}
var getCategoryWhere = function ( categories ) {
var catsWhere = "" ;
for ( var i = 0 , len = categories . length ; i < len ; i ++ ) {
var cat = categories [ i ] ;
var c = 'catid = ' + cat + ' ' ;
2017-03-25 16:32:18 +01:00
if ( i === 0 ) {
2017-03-23 19:51:21 +01:00
catsWhere = '(' + c ;
} else if ( i == len - 1 ) {
catsWhere += 'OR ' + c + ')' ;
} else {
catsWhere += 'OR ' + c ;
}
}
return catsWhere ;
2017-03-25 16:32:18 +01:00
} ;
2017-03-23 19:51:21 +01:00
var POST = POST || { } ;
POST . sql = {
2017-04-19 17:42:11 +02:00
init : "SELECT DISTINCT * FROM xm24_posts JOIN xm24_cats_to_posts USING(id) WHERE " ,
2017-03-24 02:51:21 +01:00
end : "ORDER BY date COLLATE NOCASE DESC LIMIT ?"
2017-03-25 16:32:18 +01:00
} ;
2017-03-23 19:51:21 +01:00
2017-03-26 17:40:41 +02:00
POST . table = "xm24_posts" ;
2017-03-23 19:51:21 +01:00
var selectLastNews = function ( div , categories ) {
var catsWhere = getCategoryWhere ( categories ) ;
var sql = POST . sql . init + catsWhere + POST . sql . end ;
2017-03-24 02:51:21 +01:00
FONTE . dbHandler . executeSql ( sql , [ REST _PARAMS . max _page ] , function ( resultSet ) {
prependPostsList ( div , resultSet , categories ) ;
2017-03-23 19:51:21 +01:00
} , sqlErrHandler ) ;
2017-03-25 16:32:18 +01:00
} ;
2017-03-23 19:51:21 +01:00
function renderLastNews ( div , categories ) {
var storage = window . localStorage ;
2017-03-25 16:32:18 +01:00
var type = getObjKey ( FONTE . categories , categories ) ;
var lastnewsDate = storage . getItem ( 'db_last_' + type + '_date' ) ;
var firstTime = storage . getItem ( 'db_last_' + type + '_firsttime' ) ;
2017-03-23 19:51:21 +01:00
if ( firstTime == 'yes' ) {
selectLastNews ( div , categories ) ;
} else if ( firstTime == 'no' ) {
if ( lastnewsDate ) {
var sql = POST . sql . init + "date > ? AND " + getCategoryWhere ( categories ) + POST . sql . end ;
2017-03-24 02:51:21 +01:00
FONTE . dbHandler . executeSql ( sql , [ lastnewsDate , REST _PARAMS . max _page ] , function ( resultSet ) {
prependPostsList ( div , resultSet , categories , selectLastNews ) ;
2017-03-23 19:51:21 +01:00
} , sqlErrHandler ) ;
} else {
selectLastNews ( div , categories ) ;
toastr . info ( "Non ci sono nuovi contenuti" ) ;
}
} else {
drawNoPostsFound ( div ) ;
}
2017-03-25 16:32:18 +01:00
}
2017-03-23 19:51:21 +01:00
2017-03-24 02:51:21 +01:00
function renderPrevNews ( div , categories , page , callback ) {
var sql = POST . sql . init + getCategoryWhere ( categories ) + POST . sql . end + ', ?' ;
FONTE . dbHandler . executeSql ( sql , [ page * REST _PARAMS . max _page , ( page + 1 ) * REST _PARAMS . max _page ] , function ( resultSet ) {
appendPostList ( div , resultSet , categories , callback ) ;
} , sqlErrHandler ) ;
}
2017-03-18 15:43:44 +01:00
function myJsonLastPage ( div ) {
var storage = window . localStorage ;
var lastnewsDate = storage . getItem ( 'db_lastnews_date' ) ;
var firstTime = storage . getItem ( 'db_lastnews_firsttime' ) ;
if ( firstTime != 'yes' ) {
if ( lastnewsDate ) {
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM xm24_posts WHERE date > ? ORDER BY date COLLATE NOCASE DESC LIMIT 40;" , [ lastnewsDate ] , function ( resultSet ) {
2017-03-18 15:43:44 +01:00
var items = [ ] ;
$ ( div ) . empty ( ) ;
if ( resultSet . rows . length > 0 ) {
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 ;
// console.log(Url);
var splitTime = time . split ( "T" ) ;
var cleanTime = splitTime [ 0 ] ;
//key mi dice l'indice'
2017-03-18 17:54:19 +01:00
items . push ( "<li><a href='#singleQpost' data-post='" + id + "'>" + title + "</a><br/><small>" + cleanTime + "</small>" ) ;
2017-03-18 15:43:44 +01:00
}
$ ( "<ul/>" , {
2017-03-25 16:32:18 +01:00
"class" : "my-new-list" ,
html : items . join ( "" )
2017-03-18 15:43:44 +01:00
} ) . prependTo ( div ) ;
} else {
$ ( div ) . empty ( ) ;
2017-03-25 16:32:18 +01:00
$ ( div ) . append ( '<span>Non ci sono nuovi contenuti.</span>' ) ;
2017-03-18 15:43:44 +01:00
}
} ) ;
} else {
$ ( div ) . empty ( ) ;
2017-03-25 16:32:18 +01:00
$ ( div ) . append ( '<span>Tutti i contenuti sono nuovi.</span>' ) ;
2017-03-18 15:43:44 +01:00
}
} else {
$ ( div ) . empty ( ) ;
2017-03-25 16:32:18 +01:00
$ ( div ) . append ( '<span>Tutti i contenuti sono nuovi.</span>' ) ;
2017-03-18 15:43:44 +01:00
}
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
function myJsonCategoryPaginated ( Qcategory , div , pageNumber ) {
$ . mobile . loading ( 'show' ) ;
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;" , [ Qcategory ] , function ( resultSet ) {
2017-03-18 15:43:44 +01:00
var items = [ ] ;
$ ( div ) . empty ( ) ;
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 tag = val . tags ;
var splitTime = time . split ( "T" ) ;
var cleanTime = splitTime [ 0 ] ;
//key mi dice l'indice'
2017-03-18 17:54:19 +01:00
items . push ( "<li><a href='#singleQpost' data-post='" + id + "'>" + title + "</a><br/><small>" + cleanTime + "</small></li>" ) ;
2017-03-18 15:43:44 +01:00
}
$ ( "<ul/>" , {
2017-03-25 16:32:18 +01:00
"class" : "my-new-list" ,
html : items . join ( "" )
2017-03-18 15:43:44 +01:00
} ) . prependTo ( div ) ;
} , function ( error ) {
console . log ( 'errore myJsonCategoryPaginated: ' + error ) ;
} ) ;
$ . mobile . loading ( 'hide' ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
2017-03-26 17:40:41 +02:00
var renderShareButton = function ( div _content , title , url , content ) {
$ ( '.share-btn' ) . remove ( ) ;
content = content || '' ;
var shareButton = $ ( '<button>' , {
class : "share-btn ui-btn ui-shadow ui-corner-all" ,
text : "Condividi"
} ) . click ( function ( ) {
shareMeNow ( title , content , url ) ;
} ) ;
$ ( div _content ) . after ( shareButton ) ;
} ;
2017-03-19 15:14:05 +01:00
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 ;
2017-03-25 18:37:25 +01:00
var time = val . date ;
2017-03-19 15:14:05 +01:00
var title = val . title . rendered ;
var url = val . guid . rendered ;
var content = val . content . rendered ;
2017-03-25 18:37:25 +01:00
var tags = val . tags ;
2017-03-19 15:14:05 +01:00
content = findImg ( content ) ;
2017-03-18 15:43:44 +01:00
2017-03-19 15:14:05 +01:00
$ ( div _title ) . html ( title ) ;
$ ( div _content ) . html ( "<p>" + content + "</p>" ) ;
2017-03-26 17:40:41 +02:00
renderShareButton ( div _content , title , url , '' ) ;
2017-03-19 15:14:05 +01:00
}
}
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 ;
2017-11-10 13:58:51 +01:00
var content = entityToHtml ( val . description ) ;
2017-03-19 15:14:05 +01:00
var geo = val . geo ;
2017-11-10 13:58:51 +01:00
var imgUrlThumb = getImageUrl ( val . img , 'thumb' ) ;
2017-03-19 15:14:05 +01:00
$ ( div _title ) . html ( title ) ;
2017-11-10 13:58:51 +01:00
var img = imgUrlThumb != "" ? "<a href='" + getImageUrl ( val . img , 'large' ) + "'>" +
"<img src='" + imgUrlThumb + "'/>" +
"</a><br>" : "" ;
$ ( div _content ) . html ( img + "<small>" + evInitDate + "-" + evEndDate + "</small><p>" + content + "</p>" ) ;
2017-03-26 17:40:41 +02:00
renderShareButton ( div _content , title , url , evInitDate + " " + evEndDate ) ;
2017-03-19 15:14:05 +01:00
}
}
function myJsonPost ( Qid , div _title , div _content , _class ) {
2017-03-26 17:40:41 +02:00
var table = POST . table ;
2017-03-19 15:14:05 +01:00
if ( _class ) {
table = EVENTS . table . single ;
}
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM " + table + " WHERE id = ?;" , [ Qid ] , function ( resultSet ) {
2017-03-19 15:14:05 +01:00
if ( ! _class ) {
drawPost ( div _title , div _content , resultSet ) ;
} else {
drawEvent ( div _title , div _content , resultSet ) ;
2017-03-18 15:43:44 +01:00
}
2017-03-26 17:40:41 +02:00
} , sqlErrHandler ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
function myJsonPage ( Qid , div _title , div _content ) {
$ . mobile . loading ( 'show' ) ;
var pageId = parseInt ( Qid ) ;
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM xm24_pages WHERE id = ?;" , [ pageId ] , function ( resultSet ) {
2017-03-18 15:43:44 +01:00
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 ) ;
$ ( div _content ) . html ( "<p>" + content + "</p>" ) ;
}
} ) ;
$ . mobile . loading ( 'hide' ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
function myJsonRandomPost ( div _title , div _content ) {
$ . mobile . loading ( 'show' ) ;
2017-04-19 17:42:11 +02:00
FONTE . dbHandler . executeSql ( "SELECT DISTINCT * FROM xm24_posts ORDER BY RANDOM() LIMIT 1;" , [ ] , function ( resultSet ) {
2017-03-18 15:43:44 +01:00
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>" ) ;
}
} ) ;
$ . mobile . loading ( 'hide' ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
function createDB ( ) {
//crea il databse per i posts se non esiste
FONTE . dbHandler = window . sqlitePlugin . openDatabase ( {
2017-03-25 16:32:18 +01:00
name : FONTE . dbName ,
location : 'default'
2017-03-18 15:43:44 +01:00
} , function ( ) {
2017-03-23 19:51:21 +01:00
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)' ) ;
2017-03-24 02:51:21 +01:00
FONTE . dbHandler . executeSql ( 'CREATE TABLE IF NOT EXISTS xm24_cats_to_posts (id, catid, PRIMARY KEY (id, catid))' ) ;
2017-03-23 19:51:21 +01:00
2017-04-08 17:30:50 +02:00
//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)');
2017-11-10 14:35:52 +01:00
FONTE . dbHandler . executeSql ( 'DROP TABLE IF EXISTS xm24_events_single' ) ;
2017-11-10 13:58:51 +01:00
FONTE . dbHandler . executeSql ( 'CREATE TABLE IF NOT EXISTS xm24_events_single (id INTEGER PRIMARY KEY, title, description, initDate, endDate, url, geo, img)' ) ;
2017-04-08 17:30:50 +02:00
//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 INTEGER PRIMARY KEY, title, description, initDate, endDate, url, geo)');
2017-03-18 15:43:44 +01:00
} , function ( ) {
console . log ( 'error' ) ;
console . log ( arguments ) ;
} ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
2017-03-23 19:51:21 +01:00
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" ) ;
} ) ;
}
2017-03-18 15:43:44 +01:00
function deleteDB ( ) {
window . sqlitePlugin . deleteDatabase ( {
2017-03-25 16:32:18 +01:00
name : FONTE . dbName ,
location : 'default'
2017-03-18 15:43:44 +01:00
} ) ;
var storage = window . localStorage ;
storage . setItem ( 'db_update_date' , null ) ;
storage . setItem ( 'db_lastnews_date' , null ) ;
createDB ( ) ;
2017-03-25 16:32:18 +01:00
}
2017-03-18 15:43:44 +01:00
function getSinglePageRecur ( url , category , pagenum ) {
$ . ajax ( {
2017-03-25 16:32:18 +01:00
dataType : "json" ,
url : url + "&categories=" + category + "&page=" + pagenum ,
success : function ( data , textStatus , jqXHR ) {
2017-03-18 15:43:44 +01:00
var totalPages = jqXHR . getResponseHeader ( 'X-WP-TotalPages' ) ;
2017-03-25 16:32:18 +01:00
if ( pagenum == totalPages || totalPages === 0 ) FONTE . updatedCategoriesCount += 1 ;
2017-03-18 15:43:44 +01:00
FONTE . neededPostsCount += data . length ;
2017-03-25 16:32:18 +01:00
if ( FONTE . updatedCategoriesCount >= FONTE . categoriesList . length && FONTE . neededPostsCount === 0 ) {
2017-03-18 15:43:44 +01:00
toastr . info ( 'Nessun nuovo articolo.' ) ;
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 ) ;
2017-03-25 16:32:18 +01:00
var lastUpdate = window . localStorage . getItem ( 'db_update_date' ) ;
2017-03-18 15:43:44 +01:00
window . localStorage . setItem ( 'db_update_date' , currentUpdate ) ;
window . localStorage . setItem ( 'db_lastnews_date' , lastUpdate ) ;
//feedback
$ ( "#aggiorna" ) . attr ( "src" , "./image/aggiorna.png" ) ;
}
$ . each ( data , function ( key , val ) {
var id = val . id ;
2017-03-25 17:13:16 +01:00
var time = val . date ;
2017-03-18 15:43:44 +01:00
var title = val . title . rendered ;
var tags = val . tags ;
var blob = JSON . stringify ( val ) ;
FONTE . dbHandler . executeSql ( 'INSERT OR REPLACE INTO xm24_posts VALUES (?,?,?,?,?)' , [ id , title , time , category , blob ] , function ( resultSet ) {
FONTE . updatedPostsCount += 1 ;
console . log ( 'Voci aggiornate: ' + FONTE . updatedPostsCount ) ;
if ( FONTE . updatedCategoriesCount >= FONTE . categoriesList . length && FONTE . updatedPostsCount >= FONTE . neededPostsCount ) {
2017-03-23 19:51:21 +01:00
//window.localStorage.setItem('has_run', 'true');
2017-03-18 15:43:44 +01:00
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 ) ;
2017-03-25 16:32:18 +01:00
var lastUpdate = window . localStorage . getItem ( 'db_update_date' ) ;
2017-03-18 15:43:44 +01:00
window . localStorage . setItem ( 'db_update_date' , currentUpdate ) ;
window . localStorage . setItem ( 'db_lastnews_date' , lastUpdate ) ;
toastr . info ( 'Aggiornati ' + FONTE . updatedPostsCount + ' articoli.' ) ;
//feedback
$ ( "#aggiorna" ) . attr ( "src" , "./image/aggiorna.png" ) ;
2017-03-23 19:51:21 +01:00
displayLastUpdateDate ( ) ;
2017-03-18 15:43:44 +01:00
} //manca il caso in cui sono stati cancellati dei post online, vanno cancellati anche dall'app.
} , function ( error ) {
FONTE . updatedPostsCount += 1 ;
if ( FONTE . updatedCategoriesCount >= FONTE . categoriesList . length && FONTE . updatedPostsCount >= FONTE . neededPostsCount ) {
toastr . info ( 'Aggiornati ' + FONTE . updatedPostsCount + ' articoli.' ) ;
//feedback
$ ( "#aggiorna" ) . attr ( "src" , "./image/aggiorna.png" ) ;
}
} ) ;
$ . each ( tags , function ( key , val ) {
aggiornaTagsToPosts ( id , val ) ;
} ) ;
} ) ;
if ( pagenum < totalPages ) {
pagenum += 1 ;
2017-03-25 16:32:18 +01:00
getSinglePageRecur ( url , category , pagenum ) ;
2017-03-18 15:43:44 +01:00
}
2017-03-25 16:32:18 +01:00
} ,
error : JSONErrorHandler
2017-03-18 15:43:44 +01:00
} ) ;
2017-03-25 16:32:18 +01:00
}