]> code.citadel.org Git - citadel.git/blobdiff - webcit/sieve.c
nifty 'Add Rule' button
[citadel.git] / webcit / sieve.c
index ab6050ce1f0862b7c53b89b34f4d6da8985e5169..be609ced806cb0c7de3b7b7bb8ef2ba79e48c027 100644 (file)
@@ -9,7 +9,7 @@
 #include "webcit.h"
 
 #define MAX_SCRIPTS    100
-#define MAX_RULES      8
+#define MAX_RULES      10
 
 /**
  * \brief view/edit sieve config
@@ -373,12 +373,15 @@ void create_script(void) {
 
 void display_rules_editor_inner_div(void) {
        int i;
+       char buf[256], targ[256];
 
 /*
  * This script should get called by every onChange event...
  *
  */
        wprintf("<script type=\"text/javascript\">                                      \n"
+               "                                                                       \n"
+               "var highest_active_rule = (-1);                                        \n"
                "                                                                       \n"
                "function UpdateRules() {                                               \n"
                "  for (i=0; i<%d; ++i) {                                               \n", MAX_RULES);
@@ -394,24 +397,32 @@ void display_rules_editor_inner_div(void) {
                "    $('div_redirect'+i).style.display = 'none';                        \n"
                "  }                                                                    \n"
                " }                                                                     \n"
-               "}                                                                      \n"
-               "</script>                                                              \n"
        );
-
-
 /*
- * Show/hide alternating rows.  This is obviously bogus, it's just here to test the show/hide logic.
+ * Show only the active rows...
+ */
        wprintf("  for (i=0; i<%d; ++i) {                                               \n", MAX_RULES);
-       wprintf("   if ( (i % 2) == 0 )  {                                              \n"
+       wprintf("   if ($('active'+i).checked) {                                        \n"
                "     $('rule' + i).style.display = 'block';                            \n"
+               "     highest_active_rule = i;                                          \n"
                "   }                                                                   \n"
                "   else {                                                              \n"
                "     $('rule' + i).style.display = 'none';                             \n"
                "   }                                                                   \n"
                "  }                                                                    \n"
                "}                                                                      \n"
-               "                                                                       \n"
-*/
+/*
+ * Add a rule (really, just un-hide it)
+ * FIXME check the upper bound
+ */
+               "function AddRule() {                                                   \n"
+               "  highest_active_rule = highest_active_rule + 1;                       \n"
+               "  $('active'+highest_active_rule).checked = true;                      \n"
+               "  UpdateRules();                                                       \n"
+               "}                                                                      \n"
+
+               "</script>                                                              \n"
+       );
 
 
        wprintf("<br />");
@@ -423,7 +434,13 @@ void display_rules_editor_inner_div(void) {
                
                wprintf("<tr id=\"rule%d\">", i);
 
-               wprintf("<td>%d. %s</td>", i+1, _("If") );
+               wprintf("<td>");
+
+               wprintf("<div style=\"display:none\">");
+               wprintf("<input type=\"checkbox\" id=\"active%d\">", i);
+               wprintf("</div>");
+
+               wprintf("%d. %s</td>", i+1, _("If") );
 
                wprintf("<td>");
                wprintf("<select name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">", i);
@@ -437,9 +454,7 @@ void display_rules_editor_inner_div(void) {
                wprintf("<option value=\"match\">%s</option>", _("matches"));
                wprintf("<option value=\"notmatch\">%s</option>", _("does not match"));
                wprintf("</select>");
-               wprintf("</td>");
 
-               wprintf("<td>");
                wprintf("<input type=\"text\" name=\"htext%d\">", i);
                wprintf("</td>");
 
@@ -452,7 +467,23 @@ void display_rules_editor_inner_div(void) {
                wprintf("</select>");
 
                wprintf("<div id=\"div_fileinto%d\">", i);
-               wprintf("<input type=\"text\" name=\"fileinto%d\">", i);
+               wprintf("<select name=\"fileinto%d\">", i);
+               serv_puts("LKRA");      /* FIXME buffer this and keep reusing it */
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1') {
+                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                               extract_token(targ, buf, 0, '|', sizeof targ);
+                               if (!strcasecmp(targ, "Mail")) {
+                                       wprintf("<option selected>");
+                               }
+                               else {
+                                       wprintf("<option>");
+                               }
+                               escputs(targ);
+                               wprintf("\n");
+                       }
+               }
+               wprintf("</select>\n");
                wprintf("</div>");
 
                wprintf("<div id=\"div_redirect%d\">", i);
@@ -476,8 +507,7 @@ void display_rules_editor_inner_div(void) {
        }
 
        wprintf("</table>");
-
-
+       wprintf("<a href=\"javascript:AddRule();\">Add rule</a>\n");
 
 
        wprintf("<script type=\"text/javascript\">                                      \n"