mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
admin now able to change user and date
This commit is contained in:
parent
5628b1e298
commit
7afaee4e80
7 changed files with 101 additions and 26 deletions
|
@ -11,10 +11,6 @@
|
|||
<label class="control-label">URL</label>
|
||||
<div class="controls"><input id="url" type="text" value="{{url}}" /></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Submitted</label>
|
||||
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Body</label>
|
||||
<div class="controls" id="editor"><textarea id="body" value="" class="input-xlarge">{{body}}</textarea></div>
|
||||
|
@ -36,6 +32,20 @@
|
|||
<input type="checkbox" name="sticky" id="sticky" {{#if sticky}}checked{{/if}} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Date</label>
|
||||
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">User</label>
|
||||
<div class="controls">
|
||||
<select id="postUser">
|
||||
{{#each users}}
|
||||
<option {{#if isSelected}}selected{{/if}} value="{{_id}}">{{userName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="form-actions">
|
||||
<a class="delete-link" href="/posts/deleted">Delete Post</a>
|
||||
|
|
|
@ -18,6 +18,16 @@ Template.post_edit.helpers({
|
|||
},
|
||||
submittedDate: function(){
|
||||
return moment(this.submitted).format("MMMM Do, h:mm:ss a");
|
||||
},
|
||||
users: function(){
|
||||
return Meteor.users.find();
|
||||
},
|
||||
userName: function(){
|
||||
return getDisplayName(this);
|
||||
},
|
||||
isSelected: function(){
|
||||
var post=Posts.findOne(Session.get('selectedPostId'));
|
||||
return post && this._id == post.userId;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -43,26 +53,29 @@ Template.post_edit.events = {
|
|||
var selectedPostId=Session.get('selectedPostId');
|
||||
var title= $('#title').val();
|
||||
var url = $('#url').val();
|
||||
var submitted = $('#submitted_hidden').val();
|
||||
var body = instance.editor.exportFile();
|
||||
var sticky=!!$('#sticky').attr('checked');
|
||||
var categories=[];
|
||||
var sticky=!!$('#sticky').attr('checked');
|
||||
var submitted = $('#submitted_hidden').val();
|
||||
var userId = $('#postUser').val();
|
||||
|
||||
$('input[name=category]:checked').each(function() {
|
||||
categories.push($(this).val());
|
||||
});
|
||||
|
||||
console.log('categories:', categories);
|
||||
|
||||
console.log('submitted', submitted);
|
||||
console.log('userId', userId, getDisplayNameById(userId));
|
||||
Posts.update(selectedPostId,
|
||||
{
|
||||
$set: {
|
||||
headline: title
|
||||
, url: url
|
||||
, submitted: parseInt(submitted)
|
||||
, body: body
|
||||
, sticky: sticky
|
||||
, categories: categories
|
||||
, submitted: parseInt(submitted)
|
||||
, sticky: sticky
|
||||
, userId: userId
|
||||
}
|
||||
}
|
||||
,function(error){
|
||||
|
|
|
@ -25,6 +25,28 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
{{#if isAdmin}}
|
||||
<div class="control-group">
|
||||
<label class="control-label">Sticky?</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" name="sticky" id="sticky" {{#if sticky}}checked{{/if}} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Date</label>
|
||||
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">User</label>
|
||||
<div class="controls">
|
||||
<select id="postUser">
|
||||
{{#each users}}
|
||||
<option {{#if isSelected}}selected{{/if}} value="{{_id}}">{{userName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/constant}}
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="Submit" />
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
Template.post_submit.helpers({
|
||||
categories: function(){
|
||||
return Categories.find();
|
||||
},
|
||||
users: function(){
|
||||
return Meteor.users.find();
|
||||
},
|
||||
userName: function(){
|
||||
return getDisplayName(this);
|
||||
},
|
||||
isSelected: function(){
|
||||
var post=Posts.findOne(Session.get('selectedPostId'));
|
||||
return post && this._id == post.userId;
|
||||
}
|
||||
});
|
||||
|
||||
Template.post_submit.rendered = function(){
|
||||
Session.set('selectedPostId', null);
|
||||
}
|
||||
|
||||
Template.post_submit.rendered = function(){
|
||||
this.editor= new EpicEditor(EpicEditorOptions).load();
|
||||
$('#submitted').datepicker().on('changeDate', function(ev){
|
||||
$('#submitted_hidden').val(moment(ev.date).valueOf());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Template.post_submit.events = {
|
||||
'click input[type=submit]': function(e, instance){
|
||||
e.preventDefault();
|
||||
|
@ -19,6 +41,9 @@ Template.post_submit.events = {
|
|||
var url = $('#url').val();
|
||||
var body = instance.editor.exportFile();
|
||||
var categories=[];
|
||||
var sticky=!!$('#sticky').attr('checked');
|
||||
var submitted = $('#submitted_hidden').val();
|
||||
var userId = $('#postUser').val();
|
||||
|
||||
$('input[name=category]:checked').each(function() {
|
||||
categories.push($(this).val());
|
||||
|
@ -29,6 +54,9 @@ Template.post_submit.events = {
|
|||
body: body,
|
||||
url: url,
|
||||
categories: categories,
|
||||
sticky: sticky,
|
||||
submitted: submitted,
|
||||
userId: userId
|
||||
}, function(error, postId) {
|
||||
if(error){
|
||||
console.log(error);
|
||||
|
@ -60,7 +88,3 @@ Template.post_submit.events = {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
Template.post_submit.rendered = function(){
|
||||
this.editor= new EpicEditor(EpicEditorOptions).load();
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
Meteor.methods({
|
||||
post: function(post){
|
||||
var user = Meteor.user();
|
||||
var userId = post.userId || user._id;
|
||||
var submitted = parseInt(post.submitted) || new Date().getTime();
|
||||
|
||||
if (!user || !canPost(user))
|
||||
throw new Meteor.Error(123, 'You need to login or be invited to post new stories.');
|
||||
|
@ -11,10 +13,14 @@ Meteor.methods({
|
|||
if(!this.isSimulation)
|
||||
limitRate(user, Posts, 30);
|
||||
|
||||
console.log(userId);
|
||||
console.log(submitted);
|
||||
console.log(post);
|
||||
|
||||
post = _.extend(post, {
|
||||
userId: user._id,
|
||||
author: getDisplayName(user),
|
||||
submitted: new Date().getTime(),
|
||||
userId: userId,
|
||||
author: getDisplayNameById(userId),
|
||||
submitted: submitted,
|
||||
votes: 0,
|
||||
comments: 0,
|
||||
baseScore: 0,
|
||||
|
|
|
@ -7,12 +7,12 @@ isAdmin=function(user){
|
|||
return false;
|
||||
return !!user.isAdmin;
|
||||
}
|
||||
getDisplayNameById = function(userId){
|
||||
getDisplayName(Meteor.users.findOne(userId));
|
||||
}
|
||||
getDisplayName = function(user){
|
||||
return (user.profile && user.profile.name) ? user.profile.name : user.username;
|
||||
}
|
||||
getDisplayNameById = function(userId){
|
||||
return getDisplayName(Meteor.users.findOne(userId));
|
||||
}
|
||||
getSignupMethod = function(user){
|
||||
if(user.services && user.services.twitter){
|
||||
return 'twitter';
|
||||
|
|
|
@ -24,7 +24,7 @@ Meteor.startup(function () {
|
|||
// recalculate scores every N seconds
|
||||
if(scoreInterval>0){
|
||||
intervalId=Meteor.setInterval(function () {
|
||||
console.log('tick ('+scoreInterval+')');
|
||||
// console.log('tick ('+scoreInterval+')');
|
||||
Posts.find().forEach(function (post) { updateScore(Posts, post._id); });
|
||||
Comments.find().forEach(function (comment) { updateScore(Comments, comment._id); });
|
||||
}, scoreInterval * 1000);
|
||||
|
|
Loading…
Add table
Reference in a new issue