]> git.wh0rd.org Git - tt-rss.git/commitdiff
label editor: simple control to add common rules
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 7 Aug 2008 08:06:12 +0000 (09:06 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 7 Aug 2008 08:06:12 +0000 (09:06 +0100)
functions.js
functions.php
modules/popup-dialog.php
modules/pref-labels.php

index dd7f51ea6342cd8c1af65f51acf95c89915fc05a..61eb83d9572a531235a27c1a6f60fa9563ed411f 100644 (file)
@@ -1737,3 +1737,101 @@ function remove_splash() {
                debug("removed splash!");
        }
 }
+
+function addLabelExample() {
+       try {
+               var form = document.forms["label_edit_form"];
+
+               var text = form.sql_exp;
+               var op = form.label_fields[form.label_fields.selectedIndex];
+               var p = form.label_fields_param;
+
+               if (op) {
+                       op = op.value;
+
+                       var tmp = "";
+
+                       if (text.value != "") {                 
+                               if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
+                                       tmp = " AND ";
+                               } else {
+                                       tmp = " ";
+                               }
+                       }
+
+                       if (op == "unread") {
+                               tmp = tmp + "unread = true";
+                       }
+
+                       if (op == "updated") {
+                               tmp = tmp + "last_read is null and unread = false";
+                       }
+
+                       if (op == "kw_title") {
+                               tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
+                       }
+                       if (op == "kw_content") {
+                               tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
+                       }
+
+                       if (op == "scoreE") {
+                               tmp = tmp + "score = " + p.value;
+                       }
+
+                       if (op == "scoreG") {
+                               tmp = tmp + "score > " + p.value;
+                       }
+
+                       if (op == "scoreL") {
+                               tmp = tmp + "score < " + p.value;
+                       }
+
+                       if (op == "newerD") {
+                               if (isNaN(parseInt(p))) {
+                                       alert("This action expects numeric parameter.");
+                                       return false;
+                               }
+                               tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
+                       }
+
+                       if (op == "newerH") {
+                               if (isNaN(parseInt(p))) {
+                                       alert("This action expects numeric parameter.");
+                                       return false;
+                               }
+
+                               tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
+                       }
+
+                       text.value = text.value + tmp;
+
+                       p.value = "";
+
+               }
+               
+       } catch (e) {
+               exception_error("addLabelExample", e);
+       }
+
+       return false;
+}
+
+function labelFieldsCheck(elem) {
+       try {
+               var op = elem[elem.selectedIndex].value;
+
+               var p = document.forms["label_edit_form"].label_fields_param;
+
+               if (op == "kw_title" || op == "kw_content" || op == "scoreL" || 
+                               op == "scoreG" ||       op == "scoreE" || op == "newerD" ||
+                               op == "newerH" ) {
+                       Element.show(p);
+               } else {
+                       Element.hide(p);
+               }
+
+       } catch (e) {
+               exception_error("labelFieldsCheck", e);
+
+       }
+}
index e23590d7444c017e51ae3ffcbb4926f37d1dbbd5..a4471fcfe74cb31c9fc93e5e1009dcbbb83fcd8d 100644 (file)
                print "</table>";
        }
 
+       function print_label_dlg_common_examples() {
+
+               print __("Match ") . " ";
+
+               print "<select name=\"label_fields\" onchange=\"labelFieldsCheck(this)\">";
+               print "<option value=\"unread\">".__("Unread articles")."</option>";
+               print "<option value=\"updated\">".__("Updated articles")."</option>";
+               print "<option value=\"kw_title\">".__("Title contains")."</option>";
+               print "<option value=\"kw_content\">".__("Content contains")."</option>";
+               print "<option value=\"scoreE\">".__("Score is equals")."</option>";
+               print "<option value=\"scoreG\">".__("Score is less than")."</option>";
+               print "<option value=\"scoreL\">".__("Score is greater than")."</option>";
+               print "<option value=\"newerH\">".__("Articles newer than X hours")."</option>";
+               print "<option value=\"newerD\">".__("Articles newer than X days")."</option>";
+
+               print "</select>";
+
+               print "<input style=\"display : none\" name=\"label_fields_param\"
+                       size=\"10\">";
+
+               print " <input type=\"submit\" 
+                       onclick=\"return addLabelExample()\"
+                       value=\"".__("Add")."\">";
+       }
 ?>
index 912ab03a67b771c5f3b8b1d6defc022a6329a09c..b3fb99a62d18aaea4f55285715652631dc37aabc 100644 (file)
                        print "<div class=\"dlgSecCont\">";
 
                        print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
-                                        rows=\"6\" name=\"sql_exp\" class=\"labelSQL\" cols=\"50\">$sql_exp</textarea>";
+                               rows=\"6\" name=\"sql_exp\" class=\"labelSQL\" 
+                               cols=\"50\">$sql_exp</textarea>";
+
+                       print "<br/>";
+
+                       print_label_dlg_common_examples();
+
 
                        print "</div>";
 
index eed74c263c05b0a4c93792133b46e941a8a45f40..e5455003428732efdd42c475105923ab855e538d 100644 (file)
                        print "<div class=\"dlgSecCont\">";
 
                        print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
-                                        rows=\"6\" name=\"sql_exp\" class=\"labelSQL\" cols=\"50\">$sql_exp</textarea>";
+                               rows=\"6\" name=\"sql_exp\" class=\"labelSQL\" cols=\"50\">$sql_exp</textarea>";
+
+                       print "<br/>";
+
+                       print_label_dlg_common_examples();
 
                        print "</div>";