Skip to content

Instantly share code, notes, and snippets.

@bryanaka
Created November 5, 2013 00:34
Show Gist options
  • Save bryanaka/7311881 to your computer and use it in GitHub Desktop.
Save bryanaka/7311881 to your computer and use it in GitHub Desktop.
Locations = new Meteor.Collection2('Locations', {
schema: {
country: {
type: String,
label: 'Country',
max: 50
},
city: {
type: String,
label: 'City',
max: 50
},
state: {
type: String,
label: 'State/Region',
max: 20
},
travel_type: {
type: String,
label: 'Travel Type',
optional: true
},
host_name: {
type: String,
label: 'Host Name',
optional: true
},
host_contact: {
type: String,
label: 'Host Contact Info',
optional: true
},
host_affiliation: {
type: String,
label: 'Hosts\' Affiliation',
optional: true
},
lodging_name: {
type: String,
label: 'Lodging Name',
optional: true
},
lodging_address: {
type: String,
label: 'Lodging Address',
optional: true
},
lodging_phone: {
type: String,
label: 'Lodging Phone',
optional: true
},
lodging_website: {
type: String,
regEx: SchemaRegEx.Url,
label: 'Lodging Website',
optional: true
},
conf_name: {
type: String,
label: 'Conference Name',
optional: true
},
conf_role: {
type: String,
label: 'Conference Role',
optional: true
},
conf_website: {
type: String,
regEx: SchemaRegEx.Url,
label: 'Confernce Website',
optional: true
},
depart_on: {
type: Date,
label: 'Depart On'
},
return_on: {
type: Date,
label: 'Return On'
}
}
});
TravelRequests = new Meteor.Collection2('TravelRequests', {
schema: {
first_name: {
type: String,
label: 'Traveler\'s First Name',
max: 50
},
last_name: {
type: String,
label: 'Traveler\'s Last Name',
max: 50
},
email: {
type: String,
label: 'Traveler\'s Email',
regEx: SchemaRegEx.Email,
max: 50
},
requestor_email: {
type: String,
label: 'Requestor Email',
regEx: SchemaRegEx.Email,
max: 50
},
pid: {
type: String,
label: 'Project ID',
min: 3
},
phone: {
type: String,
label: 'Phone',
max: 15
},
personal_days: {
type: Number,
label: 'Personal Days',
optional: true
},
estimated_airfare: {
type: Number,
label: 'Estimated Airfare Cost'
},
estimated_cost: {
type: Number,
label: 'Estimated Other Costs'
},
justification: {
type: String,
label: 'Justification',
max: 500
},
locations: {
type: [Locations],
minCount: 1
},
status: {
type: String,
label: 'Request Status',
optional: true,
allowedValues: ['pending', 'received', 'processed', 'approved', 'complete']
},
created_at: {
type: Date,
label: 'Created At'
},
updated_at: {
type: Date,
label: 'Updated At'
},
completed_at: {
type: Date,
label: 'Completed At',
optional: true
}
},
virtualFields: {
full_name: function(travelRequest) {
return travelRequest.first_name + ' ' + travelRequest.last_name;
},
depart_date: function(travelRequest) {
return moment(travelRequest.depart_on).format('MMM Do YYYY');
},
return_date: function(travelRequest) {
return moment(travelRequest.return_on).format('MMM Do YYYY');
},
status_level: function(travelRequest) {
var status_map = ['pending', 'received', 'processed', 'approved', 'complete'];
var arr_index = _.indexOf(status_map, travelRequest.status);
return arr_index + 1;
}
}
});
function useTimestamps(doc, inserting) {
var changeDoc = doc;
if (inserting !== true ) { changeDoc = doc.$set; }
if(typeof changeDoc.created_at === 'undefined') { changeDoc.created_at = new Date(); }
changeDoc.updated_at = new Date();
};
function setRequestStatus(doc) {
var statusNotSet = (typeof doc.status === 'undefined'),
updating = (typeof doc.$set !== 'undefined'),
updatingStatus = (typeof doc.$set.status !== 'undefined');
if (statusNotSet) { doc.status = 'pending'; }
if (updating && !updatingStatus && statusNotSet) {
doc.$set.status = 'pending';
}
};
TravelRequests.beforeInsert = function(doc) {
useTimestamps(doc, true);
setRequestStatus(doc);
return doc;
};
TravelRequests.beforeUpdate = function(docId, modifier){
useTimestamps(modifier);
setRequestStatus(modifier);
return modifier;
};
<template name="travelForm">
<div class="row">
<div class="col-sm-6">
{{afQuickField "first_name" placeholder="First Name"}}
</div>
<div class="col-sm-6">
{{afQuickField "last_name" placeholder="Last Name"}}
</div>
<div class="col-sm-6">
{{afQuickField "email" placeholder="email"}}
</div>
<div class="col-sm-6">
{{afQuickField "requestor_email" placeholder="Requestor E-mail"}}
</div>
<div class="col-sm-6">
{{afQuickField "pid" placeholder="Project ID"}}
</div>
<div class="col-sm-6">
{{afQuickField "phone" placeholder="phone #"}}
</div>
<div class="col-sm-4">
{{afQuickField "estimated_airfare"}}
</div>
<div class="col-sm-5">
{{afQuickField "estimated_cost"}}
</div>
<div class="col-sm-3">
{{afQuickField "personal_days"}}
</div>
<div class="col-sm-11">
{{afQuickField "justification" rows=5}}
</div>
<div class="form-group col-sm-11" id="travelTypes">
<h3>Is this a Domestic or Foreign Trip? </h3>
<hr>
{{afFieldInput "locations.0.travel_type" options=travelTypes noselect="true"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.depart_on"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.return_on"}}
</div>
<div class="col-sm-4">
{{afQuickField "locations.0.country" placeholder="United States"}}
</div>
<div class="col-sm-4">
{{afQuickField "locations.0.city" placeholder="San Francisco"}}
</div>
<div class="col-sm-4">
{{afQuickField "locations.0.state" placeholder="CA"}}
</div>
</div>
<div class="row" id="foreign_fields">
<div class="col-sm-4">
{{afQuickField "locations.0.host_name" placeholder="schemaLabel"}}
</div>
<div class="col-sm-4">
{{afQuickField "locations.0.host_contact" placeholder="schemaLabel"}}
</div>
<div class="col-sm-4">
{{afQuickField "locations.0.host_affiliation" placeholder="schemaLabel"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.lodging_name" placeholder="schemaLabel"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.lodging_phone" placeholder="schemaLabel"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.lodging_address" placeholder="schemaLabel"}}
</div>
<div class="col-sm-6">
{{afQuickField "locations.0.lodging_website" placeholder="schemaLabel"}}
</div>
</div>
<div class="row">
<div class="col-xs-11">
<h3>Is this a Conference?</h3>
<hr>
<label>Yes <input type="radio" name="travel[conf]" class="travel_conf" value="yes"></label>
<label>No <input type="radio" name="travel[conf]" class="travel_conf" value="no"></label>
</div>
</div>
<div class="row" id="conference_fields">
<div class="form-group col-sm-4">
{{afQuickField "locations.0.conf_name" placeholder="schemaLabel"}}
</div>
<div class="form-group col-sm-4">
{{afQuickField "locations.0.conf_website" placeholder="schemaLabel"}}
</div>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment