wechat结构分离
This commit is contained in:
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>
|
|
@ -18,7 +18,21 @@
|
|||
</div>
|
||||
|
||||
<script src="/javascripts/wechat/build/angular.all.min.js"></script>
|
||||
|
||||
<script src="/javascripts/wechat/app.js"></script>
|
||||
<script src="/javascripts/wechat/others/factory.js"></script>
|
||||
<script src="/javascripts/wechat/others/filter.js"></script>
|
||||
<script src="/javascripts/wechat/directives/input_auto.js"></script>
|
||||
<script src="/javascripts/wechat/directives/loading_spinner.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/activity.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/add_class.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/blog.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/course_notice.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/discussion.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/homework.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/issue.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/journals.js"></script>
|
||||
<script src="/javascripts/wechat/others/routes.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -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"));
|
|
@ -1,546 +1,8 @@
|
|||
var app = angular.module('wechat', ['ngRoute']);
|
||||
var apiUrl = '/api/v1/';
|
||||
var debug = false; //调试标志,如果在本地请置为true
|
||||
var debug = true; //调试标志,如果在本地请置为true
|
||||
|
||||
if(debug===true){
|
||||
//apiUrl = 'http://localhost:3000/api/v1/';
|
||||
apiUrl = 'http://www.trustie.net/api/v1/';
|
||||
apiUrl = 'http://localhost:3000/api/v1/';
|
||||
//apiUrl = 'http://www.trustie.net/api/v1/';
|
||||
}
|
||||
|
||||
|
||||
app.factory('auth', function($http,$routeParams, $q){
|
||||
var _openid = '';
|
||||
|
||||
if(typeof g_openid !== 'undefined'){
|
||||
_openid = g_openid;
|
||||
}
|
||||
|
||||
if(debug===true){
|
||||
_openid = "orgVLv8TlS6e7FDiI6xdTGHRaaRo"; //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.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);
|
||||
};
|
||||
});
|
||||
|
||||
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};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
||||
app.filter('safeHtml', function ($sce) {
|
||||
return function (input) {
|
||||
return $sce.trustAsHtml(input);
|
||||
}
|
||||
});
|
||||
|
||||
//app.directive('textAutoHeight', function($timeout){
|
||||
// return {
|
||||
// restrict: 'A',
|
||||
// scope: {},
|
||||
// link: function(scope, element, attr){
|
||||
// scope.text = '点击展开';
|
||||
// $timeout(function(){
|
||||
// var e = element.parent().children().eq(5);
|
||||
// var height = e[0].scrollHeight;
|
||||
// if(height>90){
|
||||
// element.css('display', 'block');
|
||||
// element.on('click', function(){
|
||||
// if(element.text() == "点击展开"){
|
||||
// e.css("height", height+'px');
|
||||
// element.text("点击隐藏");
|
||||
// } else {
|
||||
// e.css("height", '90px');
|
||||
// element.text("点击展开");
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
// }, false);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
|
||||
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');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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>',
|
||||
};
|
||||
}]);
|
||||
|
||||
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'
|
||||
})
|
||||
.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;
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:blog-detail',{blog: data});
|
||||
$('#blog-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'blog_comments/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
//将用户输入内容插入最后一条回复
|
||||
$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"replyType" : "homework_assignment",
|
||||
"replyContent" : postInput
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: "前台地址/后台方法", //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
alert(data.d); //用data.d来获取后台传过来的json语句,或者是单纯的语句
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点赞效果
|
||||
var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
}
|
||||
|
||||
|
||||
});
|
|
@ -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);
|
||||
};
|
||||
});
|
|
@ -1,102 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setReplyTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:c-message-detail-reply',{reply: data});
|
||||
$('#all_course_message_reply').prepend(html);
|
||||
};
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:course-discussion',{discussion: data});
|
||||
$('#c-discussion-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
/*$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});*/
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'messages/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
//将用户输入内容插入最后一条回复
|
||||
/*$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());*/
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"Type" : "Message",
|
||||
"Content" : postInput
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
setReplyTemplate(data.data);
|
||||
alert("6");
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*//点赞效果
|
||||
var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
}*/
|
||||
|
||||
|
||||
});
|
|
@ -1,101 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setReplyTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:news-detail-reply',{reply: data});
|
||||
$('#all_news_reply').prepend(html);
|
||||
};
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:course-notice',{course: data});
|
||||
$('#c-notice-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
/*$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});*/
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'newss/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
//将用户输入内容插入最后一条回复
|
||||
/*$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());*/
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"type" : "News",
|
||||
"content" : postInput
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
setReplyTemplate(data.data);
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点赞效果
|
||||
var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
}
|
||||
|
||||
|
||||
});
|
|
@ -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>',
|
||||
};
|
||||
}]);
|
|
@ -8,3 +8,10 @@ gulp.task('minify', function () {
|
|||
.pipe(concat('angular.all.min.js'))
|
||||
.pipe(gulp.dest('build'))
|
||||
});
|
||||
|
||||
gulp.task("default", function(){
|
||||
gulp.src(['app.js','others/factory.js','others/filter.js', 'controllers/*.js', 'directives/*.js', 'others/routes.js'])
|
||||
.pipe(uglify())
|
||||
.pipe(concat('app.min.js'))
|
||||
.pipe(gulp.dest('build'))
|
||||
});
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* Created by root on 3/31/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setReplyTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:homework-detail-reply',{reply: data});
|
||||
$('#all_homework_reply').prepend(html);
|
||||
};
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:homework-detail',{homework: data});
|
||||
$('#homework-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
/*$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});*/
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'whomeworks/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
/*//将用户输入内容插入最后一条回复
|
||||
$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());*/
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
getOpenId(function(openid) {
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"type": "HomeworkCommon",
|
||||
"content": postInput,
|
||||
openid: openid
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
setReplyTemplate(data.data);
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//点赞效果
|
||||
/*var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
};*/
|
||||
|
||||
|
||||
});
|
|
@ -1,108 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
/**
|
||||
* Created by root on 3/31/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setReplyTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:issue-detail-reply',{issue_reply: data});
|
||||
$('#all_issue_reply').prepend(html);
|
||||
};
|
||||
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:issue-detail',{issues: data});
|
||||
$('#issue-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
IssueReplyInsert();
|
||||
});
|
||||
/*$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});*/
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'issues/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var IssueUrl = window.location.search;
|
||||
var IssueID = IssueUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(IssueID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var IssueReplyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
//将用户输入内容插入最后一条回复
|
||||
/*$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());*/
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
getOpenId(function(openid) {
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"type": "Issue",
|
||||
"content": postInput,
|
||||
openid: openid,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: apiUrl + 'new_comment/' + IssueID, //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
setReplyTemplate(data.data);
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//点赞效果
|
||||
/*var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
};*/
|
||||
|
||||
|
||||
});
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:message-detail',{message: data});
|
||||
$('#message-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'journal_for_messages/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
//将用户输入内容插入最后一条回复
|
||||
$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"replyType" : "homework_assignment",
|
||||
"replyContent" : postInput
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: "前台地址/后台方法", //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
alert(data.d); //用data.d来获取后台传过来的json语句,或者是单纯的语句
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点赞效果
|
||||
var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
}
|
||||
|
||||
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
/**
|
||||
* Created by root on 4/1/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
|
||||
var setReplyTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:homework-detail-reply',{reply: data});
|
||||
$('#all_homework_reply').prepend(html);
|
||||
};
|
||||
|
||||
|
||||
var setTemplate = function(data){
|
||||
console.log(data);
|
||||
var html=bt('t:project-discussion',{discussion: data});
|
||||
$('#p-discussion-container').prepend(html);
|
||||
$('.post-reply-submit').click(function(){
|
||||
replyInsert();
|
||||
});
|
||||
/*$('post-interactive-praise').click(function(){
|
||||
praiseClick();
|
||||
});*/
|
||||
};
|
||||
|
||||
var loadDataFromServer = function(id){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'messages/' + id,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
|
||||
};
|
||||
|
||||
var homeworkUrl = window.location.search;
|
||||
var homeworkID = homeworkUrl.split("=")[1];
|
||||
|
||||
loadDataFromServer(homeworkID);
|
||||
|
||||
//点击回复按钮,插入回复内容
|
||||
var replyInsert = function(){
|
||||
var replyContent = $("#postInput").val();
|
||||
if (!replyContent){
|
||||
alert("请输入回复");
|
||||
}else{
|
||||
|
||||
/*//将用户输入内容插入最后一条回复
|
||||
$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
||||
$(".post-reply-content:last").append(replyContent);
|
||||
$(".post-reply-date:last").append(Date());*/
|
||||
var postInput = $("#postInput").val();
|
||||
$("#postInput").val("");
|
||||
//回复数目+1
|
||||
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
||||
replyNum++;
|
||||
$(".reply-num").text("(" + replyNum + ")");
|
||||
|
||||
//获取并传送回复用户数据
|
||||
var userInfo = {
|
||||
"type" : "Message",
|
||||
"content" : postInput
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST", //提交方式
|
||||
dataType: "json", //类型
|
||||
url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名
|
||||
data: userInfo, //参数,如果没有,可以为null
|
||||
success: function (data) { //如果执行成功,那么执行此方法
|
||||
setReplyTemplate(data.data); //用data.d来获取后台传过来的json语句,或者是单纯的语句
|
||||
},
|
||||
error: function (err) { //如果执行不成功,那么执行此方法
|
||||
alert("err:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点赞效果
|
||||
/*var praiseClick = function(){
|
||||
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
||||
praiseNum++;
|
||||
$(".praise-num").text("(" + praiseNum + ")");
|
||||
}*/
|
||||
|
||||
|
||||
});
|
Loading…
Reference in New Issue