Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1fd47c1
Merge branch 'detail-page-sample' into sample-spa-contact-module-comp…
jadedsurfer Jan 21, 2015
dfc56a9
Move spa-index to the root of client
jadedsurfer Jan 22, 2015
96acc32
Merge remote-tracking branch 'origin/add-travis' into sample-spa-cont…
jadedsurfer Jan 22, 2015
27822de
Merge branch 'add-travis' into sample-spa-contact-module-complete
jadedsurfer Jan 22, 2015
4e93404
Merge remote-tracking branch 'origin/master' into sample-spa-contact-…
jadedsurfer Jan 23, 2015
8467d37
Add make contact module available to single page application
jadedsurfer Jan 25, 2015
e8b3b44
Enable the contact module and fix path to browserified build script f…
jadedsurfer Jan 25, 2015
dd817b4
Merge branch 'sample-spa-contact-module-complete' of https://github.c…
jadedsurfer Jan 25, 2015
8b1ae51
Add leading slash to path to spa/js/build.js
jadedsurfer Feb 4, 2015
1a01bd6
Add sample of for list view
jadedsurfer Feb 5, 2015
ffc22b5
Finish contacts collection example
jadedsurfer Feb 5, 2015
37e6c60
Merge with master to get the latest
jadedsurfer Feb 5, 2015
504a048
Remove comment to stop lint error
jadedsurfer Feb 5, 2015
e86c698
Merge remote-tracking branch 'origin/master' into sample-spa-collection
jadedsurfer Feb 5, 2015
d8a58a1
merge sample collection
jeffreytu Feb 9, 2015
e865fbc
add paths to collection
jeffreytu Feb 9, 2015
d6f9edf
add table and restyle
jeffreytu Feb 9, 2015
cc4d902
rename template to appropriate single resource
jeffreytu Feb 9, 2015
e697dc7
adding files for collections and associated tests
jeffreytu Feb 9, 2015
86ddc42
edit controller expectation
jeffreytu Feb 11, 2015
3b9f864
add rendering for various sort functions and their associated tests
jeffreytu Feb 11, 2015
241a7b3
fix th class references and remove old html structure
jeffreytu Feb 11, 2015
c70b39b
add methods and tests for sorting by title, resource type, authors, d…
jeffreytu Feb 11, 2015
d1f80ba
Merge branch 'master' into iss42-add-collection
jeffreytu Feb 11, 2015
6cb818c
move css to style.css
jeffreytu Feb 11, 2015
0b75387
remove contact folder
jeffreytu Feb 11, 2015
e7f6002
remove contact model in model-config
jeffreytu Feb 11, 2015
b6da83c
remove contact require and initialization
jeffreytu Feb 11, 2015
e2432b1
rename route for continuity
jeffreytu Feb 13, 2015
6ecd12c
merge current master
jeffreytu Feb 16, 2015
0b0413c
fix string error
jeffreytu Feb 16, 2015
e3e6168
refactor some views when saving
jeffreytu Feb 16, 2015
6ac179a
change view.destroy to view.remove
jeffreytu Feb 16, 2015
2c3793a
change string to correct name
jeffreytu Feb 17, 2015
5e5d81b
replace destroy with remove
jeffreytu Feb 17, 2015
ed24eb4
line too long to pass lint
jeffreytu Feb 17, 2015
cf64530
remove self from authorsFormat since inside same scope
jeffreytu Feb 17, 2015
16d54d3
fix errors in name and remove remaining this
jeffreytu Feb 17, 2015
a9e5721
add bootstrap dependency and require
jeffreytu Feb 24, 2015
fc8beb8
add style for checkbox column
jeffreytu Feb 24, 2015
f66c099
rewrite check for this.view
jeffreytu Feb 24, 2015
386c210
add modal and create function for save and delete
jeffreytu Feb 24, 2015
7fe43e2
tell jslint to ignore window
jeffreytu Feb 25, 2015
1bb93f0
change expectation selector to fix test failure
jeffreytu Feb 25, 2015
084f5f0
change ids to classes and add select all checkbox
jeffreytu Feb 25, 2015
c77044d
remove modal instance on save and add function for select all when de…
jeffreytu Feb 25, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions client/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,43 @@ header.carousel .fill {
font-size: 14px;
}

/*---Learning Resources---*/
/*Collection*/
.lrs-tbl-header{
font-weight: bold;
background: #4F4D4D;
border: 1px solid #4F4D4D;
color: #FAFAFA;
}
.lrs-tbl-header th a:visited, .lrs-tbl-header th a {
color: #FAFAFA;
}
.lrs-tbl tr td {
background: #FDFDFD;
}

.lrs-tbl-h-n {
width: 5%;
}
.lrs-tbl-h-rt {
width: 10%;
}
.lrs-tbl-h-t {
width: 20%;
}
.lrs-tbl-h-a {
width: 10%;
}
.lrs-tbl-h-d {
width: 30%;
}
.lrs-tbl-h-de {
width: 2%;
}
.borderless {
border: none;
}

/*---Learning Resource---*/
/*Single ID*/
.edit, .b-cancel, .b-update, .b-delete, .div-space-edit {
Expand Down
1 change: 1 addition & 0 deletions client/spa-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>SPA</title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../font-awesome/css/font-awesome.min.css">
</head>
<body>
Hi, I'm the spa index from the spa folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var View = require('./learning-resource.view');
module.exports = Backbone.Controller.extend({

routes: {
'learning-resource/:id': 'showLearningResource'
'learning-resources/:id': 'showLearningResource'
},

initialize: function(){
Expand All @@ -26,7 +26,7 @@ module.exports = Backbone.Controller.extend({

//Ensures that what the view put in the DOM is removed and
//any events the view had listenTo'd are removed.
if (view) view.destroy();
if (view) view.remove();

this.initializeModel({id: learningResourceId});

Expand Down
2 changes: 0 additions & 2 deletions client/spa/js/learning-resource/learning-resource.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<style type="text/css">
</style>
<div class="vertical-center">
<div class="container">
<div class="row">
Expand Down
113 changes: 60 additions & 53 deletions client/spa/js/learning-resource/learning-resource.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,33 @@ var $ = require('../vendor/index').$;
var fs = require('fs'); //will be replaced by brfs in the browser

// readFileSync will be evaluated statically so errors can't be caught
var template = fs.readFileSync(__dirname + '/learning-resources.html', 'utf8');
var template = fs.readFileSync(__dirname + '/learning-resource.html', 'utf8');

var showMessage = function(type, msg) {
$('#msg').empty().addClass(type)
.html(msg).fadeIn().delay(2000)
.fadeOut('slow').queue(function(remove) {
$('#msg').removeClass(type);
remove();
});
};

var renderAuthors = function(self) {
var auth = self.model.get('authors').toString().split(',').join(', ');
self.input = self.$('.editing');
self.$('select option[value="'+self.model.get('resourceType')+'"]')
.attr('selected','selected');
self.$('#auth').val(auth);
self.$('#author-dsp').text(auth);
};

var initialValues = function(self) {
self.$('#title').val(self.model.get('title'));
self.$('#desc').val(self.model.get('description'));
self.$('#auth').val(self.model.get('authors'));
self.$('select option[value="'+self.model.get('resourceType')+'"]')
.attr('selected','selected');
};

module.exports = Backbone.View.extend({

Expand All @@ -34,75 +60,56 @@ module.exports = Backbone.View.extend({
},

cancel: function(){
this.$('#title').val(this.model.get('title'));
this.$('#desc').val(this.model.get('description'));
this.$('#auth').val(this.model.get('authors'));
this.$('select option[value="'+this.model.get('resourceType')+'"]')
.attr('selected','selected');
$('#form-area').removeClass('sty-form'); //remove bg color of form
$('#msg').empty()
.addClass('alert-warning')
.html('Changes cancelled')
.fadeIn().delay(2000).fadeOut('slow')
.queue(function(remove){
$('#msg').removeClass('alert-warning');
remove();
});
showMessage('alert-warning', 'Changes cancelled');
this.$el.removeClass('editing');
},

save: function(){
var view = this;
var auth = [];
if (this.$('#auth').val() === '') auth = null;
else $.each(this.$('#auth').val().split(','), function(){
auth.push($.trim(this));
});
var attributes = {
title: this.$('#title').val().trim(),
resourceType: $('#resourceType option:selected').val(),
description: this.$('#desc').val().trim(),
authors: auth

var authorsFormat = function() {
var authors = [];
// console.log($('#auth').val().split(','));
if ($('#auth').val() === '') authors = null;
else {
$.each($('#auth').val().split(','), function(key,value){
authors.push(value.trim());
});
return authors;
}
};
var options = {
success: function(){
$('#form-area').removeClass('sty-form');
view.$el.removeClass('editing');
$('#msg').empty()
.addClass('alert-success')
.html('Sucessfully updated')
.fadeIn().delay(2000).fadeOut('slow')
.queue(function(remove){
$('#msg').removeClass('alert-success');
remove();
});

var saveArgs = {
attributes: {
title: this.$('#title').val().trim(),
resourceType: $('#resourceType option:selected').val(),
description: this.$('#desc').val().trim(),
authors: authorsFormat
},
error: function(model, error){
//server response errors if no validations specified
options: {
success: function(){
$('#form-area').removeClass('sty-form');
view.$el.removeClass('editing');
showMessage('alert-success', 'Successfully updated');
},
error: function(model, error){
//server response errors if no validations specified
}
}
};
this.model.save(attributes, options);

this.model.save(saveArgs.attributes, saveArgs.options);

if (this.model.validationError) {
$('#msg').empty()
.addClass('alert-danger')
.html(this.model.validationError)
.fadeIn().delay(2000).fadeOut('slow')
.queue(function(remove){
$('#msg').removeClass('alert-danger');
remove();
});
showMessage('alert-danger', this.model.validationError);
}
},

render: function(){
var context = this.model.toJSON();
var auth = this.model.get('authors').toString().split(',').join(', ');
this.$el.html(this.template(context));
this.input = this.$('.editing');
this.$('select option[value="'+this.model.get('resourceType')+'"]')
.attr('selected','selected');
this.$('#auth').val(auth);
this.$('#author-dsp').text(auth);
renderAuthors(this);
return this;
},

Expand Down
57 changes: 57 additions & 0 deletions client/spa/js/learning-resource/learning-resources.collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

var Backbone = require('../vendor/index').Backbone;

module.exports = Backbone.Collection.extend({

url: '/api/learning-resources/',

initialize: function(){
this.on('sortById', this.sortById);
this.on('sortByTitle', this.sortByTitle);
this.on('sortByResourceType', this.sortByResourceType);
this.on('sortByAuthors', this.sortByAuthors);
this.on('sortByDescription', this.sortByDescription);
this.trigger('sortByTitle');
this.trigger('sortByResourceType');
this.trigger('sortByAuthors');
this.trigger('sortByDescription');
},

sortById: function(){
this.comparator = function(model){
return model.get('id');
};
this.sort();
},

sortByTitle: function(){
this.comparator = function(model){
return model.get('title');
};
this.sort();
},

sortByResourceType: function(){
this.comparator = function(model){
return model.get('resourceType');
};
this.sort();
},

sortByAuthors: function(){
this.comparator = function(model){
return model.get('authors');
};
this.sort();
},

sortByDescription: function(){
this.comparator = function(model){
return model.get('description');
};
this.sort();
}

});

64 changes: 64 additions & 0 deletions client/spa/js/learning-resource/learning-resources.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

var Backbone = require('../vendor/index').Backbone;
var $ = require('../vendor/index').$;
var Model = require('./learning-resource.model');
var Collection = require('./learning-resources.collection');
var View = require('./learning-resources.view');

module.exports = Backbone.Controller.extend({

routes: {
'learning-resources': 'showLearningResources'
},

initialize: function(){
this.options.container = this.options.container || 'body';
},

getCollection: function(){
if (!this.collection){
Collection = Collection.extend({model: Model});
this.collection = new Collection();
}
return this.collection;
},

getView: function(){
// if (this.view) {
// this.view.remove();
// }
if (!this.view) {
this.view = new View({collection: this.collection});
}
return this.view;
},

showLearningResources: function(){
var self = this;
this.getCollection().fetch({
success: function(collection, response, options){
self.getView();
self.renderView();
},
error: function(collection, response, options){
self.renderError();
}
});
},

renderToContainer: function(html){
return $(this.options.container).html(html);
},

renderView: function(){
this.renderToContainer(this.view.render().$el);
return this.view;
},

renderError: function(){
return this.renderToContainer(
'<p>There was a problem rendering learning resources</p>');
}

});
Loading