private string getAddEditContactForm(ContactPlaceholderData data, ContactData contactToEdit, CmsPage page, int identifier, CmsLanguage langToRenderFor) { string ControlId = "Contacts_" + page.ID.ToString() + "_" + identifier.ToString() + langToRenderFor.shortCode; bool editing = (contactToEdit.contactId > -1); // -- process form actions string action = PageUtils.getFromForm(ControlId + "action", ""); string _userErrorMessage = ""; string _userMessage = ""; bool _showContactDetails = true; if (editing && String.Compare(action, "deleteContact", true) == 0) { bool b = ContactData.DeleteContact(contactToEdit); if (b) { _userMessage = "The contact \"" + getNameDisplayOutput(data, contactToEdit) + "\" has been deleted"; _showContactDetails = false; } else { _userErrorMessage = "Error: could not delete contact. There was a database error"; } } else if (String.Compare(action, "addNewContact", true) == 0) { if (!editing) { contactToEdit = new ContactData(); } contactToEdit.firstName = PageUtils.getFromForm(ControlId + "firstName", contactToEdit.firstName); contactToEdit.lastName = PageUtils.getFromForm(ControlId + "lastName", contactToEdit.lastName); contactToEdit.title = PageUtils.getFromForm(ControlId + "title", contactToEdit.title); contactToEdit.organizationName = PageUtils.getFromForm(ControlId + "organizationName", contactToEdit.organizationName); contactToEdit.address1 = PageUtils.getFromForm(ControlId + "address1", contactToEdit.address1); contactToEdit.address2 = PageUtils.getFromForm(ControlId + "address2", contactToEdit.address2); contactToEdit.city = PageUtils.getFromForm(ControlId + "city", contactToEdit.city); contactToEdit.provinceState = PageUtils.getFromForm(ControlId + "provinceState", contactToEdit.provinceState); contactToEdit.postalZipCode = PageUtils.getFromForm(ControlId + "postalZipCode", contactToEdit.postalZipCode); contactToEdit.phoneNumber1 = PageUtils.getFromForm(ControlId + "phoneNumber1", contactToEdit.phoneNumber1); contactToEdit.phoneNumber2 = PageUtils.getFromForm(ControlId + "phoneNumber2", contactToEdit.phoneNumber2); contactToEdit.faxNumber = PageUtils.getFromForm(ControlId + "faxNumber", contactToEdit.faxNumber); contactToEdit.mobileNumber = PageUtils.getFromForm(ControlId + "mobileNumber", contactToEdit.mobileNumber); contactToEdit.emailAddress = PageUtils.getFromForm(ControlId + "emailAddress", contactToEdit.emailAddress); string[] s_catIds = PageUtils.getFromForm(ControlId + "category"); int[] catIds = StringUtils.ToIntArray(s_catIds); contactToEdit.contactCategoryIds.Clear(); contactToEdit.contactCategoryIds.AddRange(catIds); if (contactToEdit.firstName.Trim() == "") { _userErrorMessage = "Please enter the contact's first name"; } else if (contactToEdit.lastName.Trim() == "") { _userErrorMessage = "Please enter the contact's last name"; } else if (contactToEdit.contactCategoryIds.Count < 1) { _userErrorMessage = "Please select at least one category for the contact"; } else { bool b = contactToEdit.SaveToDatabase(); if (!b) { _userErrorMessage = "There was a problem saving the contact to the database"; } else { if (editing) { string nameDisplay = getNameDisplayOutput(data, contactToEdit); _userMessage = "The changes to \"" + nameDisplay + "\" have been saved."; } else { string nameDisplay = getNameDisplayOutput(data, contactToEdit); _userMessage = "The contact \"" + nameDisplay + "\" has been added."; contactToEdit = new ContactData(); // remove all previously submitted values editing = false; } } } } // if process StringBuilder html = new StringBuilder(); if (editing) { string nameDisplay = getNameDisplayOutput(data, contactToEdit); html.Append("<h2>Edit contact \"" + nameDisplay + "\":</h2>"); } else { html.Append("<h2>Add a new contact:</h2>"); } if (_userErrorMessage != "") { html.Append("<p style=\"color: red\">Error: " + _userErrorMessage + "</p>"); } if (_userMessage != "") { html.Append("<p style=\"color: green\">" + _userMessage + "</p>"); } if (!_showContactDetails) { return(html.ToString()); } string formId = "editContact"; html.Append(page.getFormStartHtml(formId)); html.Append("<table border=\"0\">"); string dividerLineHtml = getDividerLineHtml(4); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>First Name:</td>"); html.Append("<td>" + PageUtils.getInputTextHtml(ControlId + "firstName", ControlId + "firstName", contactToEdit.firstName, 20, 255) + "</td>"); html.Append("<td>Last Name:</td>"); html.Append("<td>" + PageUtils.getInputTextHtml(ControlId + "lastName", ControlId + "lastName", contactToEdit.lastName, 20, 255) + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); string colspan = "3"; html.Append("<td>Categories:</td>"); ContactDataCategory[] allCategories = ContactDataCategory.getAllContactCategories(); html.Append("<td colspan=\"" + colspan + "\">"); int cbid = 0; foreach (ContactDataCategory cat in allCategories) { bool check = (contactToEdit.contactCategoryIds.IndexOf(cat.CategoryId) > -1); string cb = PageUtils.getCheckboxHtml(cat.Title, ControlId + "category", ControlId + "category" + cbid.ToString(), cat.CategoryId.ToString(), check); html.Append(cb + "<br />"); cbid++; } // foreach html.Append("</td>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Title:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "title", ControlId + "title", contactToEdit.title, 40, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Organization:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "organizationName", ControlId + "organizationName", contactToEdit.organizationName, 40, 255) + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Address 1:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "address1", ControlId + "address1", contactToEdit.address1, 40, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Address 2:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "address2", ControlId + "address2", contactToEdit.address2, 40, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>City:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "city", ControlId + "city", contactToEdit.city, 40, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Province/State:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "provinceState", ControlId + "provinceState", contactToEdit.provinceState, 20, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Postal/Zip Code:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "postalZipCode", ControlId + "postalZipCode", contactToEdit.postalZipCode, 10, 255) + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Phone Number 1:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "phoneNumber1", ControlId + "phoneNumber1", contactToEdit.phoneNumber1, 20, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Phone Number 2:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "phoneNumber2", ControlId + "phoneNumber2", contactToEdit.phoneNumber2, 20, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Fax Number:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "faxNumber", ControlId + "faxNumber", contactToEdit.faxNumber, 20, 255) + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Mobile Number:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "mobileNumber", ControlId + "mobileNumber", contactToEdit.mobileNumber, 20, 255) + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Email Address:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + PageUtils.getInputTextHtml(ControlId + "emailAddress", ControlId + "emailAddress", contactToEdit.emailAddress, 40, 255) + "</td>"); html.Append("</tr>"); html.Append("</table>"); html.Append(PageUtils.getHiddenInputHtml(ControlId + "action", "addNewContact")); if (editing) { html.Append(PageUtils.getHiddenInputHtml(CurrentContactIdFormName, contactToEdit.contactId.ToString())); html.Append("<input type=\"submit\" value=\"save changes\">"); } else { html.Append("<input type=\"submit\" value=\"add contact\">"); } html.Append(page.getFormCloseHtml(formId)); if (editing) { formId = formId + "_Delete"; html.Append(page.getFormStartHtml(formId)); html.Append("<p align=\"right\">Delete:"); html.Append(PageUtils.getHiddenInputHtml(CurrentContactIdFormName, contactToEdit.contactId.ToString())); html.Append(PageUtils.getHiddenInputHtml(ControlId + "action", "deleteContact")); html.Append("<input type=\"submit\" value=\"delete contact\">"); html.Append("</p>"); html.Append(page.getFormCloseHtml(formId)); } return(html.ToString()); } // getAddEditContactForm
public string getSummaryDisplayFilterForm(ContactPlaceholderData data, ContactData[] contacts, CmsPage page, int identifier) { if (!data.allowFilterByCategory && !data.allowFilterByCompany) { return(""); } string ControlId = "Contacts_" + page.ID.ToString() + "_" + identifier.ToString(); string[] allOrganizations = ContactData.getAllOrganizationNames(contacts); ContactDataCategory[] allCategories = ContactDataCategory.getAllContactCategories(); if (allOrganizations.Length < 1 && allCategories.Length < 1) { return(""); } StringBuilder html = new StringBuilder(); int cbid = 0; html.Append("<div class=\"ContactsFilterForm\">"); string formId = ControlId + "filterContacts"; html.Append(page.getFormStartHtml(formId)); html.Append("<strong>Filter contacts</strong><br />"); if (data.allowFilterByCategory) { if (allCategories.Length > 1) { html.Append(" <em> by category:</em><br />"); int[] catsChecked = getCategoryIdsToDisplay(data); foreach (ContactDataCategory cat in allCategories) { bool check = (catsChecked.Length == 0 || (Array.IndexOf(catsChecked, cat.CategoryId) > -1)); string displayUrl = getContactSummaryDisplayUrl(page, new int[] { cat.CategoryId }, new string[0]); string display = cat.Title; // string link = " <a title=\"view only contacts in '" + cat.Title + "'\" href=\"" + displayUrl + "\">(view)</a>"; string cb = PageUtils.getCheckboxHtml(display, "contactCat", ControlId + "category" + cbid.ToString(), cat.CategoryId.ToString(), check); html.Append(cb + "<br />"); cbid++; } // foreach } } if (data.allowFilterByCompany) { if (allOrganizations.Length > 1) { html.Append(" <em> by organization:</em><br />"); string[] orgsChecked = getOrgNamesToDisplay(); foreach (string org in allOrganizations) { bool check = (orgsChecked.Length == 0 || (Array.IndexOf(orgsChecked, org) > -1)); string displayUrl = getContactSummaryDisplayUrl(page, new int[0], new string[] { org }); string display = org; // string link = " <a title=\"view only contacts belonging to '" + org + "'\" href=\"" + displayUrl + "\">(view)</a>"; string cb = PageUtils.getCheckboxHtml(display, "contactOrg", ControlId + "orgName" + cbid.ToString(), org, check); html.Append(cb + "<br />"); cbid++; } // foreach } } if (cbid > 0) { html.Append("<input type=\"submit\" value=\"filter\">"); string checkAllFnName = ControlId + "Check"; string checkNoneFnName = ControlId + "CheckNone"; StringBuilder js = new StringBuilder(); js.Append("function " + checkAllFnName + "() {" + Environment.NewLine); js.Append(" $('#" + formId + " input[type=checkbox]:not(:checked)' ).attr('checked', true);" + Environment.NewLine); js.Append("} " + Environment.NewLine); js.Append("function " + checkNoneFnName + "() {" + Environment.NewLine); js.Append(" $('#" + formId + " input[type=checkbox]:checked' ).attr('checked', false);" + Environment.NewLine); js.Append("} " + Environment.NewLine); page.HeadSection.AddJSStatements(js.ToString()); page.HeadSection.AddJavascriptFile(JavascriptGroup.Library, "js/_system/jquery/jquery-1.4.1.min.js"); html.Append("<br>Check: <a href=\"#\" onclick=\"" + checkAllFnName + "(); return false;\">all</a> | <a href=\"#\" onclick=\"" + checkNoneFnName + "(); return false;\">none</a>"); } html.Append(page.getFormCloseHtml(formId)); html.Append("</div>"); return(html.ToString()); }
private void RenderViewIndividual(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { ContactsDb db = new ContactsDb(); ContactPlaceholderData data = db.getContactPlaceholderData(page, identifier, true); int contactId = PageUtils.getFromForm(CurrentContactIdFormName, -1); ContactData contactToView = ContactData.getContact(contactId); bool canEdit = page.currentUserCanWrite; string backUrl = page.Url; writer.Write("<p><a href=\"" + backUrl + "\">« back to contact listing</a></p>"); // -- begin output if (canEdit) { writer.Write(getAddEditContactForm(data, contactToView, page, identifier, langToRenderFor)); } else { StringBuilder html = new StringBuilder(); html.Append("<table border=\"0\">"); string dividerLineHtml = getDividerLineHtml(2); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td colspan=\"2\" align=\"center\"><h2>" + StringUtils.JoinNonBlanks(" ", new string[] { contactToView.firstName, contactToView.lastName }) + "</h2></td>"); html.Append(dividerLineHtml); string colspan = "1"; html.Append("<td>Categories:</td>"); ContactDataCategory[] allCategories = ContactDataCategory.getAllContactCategories(); html.Append("<td colspan=\"" + colspan + "\">"); int cbid = 0; foreach (ContactDataCategory cat in allCategories) { bool check = (contactToView.contactCategoryIds.IndexOf(cat.CategoryId) > -1); string cb = PageUtils.getCheckboxHtml(cat.Title, "category", "category" + cbid.ToString(), cat.CategoryId.ToString(), check); html.Append(cb + "<br />"); cbid++; } // foreach html.Append("</td>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Title:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.title + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Organization:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.organizationName + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Address 1:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.address1 + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Address 2:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.address2 + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>City:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.city + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Province/State:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.provinceState + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Postal/Zip Code:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.postalZipCode + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); html.Append("<tr>"); html.Append("<td>Phone Number 1:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.phoneNumber1 + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Phone Number 2:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.phoneNumber2 + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Fax Number:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.faxNumber + "</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Mobile Number:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + contactToView.mobileNumber + "</td>"); html.Append("</tr>"); html.Append(dividerLineHtml); string emailDisplay = ""; if (contactToView.emailAddress.Trim() != "") { emailDisplay = "<a href=\"mailto:" + contactToView.SpamEncodedEmailAddress + "\">" + contactToView.SpamEncodedEmailAddress + "</a>"; } html.Append("<tr>"); html.Append("<td>Email Address:</td>"); html.Append("<td colspan=\"" + colspan + "\">" + emailDisplay + "</td>"); html.Append("</tr>"); html.Append("</table>"); writer.Write(html.ToString()); } }
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { string ControlId = "Contacts_" + page.ID.ToString() + "_" + identifier.ToString() + langToRenderFor.shortCode; ContactsDb db = new ContactsDb(); ContactPlaceholderData data = new ContactPlaceholderData(); data = db.getContactPlaceholderData(page, identifier, true); string action = PageUtils.getFromForm(ControlId + "_action", ""); if (String.Compare(action, "saveNewValues", true) == 0) { data.numColumnsToShow = PageUtils.getFromForm(ControlId + "numColumnsToShow", data.numColumnsToShow); data.forceFilterToCategoryId = PageUtils.getFromForm(ControlId + "forceFilterToCategoryId", data.forceFilterToCategoryId); data.nameDisplayMode = (ContactPlaceholderData.ContactNameDisplayMode)PageUtils.getFromForm(ControlId + "nameDisplayMode", typeof(ContactPlaceholderData.ContactNameDisplayMode), data.nameDisplayMode); data.allowFilterByCategory = PageUtils.getFromForm(ControlId + "allowFilterByCategory", false); data.allowFilterByCompany = PageUtils.getFromForm(ControlId + "allowFilterByCompany", false); data.accessLevelToAddContacts = (BaseCmsPlaceholder.AccessLevel)PageUtils.getFromForm(ControlId + "accessLevelToAddContacts", typeof(BaseCmsPlaceholder.AccessLevel), data.accessLevelToAddContacts); data.accessLevelToEditContacts = (BaseCmsPlaceholder.AccessLevel)PageUtils.getFromForm(ControlId + "accessLevelToEditContacts", typeof(BaseCmsPlaceholder.AccessLevel), data.accessLevelToEditContacts); db.saveUpdatedContactPlaceholderData(page, identifier, data); } StringBuilder html = new StringBuilder(); html.Append("Contacts Display Configuration:"); html.Append("<table>"); html.Append("<tr>"); html.Append("<td>Force Category filter to display: </td>"); html.Append("<td>"); ContactDataCategory[] allCats = ContactDataCategory.getAllContactCategories(); NameValueCollection options = new NameValueCollection(); options.Add("-1", "do not force category to filter"); foreach (ContactDataCategory cat in allCats) { options.Add(cat.CategoryId.ToString(), cat.Title); } // foreach html.Append(PageUtils.getDropDownHtml(ControlId + "forceFilterToCategoryId", ControlId + "forceFilterToCategoryId", options, data.forceFilterToCategoryId.ToString())); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Allow filter by: </td>"); html.Append("<td>"); html.Append(PageUtils.getCheckboxHtml("Category", ControlId + "allowFilterByCategory", ControlId + "allowFilterByCategory", true.ToString(), data.allowFilterByCompany)); html.Append("<br>"); html.Append(PageUtils.getCheckboxHtml("Company Name", ControlId + "allowFilterByCompany", ControlId + "allowFilterByCompany", true.ToString(), data.allowFilterByCompany)); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Number of columns: </td>"); html.Append("<td>"); html.Append(PageUtils.getInputTextHtml(ControlId + "numColumnsToShow", ControlId + "numColumnsToShow", data.numColumnsToShow.ToString(), 3, 5)); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td>Name display format: </td>"); html.Append("<td>"); html.Append(PageUtils.getDropDownHtml(ControlId + "nameDisplayMode", ControlId + "nameDisplayMode", Enum.GetNames(typeof(ContactPlaceholderData.ContactNameDisplayMode)), Enum.GetName(typeof(ContactPlaceholderData.ContactNameDisplayMode), data.nameDisplayMode))); html.Append("</td>"); html.Append("</tr>"); // -- deprecated items PageUtils.getHiddenInputHtml(ControlId + "accessLevelToAddContacts", Enum.GetName(typeof(BaseCmsPlaceholder.AccessLevel), BaseCmsPlaceholder.AccessLevel.CmsAuthor)); PageUtils.getHiddenInputHtml(ControlId + "accessLevelToEditContacts", Enum.GetName(typeof(BaseCmsPlaceholder.AccessLevel), BaseCmsPlaceholder.AccessLevel.CmsAuthor)); html.Append("</table>"); html.Append(PageUtils.getHiddenInputHtml(ControlId + "_action", "saveNewValues")); writer.Write(html.ToString()); } // RenderEditSummary