From edb18bd1b8941576e4ee1150a524f7d4cb499989 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 7 Apr 2016 11:16:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?api=E6=8F=90=E4=BE=9Bhas=5Fpraise?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/blog_comments.rb | 3 ++- app/api/mobile/apis/issues.rb | 3 ++- app/api/mobile/apis/journal_for_messages.rb | 3 ++- app/api/mobile/apis/messages.rb | 3 ++- app/api/mobile/apis/newss.rb | 3 ++- app/api/mobile/apis/whomeworks.rb | 3 ++- app/api/mobile/entities/activity.rb | 5 ++++- app/api/mobile/entities/blog_comment.rb | 7 +++++++ app/api/mobile/entities/issue.rb | 7 +++++++ app/api/mobile/entities/jours.rb | 7 +++++++ app/api/mobile/entities/message.rb | 7 +++++++ app/api/mobile/entities/news.rb | 9 +++++++-- app/api/mobile/entities/whomework.rb | 7 +++++++ public/assets/wechat/activities.html | 2 +- public/assets/wechat/blog_detail.html | 3 ++- public/assets/wechat/course_discussion.html | 3 ++- public/assets/wechat/course_notice.html | 3 ++- public/assets/wechat/homework_detail.html | 3 ++- public/assets/wechat/issue_detail.html | 3 ++- public/assets/wechat/jour_message_detail.html | 3 ++- public/assets/wechat/project_discussion.html | 3 ++- 21 files changed, 73 insertions(+), 17 deletions(-) diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index 01fd05c0f..5a064245a 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -7,8 +7,9 @@ module Mobile desc "get special topic" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user blog = BlogComment.find params[:id] - present :data, blog, with: Mobile::Entities::BlogComment + present :data, blog, with: Mobile::Entities::BlogComment,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index 1815c85f3..b767bd768 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -8,8 +8,9 @@ module Mobile desc "get special issuse" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user issue = Issue.find params[:id] - present :data, issue, with: Mobile::Entities::Issue + present :data, issue, with: Mobile::Entities::Issue,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb index 648924912..15a571a82 100644 --- a/app/api/mobile/apis/journal_for_messages.rb +++ b/app/api/mobile/apis/journal_for_messages.rb @@ -7,8 +7,9 @@ module Mobile desc "get special journal" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user jour = JournalsForMessage.find params[:id] - present :data, jour, with: Mobile::Entities::Jours + present :data, jour, with: Mobile::Entities::Jours,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb index 5e2fb05b7..ae2f9a39c 100644 --- a/app/api/mobile/apis/messages.rb +++ b/app/api/mobile/apis/messages.rb @@ -7,8 +7,9 @@ module Mobile desc "get special topic" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user message = Message.find params[:id] - present :data, message, with: Mobile::Entities::Message + present :data, message, with: Mobile::Entities::Message,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 6f15ae2ee..8bdd460cc 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -7,8 +7,9 @@ module Mobile desc "get special news" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user news = News.find params[:id] - present :data, news, with: Mobile::Entities::News + present :data, news, with: Mobile::Entities::News,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index 39a6faa68..a88d509a3 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -7,8 +7,9 @@ module Mobile desc "get one homework" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user homework = HomeworkCommon.find params[:id] - present :data, homework, with: Mobile::Entities::Whomework + present :data, homework, with: Mobile::Entities::Whomework,user: user present :status, 0 end end diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 945601bd6..59127dedd 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -131,8 +131,11 @@ module Mobile act_expose :course_project_name #课程/项目名字 act_expose :activity_type_name #课程问答区/项目缺陷等 expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false current_user = options[:user] - false + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise end end end diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index ac3fc3d9e..6961823d0 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -45,6 +45,13 @@ module Mobile c.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index d0bb0fa0d..e64248353 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -49,6 +49,13 @@ module Mobile f.journals.where("notes is not null and notes != ''") end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb index 9d4d85f7a..87bbd0184 100644 --- a/app/api/mobile/entities/jours.rb +++ b/app/api/mobile/entities/jours.rb @@ -51,6 +51,13 @@ module Mobile f.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index d182e5965..7a00b5725 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -52,6 +52,13 @@ module Mobile c.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index d1ec9c5c3..85504a280 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -73,8 +73,13 @@ module Mobile f.send(:comments) end end - - + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb index b24c50aa2..76b88ec6f 100644 --- a/app/api/mobile/entities/whomework.rb +++ b/app/api/mobile/entities/whomework.rb @@ -67,6 +67,13 @@ module Mobile f.journals_for_messages end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index ae8fe8136..e63bcf642 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -117,7 +117,7 @@
回复 ({{act.reply_count}})
-
一赞 ({{act.activity_praise_count}})
+
已赞 ({{act.activity_praise_count}})
赞 ({{act.activity_praise_count}})
diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index 5c1d6bf22..f678c8159 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -16,7 +16,8 @@
回复 ({{blog.comments_count}})
-
({{blog.blog_praise_count}})
+
已赞 ({{blog.blog_praise_count}})
+
赞 ({{blog.blog_praise_count}})
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index 13ae823c3..1e7b53f84 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -16,7 +16,8 @@
回复 ({{discussion.replies_count}})
-
({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index 3881d96f1..9ac5a402d 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -16,7 +16,8 @@
回复 ({{news.comments_count}})
-
({{news.news_praise_count}})
+
已赞 ({{news.news_praise_count}})
+
赞 ({{news.news_praise_count}})
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 072678ba1..25d75d583 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -18,7 +18,8 @@
回复 ({{homework.whomework_journal_count}})
-
({{homework.whomework_praise_count}})
+
已赞 ({{homework.whomework_praise_count}})
+
赞 ({{homework.whomework_praise_count}})
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index ea3fd06be..79afbb547 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -18,7 +18,8 @@
回复 ({{issue.journals_count}})
-
({{issue.issue_praise_count}})
+
已赞 ({{issue.issue_praise_count}})
+
赞 ({{issue.issue_praise_count}})
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index 857498f0a..d866e887e 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -13,7 +13,8 @@
回复 ({{message.reply_count}})
-
({{message.message_praise_count}})
+
已赞 ({{message.message_praise_count}})
+
赞 ({{message.message_praise_count}})
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index d868e0d03..2b31df8bf 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -16,7 +16,8 @@
回复 ({{discussion.replies_count}})
-
({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
From a0e95976ac5db6b0caad37d70c1718abe72d58b8 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 7 Apr 2016 11:21:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/wechat/blog_detail.html | 4 ++-- public/assets/wechat/course_discussion.html | 4 ++-- public/assets/wechat/course_notice.html | 4 ++-- public/assets/wechat/homework_detail.html | 4 ++-- public/assets/wechat/issue_detail.html | 4 ++-- public/assets/wechat/jour_message_detail.html | 4 ++-- public/assets/wechat/project_discussion.html | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index f678c8159..1fc92eabb 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -16,8 +16,8 @@
回复 ({{blog.comments_count}})
-
已赞 ({{blog.blog_praise_count}})
-
赞 ({{blog.blog_praise_count}})
+
已赞 ({{blog.blog_praise_count}})
+
赞 ({{blog.blog_praise_count}})
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index 1e7b53f84..2c2c210a9 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -16,8 +16,8 @@
回复 ({{discussion.replies_count}})
-
已赞 ({{discussion.message_praise_count}})
-
赞 ({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index 9ac5a402d..eccd91848 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -16,8 +16,8 @@
回复 ({{news.comments_count}})
-
已赞 ({{news.news_praise_count}})
-
赞 ({{news.news_praise_count}})
+
已赞 ({{news.news_praise_count}})
+
赞 ({{news.news_praise_count}})
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 25d75d583..98992da59 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -18,8 +18,8 @@
回复 ({{homework.whomework_journal_count}})
-
已赞 ({{homework.whomework_praise_count}})
-
赞 ({{homework.whomework_praise_count}})
+
已赞 ({{homework.whomework_praise_count}})
+
赞 ({{homework.whomework_praise_count}})
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index 79afbb547..0fb443e67 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -18,8 +18,8 @@
回复 ({{issue.journals_count}})
-
已赞 ({{issue.issue_praise_count}})
-
赞 ({{issue.issue_praise_count}})
+
已赞 ({{issue.issue_praise_count}})
+
赞 ({{issue.issue_praise_count}})
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index d866e887e..893d693c8 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -13,8 +13,8 @@
回复 ({{message.reply_count}})
-
已赞 ({{message.message_praise_count}})
-
赞 ({{message.message_praise_count}})
+
已赞 ({{message.message_praise_count}})
+
赞 ({{message.message_praise_count}})
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index 2b31df8bf..62d6dc728 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -16,8 +16,8 @@
回复 ({{discussion.replies_count}})
-
已赞 ({{discussion.message_praise_count}})
-
赞 ({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
From 6d8ffabb39f450ac35b1e0e846f07932d64a7b56 Mon Sep 17 00:00:00 2001 From: txz Date: Thu, 7 Apr 2016 11:40:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/wechat/activities.html | 2 +- public/javascripts/wechat/app.js | 166 +++++---------------------- 2 files changed, 28 insertions(+), 140 deletions(-) diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index ae8fe8136..e63bcf642 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -117,7 +117,7 @@
回复 ({{act.reply_count}})
-
一赞 ({{act.activity_praise_count}})
+
已赞 ({{act.activity_praise_count}})
赞 ({{act.activity_praise_count}})
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index c8edfaf84..9204d169b 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -10,7 +10,7 @@ app.factory('auth', function($http,$routeParams, $cookies, $q){ var _openid = ''; if(debug===true){ - _openid = "1"; + _openid = "2"; } var getOpenId = function() { @@ -135,7 +135,7 @@ app.factory('common', function($http, auth){ var loadCommonData = function(id, type){ return $http({ method: 'GET', - url: apiUrl+ type + "/"+id + url: apiUrl+ type + "/" + id }) }; @@ -155,238 +155,126 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co $scope.issue = response.data.data; }, function errorCallback(response) { }); - } + }; loadData($routeParams.id); $scope.addIssueReply = function(data){ - console.log("add issue reply"); + console.log(data.comment); common.addCommonReply($routeParams.id, 'Issue', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); }); }; - - - - }); -app.controller('HomeworkController', function($scope, $http, $routeParams, auth){ +app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "whomeworks/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'whomeworks').then(function successCallback(response) { console.log(response.data); $scope.homework = response.data.data; - }, function errorCallback(response) { }); - } + }; loadData($routeParams.id); - $scope.addHomeworkReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "HomeworkCommon", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'HomeworkCommon', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); - } + }; }); -app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth){ +app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "newss/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'newss').then(function successCallback(response) { console.log(response.data); $scope.news = response.data.data; - }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addNoticeReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "News", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'News', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('CourseDiscussionController', function($scope, $http, $routeParams, auth){ +app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "messages/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'messages').then(function successCallback(response) { console.log(response.data); $scope.discussion = response.data.data; - }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addDiscussionReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "Message", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'Message', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('JournalsController', function($scope, $http, $routeParams, auth){ +app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "journal_for_messages/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'journal_for_messages').then(function successCallback(response) { console.log(response.data); $scope.message = response.data.data; }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addJournalReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "JournalsForMessage", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'JournalsForMessage', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('BlogController', function($scope, $http, $routeParams, auth){ +app.controller('BlogController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "blog_comments/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'blog_comments').then(function successCallback(response) { console.log(response.data); $scope.blog = response.data.data; }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addBlogReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "BlogComment", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'BlogComment', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); @@ -409,7 +297,7 @@ app.config(['$routeProvider',function ($routeProvider) { }) .when('/project_discussion/:id', { templateUrl: 'project_discussion.html', - controller: 'CourseDiscussionController' + controller: 'DiscussionController' }) .when('/homework/:id', { templateUrl: 'homework_detail.html', @@ -421,7 +309,7 @@ app.config(['$routeProvider',function ($routeProvider) { }) .when('/course_discussion/:id', { templateUrl: 'course_discussion.html', - controller: 'CourseDiscussionController' + controller: 'DiscussionController' }) .when('/journal_for_message/:id', { templateUrl: 'jour_message_detail.html',