Permalink
Browse files

添加了心愿墙页面

  • Loading branch information...
1 parent 1221a00 commit af15f8f62efa5402314581a248e325dadcdf81ec @neekey committed May 21, 2012
Showing with 489 additions and 0 deletions.
  1. +23 −0 modules/share-wish.js
  2. +135 −0 public/js/share-wish/share-wish.js
  3. +262 −0 routers/share-wish.js
  4. +23 −0 server.js
  5. +24 −0 views/layout-share-wish.jade
  6. +20 −0 views/sharewish/share-wish.jade
  7. +2 −0 views/topbar.jade
View
@@ -0,0 +1,23 @@
+/**
+ * 许愿箱中的单个愿望
+ * @type {*}
+ */
+var mongoose = require('mongoose');
+var Schema = mongoose.Schema;
+
+var ShareWish = exports.Schema = new Schema({
+ // 期待的话题主题
+ topic: { type: String, required: true, unique: true },
+ // 许愿者
+ owner: { type: String, default: 'somebody' },
+ // 对于话题的详细描述
+ description: { type: String },
+ // 对该话题的响应者
+ response: { type: String },
+ // 该愿望是否已经实现
+ achieve: { type: Boolean, require: true, default: false },
+ // 时间
+ date: { type: Date }
+});
+
+mongoose.model('shareWish', ShareWish);
@@ -0,0 +1,135 @@
+(function(){
+
+ var API = {
+ ADD: '/sharewish/add',
+ GET: '/sharewish/get'
+ };
+
+ var ShareWishManager = {
+
+ add: function ( newWish, next ){
+
+ $.post( API.ADD, newWish, function ( res ){
+
+ next( res );
+ });
+ },
+
+ get: function ( queryObj, next ){
+
+ $.get( API.GET, {}, function ( res ){
+
+ next( res );
+ });
+ }
+ };
+
+ var ShareWishView = {
+
+ init: function (){
+
+ this.form = newWishForm.init();
+ this.wishList = $( '.J_wish-list' );
+
+ this.fetch();
+ this.attach();
+
+ },
+
+ fetch: function (){
+
+ var that = this;
+
+ ShareWishManager.get({}, function ( res ){
+
+ if( res.result ){
+
+ var wishes = res.data;
+
+ $.each( wishes, function ( index, wish ){
+
+ that.wishList.append( '<li class="label label-info">' + wish.topic + '</li>')
+ });
+ }
+ });
+ },
+
+ attach: function (){
+
+ $( this.form ).bind( 'wishAdd', function ( e, newWishObj ){
+
+ if( !newWishObj.topic ){
+ alert( '心愿主题不能为空!' );
+ }
+ else {
+
+ ShareWishManager.add( newWishObj, function ( res ){
+
+ if( res.result ){
+
+ alert( '心愿添加成功!' );
+ location.reload();
+ }
+ else {
+
+ alert( '心愿添加出错:' + res.msg + JSON.stringify( res.err ) );
+ }
+ });
+ }
+ });
+ }
+ };
+
+ var newWishForm = {
+
+ init: function (){
+ this.topic = $( '.J_topic-ipt' );
+ this.description = $( '.J_description-textarea').hide();
+ this.descTrigger = $( '.J_desc-trigger' );
+ this.descTriggerIcon = this.descTrigger.children( 'i' );
+ this.submitBtn = $( '.J_submit-wish' );
+
+ this.attach();
+
+ return this;
+ },
+
+ attach: function (){
+
+ var that = this;
+
+ this.descTrigger.bind( 'click', function (){
+
+ var ifOpen = !that.descTriggerIcon.hasClass( 'icon-chevron-down' );
+
+ that.descTriggerIcon.toggleClass( 'icon-chevron-down' );
+ that.descTriggerIcon.toggleClass( 'icon-chevron-up' );
+
+ if( ifOpen ){
+
+ that.description.hide( 500 );
+ }
+ else {
+
+ that.description.show( 500 );
+ }
+ });
+
+ this.submitBtn.bind( 'click', function (){
+
+ $( that).trigger( 'wishAdd', [ that.getValue() ] );
+ });
+ },
+
+ getValue: function (){
+
+ return {
+ topic: this.topic.val(),
+ description: this.description.val()
+ };
+ }
+
+ };
+
+ ShareWishView.init();
+})();
Oops, something went wrong.

0 comments on commit af15f8f

Please sign in to comment.