parent
0a82de1cf4
commit
b1791f4531
@ -0,0 +1,13 @@
|
||||
<div class="post-container">
|
||||
<div class="add-class-box">
|
||||
<p class="tac add-class-tip">输入班级邀请码,即刻加入班级!</p>
|
||||
<form class="mb20">
|
||||
<input type="text" class="class-number-input" />
|
||||
</form>
|
||||
<a href="javascript:void(0);" class="c-grey4 fl cancel-btn">取消</a>
|
||||
<div class="slice fl">
|
||||
<div class="slice-line"></div>
|
||||
</div>
|
||||
<a href="javascript:void(0);" class="c-blue fl submit-btn">确定</a>
|
||||
</div>
|
||||
</div>
|
@ -1,108 +0,0 @@
|
||||
/**
|
||||
* Created by guange on 16/3/19.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
var CommentBox = React.createClass({
|
||||
|
||||
loadFromServer: function(){
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
this.setState({data: data});
|
||||
}.bind(this),
|
||||
error: function(xhr,status,err){
|
||||
console.error(this.props.url, status, err.toString());
|
||||
}.bind(this)
|
||||
});
|
||||
},
|
||||
onCommentSubmit: function(comment){
|
||||
console.log(comment);
|
||||
},
|
||||
getInitialState: function(){
|
||||
return {data: []};
|
||||
},
|
||||
componentDidMount: function(){
|
||||
this.loadFromServer();
|
||||
setInterval(this.loadFromServer, 2000);
|
||||
},
|
||||
render: function(){
|
||||
return(
|
||||
<div className="commentBox">
|
||||
<CommentForm onCommentSubmit={this.onCommentSubmit}/>
|
||||
<CommentList data={this.state.data}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var CommentList = React.createClass({
|
||||
render: function(){
|
||||
|
||||
var commentNodes = this.props.data.map(function(comment){
|
||||
return (
|
||||
<Comment author={comment.author}>
|
||||
{comment.text}
|
||||
</Comment>
|
||||
)
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="commentList">
|
||||
{commentNodes}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var CommentForm = React.createClass({
|
||||
handleSubmit: function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var author = this.refs.author.value.trim();
|
||||
var text = this.refs.text.value.trim();
|
||||
if(!text || !author){
|
||||
return;
|
||||
}
|
||||
|
||||
this.props.onCommentSubmit({author: author, text: text});
|
||||
|
||||
this.refs.author.value = '';
|
||||
this.refs.text.value = '';
|
||||
return;
|
||||
},
|
||||
render: function(){
|
||||
return (
|
||||
<form className="commentForm" onSubmit={this.handleSubmit}>
|
||||
<input type="text" placeholder="Your name" ref="author" />
|
||||
<input type="text" placeholder="Say something..." ref="text" />
|
||||
<input type="submit" value="Post" />
|
||||
</form>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var Comment = React.createClass({
|
||||
|
||||
rawMarkup: function() {
|
||||
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
|
||||
return { __html: rawMarkup };
|
||||
},
|
||||
|
||||
render: function(){
|
||||
return (
|
||||
<div className="comment">
|
||||
<h2 className="commentAuthor">
|
||||
{this.props.author}
|
||||
</h2>
|
||||
<span dangerouslySetInnerHTML={this.rawMarkup()}></span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
React.render(<CommentBox url="api/comment.json"/>, document.getElementById("example"));
|
File diff suppressed because it is too large
Load Diff
@ -1,36 +0,0 @@
|
||||
$(function(){
|
||||
//获取url中的参数
|
||||
function getUrlParam(name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
||||
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
||||
if (r != null) return unescape(r[2]); return null; //返回参数值
|
||||
}
|
||||
|
||||
|
||||
var debug = false;
|
||||
|
||||
var g_openid = "";
|
||||
if(debug){
|
||||
g_openid = "填写要调试的openid即可";
|
||||
}
|
||||
|
||||
window.getOpenId = function(cb){
|
||||
if (g_openid.length>0){
|
||||
cb(g_openid);
|
||||
}
|
||||
var code = getUrlParam("code");
|
||||
$.ajax({
|
||||
url: '/wechat/get_open_id',
|
||||
data: {code: code},
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
g_openid = data.openid;
|
||||
cb(g_openid);
|
||||
},
|
||||
error: function(xhr,err){
|
||||
alert("认证失败: "+err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,66 @@
|
||||
|
||||
app.controller('ActivityController',function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){
|
||||
$scope.replaceUrl = function(url){
|
||||
return url;
|
||||
};
|
||||
|
||||
console.log("ActivityController load");
|
||||
|
||||
$scope.page = rms.get('page') || 0;
|
||||
$scope.activities = rms.get("activities") || [];
|
||||
$scope.has_more = rms.get("has_more");
|
||||
|
||||
$scope.loadActData = function(page){
|
||||
|
||||
$scope.page = page;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl+ "activities",
|
||||
data: {openid: auth.openid(), page: page}
|
||||
}).then(function successCallback(response) {
|
||||
if(response.data.page >0) {
|
||||
$scope.activities = $scope.activities.concat(response.data.data);
|
||||
} else {
|
||||
$scope.activities = response.data.data;
|
||||
}
|
||||
|
||||
rms.save("activities", $scope.activities);
|
||||
$scope.has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
||||
rms.save('has_more', $scope.has_more);
|
||||
rms.save('page', response.data.page);
|
||||
|
||||
console.log(response.data);
|
||||
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
if($scope.activities.length<=0){
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
$scope.loadActData(0);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$timeout(function(){
|
||||
window.scrollTo(0, rms.get("yoffset"));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//跳到详情页
|
||||
$scope.goDetail = function(type, act_id,id){
|
||||
rms.save("yoffset", window.document.body.scrollTop);
|
||||
$location.path('/'+type+'/'+act_id);
|
||||
}
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
|
||||
app.controller('AddClassController', ['$scope',function($scope){
|
||||
|
||||
}]);
|
@ -0,0 +1,38 @@
|
||||
|
||||
app.controller('BlogController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'blog_comments').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.blog = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addBlogReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'BlogComment', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
console.log(act);
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
console.log(act);
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,35 @@
|
||||
app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'newss').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.news = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addNoticeReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'News', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
|
||||
app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'messages').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.discussion = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addDiscussionReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'Message', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
|
||||
app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'whomeworks').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.homework = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addHomeworkReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'HomeworkCommon', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
app.controller('IssueController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'issues').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.issue = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addIssueReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'Issue', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,37 @@
|
||||
app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){
|
||||
$scope.formData = {comment: ''};
|
||||
|
||||
var loadData = function(id){
|
||||
common.loadCommonData(id, 'journal_for_messages').then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
$scope.message = response.data.data;
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
auth.getOpenId().then(
|
||||
function successCallback(response){
|
||||
loadData($routeParams.id);
|
||||
}, function errorCallback(response) {
|
||||
alert("获取openid出错:"+response);
|
||||
}
|
||||
);
|
||||
|
||||
$scope.addJournalReply = function(data){
|
||||
console.log(data.comment);
|
||||
common.addCommonReply($routeParams.id, 'JournalsForMessage', data, function(){
|
||||
$scope.formData = {comment: ''};
|
||||
loadData($routeParams.id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addPraise = function(act){
|
||||
console.log(act);
|
||||
common.addCommonPraise(act);
|
||||
};
|
||||
|
||||
$scope.decreasePraise = function(act){
|
||||
console.log(act);
|
||||
common.decreaseCommonPraise(act);
|
||||
};
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
app.directive('inputAuto',function(){
|
||||
return{
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
link: function(scope, element){
|
||||
var copyContainer = element.parent().children().eq(0);
|
||||
var sendButton = element.parent().next();
|
||||
element.on('input',function(){
|
||||
console.log(sendButton);
|
||||
copyContainer.html(element[0].value);
|
||||
var textHeight = copyContainer[0].scrollHeight;
|
||||
element.css('height', textHeight + 'px');
|
||||
});
|
||||
sendButton.on('click',function(){
|
||||
element.css('height','28px');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
app.directive('loadingSpinner', ['$http', function ($http) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
replace: true,
|
||||
template: '<div ng-show="activeCalls>0" class="loading-bg"><div class="loading-box"><img src="/images/loading.gif" alt=""/><span>加载中...</span></div></div>',
|
||||
};
|
||||
}]);
|
@ -0,0 +1,120 @@
|
||||
app.factory('auth', function($http,$routeParams, $q){
|
||||
var _openid = '';
|
||||
|
||||
if(typeof g_openid !== 'undefined'){
|
||||
_openid = g_openid;
|
||||
}
|
||||
|
||||
if(debug===true){
|
||||
_openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; //guange的帐号
|
||||
}
|
||||
|
||||
var getOpenId = function() {
|
||||
var deferred = $q.defer();
|
||||
if (typeof _openid !== 'undefined' && _openid.length > 0){
|
||||
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;
|
||||
deferred.resolve(_openid);
|
||||
}, function errorCallback(response) {
|
||||
deferred.reject(response);
|
||||
});
|
||||
}
|
||||
return deferred.promise;
|
||||
};
|
||||
var openid = function(){
|
||||
return _openid;
|
||||
};
|
||||
return {getOpenId: getOpenId, openid: openid};
|
||||
});
|
||||
|
||||
|
||||
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.factory('common', function($http, auth, $routeParams){
|
||||
var addCommonReply = function(id, type, data, cb){
|
||||
|
||||
if(!data.comment || data.comment.length<=0){
|
||||
return;
|
||||
}
|
||||
|
||||
var temp = data.comment.replace(/\n/g,'<br/>');
|
||||
|
||||
var userInfo = {
|
||||
type: type,
|
||||
content: temp,
|
||||
openid: auth.openid()
|
||||
};
|
||||
//回复按钮禁用
|
||||
data.disabled = true;
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl+ "new_comment/"+id,
|
||||
data: userInfo
|
||||
}).then(function successCallback(response) {
|
||||
//alert("提交成功");
|
||||
//数据提交完成,回复按钮启用
|
||||
data.disabled = false;
|
||||
if(typeof cb === 'function'){
|
||||
cb();
|
||||
}
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
var loadCommonData = function(id, type){
|
||||
return $http({
|
||||
method: 'GET',
|
||||
url: apiUrl+ type + "/" + id+"?openid="+auth.openid()
|
||||
})
|
||||
};
|
||||
|
||||
var addCommonPraise = function(act){
|
||||
act.praise_count += 1;
|
||||
act.has_praise = true;
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "praise/" + act.act_id,
|
||||
data:{openid:auth.openid(),type:act.act_type}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var decreaseCommonPraise = function(act){
|
||||
act.praise_count -= 1;
|
||||
act.has_praise = false;
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "praise/" + act.act_id,
|
||||
data:{openid:auth.openid(),type:act.act_type}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
}, function errorCallback(response) {
|
||||
});
|
||||
};
|
||||
|
||||
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
app.filter('safeHtml', function ($sce) {
|
||||
return function (input) {
|
||||
return $sce.trustAsHtml(input);
|
||||
}
|
||||
});
|
@ -0,0 +1,70 @@
|
||||
app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($routeProvider, $httpProvider, $locationProvider) {
|
||||
var rootPath = '/assets/wechat/'
|
||||
//$locationProvider.html5Mode(true);
|
||||
$routeProvider
|
||||
.when('/activites', {
|
||||
templateUrl: rootPath + 'activities.html',
|
||||
controller: 'ActivityController'
|
||||
})
|
||||
.when('/issues/:id', {
|
||||
templateUrl: rootPath + 'issue_detail.html',
|
||||
controller: 'IssueController'
|
||||
})
|
||||
.when('/project_discussion/:id', {
|
||||
templateUrl: rootPath + 'project_discussion.html',
|
||||
controller: 'DiscussionController'
|
||||
})
|
||||
.when('/homework/:id', {
|
||||
templateUrl: rootPath + 'homework_detail.html',
|
||||
controller: 'HomeworkController'
|
||||
})
|
||||
.when('/course_notice/:id', {
|
||||
templateUrl: rootPath + 'course_notice.html',
|
||||
controller: 'CourseNoticeController'
|
||||
})
|
||||
.when('/course_discussion/:id', {
|
||||
templateUrl: rootPath + 'course_discussion.html',
|
||||
controller: 'DiscussionController'
|
||||
})
|
||||
.when('/journal_for_message/:id', {
|
||||
templateUrl: rootPath + 'jour_message_detail.html',
|
||||
controller: 'JournalsController'
|
||||
})
|
||||
.when('/blog_comment/:id', {
|
||||
templateUrl: rootPath + 'blog_detail.html',
|
||||
controller: 'BlogController'
|
||||
})
|
||||
.when('/add_class', {
|
||||
templateUrl: rootPath + 'add_class.html',
|
||||
controller: 'AddClassController'
|
||||
})
|
||||
.otherwise({
|
||||
redirectTo: '/activites'
|
||||
});
|
||||
|
||||
//监听异步请求,实现加载中显隐标记
|
||||
$httpProvider.interceptors.push(function ($q, $rootScope) {
|
||||
if ($rootScope.activeCalls == undefined) {
|
||||
$rootScope.activeCalls = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
request: function (config) {
|
||||
$rootScope.activeCalls += 1;
|
||||
return config;
|
||||
},
|
||||
requestError: function (rejection) {
|
||||
$rootScope.activeCalls -= 1;
|
||||
return rejection;
|
||||
},
|
||||
response: function (response) {
|
||||
$rootScope.activeCalls -= 1;
|
||||
return response;
|
||||
},
|
||||
responseError: function (rejection) {
|
||||
$rootScope.activeCalls -= 1;
|
||||
return rejection;
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue