]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement assign-to-label in subtoolbar
authorAndrew Dolgov <fox@bah.spb.su>
Sun, 18 Jan 2009 08:47:34 +0000 (09:47 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sun, 18 Jan 2009 08:47:34 +0000 (09:47 +0100)
functions.php
modules/backend-rpc.php
viewfeed.js

index 2a3472902a9c6c55f5a106ecd44e074617435929..665825e41909ea8c96fc58542c9dff333c807927 100644 (file)
                                                        <li onclick=\"$tog_unread_link\">&nbsp;&nbsp;".__('Unread')."</li>
                                                        <li onclick=\"$tog_marked_link\">&nbsp;&nbsp;".__('Starred')."</li>
                                                        <li onclick=\"$tog_published_link\">&nbsp;&nbsp;".__('Published')."</li>
-                                                       <li><span class=\"insensitive\">--------</span></li>
+                                                       <!-- <li><span class=\"insensitive\">--------</span></li> -->
                                                        <li><span class=\"insensitive\">".__('Mark as read:')."</span></li>
                                                        <li onclick=\"$catchup_sel_link\">&nbsp;&nbsp;".__('Selection')."</li>";
 
 
                                print "<li onclick=\"$catchup_feed_link\">&nbsp;&nbsp;".__('Entire feed')."</li>";
 
-                               print "<li><span class=\"insensitive\">--------</span></li>";
-                               print "<li><span class=\"insensitive\">".__('Other actions:')."</span></li>";
-                               
+                               //print "<li><span class=\"insensitive\">--------</span></li>";
+                               print "<li><span class=\"insensitive\">".__('Assign label:')."</span></li>";
+
+                               $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 WHERE
+                                       owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
+
+                               while ($line = db_fetch_assoc($result)) {
+
+                                       $label_id = $line["id"];
+                                       $label_caption = $line["caption"];
+
+                                       print "<li onclick=\"javascript:selectionAssignLabel($label_id)\">
+                                               &nbsp;&nbsp;$label_caption</li>";
+                       }
+
                                print   "</ul></li></ul>";
                                print "</td>"; 
        
                }
        }
 
+       function label_find_caption($link, $label, $owner_uid) {
+               $result = db_query($link, 
+                       "SELECT caption FROM ttrss_labels2 WHERE id = '$label' 
+                               AND owner_uid = '$owner_uid' LIMIT 1");
+
+               if (db_num_rows($result) == 1) {
+                       return db_fetch_result($result, 0, "caption");
+               } else {
+                       return "";
+               }
+       }
+
        function label_add_article($link, $id, $label, $owner_uid) {
 
                $label_id = label_find_id($link, $label, $owner_uid);
index 4d65ee23ed924943ed866324d76ae86dc401cce0..691771f736ccb2665c3d0e90333ff6a5d1095745 100644 (file)
                        return;
                }
 
+               if ($subop == "assignToLabel") {
+
+                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
+                       $label_id = db_escape_string($_REQUEST["lid"]);
+
+                       $label = label_find_caption($link, $label_id, $_SESSION["uid"]);
+
+                       if ($label) {
+
+                               foreach ($ids as $id) {
+                                       label_add_article($link, $id, $label, $_SESSION["uid"]);
+                               }
+                       }
+
+                       print "<rpc-reply><counters>";
+
+                       if ($label) {
+                               getGlobalCounters($link);
+                               getLabelCounters($link);
+                               if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                                       getCategoryCounters($link);
+                               }
+                       }
+
+                       print "</counters></rpc-reply>";
+
+                       return;
+               }
+
                print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
        }
 ?>
index a93f886deb1024f6c41c7fbe449eca4a28bdab2f..b0cb068e1cc6c47cb01e017a1473481d9e2a3bc8 100644 (file)
@@ -850,6 +850,38 @@ function toggleUnread(id, cmode, effect) {
        }
 }
 
+function selectionAssignLabel(id) {
+       try {
+
+               var ids = getSelectedArticleIds2();
+
+               if (ids.length == 0) {
+                       alert(__("No articles are selected."));
+                       return;
+               }
+
+               var ok = confirm(__("Assign selected articles to label?"));
+
+               if (ok) {
+
+                       var query = "backend.php?op=rpc&subop=assignToLabel&ids=" +
+                               param_escape(ids.toString()) + "&lid=" + param_escape(id);
+
+//                     notify_progress("Loading, please wait...");
+
+                       new Ajax.Request(query, {
+                               onComplete: function(transport) { 
+                                       all_counters_callback2(transport); 
+                               } });
+
+               }
+
+       } catch (e) {
+               exception_error("selectionAssignLabel", e);
+
+       }
+}
+
 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
        try {
                var rows;