From 3a7c880edf1faefd851a01c417bd00a6d4d7431e Mon Sep 17 00:00:00 2001 From: gine Date: Fri, 24 Mar 2017 02:48:43 +0100 Subject: [PATCH] Spostate le funzioni di update tag --- www/js/tag.update.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 www/js/tag.update.js 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