Skip to content

Commit

Permalink
Refactor Library/Collection stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Aufreiter committed Sep 23, 2013
1 parent 5fd3d67 commit b95d07c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 56 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

var Library = require("./src/library");
Library.Controller = require("./src/library_controller");
Library.View = require("./src/library_controller");
Library.View = require("./src/library_view");
Library.Collection = {};
Library.Collection.Controller = require("./src/collection_controller");
Library.Collection.View = require("./src/collection_view");

module.exports = Library;
18 changes: 9 additions & 9 deletions library.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
width: 300px;
}

.library .toggle-collection {
.library .collection {
font-family: 'Avenir LT W01 85 Heavy', 'Montserrat', 'Source Sans Pro';
font-size: 16px;
display: block;
padding: 20px 10px;
}

.library .toggle-collection:hover {
.library .collection:hover {
background: rgba(255,255,255,0.6);
}

.library .toggle-collection.active {
.library .collection.active {
background: #fff;
}

Expand All @@ -35,8 +35,9 @@
font-size: 16px;
}

/* Main collection */

.library .collection {
#main .collection {
background: white;
position: absolute;
left: 300px;
Expand All @@ -45,8 +46,7 @@
width: 800px;
}


.library .collection a.document {
#main .collection a.document {
display: block;
background: white;
width: 400px;
Expand All @@ -57,18 +57,18 @@
float: left;
}

.library .collection a.document .title {
#main .collection a.document .title {
color: #1B6685;
font-family: 'Avenir LT W01 85 Heavy', 'Montserrat', 'Source Sans Pro';
font-size: 16px;
}

.library .collection a.document .authors {
#main .collection a.document .authors {
color: #777;
font-size: 15px;
padding: 10px 0;
}

.library .collection a.document:hover .title {
#main .collection a.document:hover .title {
color: rgba(11, 157, 217, 1);
}
40 changes: 40 additions & 0 deletions src/collection_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

var _ = require("underscore");
var Controller = require("substance-application").Controller;
var CollectionView = require("./collection_view");
var util = require("substance-util");


// Substance.Library.Controller
// -----------------
//

var CollectionController = function(collection, state) {
this.collection = collection;
this.state = state;
Controller.call(this);
};


CollectionController.Prototype = function() {

this.createView = function() {
var view = new CollectionView(this);
return view;
};

this.getActiveControllers = function() {
return [];
};
};


// Exports
// --------

CollectionController.Prototype.prototype = Controller.prototype;
CollectionController.prototype = new CollectionController.Prototype();
_.extend(CollectionController.prototype, util.Events);

module.exports = CollectionController;
9 changes: 6 additions & 3 deletions src/collection_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var $$ = require("substance-application").$$;
//
// The Substance Collection display

var CollectionView = function(libraryCtrl) {
var CollectionView = function(collectionCtrl) {
View.call(this);

this.$el.addClass('collection');
this.libraryCtrl = libraryCtrl;
this.collectionCtrl = collectionCtrl;
};

CollectionView.Prototype = function() {
Expand All @@ -27,9 +27,12 @@ CollectionView.Prototype = function() {
// .title

this.render = function() {


// Render the collection
var collection = this.libraryCtrl.collection;
var collection = this.collectionCtrl.collection;
var records = collection.records;
console.log(this.collectionCtrl);

_.each(records, function(record) {
this.el.appendChild($$('a.document', {
Expand Down
1 change: 0 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Library.Prototype = function() {
cb(null, doc);
});
};

};


Expand Down
27 changes: 1 addition & 26 deletions src/library_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ var LibraryController = function(library, state) {

this.state = state;

this.collection = this.library.getCollection(state.collection);

Controller.call(this);

// Create library view
Expand All @@ -34,31 +32,8 @@ LibraryController.Prototype = function() {
// Transitions
// ==================================


// Provides an array of (context, controller) tuples that describe the
// current state of responsibilities
// --------
//
// E.g., when a document is opened:
// ["application", "document"]
// with controllers taking responisbility:
// [this, this.document]
//
// The child controller (e.g., document) should itself be allowed to have sub-controllers.
// For sake of prototyping this is implemented manually right now.
// TODO: discuss naming

this.getActiveControllers = function() {
var result = [ ["sandbox", this] ];

var state = this.state;

if (state === "editor") {
result = result.concat(this.editor.getActiveControllers());
} else if (state === "test_center") {
result.push(["test_center", this.testRunner]);
}
return result;
return [];
};
};

Expand Down
21 changes: 5 additions & 16 deletions src/library_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ var LibraryView = function(libraryCtrl) {

this.$el.addClass('library');
this.libraryCtrl = libraryCtrl;

this.collectionView = new CollectionView(libraryCtrl);
};

LibraryView.Prototype = function() {
Expand All @@ -33,31 +31,22 @@ LibraryView.Prototype = function() {

this.render = function() {
var collections = this.libraryCtrl.library.collections;
var activeCollection = this.libraryCtrl.collection;

// var activeCollection = this.libraryCtrl.collection;

var collectionToggles = $$('.collection-toggles', {
children: _.map(collections, function(c) {
function active() {
return c.id === activeCollection.id;
}

return $$('a', {
id: "collection_toggle_"+c.id,
class: "toggle-collection"+(active() ? " active": ""),
href: "#"+c.id,
id: "collection"+c.id,
class: "toggle-collection", // +(active() ? " active": "")
href: "#collections/"+c.id,
text: c.name
})
});
})
});

this.el.appendChild(collectionToggles);

// Container for collection view
this.el.appendChild($$('.collection'));

// Render current collection
this.$('.collection').replaceWith(this.collectionView.render().el);
return this;
};

Expand Down

0 comments on commit b95d07c

Please sign in to comment.