Permalink
Browse files

add like

  • Loading branch information...
1 parent 159b306 commit 1051581f88689393998d1821317f37d80026b2ad @maxbbn maxbbn committed Nov 6, 2011
View
61 app.js
@@ -11,6 +11,7 @@ var resource = require('express-resource');
var auth = require('./modules/auth').everyauth;
var RedisStore = require('connect-redis')(express);
var dateFormat = require('dateformat');
+require('./datei18n');
var form = require('connect-form');
var app = module.exports = express.createServer(
@@ -82,9 +83,6 @@ app.get('/json/tags', function(req, res){
});
});
-
-
-
var shareset = app.resource('shareset', require('./routers/shareset'));
var share = app.resource('share', require('./routers/share'));
//shareset.add(share);
@@ -134,21 +132,72 @@ app.get('/qrcode2',function(req,res){
});
});
+app.get('/share/:share/like', function(req,res){
+ if(!req.session){
+ res.send({ errors : ["您已经投过票了"]});
+ return;
+ }
+ var liked = req.session.shareliked,
+ share = req.share,
+ shareId = req.params.share;
+
+ if(!liked){
+ liked = [];
+ }
+ console.log(liked);
+
+ if(liked.indexOf(shareId) !== -1){
+ res.send({ errors : ["您已经投过票了"]});
+ return;
+ };
+
+ console.log('like',share.like);
+ share.like += 1;
+ share.save(function(err, doc){
+ if(err) return res.send({
+ errors : err.errors || err
+ });
+ liked.push(shareId);
+ req.session.shareliked = liked;
+ res.send({
+ errors : null,
+ action : 'redirect',
+ redirect : ''
+ });
+ });
+});
// 编辑幻灯片
-app.post('/edit/slider/:share',function(req, res){
+app.post('/share/:share/editslider',function(req, res){
var share = req.share,
slideshare = req.param('slideshare');
//get the id out of the slideshare
var match = slideshare.match(/\d{6,}/);
if(match){
share.slider.slideshare = match[0];
+ }else{
+ res.send({
+ errors : ['错误的embed Code']
+ });
+ return;
}
share.save(function(err){
- if(err) return next(err);
- res.redirect('back');
+ if(err) {
+ res.send({
+ errors : ['保存出错']
+ });
+ }
+ res.send({
+ errors : null,
+ action : 'redirect',
+ redirect : ''
+ });
});
});
+app.post('/api/share/:share/rate', function(req,res){
+
+});
+
/**
* helpers for view
*/
View
@@ -0,0 +1,12 @@
+var dateFormat = require('dateformat')
+
+dateFormat.i18n = {
+ dayNames: [
+ "", "", "", "", "", "", "",
+ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",
+ ],
+ monthNames: [
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
+ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
+ ]
+};
View
@@ -14,3 +14,13 @@ var ShareSet = db.model('shareset');
exports.User = User;
exports.Share = Share;
exports.ShareSet= ShareSet;
+ShareSet.schema.path('postname').validate(function(postname, fn){
+ ShareSet.findOne({postname : postname}, function(err,doc){
+ if(err) return fn(false);
+ if(doc){
+ return fn(false);
+ }
+ return fn(true);
+ });
+ return fn;
+},'POSTNAME_REPEAT');
View
@@ -13,6 +13,10 @@ var ShareSchema = new Schema({
'type' : String
,'set' : helper.trim
}
+ ,like : {
+ 'type' : Number,
+ 'default' : 0
+ }
,cover : {
'type' : String
,'default' : '/img/default-cover.png'
View
@@ -45,6 +45,15 @@ var ShareSetSchema = new Schema({
,owner : {
'type' : Schema.Types.ObjectId
}
+ ,postname : {
+ 'type' : String,
+ 'required' : true
+ }
+ //分享会面向受众
+ ,category : {
+ 'type' : String
+ }
+ //分享会
,deleted : {
'type' : Boolean,
'default' : false
View
@@ -20,3 +20,7 @@ a:active {
background-color: rgba(27,94,134,.5);
}
}
+.help-block, .help-inline {
+ font-size:12px;
+ color:#333;
+}
View
@@ -24,7 +24,7 @@ html,body {
.shareitem{
width:@shareWidth;
height:@shareWidth;
- margin:0 50px 50px 0;
+ margin:0 1px 1px 0;
color:#666;
float:left;
position:relative;
@@ -84,12 +84,9 @@ html,body {
}
.slideshare {
- width:580px;
- background:#fff;
}
.desc {
color : @gray;
- margin-bottom:20px;
}
// 标签
@@ -155,4 +152,11 @@ html,body {
margin-left:5px;
}
}
+.sliderform {
+ padding:0;
+ margin:0;
+}
+.share-list-item {
+ margin-bottom:20px;
+}
@@ -0,0 +1,8 @@
+KISSY.add('rate/addslider',function(S){
+ var elslider = S.all('.slideshare');
+ elslider.delegate('click','.slider-edit',function(){
+ elslider.one('.bd').html(S.Template(S.one('#template-add-slider')).render({}));
+ });
+},{
+ require : ['tempalte']
+});
View
@@ -26,4 +26,6 @@ KISSY.add('rate/create',function(S){
elinput.val(eltext + et.text());
elinput[0].focus();
});
+},{
+ requires : ['template']
});
@@ -24,4 +24,6 @@ KISSY.add('rate/form-error', function(S){
}
});
return FormError;
+}, {
+ requires : ['template']
});
View
@@ -12,4 +12,6 @@ KISSY.add('rate/tags',function(S){
$('#tags .bd').html(tagsTmpl.render(data));
}
});
+},{
+ requires : ['template']
});
View
@@ -27,10 +27,10 @@ exports.index = function(req,res){
};
exports.new = function(req,res){
var sharesetId = req.query.shareset;
- var share = new Share({
- shareset : sharesetId
- });
- ShareSet.findById(sharesetId, function(err,shareset){
+ ShareSet.findOne({postname:sharesetId}, function(err,shareset){
+ var share = new Share({
+ shareset :shareset._id
+ });
res.render('share/new', {
title: '添加分享到分享会',
share : share,
@@ -81,10 +81,18 @@ exports.create = function(req,res,next){
return;
//return next(error);
}
- res.send({
- errors : null,
- action : 'redirect',
- redirect : '/shareset/'+saved.shareset
+ ShareSet.findById(body.shareset, function(err, docs){
+ if(err) return next(err);
+ if(!docs)
+ return res.send({
+ errors : [{type:"分享会不存在"}]
+ });
+
+ res.send({
+ errors : null,
+ action : 'redirect',
+ redirect : '/shareset/'+ docs.postname
+ });
});
});
@@ -99,7 +107,7 @@ exports.show = function(req,res){
});
return;
}
- ShareSet.findById(share.shareset,function(err, doc){
+ ShareSet.findById(share.shareset, function(err, doc){
if(err) return next(err);
res.render('share/show', {
title : share.authors.join(',') + ':' + share.title,
@@ -113,9 +121,13 @@ exports.show = function(req,res){
exports.edit = function(req,res){
var share= req.share;
- res.render('share/edit',{
- title : '编辑 ' + share.title
- ,share : share
+ ShareSet.findById(share.shareset,function(err,doc){
+ if(err) return next(err);
+ res.render('share/edit',{
+ title : '编辑 ' + share.title
+ ,share : share
+ ,shareset : doc
+ });
});
}
View
@@ -2,16 +2,26 @@ var ShareSet = require('../modules/').ShareSet;
var Share = require('../modules/').Share;
exports.load = function(id,next){
- ShareSet.findById(id,function(err,doc){
+ ShareSet.findOne({
+ postname : id
+ },function(err,doc){
next(err,doc)
});
};
exports.index = function(req,res){
- var q= req.query;
+ var q= req.query,
+ queryobj = {};
q.deleted = { "$ne" : true };
- var query = ShareSet.find(q);
+ if(q.tab === 'upcoming'){
+ queryobj.startTime = {
+ $gt : Date.now()
+ ,$lt : Date.now() + 7*24*60*60*1000
+ }
+ };
+ var query = ShareSet.find(queryobj);
query.sort('_id',-1);
+ query.limit(20);
query.exec(function(err,shares){
if(err) return next(err);
req.results = shares;
@@ -32,12 +42,16 @@ exports.new = function(req,res){
});
};
exports.create = function(req,res){
- var shareset = new ShareSet();
- shareset.subject = req.body.subject;
- shareset.endTime = req.body.endTime;
- shareset.startTime = req.body.startTime;
- shareset.position = req.body.position;
- shareset.desc = req.body.desc;
+ var shareset = new ShareSet(),
+ reqbody = req.body;
+ shareset.subject = reqbody.subject;
+ shareset.endTime = reqbody.endTime;
+ shareset.startTime = reqbody.startTime;
+ shareset.position = reqbody.position;
+ shareset.desc = reqbody.desc;
+ shareset.postname = reqbody.postname;
+ shareset.category = reqbody.category;
+
shareset.owner = req.user._id;
shareset.save(function(error,saved){
View
@@ -6,7 +6,7 @@ script
script#temp-tags(type='kissy/template')
|<ul class='tags'>
| {{#each tags as tag}}
- | <li><a href='/list?tags={{tag}}'>{{tag}}</a></li>
+ | <li><a href='/share?tags={{tag}}'>{{tag}}</a></li>
| {{/each}}
|</ul>
@@ -26,4 +26,4 @@ div#tags.box
h3 标签
.bd
script
- KISSY.use('rate/home');
+ KISSY.use('rate/tags');
View
@@ -9,8 +9,6 @@ html
-if(css=="rate")
link(rel='stylesheet', href='/stylesheets/rate2.css')
script(src='http://a.tbcdn.cn/s/kissy/1.2.0/kissy-min.js')
- script(src='');
- script(src='/js/template-pkg-min.js')
script
KISSY.config({
packages : [{
@@ -55,3 +53,4 @@ html
div.footer
script(src="/lib/jquery/1.6.4/jquery.min.js")
script(src="/bootstrap/js/bootstrap-dropdown.js")
+ script(src="/bootstrap/js/bootstrap-modal.js")
View
@@ -16,7 +16,6 @@ script#temp-errors(type='text/template')
|{{/each}}
form.ajax-form(action='/share', method="post")
- input(type='hidden',name='shareset', value=share.shareset)
.error-holder
fieldset
legend 编辑分享
@@ -51,7 +50,7 @@ form.ajax-form(action='/share', method="post")
.actions
button.btn.primary(type="submit") 修改
|
- a.btn(href='/shareset/shareset._id') 返回
+ a.btn(href='/shareset/#{shareset.postname}') 返回
script
KISSY.use('rate/create,rate/ajax')
View
@@ -17,11 +17,6 @@ script
#page
- if (shares.length)
- ul.ratelist
- - each share in shares
- li.rateitem
- h3.title
- a(href="/share/#{share._id}") #{share.authors.join(', ')}: #{share.title}
- .desc=share.desc
+ ul.ratelist!= partial('shareitem', shares)
- else
p results is empty
Oops, something went wrong.

0 comments on commit 1051581

Please sign in to comment.