Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modified/refactored field validator to be more generic, and used it f…

…or edit issues page to prevent empty title or descriptions
  • Loading branch information...
commit d7097d398d234a7d3d98a936ded139a43a8bc8ea 1 parent 736ed3a
@andrewxu andrewxu authored
View
4 node_modules/editIssue.js 100755 → 100644
@@ -34,7 +34,7 @@ function displayPage(response, user_id, isEditor) {
location: issue.location,
description: issue.description,
link: issue.link,
- id: issue.id,
+ issueId: issue.id,
openSelected: (issue.status == 'open'),
resolvedSelected: (issue.status == 'resolved')
}
@@ -45,7 +45,7 @@ function displayPage(response, user_id, isEditor) {
else {
variables = {
canEdit: canEdit,
- id: issue.id
+ issueId: issue.id
}
response.render('views/editIssue.html', variables);
View
5 node_modules/saveIssue.js 100755 → 100644
@@ -15,8 +15,8 @@ function serve(response,id) {
if (error) {console.log("Error Adding Issue"); throw error;}
console.log("Issue saved.");
- response.writeHeader(200, {'Content-Type': 'text/html'});
- response.end(' Redirecting....... <script language="JavaScript"> self.location="viewIssue?id='+id+'"; </script>');
+ response.writeHeader(200, {'Content-Type': 'text/html'});
+ response.end(' Redirecting....... <script language="JavaScript"> self.location="viewIssue?id='+id+'"; </script>');
};
}
/**
@@ -28,6 +28,7 @@ function updateDB(POST,response){
title=POST.title; description=POST.description; location=POST.location; id=POST.id; link=POST.link; status=POST.status;
var sqlQuery = 'UPDATE issues SET title="'+title+'",description="'+description+'",location="'+location+'",link="'+link+'", status="'+status +'" WHERE id=' + id;
+
dbAccess.runQuery(sqlQuery, serve(response,id));
}
/**
View
15 public/fieldValidations.js 100755 → 100644
@@ -187,15 +187,20 @@ function validateConfirmPassword(e){
* NOTE: 'new_issue' is the form name, 'title' and 'description' are the names of their respective fields in the HTML form.
* All of these can are found in the addIssue.js.
*/
-function checkMandatoryFields()
+function checkMandatoryFields(form)
{
- var message = "Oops, you forgot to include the following mandatory fields:";
- if (document.new_issue.title.value == "" )
+ var pass = true;
+ var message = "Oops, you forgot the following mandatory fields, they cannot be empty:";
+ if (form.title.value == "" ){
message += "\nTitle";
- if (document.new_issue.description.value == "")
+ pass = false;
+ }
+ if (form.description.value == ""){
message += "\nDescription"
+ pass = false;
+ }
- if (message != "Oops, you forgot to include the following mandatory fields:") {
+ if (!pass) {
alert(message);
return false;
}
View
2  views/addIssue.html
@@ -2,7 +2,7 @@
{{#display}}
{{#loggedIn}}
What do you feel is an important issue that should be addressed by your city? Create a new issue here! (Fields marked with a <font color="#cc0000">*</font> are mandatory)<br>
- <form id="new_issue" name="new_issue" action="/addIssue" method="post" onsubmit="return checkMandatoryFields();">
+ <form id="new_issue" name="new_issue" action="/addIssue" method="post" onsubmit="return checkMandatoryFields(this);">
<p>Title<font color="#cc0000">*</font><input type="text" name="title" /></p>
<p>Description<font color="#cc0000">*</font><br>
<textarea rows="10" cols="50" name="description"></textarea></p>
View
4 views/editIssue.html
@@ -1,7 +1,7 @@
{{#canEdit}}
<h1> Edit Issue Details </h1>
-<form id="edit_issue" action="saveIssue" method="post">
- <p><input type="hidden" name="id" value= "{{id}}"/></p>
+<form id="edit_issue" action="saveIssue" method="post" onsubmit="return checkMandatoryFields(this);">
+ <p><input type="hidden" name="id" value="{{issueId}}"/></p>
<p>Title</p> <p><input type="text" name="title" value= "{{title}}"/></p>
<p>Description</p><p><textarea rows="10" cols="50" name="description">{{description}}</textarea></p>
<p>Location</p> <p><input type="text" name="location" value= "{{location}}"/></p>
View
2  views/layouts/defaultLayout.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="/css/style.css" type="text/css" />
<link rel="stylesheet" href="/css/view_votes_style.css" type="text/css" />
<link rel="icon" type="image/png" href="/images/favicon.png" />
- <link rel="shortcut icon" type="image/png" href="images/favicon.png" />
+ <link rel="shortcut icon" type="image/png" href="/images/favicon.png" />
<link rel="apple-touch-icon" href="/images/apple-logo.png" />
<script src="/fieldValidations.js"></script>
</head>
Please sign in to comment.
Something went wrong with that request. Please try again.