Skip to content

Commit

Permalink
CSS Style Tweaks, added custom checkbox javascript helper and got rid…
Browse files Browse the repository at this point in the history
… of empty post view bug
  • Loading branch information
distracteddev committed Oct 30, 2012
1 parent 5654025 commit 2eb735b
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 242 deletions.
4 changes: 2 additions & 2 deletions dictum/client/code/app/app.coffee
Expand Up @@ -26,9 +26,9 @@ ss.event.on 'newReply', (reply) ->

# Show the chat form and bind to the submit action
exports.bindSubmit = () ->
console.log $('#commentForm').data('events')
#console.log $('#commentForm').data('events')
unless $('#commentForm').data('events')
console.log "**************Binding Submit**************"
#console.log "**************Binding Submit**************"
$('#commentForm').submit () ->
# Grab the message from the text box
text = $('#myMessage').val()
Expand Down
122 changes: 84 additions & 38 deletions public/app.js
Expand Up @@ -72,14 +72,14 @@ Ember.registerBoundHelper = function(name, func) {
var path = window.location.pathname;

if (path !== "/") {
console.log("PATH:" + path);
//console.log("PATH:" + path);
//newState = window.location.origin
// + "/#" + (window.location.pathname.slice(1
// Turns /pathName into pathName
var newState = (window.location.pathname.slice(1));
//App.routeManager.set('baseURI', window.location.origin);
//window.history.pushState(null, null, window.location.origin);
console.log(newState);
//console.log(newState);
App.routeManager.set('location', newState);
//window.location.pathname = "";
//window.location.hash = newState;
Expand All @@ -93,7 +93,7 @@ var App = Em.Application.create();
// Custom Ember Data Structure to Store an Array of tags
DS.attr.transforms.array = {
from: function(serialized) {
console.log("Serialized", serialized);
//console.log("Serialized", serialized);
if (typeof serialized !== 'string') {
return serialized.join(', ');
} else {
Expand All @@ -102,7 +102,7 @@ DS.attr.transforms.array = {
},

to: function(deserialized) {
console.log("Deserialized", deserialized);
//console.log("Deserialized", deserialized);
return deserialized.split(', ');
}
};
Expand Down Expand Up @@ -158,17 +158,16 @@ App.BlogPost = DS.Model.extend({
}.property('tags').cacheable(),

didLoad: function() {
console.log(this.get('ctime'));
//console.log(this.get('ctime'));
},

didUpdate: function() {
console.log(this.get("body") + " was updated");
//console.log(this.get("body") + " was updated");
// Refresh the view so that it updates with the latest content
// TODO: Refactor this so that Ember native observers work as intended
Ember.run.later(function() {
App.layout.set('content', '');
App.layout.set('content', App.selectedPostView);
console.log("later");
}, 800);
}
});
Expand All @@ -195,13 +194,13 @@ App.PostController = Ember.ArrayController.create({
return ctn.objectAt(this.get('selectedIndex'));
}.property('selectedIndex','content.@each'),

selectedIndex: null,
selectedIndex: 0,
hasEdited: false,
postPreview: null,

save: function () {
App.store.commit();
console.log("Store was committed");
//console.log("Store was committed");
},

revert: function() {
Expand Down Expand Up @@ -230,7 +229,7 @@ App.PostController = Ember.ArrayController.create({
setSelectedPost: function(title) {
var clientId = App.store.find(App.BlogPost, title).clientId;
var targetIndex = this.get('content').get('content').indexOf(clientId);
console.log("clientId: ", clientId, "targetIndex", targetIndex);
//console.log("clientId: ", clientId, "targetIndex", targetIndex);
if (targetIndex !== -1 ) {
this.set('selectedIndex', targetIndex);
} else {
Expand All @@ -243,7 +242,9 @@ App.PostController = Ember.ArrayController.create({
this.selectLatestPost();
}
else {
this.set('selectedIndex', this.selectedIndex + idx);
if (this.get('selectedIndex') + idx > 0) {
this.set('selectedIndex', this.get('selectedIndex') + idx);
}
}
},

Expand Down Expand Up @@ -307,22 +308,25 @@ App.PostController = Ember.ArrayController.create({
}.property('selectedIndex', 'content.@each'),

getPostPreview: function() {
console.log("Selected Post", this.get('selectedPost'));
if (this.get('selectedPost')) {
var rawMarkdown = this.get('selectedPost').get('body_raw');
var obj = {};
obj.md = rawMarkdown;
var that = this;
$.post('/markdown', obj, function(data) {
window.d = data;
console.log('getPostPreview fired');
//console.log('getPostPreview fired');
//return $(data).children();
that.propertyWillChange('postPreview');
that.set('postPreview',data);
that.propertyDidChange('postPreview');
var editedPost = that.get('selectedPost');
editedPost.propertyWillChange('body');
editedPost.set('body', data);
editedPost.propertyDidChange('body');
if (editedPost) {
editedPost.propertyWillChange('body');
editedPost.set('body', data);
editedPost.propertyDidChange('body');
}
}, 'text');
}
return this.get('postPreview');
Expand Down Expand Up @@ -395,6 +399,11 @@ App.bannerView = Ember.View.create({
templateName: 'top-banner'
});

Ember.Checkbox.prototype.didInsertElement = function() {
$.foundation.customForms.appendCustomMarkup();
};


/*
*END OF EMBER-VIEWS
*/
Expand Down Expand Up @@ -469,15 +478,15 @@ App.EditField = Ember.View.extend({
// {{ editable blog_post_content textArea="true"}}
Ember.Handlebars.registerHelper('editable', function(path, options) {
options.hash.valueBinding = path;
console.log(path);
//console.log(path);
if (path === "body") {
options.hash.rawBinding = path + "_raw";
console.log(options.hash);
//console.log(options.hash);
}
else if (path == "tags") {
options.hash.tagsArrayBinding = path + "_array";
}
else { console.log(path); }
//else { console.log(path); }
return Ember.Handlebars.helpers.view.call(this, App.EditField, options);
});

Expand All @@ -494,7 +503,7 @@ Ember.registerBoundHelper('preview', function(path) {

// Returns a nicely formatted and localized date from a javascript Date() object
Ember.Handlebars.registerHelper('date', function(path, options) {
console.log(path);
//console.log(path);
date = options.contexts[0].get(path);
if (typeof date === "undefined") {date = new Date()}
dateArray = date.toDateString().split(' ');
Expand All @@ -513,7 +522,7 @@ Ember.Handlebars.registerHelper('date', function(path, options) {
var bindLinks = function() {
// Bind all HashMark Links to
Ember.run.next(function() {
console.log(" BINDING LINKS ")
//console.log(" BINDING LINKS ")
$('a').click(function() {
var el = $(this);
var target = el.attr('href').replace('#', '');
Expand Down Expand Up @@ -559,23 +568,52 @@ var bindLinks = function() {

var t = setTimeout(function() {
require('./app').getAll();
}, 500)
}, 500);
}
});
}
};

var updateNav = function(loc) {
Ember.run.next(function() {
$('.sub-nav a').show().removeClass('current');
var selector = "a[href=#" + loc + "]"
console.log(selector);
var selector = "a[href=#" + loc + "]";
//console.log(selector);
$(selector).addClass('current');
});
}
};

window.insertComments = function() {

}
};

App.autoLogin = function(username, password) {

if (arguments.length > 0) {
setLoginInfo();
} else {
login();
}

function setLoginInfo() {
if (window.localStorage) {
localStorage.setItem('username', username);
localStorage.setItem('password', password);
}
}

function login() {
if (window.localStorage) {
var username = localStorage.getItem('username');
var pass = localStorage.getItem('password');
if (username && pass) {
$("input[name=username]").val(username);
$("input[name=password]").val(pass);
Author.getObject().logIn();
}
}
}

};

App.routeManager = Ember.RouteManager.create({

Expand All @@ -585,7 +623,8 @@ App.routeManager = Ember.RouteManager.create({
home: Em.State.create({
enter: function(stateManager, transition) {
this._super(stateManager, transition);
App.routeManager.set('location', 'portfolio')
App.routeManager.set('location', 'blog');
App.autoLogin();
}
}),

Expand All @@ -604,6 +643,7 @@ App.routeManager = Ember.RouteManager.create({
// App.layout.set('content', App.selectedPostView);
bindLinks();
bindPortfolioAnimation();
App.autoLogin();
Ember.run.next(function() {
$("#switch").hide();
$("#content").hide();
Expand All @@ -620,10 +660,11 @@ App.routeManager = Ember.RouteManager.create({
this._super(stateManager, transition);
var params = stateManager.get('params');
var postId = params.id;
console.log(postId);
//console.log(postId);
$('body').removeClass('blog').addClass('portfolio');
App.layout.set('header', App.portfolioHeaderView);
App.layout.set('content', App.faceView);
App.autoLogin();
}
})
}),
Expand All @@ -632,11 +673,12 @@ App.routeManager = Ember.RouteManager.create({
route: 'blog',
enter: function(stateManager, transition) {
this._super(stateManager, transition);
console.log("Entering Blog");
//console.log("Entering Blog");
$('body').removeClass('portfolio').addClass('blog');
App.layout.set('banner', '');
App.layout.set('header', App.headerView);
App.layout.set('content', App.selectedPostView);
App.autoLogin();
//bindLinks();
//$('body').removeClass('blog').addClass('portfolio');
//App.layout.set('header', App.portfolioHeaderView);
Expand Down Expand Up @@ -694,6 +736,7 @@ App.routeManager = Ember.RouteManager.create({
enter: function(statemanager, transition) {
this._super(statemanager, transition);
$("#reveal-Login").reveal();
$("input[name=username]").focus();
}
})
}),
Expand All @@ -708,6 +751,7 @@ App.routeManager = Ember.RouteManager.create({
App.layout.set('banner', '');
App.layout.set('header', App.headerView);
App.layout.set('content', App.selectedPostView);
App.autoLogin();
bindLinks();
$('body').hide();
Ember.run.next(function() {
Expand Down Expand Up @@ -742,8 +786,9 @@ ExposedAuthor = function() {
var authorized = false;

var loginPrivate = function() {
$.post("login", $("#login-form").serialize(), function(data) {
var auth = String(data)
var form = $("#login-form");
$.post("/login", form.serialize(), function(data) {
var auth = String(data);
if (auth === 'true') {
$("#login-sucess").fadeIn().delay(3000).fadeOut();
App.PostController.propertyWillChange('authorized');
Expand All @@ -753,6 +798,8 @@ ExposedAuthor = function() {
App.PostController.set('content', allPosts);
App.PostController.propertyDidChange('content');
$("#reveal-Login").trigger("reveal:close");
var formData = form.serializeArray();
App.autoLogin(formData[0].value, formData[1].value);
}
else {
authorized = false;
Expand All @@ -767,12 +814,13 @@ ExposedAuthor = function() {
isLoggedIn: function() {
return authorized;
}
}
};
}();

function objectHider(obj)
{
this.getObject=function(){return obj;}
function objectHider(obj) {
this.getObject=function(){
return obj;
};
}
// Call Author.getObject() to get the instance of our hidden
// ExposedAuthor object.
Expand All @@ -790,7 +838,6 @@ $(function() {
// Bind the reveal:close event so that it replaces the route-managers
// state with its previous one.
$('body').bind('reveal:close', function () {
console.log("reveal was closed");
App.routeManager.set('location','blog');
});

Expand All @@ -813,15 +860,14 @@ $(function() {
});

$("#login").click(function() {
console.log(" I RAN ");
App.routeManager.set('location', 'login');
return false;
});
});

$('body').bind("soapbox:blog_posts_loaded.soapbox",function() {
Ember.run.next(function() {
App.PostController.selectNextPost();
App.PostController.selectLatestPost();
});
});
var hiddenText = $("#ce");
Expand Down
3 changes: 2 additions & 1 deletion public/index.html
Expand Up @@ -69,7 +69,7 @@ <h5 class="post-sub-title">{{editable sub_title}}</h5>
<div class="post-body post row">
<section class="post post-sidebar">
{{#if App.PostController.authorized}}
{{view Ember.Checkbox title="Published" valueBinding="published" classNames="custom"}}
{{view Ember.Checkbox title="Published" valueBinding="published" classNames="custom published" tagName="form"}}
{{#view App.PostButton action="save" classNames="button green" tagName="button"}}
Save
{{/view}}
Expand Down Expand Up @@ -299,6 +299,7 @@ <h1> Hello </h1>
<script src="/javascripts/jquery.tooltips.js"></script>
<script src="/javascripts/jquery.text-expander.js"></script>
<script src="/javascripts/jquery.hoverIntent.min.js"></script>
<script src="/javascripts/jquery.customforms.js"></script>
<script src="/javascripts/lib/ember.js"></script>
<script src="/javascripts/lib/ember-data.js"></script>
<script src="/javascripts/lib/ember-routemanager.js"></script>
Expand Down

0 comments on commit 2eb735b

Please sign in to comment.