Phew, I’ve more or less finished the polls

I’d rather not even write here how long it took me. It’s true that I was doing other things in the meantime, mainly playing around with Dart from Google, but even so I’m not happy with my pace. Back to the polls and what they can do. Only logged-in users can vote in polls or contribute to them. Each user can vote for just one answer in a poll, and only once. That’s so that nobody votes like crazy to make some answer the (very) best, so that my DB doesn’t get flooded, and also so that the voting is more objective and not manipulated by multiple votes. If a user votes and changes their mind within 60s, they can click a link that disappears after exactly 60s.

The same goes for adding answers – only logged-in users can add them, and only once per poll (the exception being poll owners, who can add as many answers as they like directly in the poll), and if they change their mind about the added answer within 60s, they can take it back and write a new one or vote for something. The only unfinished bit here is that when a user takes back their vote by clicking the link, the recorded vote and the answer are deleted, but they visually remain in the poll, and a message just appears telling the user to refresh the page if they want to enter a different custom value. If the user clicks the answer they just deleted, the site doesn’t crash or show an ASP.NET error message; instead, a box above the poll shows This answer was not found in the DB.. So the site is protected against that as well. There are 7 colors so far to choose from for poll options, but I’ll try to add more soon.

When a user specifies an answer that isn’t in the table yet, it gets assigned a random color from these very 7 colors. It doesn’t take into account whether that color is already in the poll, so even if the poll has fewer than 7 items, the 8th item may end up with the same color as one of the previous ones. The text length limit is 80 characters for the question and 30 characters for an answer. The limit of answers in one poll is 255 (which would already be an extremely long poll on the page, since my polls can’t hide answers that are lower down or don’t have many votes yet), and the number of votes and the number of polls are unlimited in the sense that I don’t artificially limit them, although the DB does have some limit. But that’s my problem: once the indexes start running out, I’ll change the column data type or solve it some other way.

In the resulting poll HTML, the items can be sorted by number of clicks in descending order. For each poll I store the date it was created and the date it can expire, which can be set to Never. The creation date can’t be changed once the poll is created, whereas the expiration date can be changed freely in poll management. For me as a webmaster, the advantage is that I managed to bundle all the JS with the HTML output, so now I just specify a <div> and in the C# code I call a single method that fills this div. This method takes a single parameter, the poll ID. I don’t have to worry about anything else, no copying JS code into pages that may or may not contain a poll. There can be multiple polls on one page, but each has its own JS methods and functions, so the downside is more code and the upside is that browsers won’t get confused about which function to use.

Another unfinished bit of the polls is that when you vote or enter a new answer, only the vote count, % and chart of the answer you voted for are updated. All the other answers, even though the vote ratio has changed, stay unchanged until you reload the page. At the top there’s a box showing the information the poll provides, and at the bottom is the total number of votes, which goes up or down depending on whether you vote / add an answer or remove a vote. That’s it for the polls themselves on the pages, and now to the pages that manage these polls:


The poll was successfully deleted

I have a page for viewing all of a user’s polls, where clicking an icon loads the poll editing page. This page contains just a paginated table with information about the poll and an edit button. You can also sort the polls by these criteria:

  1. Default (unsorted)
  2. By number of answers
  3. By whether more answers can be added
  4. By creation date
  5. By expiration date
  6. By total number of votes
  7. By poll name a > z

The poll editing page has 2 modes – Creating a new poll and Editing an existing poll. If you specify new in the address instead of the poll ID, it opens in Create new poll mode. After you fill in the basic meta information and click the button, the poll is created in the DB and you’re redirected to the same page, just with this poll’s ID, where you can add answers. Answers are added in a popup: you fill in the answer name (the save button appears only once you enter non-empty text), change the color if you don’t like it, and press the button. If you decide you don’t want to add a new answer after all, press the “close” button or click anywhere outside the popup and it closes.

Right after an answer is added, it’s appended to the existing ones without a postback. Editing an answer also uses a popup, but you can change only the color; the answer text can’t be changed. The last action is deleting an answer, which works without a popup. There’s also a statistics button, but that’s an empty page for now. Another thing the site can do is delete an entire poll completely, including all its answers and votes. If a user somewhere doesn’t update the ID or doesn’t remove the link to the poll entirely, they’ll see “this poll was not found” in that spot. A few older screenshots of the administration from a not yet finished version:


Until text is entered, the save button stays hidden

Adding a new answer. Until text is entered, the save button stays hidden.


Once text is typed, the button becomes active

After you enter any text, the button becomes active.


I can change the poll color

The popup for editing an answer.

And the finished polls in action, first with the “dummy” data I used for testing on localhost:


Working polls

And if you want to try it out right on the page, you can go to 👻 The domain expired like prepaid credit on a phone.. I haven’t put this poll anywhere else yet (although more will gradually appear, and on top of that I’m preparing a blogging system (phew), where it will be possible to put a poll under every article). Someday, once I implement the API so I can post to it using Windows Live Writer and make the blog system capable, I might move this blog from Blogger over there too :).

Categories

Leave a Reply