From 1918f6d64352f1fc1d969c7e6a88485a1e6e3fd7 Mon Sep 17 00:00:00 2001 From: gine Date: Sat, 25 Mar 2017 16:30:49 +0100 Subject: [PATCH] Spostate altre funzioni in file autonomi --- www/js/tag.js | 136 +++++++++++++++++++++++++++++++++++++++++++ www/js/tag.update.js | 36 ------------ www/js/util.js | 44 ++++++++++++++ 3 files changed, 180 insertions(+), 36 deletions(-) create mode 100644 www/js/tag.js delete mode 100644 www/js/tag.update.js create mode 100644 www/js/util.js diff --git a/www/js/tag.js b/www/js/tag.js new file mode 100644 index 0000000..d61e343 --- /dev/null +++ b/www/js/tag.js @@ -0,0 +1,136 @@ +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 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: "
  • " + title + "
    " + cleanTime + "
  • ", + title: title + }); + } + // fallo solo quando items รจ stato riempito + if (finishCounter >= resultSet.rows.length - 1) { + $(div).empty(); + $("