Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start use express resource

  • Loading branch information...
commit 4caab15a3a0f231875abaf55b11395833f7a570e 1 parent 6c52461
@maxbbn maxbbn authored
View
202 app.js
@@ -4,96 +4,24 @@
var express = require('express');
-
//var QRcode = require('qrcode');
var _ = require("underscore");
var apptitle = '火鸟打分系统';
var average = require('./modules/average').average;
var modules = require('./modules/');
-var everyauth = require('everyauth');
-var sechash = require('sechash');
+var resource = require('express-resource');
+var auth = require('./modules/auth').everyauth;
var RedisStore = require('connect-redis')(express);
var dateFormat = require('dateformat');
-//everyauth.debug = true;
+var form = require('connect-form');
-var app = module.exports = express.createServer(); // Configuration
+var app = module.exports = express.createServer(
+ form({keepExtensions : true })
+ ); // Configuration
var Share = modules.Share;
var User = modules.User;
var ShareSet = modules.ShareSet;
-everyauth.everymodule.findUserById(function(userId, callback){
- User.findById(userId, callback);
-});
-everyauth.password
- .loginWith('login')
- .getLoginPath('/login')
- .postLoginPath('/login')
- .loginView('login')
- .loginLocals({
- layout : 'layout-auth',
- title : ' 登录'
- })
- .authenticate(function(login, password){
- var promise = this.Promise();
- User.findOne({login:login}, function(err, user){
- if(err){
- return promise.fulfill([err])
- }
- if(!user){
- return promise.fulfill(['用户名和密码错误'])
- }
- if(sechash.testBasicHash('md5',password, user.password)){
- return promise.fulfill(user);
- }else{
- return promise.fulfill(['password not match']);
- }
- });
- return promise;
- })
- .getRegisterPath('/register')
- .postRegisterPath('/register')
- .registerView('register')
- .registerLocals({
- layout : 'layout-auth',
- title : '注册'
- })
- .validateRegistration(function(newUser, errors){
- console.log('validate', newUser, errors);
- var promise = this.Promise();
-
- var user = User.findOne({ login : newUser.login}, function(err, user){
- if(err){
- errors.push(err)
- promise.fulfill(errors);
- return;
- }
- if(user){
- errors.push("用户已经存在")
- promise.fulfill(errors);
- return;
- }
- promise.fulfill(errors);
- });
- return promise;
- })
- .registerUser(function(newUser, errors){
- console.log('newUser', newUser, errors);
- var promise = this.Promise();
- newUser.password = sechash.basicHash('md5',newUser.password)
- var user = new User(newUser);
- user.save(function(err,doc){
- if(err){
- errors.push(err);
- promise.fulfill([errors]);
- }
- promise.fulfill(user);
- });
-
- return promise;
- })
- .loginSuccessRedirect('/')
- .registerSuccessRedirect('/')
-
function checkauth(req,res,next){
if(!req.loggedIn){
res.redirect('/login');
@@ -110,10 +38,16 @@ app.configure(function(){
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "supershare!", store: new RedisStore }));
- app.use(everyauth.middleware());
- app.use(express.methodOverride());
- app.use(app.router);
+ app.use(auth.middleware());
+ //app.use(express.methodOverride());
+ //app.use(parted({
+ //path : __dirname + '/public/uploads',
+ //limit : 30 * 1024,
+ //diskLimit : 30 * 1024 * 1024,
+ //multiple : true
+ //}));
+ app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
@@ -159,23 +93,37 @@ app.get('/json/tags', function(req, res){
});
});
+function getShareset(req,res,next){
+ if(req.share.shareset){
+ ShareSet.findById(req.share.shareset, function(err, shareset){
+ if(err) return next(err);
+ req.shareset = shareset;
+ next();
+ });
+ }else{
+ req.shareset = null;
+ next();
+ }
+}
-app.get('/create-ok/:shareId',function(req,res){
+app.get('/create-ok/:shareId', getShareset, function(req,res){
res.render('create-ok', {
title: '创建成功',
- share : req.share
+ share : req.share,
+ shareset : req.shareset
});
});
//show a rate
-app.get('/show/:shareId', function(req, res){
- var share = req.share;
- res.render('showrate', {
- title : share.authors.join(',') + ':' + share.title,
- share : share
- });
-});
+//app.get('/share/show/:shareId', getShareset, function(req, res){
+ //var share = req.share;
+ //res.render('showrate', {
+ //title : share.authors.join(',') + ':' + share.title,
+ //share : share,
+ //shareset : req.shareset
+ //});
+//});
//** jsonp
app.get('/getrate/:rid', function(req, res){
@@ -195,6 +143,15 @@ app.get('/getrate/:rid', function(req, res){
});
});
+
+Share.load = function(req,id,fn){
+ console.log('sload',req,id,fn);
+}
+
+var shareset = app.resource('shareset', require('./routers/shareset'));
+var share = app.resource('share', require('./routers/share'));
+
+
function squery(req, res, next){
//console.dir(_.keys(req));
var query = req.query;
@@ -210,6 +167,7 @@ function squery(req, res, next){
function setQuery(req, res, next){
//console.dir(_.keys(req));
var query = req.query;
+ query.deleted = {"$ne":true};
var sharequery = ShareSet.find(query);
sharequery.sort('_id',-1);
sharequery.exec(function(err,shares){
@@ -250,23 +208,24 @@ app.param('listtype',function(req,res,next,type){
});
//list the rates
-app.get('/list/:listtype?',squery, function(req,res){
- res.render('list', {
- results : req.results,
- query : req.query,
- type : req.params.listtype,
- title : '所有分享'
- });
-});
+//app.get('/share/list/:listtype?',squery, function(req,res){
+ //res.render('list', {
+ //results : req.results,
+ //query : req.query,
+ //type : req.params.listtype,
+ //title : '所有分享'
+ //});
+//});
+
+//app.get('/shareset/list/:listtype?',setQuery, function(req,res){
+ //res.render('setlist', {
+ //results : req.results,
+ //query : req.query,
+ //type : req.params.listtype,
+ //title : '所有分享'
+ //});
+//});
-app.get('/setlist/:listtype?',setQuery, function(req,res){
- res.render('setlist', {
- results : req.results,
- query : req.query,
- type : req.params.listtype,
- title : '所有分享'
- });
-});
function getShares(req,res,next){
console.log('getShares setId', req.params.setId);
Share.find({
@@ -279,16 +238,14 @@ function getShares(req,res,next){
}
);
}
-app.get('/shareset/:setId', getShares, function(req, res){
- var ss = req.shareset;
-
- res.render('shareset',{
- title : ss.subject
- ,shareset : ss
- ,shares : req.shares
- });
-
-});
+//app.get('/shareset/show/:setId', getShares, function(req, res){
+ //var ss = req.shareset;
+ //res.render('shareset',{
+ //title : ss.subject
+ //,shareset : ss
+ //,shares : req.shares
+ //});
+//});
app.post("/ratedo", function(req, res){
var id = req.param("rid");
@@ -390,11 +347,12 @@ app.get('/rate/:rid',function(req,res){
});
});
-_(require('./routers/manage')).each(function(o, key){
- _(o).each(function(fn, k){
- app[k]('/' + key, checkauth, fn);
- });
-});
+//_(require('./routers/manage')).each(function(o, key){
+ //_(o).each(function(fn, k){
+ //console.log(k, key);
+ //app[k](key, checkauth, fn);
+ //});
+//});
//_(require('./routers/')).each(function(pack,packname){
@@ -409,5 +367,5 @@ app.helpers({
dateFormat : dateFormat
});
-everyauth.helpExpress(app);
+auth.helpExpress(app);
exports.app = app;
View
80 modules/auth.js
@@ -0,0 +1,80 @@
+var everyauth = require('everyauth');
+var sechash = require('sechash');
+var User = require('./index').User;
+
+
+exports.everyauth = everyauth;
+
+//everyauth.debug = true;
+everyauth.everymodule.findUserById(function(userId, callback){
+ User.findById(userId, callback);
+});
+everyauth.password
+ .loginWith('login')
+ .getLoginPath('/login')
+ .postLoginPath('/login')
+ .loginView('login')
+ .loginLocals({
+ layout : 'layout-auth',
+ title : ' 登录'
+ })
+ .authenticate(function(login, password){
+ var promise = this.Promise();
+ User.findOne({login:login}, function(err, user){
+ if(err){
+ return promise.fulfill([err])
+ }
+ if(!user){
+ return promise.fulfill(['用户名和密码错误'])
+ }
+ if(sechash.testBasicHash('md5',password, user.password)){
+ return promise.fulfill(user);
+ }else{
+ return promise.fulfill(['password not match']);
+ }
+ });
+ return promise;
+ })
+ .getRegisterPath('/register')
+ .postRegisterPath('/register')
+ .registerView('register')
+ .registerLocals({
+ layout : 'layout-auth',
+ title : '注册'
+ })
+ .validateRegistration(function(newUser, errors){
+ console.log('validate', newUser, errors);
+ var promise = this.Promise();
+
+ var user = User.findOne({ login : newUser.login}, function(err, user){
+ if(err){
+ errors.push(err)
+ promise.fulfill(errors);
+ return;
+ }
+ if(user){
+ errors.push("用户已经存在")
+ promise.fulfill(errors);
+ return;
+ }
+ promise.fulfill(errors);
+ });
+ return promise;
+ })
+ .registerUser(function(newUser, errors){
+ console.log('newUser', newUser, errors);
+ var promise = this.Promise();
+ newUser.password = sechash.basicHash('md5',newUser.password)
+ var user = new User(newUser);
+ user.save(function(err,doc){
+ if(err){
+ errors.push(err);
+ promise.fulfill([errors]);
+ }
+ promise.fulfill(user);
+ });
+
+ return promise;
+ })
+ .loginSuccessRedirect('/')
+ .registerSuccessRedirect('/')
View
10 modules/index.js
@@ -7,6 +7,10 @@ require('./user.js');
var db = mongoose.connect('mongodb://127.0.0.1/ratting');
-exports.User = db.model('user');
-exports.Share = db.model('share');
-exports.ShareSet= db.model('shareset');
+var User = db.model('user');
+var Share = db.model('share');
+var ShareSet = db.model('shareset');
+
+exports.User = User;
+exports.Share = Share;
+exports.ShareSet= ShareSet;
View
4 modules/share.js
@@ -14,6 +14,10 @@ var ShareSchema = new Schema({
,'default' : ''
,'set' : helper.trim
}
+ ,cover : {
+ 'type' : String
+ ,'default' : '/img/default-cover.png'
+ }
,ts_save : {
'type' : Date
,'default' : Date.now
View
15 modules/shareset.js
@@ -20,7 +20,6 @@ var ShareSetSchema = new Schema({
// 分享主题
subject : {
'type' : String
- ,'default' : ''
}
// 创建时间
,ts : {
@@ -46,9 +45,21 @@ var ShareSetSchema = new Schema({
,owner : {
'type' : Schema.Types.ObjectId
}
+ ,deleted : {
+ 'type' : Boolean,
+ 'default' : false
+ }
,rates : [helper.Rate]
});
-ShareSetSchema.path('subject').validate(helper.noempty, '主题不能为空');
mongoose.model('shareset', ShareSetSchema);
+// 必须指定主题
+ShareSetSchema.path('subject').validate(helper.noempty, 'SUBJECT_MISSING');
+// 结束时间必须在开始时间之后
+ShareSetSchema.path('endTime').validate(function(endTime, b, c){
+ return endTime > this.startTime;
+}, 'TIME_ERROR_ENDTIME');
+// 必须先登录
+ShareSetSchema.path('owner').validate(helper.noempty, '请先登录');
+
View
9 public/css/boothack.less
@@ -0,0 +1,9 @@
+.topbar div > ul, .nav {
+ .active > a {
+ background-color: #1d648e;
+ background-color: rgba(27,94,134,.5);
+ }
+ .menu-dropdown,.dropdown-menu {
+ background-color:#123e58;
+ }
+}
View
16 public/css/share.less
@@ -1,11 +1,12 @@
@import "../bootstrap/lib/bootstrap.less";
-
+@import "./boothack.less";
#main{
- padding-top:40px;
+ padding-top:50px;
}
.navback {
float:right;
+ padding:10px;
}
.ratelist {
@@ -31,7 +32,9 @@
margin:0;
li {
float:left;
+ padding:5px;
margin-right:10px;
+ background:#eee;
}
}
.slideshare {
@@ -39,11 +42,9 @@
}
.setitem {
- .border-radius();
- .box-shadow();
- #gradient .vertical(#eee,#fff);
padding:10px 0;
margin-bottom:20px;
+ border-bottom:1px solid #ddd;
}
//fix calendar
@@ -55,3 +56,8 @@
margin-left:5px;
}
}
+
+.desc {
+ color : @gray;
+ margin-bottom:20px;
+}
View
15 public/js/ajax.js
@@ -0,0 +1,15 @@
+define(function(require,exports,module){
+ var $ = require('jquery');
+ $('form.ajax-form').each(function(et){
+ $this = $(this);
+ $this.bind('submit',function(ev){
+ ev.preventDefault();
+ $.ajax({
+ url : $this.attr('action'),
+ type : $this.attr('method')
+ }).success(function(res){
+ console.log(res);
+ });
+ });
+ });
+});
View
68 public/js/rate/ajax.js
@@ -0,0 +1,68 @@
+KISSY.add('rate/ajax', function(S, FormError){
+ var $ = S.all;
+ var actions = {
+ redirect : function(res){
+ location.href = res.redirect
+ }
+ };
+
+ $('form.ajax-form').each(function(et){
+ $this = $(this);
+ var formerror = new FormError({
+ template : $('#temp-errors').html(),
+ container : $this.one('.error-holder')
+ });
+ $this.on('submit',function(ev){
+ ev.preventDefault();
+ S.ajax({
+ url : $this.attr('action'),
+ type : $this.attr('method'),
+ data : S.io.serialize($this),
+ dataType: 'json',
+ success : function(res){
+ if(res.errors){
+ formerror.render({
+ errors : res.errors
+ });
+ return;
+ }
+ //if(actions[res.action]){
+ //actions[res.action](res);
+ //}
+ }
+ });
+ });
+ });
+
+ $('.ajax-btn').each(function(btn){
+ var $t = $(this),
+ url = $t.attr('href'),
+ type;
+
+ if(url && !$t.attr('data-url')){
+ $t.attr('data-url', url);
+ }
+ url = $t.attr('data-url');
+ type = $t.attr('data-type');
+ if(url && type){
+ $t.on('click',function(ev){
+ ev.preventDefault();
+ S.ajax({
+ url : $t.attr('data-url'),
+ type : $t.attr('data-type'),
+ dataType : 'json',
+ success : function(res){
+ if(res.errors){
+ return;
+ }
+ if(actions[res.action]){
+ actions[res.action](res);
+ }
+ }
+ });
+ });
+ }
+ });
+}, {
+ requires : ['rate/form-error']
+});
View
3  public/js/rate/app.js
@@ -26,4 +26,5 @@ KISSY.add('rate/app',function(S){
});
}
};
-});
+}
+);
View
27 public/js/rate/form-error.js
@@ -0,0 +1,27 @@
+KISSY.add('rate/form-error', function(S){
+ var $ = S.all;
+ var FormError = function(cfg){
+ this.template = S.Template(cfg.template);
+ this.container = $(cfg.container);
+ }
+ S.augment(FormError,{
+ render : function(msg){
+ var errors;
+ if(S.isString(msg.errors)){
+ errors = [{type : msg.errors}];
+ }else{
+ errors = msg.errors
+ }
+
+ console.log(errors);
+ this.container
+ .html(this.template.render({errors : errors}))
+ .show();;
+ },
+ clear : function(){
+ this.container.hide()
+ .html('')
+ }
+ });
+ return FormError;
+});
View
125 routers/manage.js
@@ -2,7 +2,20 @@ var modules = require('../modules/')
var Share = modules.Share;
var ShareSet = modules.ShareSet;
-exports.create = {
+
+//exports['/shareset/show'] = {
+ //get : function(req, res){
+ //var ss = req.shareset;
+
+ //res.render('shareset',{
+ //title : ss.subject
+ //,shareset : ss
+ //,shares : req.shares
+ //});
+ //}
+//}
+
+exports['/shareset/add']= {
get : function(req,res){
var shareset = new ShareSet();
res.render('create', {
@@ -35,40 +48,102 @@ exports.create = {
}
};
-exports['add-share/:setId']= {
+exports['/shareset/edit/:setId'] = {
get : function(req, res){
- var share = new Share();
- res.render('create-share', {
- title: '添加分享',
- setId : req.params.setId,
- shareset : req.shareset,
- error : [],
- share : share
+ var shareset = req.shareset;
+
+ res.render('create',{
+ title : '编辑 ' + shareset.subject
+ ,shareset : shareset
+ ,shares : req.shares
});
- },
+ },
post : function(req,res){
- var share = new Share({
- title : req.body['title']
- ,authors : req.body['authors']
- ,tags : req.body['tags']
- ,desc : req.body['desc']
- ,owner : req.user._id
- ,shareset : req.params.setId
- });
- share.save(function(error,saved){
- console.log('save', error);
+ console.log('post');
+ var shareset = req.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;
+
+ shareset.save(function(error,saved){
if(error && error.errors){
res.render('create', {
title: 'Create a Cate',
errors : error.errors,
- share : share
+ shareset : shareset
});
return;
}
- res.redirect('/create-ok/' + saved._id);
+ res.redirect('/shareset/' + saved._id);
+ });
+ }
+};
+
+exports['/shareset/delete/$setId'] = {
+ get : function(req,res,next){
+ req.shareset.deleted = true;
+
+ req.save(function(err, doc){
+ if(err) return next(err);
+ res.redirect('/shareset/list');
+ });
+ }
+};
+
+exports['/share/add/:setId']= {
+ get : function(req, res){
+ var share = new Share();
+ res.render('create-share', {
+ title: '添加分享',
+ setId : req.params.setId,
+ shareset : req.shareset,
+ error : [],
+ share : share
+ });
+ },
+
+ post : function(req,res,next){
+ console.log(req.form);
+ console.log(req.body);
+ req.form.complete(function(err, fields, files){
+ console.log('complete');
+ if(err){
+ next(err);
+ }else{
+ console.dir('fields', fields);
+ console.log('upload s% to s%', files.cover.filename, files.cover.path);
+ //var share = new Share({
+ //title : req.body['title']
+ //,authors : req.body['authors']
+ //,tags : req.body['tags']
+ //,desc : req.body['desc']
+ //,owner : req.user._id
+ //,shareset : req.params.setId
+ //});
+ }
});
+ req.form.on('progress', function(bytesReceived, bytesExpected){
+ var percent = (bytesReceived / bytesExpected * 100) | 0;
+ process.stdout.write('Uploading: %' + percent + '\r');
+ });
+
+ //share.save(function(error,saved){
+ //console.log('save', error);
+ //if(error && error.errors){
+ //res.render('create', {
+ //title: 'Create a Cate',
+ //errors : error.errors,
+ //share : share
+ //});
+ //return;
+ //}
+ //res.redirect('/create-ok/' + saved._id);
+ //});
}
};
@@ -83,9 +158,3 @@ exports.edit = {
}
};
-exports.delete = {
- post : function(req,res){
- res.send('delete get');
- res.end();
- }
-};
View
72 routers/share.js
@@ -0,0 +1,72 @@
+var ShareSet = require('../modules/').ShareSet;
+var Share = require('../modules/').Share;
+
+//auto load
+exports.load = function(id,next){
+ Share.findById(id,function(err,doc){
+ next(err,doc)
+ });
+};
+
+exports.index = function(req,res){
+ var query = req.query;
+ query.deleted = {"$ne":true};
+ var sharequery = Share.find(query);
+ sharequery.sort('_id',-1);
+
+ sharequery.exec(function(err,shares){
+ if(err) return next(err);
+ res.render('share/index', {
+ shares : shares,
+ query : shares,
+ type : req.params.listtype,
+ title : '所有分享'
+ });
+ });
+
+};
+exports.new = function(req,res){
+ var share = new Share();
+ var sharesetId = req.query.shareset;
+ ShareSet.findById(sharesetId, function(err,shareset){
+ res.render('share/new', {
+ title: '添加分享到分享会',
+ share : share,
+ shareset : shareset
+ });
+ })
+};
+exports.create = function(req,res){
+
+};
+exports.show = function(req,res){
+ var share = req.share;
+ if(!share.shareset){
+ res.render('share/show', {
+ title : share.authors.join(',') + ':' + share.title,
+ share : share,
+ shareset : null
+ });
+ return;
+ }
+ ShareSet.findById(share.shareset,function(err, doc){
+ if(err) return next(err);
+
+ res.render('share/show', {
+ title : share.authors.join(',') + ':' + share.title,
+ share : share,
+ shareset : doc
+ });
+
+ });
+
+};
+exports.edit = function(req,res){
+
+}
+exports.update = function(req,res){
+
+}
+exports.delete = function(req,res){
+
+}
View
198 routers/shareset.js
@@ -0,0 +1,198 @@
+var ShareSet = require('../modules/').ShareSet;
+var Share = require('../modules/').Share;
+
+exports.load = function(id,next){
+ ShareSet.findById(id,function(err,doc){
+ next(err,doc)
+ });
+};
+
+exports.index = function(req,res){
+ var q= req.query;
+ q.deleted = { "$ne" : true };
+ var query = ShareSet.find(q);
+ query.sort('_id',-1);
+ query.exec(function(err,shares){
+ if(err) return next(err);
+ req.results = shares;
+ res.render('shareset/index', {
+ results : req.results,
+ query : req.query,
+ type : req.params.listtype,
+ title : '所有分享'
+ });
+ });
+};
+exports.new = function(req,res){
+ var shareset = new ShareSet();
+ res.render('shareset/new', {
+ title: '组织一次分享',
+ error : [],
+ shareset : shareset
+ });
+};
+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;
+ shareset.owner = req.loggedIn? req.user._id : '';
+
+ shareset.save(function(error,saved){
+ if(error){
+ console.log(error);
+ res.send({
+ errors : error.errors || error.message
+ });
+ return;
+ };
+ res.send({
+ errors : null,
+ action : 'redirect',
+ redirect : '/shareset/' + saved._id
+ });
+ });
+
+};
+exports.show = function(req,res, next){
+ var ss = req.shareset;
+ Share.find({shareset : ss._id}, function(err, docs){
+ if(err) return next(err);
+ res.render('shareset/show',{
+ title : ss.subject
+ ,shareset : ss
+ ,shares : docs
+ });
+ });
+};
+exports.edit = function(req,res){
+ var shareset = req.shareset;
+
+ res.render('shareset/edit',{
+ title : '编辑 ' + shareset.subject
+ ,shareset : shareset
+ });
+
+}
+exports.update = function(req,res){
+ var shareset = req.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;
+
+ shareset.save(function(error,saved){
+ if(error && error.errors){
+ res.send({
+ success : false
+ ,errors : error.errors
+ });
+ return;
+ }
+ res.send({
+ success : true,
+ redirect : '/shareset/' + saved._id
+ });
+ });
+
+}
+
+exports.destroy = function(req,res, next){
+ req.shareset.deleted = true;
+ req.shareset.save(function(err, doc){
+ console.log('destroy', err, doc)
+ if(err) {
+ res.send({
+ errors : [{error : err, type : '出错了'}]
+ });
+ return;
+ }
+ res.send({
+ errors : null,
+ action : 'redirect',
+ redirect : '/shareset'
+ });
+ });
+};
+
+//exports['/shareset/add']= {
+ //get : function(req,res){
+ //var shareset = new ShareSet();
+ //res.render('create', {
+ //title: '组织一次分享',
+ //error : [],
+ //shareset : shareset
+ //});
+ //},
+ //post : function(req,res){
+ //var shareset = new ShareSet({
+ //subject : req.body.subject,
+ //endTime : req.body.endTime,
+ //startTime : req.body.startTime,
+ //position : req.body.position,
+ //desc : req.body.desc,
+ //owner : req.user._id
+ //});
+
+ //shareset.save(function(error,saved){
+ //if(error && error.errors){
+ //res.render('create', {
+ //title: 'Create a Cate',
+ //errors : error.errors,
+ //shareset : shareset
+ //});
+ //return;
+ //}
+ //res.redirect('/shareset/' + saved._id);
+ //});
+ //}
+//};
+
+//exports['/shareset/edit/:setId'] = {
+ //get : function(req, res){
+ //var shareset = req.shareset;
+
+ //res.render('create',{
+ //title : '编辑 ' + shareset.subject
+ //,shareset : shareset
+ //,shares : req.shares
+ //});
+
+ //},
+ //post : function(req,res){
+
+ //var shareset = req.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;
+
+ //shareset.save(function(error,saved){
+ //if(error && error.errors){
+ //res.render('create', {
+ //title: 'Create a Cate',
+ //errors : error.errors,
+ //shareset : shareset
+ //});
+ //return;
+ //}
+ //res.redirect('/shareset/' + saved._id);
+ //});
+ //}
+//};
+
+//exports['/shareset/delete/$setId'] = {
+ //get : function(req,res,next){
+ //req.shareset.deleted = true;
+
+ //req.save(function(err, doc){
+ //if(err) return next(err);
+ //res.redirect('/shareset/list');
+ //});
+ //}
+//};
View
31 test/shareset.js
@@ -0,0 +1,31 @@
+var ShareSet = require('../modules/').ShareSet;
+
+var shareset = new ShareSet({
+ subject : ''
+});
+
+shareset.save(function(err, saved){
+ console.log(err);
+ console.log(saved);
+ shareset = ShareSet.findById( saved._id, function(err,doc){
+ console.log('find', err);
+ console.log(doc);
+ doc.save(function(err,doc){
+ console.log('save back ', err)
+ console.log(doc);
+ })
+ })
+});
+exports = {
+ 'Module test:Shareset' : function(beforeExit, assert){
+ var shareset = new ShareSet({
+ subject : ''
+ });
+
+ shareset.save(function(err, saved){
+ assert.eql(true, !!err);
+ assert.eql('请填写主题', err.errors[0].type);
+ });
+ console.log('xxx')
+ }
+};
View
7 views/create-share.jade
@@ -9,7 +9,7 @@ script#temp-tags(type='kissy/template')
| {{/each}}
|</ul>
h1= shareset.subject
-form(action='/add-share/#{shareset._id}', method="post")
+form(action='/share/add/#{shareset._id}', method="post",enctype='multipart/form-data')
input(type='hidden',value=setId)
- if('undefined' !== typeof errors && errors)
.alert-message.block-message.warning
@@ -35,6 +35,11 @@ form(action='/add-share/#{shareset._id}', method="post")
input.text#input_tags(name="tags",value=share.tags.join(' '))
.tags#tagfield
.clearfix
+ label(for='cover') 封面
+ .input
+ input#cover(name='cover',type='file')
+ span.help-block= share.cover
+ .clearfix
label(for='desc') 介绍
.input
textarea.xxlarge(name='desc')= share.desc
View
8 views/index.jade
@@ -8,7 +8,6 @@ script#temp-tags(type='kissy/template')
| <li><a href='/list?tags={{tag}}'>{{tag}}</a></li>
| {{/each}}
|</ul>
-h1= title
div.box
.hd
h3 分享会
@@ -16,6 +15,13 @@ div.box
ul
li
a(href="/list/?tag=firebird") 火鸟分享
+.box
+ .hd
+ h3 常用链接
+ .bd
+ ul.links
+ li
+ a(href='https://is.taobao.org/meeting/') 会议室预定
div#tags.box
.hd
h3 标签
View
15 views/layout.jade
@@ -9,8 +9,8 @@ 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(src='/js/rate/app.js')
script
KISSY.config({
packages : [{
@@ -19,6 +19,8 @@ html
}]
});
KISSY.Config.debug = true;
+ script
+ KISSY.use('rate/app');
body
div.topbar(data-dropdown='dropdown')
div.topbar-inner
@@ -29,16 +31,11 @@ html
li(id='nav-home')
a(href="/") 首页
li(id='nav-setlist')
- a(href="/setlist") 分享会
+ a(href="/shareset/") 分享会
li(id='nav-list')
- a(href="/list") 分享
- - if(everyauth.loggedIn)
- li(id='nav-listmy')
- a(href="/list/my") 我的分享
- li(id='nav-setlistmy')
- a(href="/setlist/my") 我的分享会
+ a(href="/share") 分享
li#nav-create
- a(href='/create') 组织分享
+ a(href='/shareset/new') 组织分享
ul.nav.secondary-nav
- if(!everyauth.loggedIn)
li.dropdown
View
12 views/share-create-ok.jade
@@ -0,0 +1,12 @@
+script
+ KISSY.use('rate/app',function(S,App){
+ App.nav('create');
+ });
+h1 分享创建成功
+ul
+ li
+ a(href="/shareset/#{share.shareset}") 返回分享会
+ li
+ a(href="/share/add/#{share._id}") 进入分享页
+ li
+ a(href="/create-share/#{share.shareset}") 继续创建
View
10 views/list.jade → views/share/index.jade
@@ -16,14 +16,12 @@ script
h1 所有分享
#page
- - if (results.length)
+ - if (shares.length)
ul.ratelist
- - each item in results
+ - each share in shares
li.rateitem
h3.title
- a(href="/show/#{item._id}") #{item.authors.join(', ')}: #{item.title}
- p.meta
- span.time #{item.ts_save.getFullYear()}-#{item.ts_save.getMonth()}-#{item.ts_save.getDate()}
- div.desc=item.desc
+ a(href="/share/#{share._id}") #{share.authors.join(', ')}: #{share.title}
+ .desc=share.desc
- else
p results is empty
View
26 views/showrate.jade → views/share/show.jade
@@ -60,22 +60,21 @@ h1 #{share.authors.join(',')}: #{share.title}
document.getElementsByTagName("head")[0].appendChild(dsq);
})()
.span6
+ .action
+ p
+ a.disabled(href='#') 我参加过
+ | -
+ a.disabled(href='#') 我想参加
+ p 手机扫描此条码直接打分
.meta
- h3 分享信息
dl.author
dt 分享者
dd= share.authors.join(",")
-
- dl.time
- dt 创建时间
- dd #{share.ts_save.getFullYear()}-#{share.ts_save.getMonth()}-#{share.ts_save.getDate()}
-
- dl
- dt 分享地点
- dd.editable(data-key='place')= share.place || ''
- dl
- dt 分享时间
- dd 2011-20-20 17:00 - 17:30
+ - if(share.shareset)
+ dl
+ dt 分享会
+ dd
+ a(href='/shareset/#{share.shareset}')= shareset.subject
- if(share.tags && share.tags.length);
.ftags
h3 Tags
@@ -85,9 +84,6 @@ h1 #{share.authors.join(',')}: #{share.title}
a(href="/list/?tags=#{tag}")=tag
-})
- .action
- p 手机扫描此条码直接打分
- a.btn.primary.ratebtn(href="/rate/#{share._id}") 开始打分
div.records#rate_records(style='display:none')
View
72 views/shareset/edit.jade
@@ -0,0 +1,72 @@
+// 创建分享会
+script
+ KISSY.use('rate/app',function(S,App){
+ App.nav('create');
+ });
+script#temp-tags(type='text/template')
+ |<ul class='tags'>
+ | {{#each tags as tag}}
+ | <li><a class='tag' href='/list?tag={{tag}}'>{{tag}}</a></li>
+ | {{/each}}
+ |</ul>
+
+script#temp-errors(type='text/template')
+ |{{#each errors as err}}
+ |<div class='alert-message warning'>
+ |<p>{{err.type}}</p>
+ |</div>
+ |{{/each}}
+
+form.ajax-form(action='/shareset/#{shareset._id}', method="put")
+ .error-holder
+ fieldset
+ legend 编辑
+ .clearfix
+ label(for="subject") 分享主题
+ .input
+ input.text#subject(name="subject",value=shareset.subject)
+ .clearfix
+ label(for="time") 开始时间
+ .input
+ input.text.date-time#time-start(name="startTime",value=dateFormat(shareset.startTime,'yyyy-mm-dd HH:MM:ss'))
+ .clearfix
+ label(for="time-end") 结束时间
+ .input
+ input.text.date-time#time-end(name="endTime",value=dateFormat(shareset.endTime,'yyyy-mm-dd HH:MM:ss'))
+ .clearfix
+ label(for="position") 分享地址
+ .input
+ input.text#position(name="position",value=shareset.position)
+ .clearfix
+ label(for='desc') 介绍
+ .input
+ textarea.xxlarge(name='desc')= shareset.desc
+ .actions
+ button.btn.primary(type="submit") 提交
+
+script
+ KISSY.use('rate/ajax');
+ KISSY.use('calendar,calendar/assets/base.css',function(S,Calendar){
+ var calendars = [];
+ var $ = S.all;
+ $('.date-time').each(function(el){
+ $el = $(el);
+ var date = S.Date.parse(el.val()) || new Date();
+ date.setMinutes(0);
+ date.setSeconds(0);
+ date.setMilliseconds(0);
+ var c = new Calendar(el, {
+ popup : true,
+ selected : date,
+ showTime : true,
+ triggerType : ['focus','click']
+ }).on('timeSelect',function(ev){
+ this.hide();
+ el.val(S.Date.format(ev.date,"yyyy-mm-dd HH:MM:ss"));
+ });
+ calendars.push(c);
+ calendars[0].on('timeSelect',function(ev){
+ calendars[1].render({selected : ev.date});
+ });
+ });
+ })
View
0  views/setlist.jade → views/shareset/index.jade
File renamed without changes
View
25 views/create.jade → views/shareset/new.jade
@@ -9,14 +9,16 @@ script#temp-tags(type='kissy/template')
| <li><a class='tag' href='/list?tag={{tag}}'>{{tag}}</a></li>
| {{/each}}
|</ul>
-h1 创建
-form(action='/create', method="post")
- - if('undefined' !== typeof errors && errors)
- .alert-message.block-message.warning
- a.close(href='#') ×
- ul.errors
- - each err in errors
- li.error= err.type
+script#temp-errors(type='text/template')
+ |{{#each errors as err}}
+ |<div class='alert-message warning'>
+ |<p>{{err.type}}</p>
+ |</div>
+ |{{/each}}
+
+h1 创建分享会
+form.ajax-form(action='/shareset', method="post")
+ .error-holder
fieldset
legend 组织一次分享会
.clearfix
@@ -26,11 +28,11 @@ form(action='/create', method="post")
.clearfix
label(for="time") 开始时间
.input
- input.text.date-time#time-start(name="startTime",value=shareset.startTime)
+ input.text.date-time#time-start(name="startTime",value=dateFormat(shareset.startTime,'yyyy-mm-dd HH:MM:ss'))
.clearfix
label(for="time-end") 结束时间
.input
- input.text.date-time#time-end(name="endTime",value=shareset.endTime)
+ input.text.date-time#time-end(name="endTime",value=dateFormat(shareset.endTime,'yyyy-mm-dd HH:MM:ss'))
.clearfix
label(for="position") 分享地址
.input
@@ -66,4 +68,5 @@ script
calendars[1].render({selected : ev.date});
});
});
- })
+ });
+ KISSY.use('rate/ajax');
View
13 views/shareset.jade → views/shareset/show.jade
@@ -3,7 +3,7 @@ script
App.nav('setlist');
});
.navback
- a(href='/setlist') 返回到分享会列表
+ a(href='/shareset') 返回到分享会列表
h1 分享会:#{shareset.subject}
.row
.span5
@@ -14,15 +14,22 @@ h1 分享会:#{shareset.subject}
dd= dateFormat(shareset.endTime,'yyyy-mm-dd HH:MM:ss')
dt 分享地点
dd= shareset.position
+ .desc= shareset.desc
+ .action
+ a.btn.small(href='/shareset/#{shareset._id}/edit') 编辑
+ |
+ a.btn.small.ajax-btn(data-type='delete',href='/shareset/#{shareset._id}') 删除
.span11
- if (shares && shares.length)
ul.ratelist
- each item in shares
li.rateitem
h3.title
- a(href="/show/#{item._id}") #{item.authors.join(', ')}: #{item.title}
+ a(href="/share/#{item._id}") #{item.authors.join(', ')}: #{item.title}
p.meta
span.time #{item.ts_save.getFullYear()}-#{item.ts_save.getMonth()}-#{item.ts_save.getDate()}
div.desc=item.desc
.actions
- a.btn(href='/add-share/#{shareset._id}')添加分享
+ a.primary.btn(href='/share/new?shareset=#{shareset._id}')添加分享
+script
+ KISSY.use('rate/ajax');
Please sign in to comment.
Something went wrong with that request. Please try again.