This commit is contained in:
guange 2016-06-24 13:52:11 +08:00
parent f9075e08ba
commit e21f4e0b4d
1 changed files with 1 additions and 438 deletions

View File

@ -1,66 +1,9 @@
var app = angular.module('wechat', ['ngRoute']);
<<<<<<< HEAD
app.constant('config', {
rootPath: '/assets/wechat/',
rootUrl: '/',
apiUrl: '/api/v1/'
=======
if(debug===true){
//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 = "1"; //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};
>>>>>>> b17b92cc3ec7341ef1d1e2179be0de623605a725
});
@ -73,394 +16,14 @@ app.run(['$rootScope', 'auth', '$location', '$routeParams', function($rootScope,
$rootScope.$on('$routeChangeError', function(event, next, current){
<<<<<<< HEAD
if(next && next.templateUrl){
if(!next.templateUrl.endsWith("login.html") && !next.templateUrl.endsWith("reg.html")){
$location.path("/login");
=======
$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("提交成功");
if(typeof cb === 'function'){
cb();
>>>>>>> b17b92cc3ec7341ef1d1e2179be0de623605a725
}
}
<<<<<<< HEAD
});
$rootScope.$on('$routeChangeStart', function(event, next, current){
});
}
]);
=======
);
$scope.addIssueReply = function(data){
console.log(data.comment);
common.addCommonReply($routeParams.id, 'Issue', data, function(){
$scope.formData = {comment: ''};
loadData($routeParams.id);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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);
//数据提交完成,回复按钮启用
data.disabled = false;
});
};
$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;
}
};
});
}]);
>>>>>>> b17b92cc3ec7341ef1d1e2179be0de623605a725