lunch/js/models.js

308 lines
7.7 KiB
JavaScript
Raw Normal View History

2016-12-22 21:22:47 -05:00
function getJSONObj(json_input) {
if (typeof json_input == "string")
return $.parseJSON(json_input)
else if (typeof json_input == "object")
return json_input;
console.error("Unable to parse json:", json_input);
return null
}
function User() {
this.UserId = -1;
2017-01-10 08:08:45 -05:00
this.GroupId = -1;
this.GroupPassword = "";
2016-12-22 21:22:47 -05:00
this.Name = "";
this.Username = "";
this.Password = "";
this.Email = "";
}
User.prototype.toJSON = function() {
var json_obj = {};
json_obj.UserId = this.UserId;
2017-01-10 08:08:45 -05:00
json_obj.GroupId = this.GroupId;
json_obj.GroupPassword = this.GroupPassword;
2016-12-22 21:22:47 -05:00
json_obj.Name = this.Name;
json_obj.Username = this.Username;
json_obj.Password = this.Password;
json_obj.Email = this.Email;
return JSON.stringify(json_obj);
}
User.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("UserId"))
this.UserId = json_obj.UserId;
2017-01-10 08:08:45 -05:00
if (json_obj.hasOwnProperty("GroupId"))
this.GroupId = json_obj.GroupId;
if (json_obj.hasOwnProperty("GroupPassword"))
this.GroupPassword = json_obj.GroupPassword;
2016-12-22 21:22:47 -05:00
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
if (json_obj.hasOwnProperty("Username"))
this.Username = json_obj.Username;
if (json_obj.hasOwnProperty("Password"))
this.Password = json_obj.Password;
if (json_obj.hasOwnProperty("Email"))
this.Email = json_obj.Email;
}
User.prototype.isUser = function() {
var empty_user = new User();
2017-01-10 08:08:45 -05:00
return this.UserId != empty_user.UserId &&
this.GroupId != empty_user.GroupId &&
2016-12-22 21:22:47 -05:00
this.Username != empty_user.Username;
}
2017-01-10 08:08:45 -05:00
function Group() {
this.GroupId = -1;
this.Name = "";
this.Password = "";
}
Group.prototype.toJSON = function() {
var json_obj = {};
json_obj.GroupId = this.GroupId;
json_obj.Name = this.Name;
json_obj.Password = this.Password;
return JSON.stringify(json_obj);
}
Group.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("GroupId"))
this.GroupId = json_obj.GroupId;
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
if (json_obj.hasOwnProperty("Password"))
this.Password = json_obj.Password;
}
Group.prototype.isGroup = function() {
var empty_group = new Group();
return this.GroupId != empty_group.GroupId &&
this.Name != empty_group.Name;
}
2016-12-22 21:22:47 -05:00
function Session() {
this.SessionId = -1;
this.UserId = -1;
}
Session.prototype.toJSON = function() {
var json_obj = {};
json_obj.SessionId = this.SessionId;
json_obj.UserId = this.UserId;
return JSON.stringify(json_obj);
}
Session.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("SessionId"))
this.SessionId = json_obj.SessionId;
if (json_obj.hasOwnProperty("UserId"))
this.UserId = json_obj.UserId;
}
Session.prototype.isSession = function() {
var empty_session = new Session();
return this.SessionId != empty_session.SessionId ||
this.UserId != empty_session.UserId;
}
2016-12-23 08:30:29 -05:00
function Attendee() {
this.AttendeeId = -1;
this.Name = "";
}
Attendee.prototype.toJSON = function() {
var json_obj = {};
json_obj.AttendeeId = this.AttendeeId;
json_obj.Name = this.Name;
return JSON.stringify(json_obj);
}
Attendee.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("AttendeeId"))
this.AttendeeId = json_obj.AttendeeId;
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
}
Attendee.prototype.isAttendee = function() {
var empty_attendee = new Attendee();
return this.AttendeeId != empty_attendee.AttendeeId ||
this.Name != empty_attendee.Name;
}
function PopularAttendee() {
this.Name = "";
this.Popularity = 0;
}
PopularAttendee.prototype.toJSON = function() {
var json_obj = {};
json_obj.Name = this.Name;
json_obj.Popularity = this.Popularity;
return JSON.stringify(json_obj);
}
PopularAttendee.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("Popularity"))
this.Popularity = json_obj.Popularity;
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
}
PopularAttendee.prototype.isPopularAttendee = function() {
var empty_attendee = new PopularAttendee();
return this.Popularity != empty_attendee.Popularity ||
this.Name != empty_attendee.Name;
}
2016-12-24 10:00:21 -05:00
function Suggestion() {
this.SuggestionId = -1;
this.VetoingId = -1;
this.AttendeeId = -1;
this.RestaurantName = "";
2016-12-23 20:38:59 -05:00
}
2016-12-24 10:00:21 -05:00
Suggestion.prototype.toJSON = function() {
2016-12-23 20:38:59 -05:00
var json_obj = {};
2016-12-24 10:00:21 -05:00
json_obj.SuggestionId = this.SuggestionId;
2017-01-07 08:39:22 -05:00
json_obj.VetoingId = this.VetoingId;
2016-12-24 10:00:21 -05:00
json_obj.AttendeeId = this.AttendeeId;
json_obj.RestaurantName = this.RestaurantName;
2016-12-23 20:38:59 -05:00
return JSON.stringify(json_obj);
}
2016-12-24 10:00:21 -05:00
Suggestion.prototype.fromJSON = function(json_input) {
2016-12-23 20:38:59 -05:00
var json_obj = getJSONObj(json_input);
2016-12-24 10:00:21 -05:00
if (json_obj.hasOwnProperty("SuggestionId"))
this.SuggestionId = json_obj.SuggestionId;
2017-01-07 08:39:22 -05:00
if (json_obj.hasOwnProperty("VetoingId"))
this.VetoingId = json_obj.VetoingId;
2016-12-24 10:00:21 -05:00
if (json_obj.hasOwnProperty("AttendeeId"))
this.AttendeeId = json_obj.AttendeeId;
if (json_obj.hasOwnProperty("RestaurantName"))
this.RestaurantName = json_obj.RestaurantName;
2016-12-23 20:38:59 -05:00
}
2016-12-24 10:00:21 -05:00
Suggestion.prototype.isSuggestion = function() {
var empty_suggestion = new Suggestion();
return this.SuggestionId != empty_suggestion.SuggestionId &&
this.AttendeeId != empty_suggestion.AttendeeId &&
this.RestaurantName != empty_suggestion.RestaurantName;
2016-12-23 20:38:59 -05:00
}
function PopularSuggestion() {
this.RestaurantName = "";
this.Popularity = 0;
}
PopularSuggestion.prototype.toJSON = function() {
var json_obj = {};
json_obj.RestaurantName = this.RestaurantName;
json_obj.Popularity = this.Popularity;
return JSON.stringify(json_obj);
}
PopularSuggestion.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("RestaurantName"))
this.RestaurantName = json_obj.RestaurantName;
if (json_obj.hasOwnProperty("Popularity"))
this.Popularity = json_obj.Popularity;
}
PopularSuggestion.prototype.isPopularSuggestion = function() {
var empty_suggestion = new PopularSuggestion();
return this.RestaurantName != empty_suggestion.RestaurantName &&
this.Popularity != empty_suggestion.Popularity;
}
2016-12-22 21:22:47 -05:00
function Error() {
this.ErrorId = -1;
this.ErrorString = "";
}
Error.prototype.toJSON = function() {
var json_obj = {};
json_obj.ErrorId = this.ErrorId;
json_obj.ErrorString = this.ErrorString;
return JSON.stringify(json_obj);
}
Error.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("ErrorId"))
this.ErrorId = json_obj.ErrorId;
if (json_obj.hasOwnProperty("ErrorString"))
this.ErrorString = json_obj.ErrorString;
}
Error.prototype.isError = function() {
var empty_error = new Error();
return this.ErrorId != empty_error.ErrorId ||
this.ErrorString != empty_error.ErrorString;
}
2017-01-08 09:47:30 -05:00
function Report() {
this.ReportId = "invalid";
this.Title = "";
this.Data = [];
}
Report.prototype.toJSON = function() {
var json_obj = {};
json_obj.ReportId = this.ReportId;
json_obj.Title = this.Title;
json_obj.Data = this.Data;
return JSON.stringify(json_obj);
}
Report.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("ReportId"))
this.ReportId = json_obj.ReportId;
if (json_obj.hasOwnProperty("Title"))
this.Title = json_obj.Title;
if (json_obj.hasOwnProperty("Data"))
this.Data = json_obj.Data;
}
Report.prototype.isReport = function() {
var empty_report = new Report();
return this.ReportId != empty_report.ReportId ||
this.Title != empty_report.Title;
}
2016-12-22 21:22:47 -05:00
module.exports = models = {
// Classes
User: User,
2017-01-10 08:08:45 -05:00
Group: Group,
2016-12-22 21:22:47 -05:00
Session: Session,
Error: Error,
Attendee: Attendee,
PopularAttendee: PopularAttendee,
Suggestion: Suggestion,
PopularSuggestion: PopularSuggestion,
2017-01-08 09:47:30 -05:00
Report: Report,
2016-12-22 21:22:47 -05:00
// Constants
BogusPassword: "password"
};