-
-
-
+
+
{{discussion.subject}}
+
-
+
{{discussion.created_on}}
-
回复 ()
-
赞 (())
+
回复 ({{discussion.replies_count}})
+
赞 ({{discussion.message_praise_count}})
- = 0; --j){ !>
-
+
-
+
-
-
-
+
{{journal.user.realname}}
+
+
{{journal.lasted_comment}}
回复
-
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html
index 2e8caf15a..b8e468701 100644
--- a/public/assets/wechat/course_notice.html
+++ b/public/assets/wechat/course_notice.html
@@ -24,7 +24,7 @@
{{comments.author.realname}}
-
{{comments.comments}}
+
{{comments.created_on}}
回复
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html
index 45c84c822..be9ee8328 100644
--- a/public/assets/wechat/project_discussion.html
+++ b/public/assets/wechat/project_discussion.html
@@ -1,89 +1,44 @@
-
-
-
-
项目讨论区
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js
index b465dfcf6..c69b119c1 100644
--- a/public/javascripts/wechat/app.js
+++ b/public/javascripts/wechat/app.js
@@ -1,41 +1,45 @@
var app = angular.module('wechat', ['ngRoute','ngCookies']);
-var apiUrl = 'http://localhost:3000/api/v1/';
-var debug = true; //调试标志,如果在本地请置为true
+var apiUrl = 'http://wechat.trustie.net/api/v1/';
+var debug = false; //调试标志,如果在本地请置为true
-app.factory('auth', function($http,$routeParams, $cookies){
+if(debug===true){
+ apiUrl = 'http://localhost:3000/api/v1/';
+}
+
+app.factory('auth', function($http,$routeParams, $cookies, $q){
var _openid = '';
if(debug===true){
- _openid = "2";
+ _openid = "1";
}
- var getOpenId = function(cb) {
+ var getOpenId = function() {
+ var deferred = $q.defer();
if (typeof _openid !== 'undefined' && _openid.length > 0) {
- cb(_openid);
- return;
- }
- var code = $routeParams.code;
- $http({
- url: '/wechat/get_open_id',
- data: {code: code},
- method: 'POST'
- }).then(function successCallback(response) {
- _openid = response.data.openid;
- if(typeof _openid !== 'undefined' && _openid.length>0){
- if(debug !== true){ //如果是生产环境,就存到cookies中
- $cookies.put("openid", _openid);
- }
- } else {
- if(debug!==true){//考虑从cookies中取出
- _openid = $cookies.get('openid');
+ deferred.resolve(_openid);
+ } else {
+ var code = $routeParams.code;
+ $http({
+ url: '/wechat/get_open_id',
+ data: {code: code},
+ method: 'POST'
+ }).then(function successCallback(response) {
+ _openid = response.data.openid;
+ if(typeof _openid !== 'undefined' && _openid.length>0){
+ if(debug !== true){ //如果是生产环境,就存到cookies中
+ $cookies.put("openid", _openid);
+ }
+ } else {
+ if(debug!==true){//考虑从cookies中取出
+ _openid = $cookies.get('openid');
+ }
}
- }
-
- cb(_openid);
- }, function errorCallback(response) {
- cb(null);
- });
-
+ deferred.resolve(_openid);
+ }, function errorCallback(response) {
+ deferred.reject(response);
+ });
+ }
+ return deferred.promise;
};
var openid = function(){
return _openid;
@@ -43,14 +47,28 @@ app.factory('auth', function($http,$routeParams, $cookies){
return {getOpenId: getOpenId, openid: openid};
});
-app.controller('ActivityController',function($scope, $http, auth){
- $scope.replaceUrl = function(url){
+
+app.factory('rms', function(){
+ var _saveStorage = {};
+ var save = function(key, value){
+ _saveStorage[key] = value;
+ };
+
+ var get = function(key){
+ return _saveStorage[key];
+ }
+
+ return {save: save, get: get};
+});
+
+app.controller('ActivityController',function($scope, $http, auth, rms){
+ $scope.repaceUrl = function(url){
return "http://www.trustie.net/" + url;
}
console.log("ActivityController load");
- $scope.activities = [];
+ $scope.activities = rms.get("activities") || [];
$scope.page = 1;
var loadActData = function(page){
@@ -61,17 +79,18 @@ app.controller('ActivityController',function($scope, $http, auth){
data: {openid: auth.openid(), page: page},
}).then(function successCallback(response) {
$scope.activities = $scope.activities.concat(response.data.data);
+ rms.save('activities', $scope.activities);
}, function errorCallback(response) {
});
}
-
- auth.getOpenId(function(oid){
- if(!oid){
- alert("获取openid出错");
- } else {
+ auth.getOpenId().then(
+ function successCallback(response){
loadActData($scope.page);
+ }, function errorCallback(response) {
+ alert("获取openid出错:"+response);
}
- });
+ );
+
$scope.loadActData = loadActData;
});
@@ -177,7 +196,7 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a
}, function errorCallback(response) {
});
- }
+ };
loadData($routeParams.id);
@@ -208,6 +227,50 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a
}
});
+app.controller('CourseDiscussionController', function($scope, $http, $routeParams, auth){
+ $scope.formData = {comment: ''};
+
+ var loadData = function(id){
+ $http({
+ method: 'GET',
+ url: apiUrl+ "messages/"+id,
+ }).then(function successCallback(response) {
+ console.log(response.data);
+ $scope.discussion = response.data.data;
+
+ }, function errorCallback(response) {
+ });
+ };
+
+ loadData($routeParams.id);
+
+
+ $scope.addIssueReply = 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("提交成功");
+ $scope.formData = {comment: ''};
+ loadData($routeParams.id);
+ }, function errorCallback(response) {
+ });
+ }
+});
+
app.filter('safeHtml', function ($sce) {
return function (input) {
return $sce.trustAsHtml(input);
@@ -232,6 +295,14 @@ app.config(['$routeProvider',function ($routeProvider) {
templateUrl: 'course_notice.html',
controller: 'CourseNoticeController'
})
+ .when('/course_discussion/:id', {
+ templateUrl: 'course_discussion.html',
+ controller: 'CourseDiscussionController'
+ })
+ .when('/project_discussion/:id', {
+ templateUrl: 'project_discussion.html',
+ controller: 'CourseDiscussionController'
+ })
.otherwise({
redirectTo: '/activities'
});