Skip to content

Commit

Permalink
Some event bind between views cleaning and getting the heading to sta…
Browse files Browse the repository at this point in the history
…rt responding to file name changes
  • Loading branch information
tristen committed Apr 10, 2013
1 parent a23e199 commit f354b3f
Show file tree
Hide file tree
Showing 9 changed files with 10,979 additions and 10,949 deletions.
17 changes: 17 additions & 0 deletions app.css
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,23 @@ em { font-style:italic; }
width:960px;
}

/* Alterable filename input */
.heading .filepath {
background:transparent;
border:none;
color:#57676e;
margin:0;
font-size:20px;
line-height:1.5em;
font-weight:700;
padding:0;
width:620px;
}
.heading .filepath:focus,
.heading .filepath:hover {
background:#e0e7eb;
}

.inner {
padding:15px;
}
Expand Down
19 changes: 13 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@
</script>

<script data-template='heading' type='text/html'>
<% if (avatar) { %><div class='avatar round fl'><%= avatar %></div><% } %>

<div class='fl details'>
<h4><a class='user' href='#<%= parentUrl %>'><%= parent %></a></h4>
<h2><a class='repo' href='#<%= titleUrl %>'><%= title %></a></h2>
</div>
<% if (alterable) { %>
<div class='avatar round fl'><%= avatar %></div>
<div class='fl details'>
<h4><a class='user' href='#<%= parentUrl %>'><%= parent %></a></h4>
<input type='text' class='filepath' value='<%= title %>'>
</div>
<% } else { %>
<div class='avatar round fl'><%= avatar %></div>
<div class='fl details'>
<h4><a class='user' href='#<%= parentUrl %>'><%= parent %></a></h4>
<h2><a class='repo' href='#<%= titleUrl %>'><%= title %></a></h2>
</div>
<% } %>
</script>

<script data-template='notification' type='text/html'>
Expand Down
23 changes: 13 additions & 10 deletions js/prose/views/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
},

initialize: function(options) {
this.eventRegister = options.eventRegister;
this.eventRegister = app.eventRegister;

_.bindAll(this, 'sidebarContext');
options.eventRegister.bind('sidebarContext', this.sidebarContext);
_.bindAll(this, 'headerContext', 'sidebarContext');
this.eventRegister.bind('headerContext', this.headerContext);
this.eventRegister.bind('sidebarContext', this.sidebarContext);
},

render: function () {
Expand All @@ -47,17 +48,18 @@
return this;
},

headerContext: function(data) {
$('#heading').empty().append(templates.heading(data));
},

sidebarContext: function(data, context) {
if (context === 'post') {
$('#drawer')
.empty()
.html(templates.settings(_.extend(data, app.state, {
mode: this.mode
})));
.html(templates.settings(data));

} else if (context === 'posts') {
$('#drawer').empty().append(templates.sidebarProject(_.extend(this.model, app.state, {
currentPath: app.state.path
})));
$('#drawer').empty().append(templates.sidebarProject(data));

// Branch Switching
$('.chzn-select').chosen().change(function() {
Expand Down Expand Up @@ -137,7 +139,8 @@

remove: function () {
// Unbind pagehide event handler when View is removed
this.options.eventRegister.unbind('sidebarContext', this.sidebarContext);
this.eventRegister.unbind('sidebarContext', this.sidebarContext);
this.eventRegister.unbind('headerContext', this.headerContext);
}
});

Expand Down
12 changes: 4 additions & 8 deletions js/prose/views/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
_.bindAll(this);
var that = this;
this.app = new views.App({
model: this.model,
eventRegister: app.eventRegister
model: this.model
});

function calculateLayout() {
Expand Down Expand Up @@ -127,8 +126,7 @@
// Render out the application view
$(that.app.render().el).prependTo(that.el);
this.replaceMainView('posts', new views.Posts({
model: data,
eventRegister: app.eventRegister
model: data
}).render());
}, this));
},
Expand All @@ -149,8 +147,7 @@
data.preview = (mode !== 'edit');
data.lang = _.mode(file);
this.replaceMainView(window.authenticated ? 'post' : 'read-post', new views.Post({
model: data,
eventRegister: app.eventRegister
model: data
}).render());
}, this));

Expand Down Expand Up @@ -188,8 +185,7 @@
data.lang = _.mode(data.file);

this.replaceMainView('post', new views.Post({
model: data,
eventRegister: app.eventRegister
model: data
}).render());

this.mainView._makeDirty();
Expand Down
75 changes: 40 additions & 35 deletions js/prose/views/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,48 @@

render: function() {

var data = _.extend(this.model, {
mode: this.mode,
metadata: jsyaml.load(this.model.raw_metadata)
});

this.eventRegister = app.eventRegister;

// Listen for button clicks from the vertical nav
_.bindAll(this, 'edit', 'preview', 'settings', 'deleteFile', 'updateMetaData', 'save', 'translate', 'updateFile');
this.options.eventRegister.bind('edit', this.edit);
this.options.eventRegister.bind('preview', this.preview);
this.options.eventRegister.bind('settings', this.settings);
this.options.eventRegister.bind('deleteFile', this.deleteFile);
this.options.eventRegister.bind('updateMetaData', this.updateMetaData);
this.options.eventRegister.bind('save', this.save);
this.options.eventRegister.bind('updateFile', this.updateFile);
this.options.eventRegister.bind('translate', this.translate);
this.eventRegister.bind('edit', this.edit);
this.eventRegister.bind('preview', this.preview);
this.eventRegister.bind('settings', this.settings);
this.eventRegister.bind('deleteFile', this.deleteFile);
this.eventRegister.bind('updateMetaData', this.updateMetaData);
this.eventRegister.bind('save', this.save);
this.eventRegister.bind('updateFile', this.updateFile);
this.eventRegister.bind('translate', this.translate);

// Ping `views/app.js` to let know we should swap out the sidebar
this.eventRegister = this.options.eventRegister;
this.eventRegister.trigger('sidebarContext', this.model, 'post');
this.eventRegister.trigger('sidebarContext', data, 'post');

var that = this;
// Render heading
var isPrivate = app.state.isPrivate ? 'private' : '';

var header = {
avatar: '<span class="icon round file ' + isPrivate + '"></span>',
parent: app.state.repo,
parentUrl: app.state.user + '/' + app.state.repo,
title: data.file,
titleUrl: '#',
alterable: true
}

this.eventRegister.trigger('headerContext', header);

$(this.el)
.empty()
.append(templates.post(_.extend(this.model, {
mode: this.mode,
metadata: jsyaml.load(this.model.raw_metadata)
})));
.append(templates.post(data));

// TODO Add an unpublished class to .application
if (!this.model.published) $(this.el).addClass('published');

$('#heading')
.empty()
.append(templates.heading({
avatar: '<span class="icon round file ' + isPrivate + '"></span>',
parent: this.model.repo,
parentUrl: this.model.user + '/' + this.model.repo,
title: this.model.file,
titleUrl: '#'
}));

this.initEditor();

// Editor is first up so trigger an active class for it
Expand Down Expand Up @@ -81,6 +85,7 @@

preview: function(e) {
var that = this;

$('#prose').toggleClass('open', false);

if (this.model.metadata && this.model.metadata.layout) {
Expand Down Expand Up @@ -144,7 +149,7 @@
if (this.editor) this.model.content = this.editor.getValue();
if (this.metadataEditor) this.model.raw_metadata = this.metadataEditor.getValue();
if (!this.$('.button.save').hasClass('saving')) {
this.$('.button.save').html(this.model.writeable ? "SAVE" : "SUBMIT CHANGE");
this.$('.button.save').html(this.model.writeable ? 'Save' : 'Submit Change');
this.$('.button.save').removeClass('inactive error');
}
},
Expand Down Expand Up @@ -415,7 +420,7 @@
hash.splice(-2, 2, href, hash[hash.length - 1]);
}

console.log(_(hash).compact().join('/'));
// console.log(_(hash).compact().join('/'));
router.navigate(_(hash).compact().join('/'), true);

return false;
Expand Down Expand Up @@ -564,14 +569,14 @@

remove: function () {
// Unbind pagehide event handler when View is removed
this.options.eventRegister.unbind('edit', this.postViews);
this.options.eventRegister.unbind('preview', this.preview);
this.options.eventRegister.unbind('settings', this.settings);
this.options.eventRegister.unbind('deleteFile', this.deleteFile);
this.options.eventRegister.unbind('updateMetaData', this.updateMetaData);
this.options.eventRegister.unbind('save', this.save);
this.options.eventRegister.unbind('translate', this.translate);
this.options.eventRegister.unbind('updateFile', this.updateFile);
this.eventRegister.unbind('edit', this.postViews);
this.eventRegister.unbind('preview', this.preview);
this.eventRegister.unbind('settings', this.settings);
this.eventRegister.unbind('deleteFile', this.deleteFile);
this.eventRegister.unbind('updateMetaData', this.updateMetaData);
this.eventRegister.unbind('save', this.save);
this.eventRegister.unbind('translate', this.translate);
this.eventRegister.unbind('updateFile', this.updateFile);

$(window).unbind('pagehide');
Backbone.View.prototype.remove.call(this);
Expand Down
34 changes: 15 additions & 19 deletions js/prose/views/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@

render: function () {
var that = this;
var h = this.model;
var data = _.extend(this.model, app.state, {
currentPath: app.state.path
});

// Ping `views/app.js` to let know we should swap out the sidebar
this.eventRegister = this.options.eventRegister;
this.eventRegister.trigger('sidebarContext', this.model, 'posts');

this.eventRegister = app.eventRegister;
this.eventRegister.trigger('sidebarContext', data, 'posts');
var isPrivate = app.state.isPrivate ? 'private' : '';

$(this.el).empty().append(templates.posts(_.extend(this.model, app.state, {
currentPath: app.state.path
})));
var header = {
avatar: '<span class="icon round repo ' + isPrivate + '"></span>',
parent: data.user,
parentUrl: data.user,
title: data.repo,
titleUrl: data.user + '/' + data.repo,
alterable: false
}

$('#heading')
.empty()
.append(templates.heading({
avatar: '<span class="icon round repo ' + isPrivate + '"></span>',
parent: h.user,
parentUrl: h.user,
title: h.repo,
titleUrl: h.user + '/' + h.repo
}));
this.eventRegister.trigger('headerContext', header);
$(this.el).empty().append(templates.posts(data));

_.delay(function () {
that.renderResults();
Expand All @@ -50,10 +49,7 @@
search: function () {
_.delay(_.bind(function() {
var searchstr = this.$('#filter').val();

this.model = getFiles(this.model.tree, app.state.path, searchstr);


this.renderResults();
}, this), 10);
},
Expand Down
Loading

0 comments on commit f354b3f

Please sign in to comment.