[self debugWithFormat:@"Note: will take values ..."];
+ NSLog(@"formValues: %@", [_rq formValues]);
+
tmp = [self getAddressesOfType:@"to"
fromFormValues:[_rq formValuesForKey:@"to"]];
[self setTo:tmp];
- (NSString *)jsCode {
static NSString *script = \
+ @"var currentIndex = 0;\n"
+ @"\n"
+ @"function hasAddress(email) {\n"
+ @" var e = document.getElementById(email);\n"
+ @" if(e)\n"
+ @" return true;\n"
+ @" return false;\n"
+ @"}\n"
+ @"\n"
+ @"function rememberAddress(email) {\n"
+ @" var list, e;\n"
+ @" \n"
+ @" list = document.getElementById(\"addr_addresses\");\n"
+ @" e = document.createElement(\"span\");\n"
+ @" e.id = email;\n"
+ @" list.appendChild(e);\n"
+ @"}\n"
+ @"\n"
@"function addAddress(type, cn, dn, email, uid, sn) {\n"
- @"}\n";
+ @" var shouldAddRow, s;\n"
+ @" \n"
+ @" shouldAddRow = true;\n"
+ @" s = cn + \" <\" + email + \">\";\n"
+ @"\n"
+ @" if(this.hasAddress(email))\n"
+ @" return;\n"
+ @"\n"
+ @" this.rememberAddress(email);\n"
+ @"\n"
+ @" var e = document.getElementById(\"addr_0\");\n"
+ @" if(e.value == '') {\n"
+ @" e.value = s;\n"
+ @" shouldAddRow = false;\n"
+ @" }\n"
+ @" if(shouldAddRow) {\n"
+ @" this.fancyAddRow(false, s);\n"
+ @" }\n"
+ @"}\n"
+ @"\n"
+ @"function fancyAddRow(shouldEdit, text) {\n"
+ @" var table = document.getElementById(\"addr_table\").childNodes[1];\n"
+ @" var lastChild = document.getElementById(\"addr_lastentry\");\n"
+ @" var proto, row, select, input;\n"
+ @"\n"
+ @" currentIndex++;\n"
+ @"\n"
+ @" proto = document.getElementById(\"addr_proto\");\n"
+ @" row = proto.cloneNode(true);\n"
+ @" row.id = \"\";\n"
+ @"\n"
+ @" select = row.childNodes[1].childNodes[1];\n"
+ @" select.name = \"popup_\" + currentIndex;\n"
+ @" input = row.childNodes[3].childNodes[1];\n"
+ @" input.name = \"addr_\" + currentIndex;\n"
+ @" input.id = \"addr_\" + currentIndex;\n"
+ @" input.value = text;\n"
+ @"\n"
+ @" table.insertBefore(row, lastChild);\n"
+ @" if(shouldEdit) {\n"
+ @" input.focus();\n"
+ @" input.select();\n"
+ @" }\n"
+ @"}\n"
+ @"\n";
return script;
}
<script language="JavaScript">
<var:string value="jsCode" const:escapeHTML="NO" />
</script>
- <table>
- <!-- TODO: make repetition -->
- <!-- TODO: form field needs to have an index -->
- <tr>
+ <table id="addr_table">
+ <tr id="addr_proto">
<td width="20%">
- <!-- var:popup? -->
- <select name="totype_00" style="width: 100%;">
+ <select id="popup_0" name="popup_0" style="width: 100%;">
<option value="to" ><var:string label:value="TO" />:</option>
<option value="cc" ><var:string label:value="CC" />:</option>
<option value="bcc"><var:string label:value="BCC" />:</option>
</select>
</td>
<td width="80%">
- <input name="email_00" type="text" style="width: 100%;"/>
- </td>
- </tr>
- <tr id="to_lastentry">
- <td width="20%">
- <var:entity const:name="nbsp" />
- </td>
- <td width="80%">
- <a href="#" ><var:string label:value="new" /></a>
+ <input id="addr_0" name="addr_0" type="text" style="width: 100%;"/>
</td>
</tr>
+ <tr id="addr_lastentry">
+ <td width="20%">
+ <var:entity const:name="nbsp" />
+ </td>
+ <td width="80%">
+ <a href="javascript:fancyAddRow(true,'');"
+ ><var:string label:value="Add address" /></a>
+ </td>
+ </tr>
</table>
+ <span id="addr_addresses" style="visibility: hidden;">
+ </span>
</span>
\ No newline at end of file