Vulcan/client/app.js

141 lines
3.8 KiB
JavaScript
Raw Normal View History

var current_user_id=0;
if(Meteor.user()){
current_user_id=Meteor.user()._id;
}
2012-09-19 10:12:51 +09:00
Meteor.subscribe('users', current_user_id, function(){
// once we've subscribed, set a session variable to check if the current user is an admin
Session.set('currentUserIsAdmin', (Meteor.user() && !Meteor.user().loading) ? isAdmin(Meteor.user()) : false );
});
2012-09-06 15:28:58 +09:00
2012-08-22 21:27:22 -04:00
Posts = new Meteor.Collection('posts');
Meteor.subscribe('posts');
2012-08-22 23:24:33 -04:00
Comments = new Meteor.Collection('comments');
Meteor.subscribe('comments', function() {
StyleNewRecords = new Date();
});
2012-08-23 00:15:48 -04:00
2012-08-30 21:35:48 -04:00
MyVotes = new Meteor.Collection('myvotes');
Meteor.subscribe('myvotes');
2012-09-06 19:42:11 +09:00
Settings = new Meteor.Collection('settings');
Meteor.subscribe('settings');
2012-08-23 00:15:48 -04:00
Session.set('state', 'list');
2012-09-02 23:51:18 +09:00
if (Meteor.is_client) {
SimpleRouter = FilteredRouter.extend({
initialize: function() {
FilteredRouter.prototype.initialize.call(this);
this.filter(this.require_login, {only: ['submit']});
},
require_login: function(page) {
console.log(Meteor.user());
if (Meteor.user()) {
return page;
} else {
return 'signin';
2012-09-02 23:51:18 +09:00
}
},
routes: {
'': 'top',
2012-09-18 11:49:17 +09:00
'top':'top',
'new':'new',
'test':'test',
'signin':'signin',
'signup':'signup',
'submit':'submit',
2012-09-07 10:57:57 +09:00
'posts/deleted':'post_deleted',
2012-09-05 11:55:06 +09:00
'posts/:id':'post',
'posts/:id/edit':'post_edit',
2012-09-07 10:57:57 +09:00
'comments/deleted':'comment_deleted',
2012-09-06 11:34:05 +09:00
'comments/:id':'comment',
2012-09-06 19:42:11 +09:00
'comments/:id/edit':'comment_edit',
2012-09-18 12:21:43 +09:00
'settings':'settings',
'users':'users',
2012-09-19 09:03:25 +09:00
'account':'user_edit',
'forgot_password':'forgot_password',
'users/:id/edit':'user_edit'
},
2012-09-18 11:49:17 +09:00
top: function() { this.goto('posts_top'); },
new: function() { this.goto('posts_new'); },
signup: function() { this.goto('signup'); },
signin: function() { this.goto('signin'); },
submit: function() { this.goto('post_submit'); },
settings: function() { this.goto('settings'); },
2012-09-18 12:21:43 +09:00
users: function() { this.goto('users'); },
2012-09-18 11:49:17 +09:00
post_deleted: function() { this.goto('post_deleted'); },
comment_deleted: function() { this.goto('comment_deleted'); },
2012-09-19 09:03:25 +09:00
forgot_password: function() { this.goto('user_password'); },
2012-09-05 11:55:06 +09:00
post: function(id) {
console.log("post, id="+id);
Session.set('selected_post_id', id);
this.goto('post_page');
// on post page, we show the comment recursion
window.repress_recursion=false;
// reset the new comment time at each new request of the post page
window.newCommentTimestamp=new Date();
},
post_edit: function(id) {
console.log("post_edit, id="+id);
Session.set('selected_post_id', id);
this.goto('post_edit');
},
2012-09-05 11:55:06 +09:00
comment: function(id) {
console.log("comment, id="+id);
Session.set('selected_comment_id', id);
this.goto('comment_page');
window.repress_recursion=true;
2012-09-13 14:57:57 +09:00
window.newCommentTimestamp=new Date();
2012-09-06 11:34:05 +09:00
},
comment_edit: function(id) {
console.log("comment_edit, id="+id);
Session.set('selected_comment_id', id);
2012-09-13 14:57:57 +09:00
this.goto('comment_edit');
window.newCommentTimestamp=new Date();
2012-09-19 09:03:25 +09:00
},
user_edit: function(id){
if(typeof id !== undefined){
window.selected_user_id=id;
}
this.goto('user_edit');
}
});
var Router = new SimpleRouter();
Meteor.startup(function() {
Backbone.history.start({pushState: true});
});
2012-09-02 23:51:18 +09:00
}
2012-09-07 10:57:57 +09:00
t=function(message){
var d=new Date();
console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
}
2012-09-07 10:57:57 +09:00
2012-09-13 10:55:05 +09:00
function nl2br (str) {
var breakTag = '<br />';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
2012-09-15 18:41:08 +09:00
$.fn.exists = function () {
return this.length !== 0;
}
currentUserIsAdmin = function(){
return Session.get('currentUserIsAdmin');
}
2012-09-13 11:05:49 +09:00
EpicEditorOptions={
container: 'editor',
basePath: '/editor',
clientSideStorage: false,
theme: {
base:'/themes/base/epiceditor.css',
preview:'/themes/preview/github.css',
editor:'/themes/editor/epic-light.css'
}
2012-09-19 10:12:51 +09:00
};