]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/share/share.js
plugins: add some xhrPost refactoring
[tt-rss.git] / plugins / share / share.js
index bbfb553d5c3cccea18cc46b11ed8e20d51123059..11748d8fe73e0dfb26d35017b7f8ea74c6dc076e 100644 (file)
@@ -10,59 +10,55 @@ function shareArticle(id) {
                        title: __("Share article by URL"),
                        style: "width: 600px",
                        newurl: function() {
-
-                               var ok = confirm(__("Generate new share URL for this article?"));
-
-                               if (ok) {
+                               if (confirm(__("Generate new share URL for this article?"))) {
 
                                        notify_progress("Trying to change URL...", true);
 
-                                       var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
-
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function(transport) {
-                                                               var reply = JSON.parse(transport.responseText);
-                                                               var new_link = reply.link;
+                                       const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };
 
-                                                               var e = $('gen_article_url');
+                                       xhrJson("backend.php", query, (reply) => {
+                                               if (reply) {
+                                                       const new_link = reply.link;
+                                                       const e = $('gen_article_url');
 
-                                                               if (new_link) {
+                                                       if (new_link) {
 
-                                                                       e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
-                                                                               "&key=" + new_link);
+                                                               e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
+                                                                       "&key=" + new_link);
 
-                                                                       e.href = e.href.replace(/\&key=.*$/,
-                                                                               "&key=" + new_link);
+                                                               e.href = e.href.replace(/\&key=.*$/,
+                                                                       "&key=" + new_link);
 
-                                                                       new Effect.Highlight(e);
+                                                               new Effect.Highlight(e);
 
-                                                                       notify('');
+                                                               const img = $("SHARE-IMG-" + id);
+                                                               if (img) img.src = img.src.replace("notshared.png", "share.png");
 
-                                                               } else {
-                                                                       notify_error("Could not change URL.");
-                                                               }
-                                               } });
+                                                               notify('');
 
+                                                       } else {
+                                                               notify_error("Could not change URL.");
+                                                       }
+                                               }
+                                       });
                                }
 
                        },
                        unshare: function() {
+                               if (confirm(__("Remove sharing for this article?"))) {
 
-                               var ok = confirm(__("Remove sharing for this article?"));
+                                       notify_progress("Trying to unshare...", true);
 
-                               if (ok) {
+                                       const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };
 
-                                       notify_progress("Trying to unshare...", true);
+                                       xhrPost("backend.php", query, () => {
+                                               notify("Article unshared.");
 
-                                       var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
+                                               var img = $("SHARE-IMG-" + id);
+                                               if (img) img.src = img.src.replace("share.png", "notshared.png");
 
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function(transport) {
-                                                       notify("Article unshared.");
-                                                       dialog.hide();
-                                               } });
+                                               dialog.hide();
+                                       });
                                }
 
                        },
@@ -70,6 +66,9 @@ function shareArticle(id) {
 
                dialog.show();
 
+               const img = $("SHARE-IMG-" + id);
+               if (img) img.src = img.src.replace("notshared.png", "share.png");
+
        } catch (e) {
                exception_error("shareArticle", e);
        }