#include "webcit.h"
#define MAX_SCRIPTS 100
+#define MAX_RULES 10
/**
* \brief view/edit sieve config
wprintf(_("Leave it in my inbox without filtering"));
wprintf("</option>\n");
- /*
- * FIXME uncomment this when we write the rules editor
- *
wprintf("<option value=\"1\">");
wprintf(_("Filter it according to rules selected below"));
wprintf("</option>\n");
- *
- */
wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
wprintf(_("Filter it through a manually edited script (advanced users only)"));
/* The "webcit managed scripts" div */
wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
- wprintf("<div align=\"center\"><br /><br />");
- wprintf("FIXME");
- wprintf("<br /><br /></div>\n");
+ display_rules_editor_inner_div();
wprintf("</div>\n");
/* The "I'm smart and can write my own Sieve scripts" div */
display_add_remove_scripts(&buf[4]);
}
+
+
+
+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);
+ wprintf(" d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
+ " if (d == 'fileinto') { \n"
+ " $('div_fileinto'+i).style.display = 'block'; \n"
+ " $('div_redirect'+i).style.display = 'none'; \n"
+ " } else if (d == 'redirect') { \n"
+ " $('div_fileinto'+i).style.display = 'none'; \n"
+ " $('div_redirect'+i).style.display = 'block'; \n"
+ " } else { \n"
+ " $('div_fileinto'+i).style.display = 'none'; \n"
+ " $('div_redirect'+i).style.display = 'none'; \n"
+ " } \n"
+ " } \n"
+ );
+/*
+ * Show only the active rows...
+ */
+ wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
+ 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"
+/*
+ * 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 />");
+ wprintf("<table class=\"mailbox_summary\" rules=rows cellpadding=2 "
+ "style=\"width:100%%;-moz-user-select:none;\">"
+ );
+
+ for (i=0; i<MAX_RULES; ++i) {
+
+ wprintf("<tr id=\"rule%d\">", i);
+
+ 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);
+ wprintf("<option value=\"sender\">%s</option>", _("Sender"));
+ wprintf("<option value=\"recipient\">%s</option>", _("Recipient"));
+ wprintf("</select>");
+ wprintf("</td>");
+
+ wprintf("<td>");
+ wprintf("<select name=\"compare%d\" size=1 onChange=\"UpdateRules();\">", i);
+ wprintf("<option value=\"match\">%s</option>", _("matches"));
+ wprintf("<option value=\"notmatch\">%s</option>", _("does not match"));
+ wprintf("</select>");
+
+ wprintf("<input type=\"text\" name=\"htext%d\">", i);
+ wprintf("</td>");
+
+ wprintf("<td>");
+ wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
+ i, i);
+ wprintf("<option value=\"fileinto\">%s</option>", _("file into"));
+ wprintf("<option value=\"redirect\">%s</option>", _("forward to"));
+ wprintf("<option value=\"reject\">%s</option>", _("reject"));
+ wprintf("</select>");
+
+ wprintf("<div id=\"div_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);
+ wprintf("<input type=\"text\" name=\"redirect%d\">", i);
+ wprintf("</div>");
+ wprintf("</td>");
+
+
+
+ wprintf("<td>%s</td>", _("and then") );
+
+ wprintf("<td>");
+ wprintf("<select name=\"final%d\" size=1 onChange=\"UpdateRules();\">", i);
+ wprintf("<option value=\"stop\">%s</option>", _("stop"));
+ wprintf("<option value=\"continue\">%s</option>", _("continue processing"));
+ wprintf("</select>");
+ wprintf("</td>");
+
+ wprintf("</tr>\n");
+
+ }
+
+ wprintf("</table>");
+ wprintf("<a href=\"javascript:AddRule();\">Add rule</a>\n");
+
+
+ wprintf("<script type=\"text/javascript\"> \n"
+ "UpdateRules(); \n"
+ "</script> \n"
+ );
+
+}
+
+
+
+
+
+
/*@}*/