Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Created core task modules
Browse files Browse the repository at this point in the history
  • Loading branch information
donnielrt committed Sep 30, 2012
1 parent d5b8184 commit 9825599
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ npm-debug.log

.idea
.idea/*

*.sublime*
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function () {
var schema = new Schema({
attributeId: mongoose.Schema.ObjectId,
name: String,
description: String,
points: Number,
deadline: Date,
status: [that.Status],
Expand Down
25 changes: 25 additions & 0 deletions public/js/app/collections/tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define(['backbone', 'models/task', 'views/tasks/single'], function (Backbone, Task, TaskView) {

"use strict";

return Backbone.Collection.extend({

url:"/api/tasks",

model:Task,

initialize:function (options) {

options = options || {};
this.limit = options.limit || -1;

// used when fetching a limited number of results
if (this.limit > 0) {
this.url = this.url + "/limit/" + this.limit;
}

}

});

});
2 changes: 1 addition & 1 deletion public/js/app/models/quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define(['backbone', 'backbone-validate', 'moment'], function(Backbone, validatio
_id: null,
name: "Untitled Quest",
description: "",
deadline: "",
deadline: new Date(),
created: new Date(),
updated: new Date()

Expand Down
83 changes: 83 additions & 0 deletions public/js/app/models/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
define(['backbone', 'backbone-validate', 'moment'], function(Backbone, validation, moment) {

"use strict";

return Backbone.Model.extend({

idAttribute: "_id",

urlRoot: "/api/tasks",

/*validation: {
name: {
required: true,
min: 3,
max: 100,
msg: "Name is required"
},
description: {
max: 1000,
msg: "Invalid description"
},
deadline: {
}
},*/

defaults: {
_id: null,
name: "Untitled Task",
description: "",
points: 0,
deadline: new Date(),
created: new Date(),
updated: new Date()

},

initialize: function() {
},

parse: function(response) {

var deadline, deadlineStatus = "", today = moment();

if(response) {

if(response.deadline && moment(response.deadline).isValid()) {

deadline = moment(response.deadline);

if(deadline.unix() < today.unix()) {
deadlineStatus = "deadline-past";
} else {
deadlineStatus = "deadline-future";
}

// "6 days from now formatting"
response.humanFriendlyDeadline = deadline.fromNow();
response.deadline = deadline.format("MM/DD/YYYY");

} else {
response.deadline = "date missing or invalid";
}

if(!response.status || !response.status.length) {
response.status = "Pending";
} else {
// decipher status
response.status = response.status[0].name;
}

response.deadlineStatus = deadlineStatus;


}

return response;

}

});

});
112 changes: 103 additions & 9 deletions public/js/app/routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ define([
'views/quests/form',
'views/quests/remove',
'views/quests/list',
'text!templates/common/header.html',
'views/tasks/single',
'views/tasks/form',
'views/tasks/remove',
'views/tasks/list',
'models/quest',
'collections/quests',
'models/task',
'collections/tasks',
'questience'],
function(
Backbone,
Expand All @@ -16,9 +21,14 @@ define([
QuestFormView,
QuestDeleteView,
QuestsView,
HeaderView,
TaskView,
TaskFormView,
TaskDeleteView,
TasksView,
Quest,
Quests,
Task,
Tasks,
Questience){

"use strict";
Expand All @@ -32,7 +42,12 @@ define([
"quests/new": "questNew",
"quests/:id": "questView",
"quests/:id/edit": "questEdit",
"quests/:id/remove": "questRemove"
"quests/:id/remove": "questRemove",
"tasks": "tasks",
"tasks/new": "taskNew",
"tasks/:id": "taskView",
"tasks/:id/edit": "taskEdit",
"tasks/:id/remove": "taskRemove"
},

initialize: function () {
Expand Down Expand Up @@ -75,7 +90,7 @@ define([
quests: function () {

// list quests
var collection = new Quests(), questsView = new QuestsView({collection: collection, $el: $("#questience-app")}); // render quests
var collection = new Quests(), questsView = new QuestsView({collection: collection, $el: $("#questience-app")}); // render quests

collection.fetch();

Expand Down Expand Up @@ -115,25 +130,25 @@ define([

},

questEdit: function (id) {
questEdit: function (id) {

var quest = new Quest({_id: id}),
var quest = new Quest({_id: id}),
questView,
$root = this.appView.$el,
that = this;

questView = new QuestFormView({model: quest});
quest.fetch({
quest.fetch({
success: function(model, response) {
$root.html(questView.$el);
}
});

return this;

},
},

questRemove: function (id) {
questRemove: function (id) {

var quest = new Quest({_id: id}),
questView,
Expand All @@ -147,6 +162,85 @@ define([
}
});

return this;

},

tasks: function () {

// list tasks
var collection = new Tasks(), tasksView = new TasksView({collection: collection, $el: $("#questience-app")}); // render tasks

collection.fetch();

return this;

},

taskView: function (id) {

var task = new Task({_id: id}),
tasksView,
$root = this.appView.$el,
that = this;

tasksView = new TaskView({model: task, singleView: true});

task.fetch({
success: function(model, response) {

$root.html(tasksView.$el);

}
});

return this;

},

taskNew: function () {

var task = new Task(),
taskView = new TaskFormView({model: task});

this.appView.$el.html(taskView.render().$el);

return this;

},

taskEdit: function (id) {

var task = new Task({_id: id}),
taskView,
$root = this.appView.$el,
that = this;

taskView = new TaskFormView({model: task});
task.fetch({
success: function(model, response) {
$root.html(taskView.$el);
}
});

return this;

},

taskRemove: function (id) {

var task = new Quest({_id: id}),
taskView,
$root = this.appView.$el,
that = this;

taskView = new TaskDeleteView({model: task});
task.fetch({
success: function(model, response) {
$root.html(taskView.$el);
}
});

return this;

}
Expand Down
60 changes: 60 additions & 0 deletions public/js/app/templates/tasks/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<div class="alert is-not-displayed"></div>
<fieldset>

<legend><%= formEditMode %> Task</legend>

<div class="control-group">

<label class="control-label" for="status">Status</label>
<div class="controls">
<select id="status" name="status">
<option value="Pending">Pending</option>
<option value="Completed">Completed</option>
<option value="Archived">Archived</option>
</select>
</div>

</div>

<div class="control-group">
<label class="control-label" for="name">Name</label>

<div class="controls">
<input type="text" id="name" class="input-xxlarge" name="name" placeholder="Quest Name" value="<%= name %>"/>
</div>
</div>

<div class="control-group">
<label class="control-label" for="description">Description</label>

<div class="controls">
<textarea id="description" class="input-xxlarge" name="description" placeholder="Quest Description"><%= description %></textarea>
</div>
</div>

<div class="control-group">
<label class="control-label" for="deadline">Deadline</label>

<div class="controls">
<input type="datetime" id="deadline" name="deadline" placeholder="Quest Deadline" class="human-friendly-date" data-machine-date="<%= deadline %>" value="<%= deadline %>"/>
</div>
</div>

<div class="control-group">

<label class="control-label" for="status">Points</label>
<div class="controls">
<select id="points" name="points">
<% for(var ctr = 0; ctr < 1; ctr += 0.1) { %>
<option value="<%= ctr %>"><%= ctr %></option>
<% } %>
</select>
</div>

</div>

<div class="controls">
<input type="button" name="save" class="btn btn-primary btn-save" value="save"/> <a href="/tasks/<%= _id %>" class="btn btn-cancel">Cancel</a>
</div>

</fieldset>
Loading

0 comments on commit 9825599

Please sign in to comment.