parent
b1791f4531
commit
ada15b4212
@ -0,0 +1,14 @@
|
||||
var app=angular.module("wechat",["ngRoute"]);
|
||||
app.factory("auth",["$http","$routeParams","$q",function(e,n,t){var o="";"undefined"!=typeof g_openid&&(o=g_openid);var a=function(){var a=t.defer();if("undefined"!=typeof o&&o.length>0)a.resolve(o);else{var i=n.code;e({url:"/wechat/get_open_id",data:{code:i},method:"POST"}).then(function(e){o=e.data.openid,a.resolve(o)},function(e){a.reject(e)})}return a.promise},i=function(){return o};return{getOpenId:a,openid:i}}]),app.factory("rms",function(){var e={},n=function(n,t){e[n]=t},t=function(n){return e[n]};return{save:n,get:t}}),app.factory("common",["$http","auth","$routeParams",function(e,n,t){var o=function(t,o,a,i){if(a.comment&&!(a.comment.length<=0)){var r=a.comment.replace(/\n/g,"<br/>"),d={type:o,content:r,openid:n.openid()};a.disabled=!0,e({method:"POST",url:apiUrl+"new_comment/"+t,data:d}).then(function(e){a.disabled=!1,"function"==typeof i&&i()},function(e){})}},a=function(t,o){return e({method:"GET",url:apiUrl+o+"/"+t+"?openid="+n.openid()})},i=function(t){t.praise_count+=1,t.has_praise=!0,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})},r=function(t){t.praise_count-=1,t.has_praise=!1,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})};return{addCommonReply:o,loadCommonData:a,addCommonPraise:i,decreaseCommonPraise:r}}]);
|
||||
app.filter("safeHtml",["$sce",function(t){return function(n){return t.trustAsHtml(n)}}]);
|
||||
app.controller("ActivityController",["$anchorScroll","$location","$scope","$http","$timeout","auth","rms","common",function(t,a,e,o,i,n,c,s){e.replaceUrl=function(t){return t},console.log("ActivityController load"),e.page=c.get("page")||0,e.activities=c.get("activities")||[],e.has_more=c.get("has_more"),e.loadActData=function(t){e.page=t,o({method:"POST",url:apiUrl+"activities",data:{openid:n.openid(),page:t}}).then(function(t){t.data.page>0?e.activities=e.activities.concat(t.data.data):e.activities=t.data.data,c.save("activities",e.activities),e.has_more=t.data.count+10*t.data.page<t.data.all_count,c.save("has_more",e.has_more),c.save("page",t.data.page),console.log(t.data)},function(t){})},e.activities.length<=0?n.getOpenId().then(function(t){e.loadActData(0)},function(t){alert("获取openid出错:"+t)}):i(function(){window.scrollTo(0,c.get("yoffset"))}),e.goDetail=function(t,e,o){c.save("yoffset",window.document.body.scrollTop),a.path("/"+t+"/"+e)},e.addPraise=function(t){s.addCommonPraise(t)},e.decreasePraise=function(t){s.decreaseCommonPraise(t)}}]);
|
||||
app.controller("AddClassController",["$scope",function(o){}]);
|
||||
app.controller("BlogController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"blog_comments").then(function(n){console.log(n.data),o.blog=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addBlogReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"BlogComment",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){console.log(o),a.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),a.decreaseCommonPraise(o)}}]);
|
||||
app.controller("CourseNoticeController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"newss").then(function(n){console.log(n.data),o.news=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addNoticeReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"News",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){a.addCommonPraise(o)},o.decreasePraise=function(o){a.decreaseCommonPraise(o)}}]);
|
||||
app.controller("DiscussionController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var i=function(n){t.loadCommonData(n,"messages").then(function(n){console.log(n.data),o.discussion=n.data.data},function(o){})};e.getOpenId().then(function(o){i(a.id)},function(o){alert("获取openid出错:"+o)}),o.addDiscussionReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"Message",n,function(){o.formData={comment:""},i(a.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
||||
app.controller("HomeworkController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var m=function(n){t.loadCommonData(n,"whomeworks").then(function(n){console.log(n.data),o.homework=n.data.data},function(o){})};a.getOpenId().then(function(o){m(e.id)},function(o){alert("获取openid出错:"+o)}),o.addHomeworkReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"HomeworkCommon",n,function(){o.formData={comment:""},m(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
||||
app.controller("IssueController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var s=function(n){t.loadCommonData(n,"issues").then(function(n){console.log(n.data),o.issue=n.data.data},function(o){})};a.getOpenId().then(function(o){s(e.id)},function(o){alert("获取openid出错:"+o)}),o.addIssueReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"Issue",n,function(){o.formData={comment:""},s(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
||||
app.controller("JournalsController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var c=function(n){t.loadCommonData(n,"journal_for_messages").then(function(n){console.log(n.data),o.message=n.data.data},function(o){})};e.getOpenId().then(function(o){c(a.id)},function(o){alert("获取openid出错:"+o)}),o.addJournalReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"JournalsForMessage",n,function(){o.formData={comment:""},c(a.id)})},o.addPraise=function(o){console.log(o),t.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),t.decreaseCommonPraise(o)}}]);
|
||||
app.directive("inputAuto",function(){return{restrict:"A",scope:{},link:function(n,t){var e=t.parent().children().eq(0),i=t.parent().next();t.on("input",function(){console.log(i),e.html(t[0].value);var n=e[0].scrollHeight;t.css("height",n+"px")}),i.on("click",function(){t.css("height","28px")})}}});
|
||||
app.directive("loadingSpinner",["$http",function(i){return{restrict:"A",replace:!0,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(e,r,t){var o="/assets/wechat/";e.when("/activites",{templateUrl:o+"activities.html",controller:"ActivityController"}).when("/issues/:id",{templateUrl:o+"issue_detail.html",controller:"IssueController"}).when("/project_discussion/:id",{templateUrl:o+"project_discussion.html",controller:"DiscussionController"}).when("/homework/:id",{templateUrl:o+"homework_detail.html",controller:"HomeworkController"}).when("/course_notice/:id",{templateUrl:o+"course_notice.html",controller:"CourseNoticeController"}).when("/course_discussion/:id",{templateUrl:o+"course_discussion.html",controller:"DiscussionController"}).when("/journal_for_message/:id",{templateUrl:o+"jour_message_detail.html",controller:"JournalsController"}).when("/blog_comment/:id",{templateUrl:o+"blog_detail.html",controller:"BlogController"}).when("/add_class",{templateUrl:o+"add_class.html",controller:"AddClassController"}).otherwise({redirectTo:"/activites"}),r.interceptors.push(["$q","$rootScope",function(e,r){return void 0==r.activeCalls&&(r.activeCalls=0),{request:function(e){return r.activeCalls+=1,e},requestError:function(e){return r.activeCalls-=1,e},response:function(e){return r.activeCalls-=1,e},responseError:function(e){return r.activeCalls-=1,e}}}])}]);
|
@ -1,5 +1,5 @@
|
||||
app.filter('safeHtml', function ($sce) {
|
||||
app.filter('safeHtml', ['$sce',function ($sce) {
|
||||
return function (input) {
|
||||
return $sce.trustAsHtml(input);
|
||||
}
|
||||
});
|
||||
}]);
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Created by root on 3/25/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
var loadDataFromServer = function(id, page){
|
||||
getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'activities',
|
||||
data: {openid: openid, page: page},
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data, data.all_count, data.count, data.page);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
};
|
||||
var setTemplate = function(data, all_count, count, page){
|
||||
console.log(data);
|
||||
var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page});
|
||||
if (page == 0) {
|
||||
$('#container').prepend(html);
|
||||
} else {
|
||||
$("#more_activities").remove();
|
||||
$('#container').append(html);
|
||||
}
|
||||
descToggle();
|
||||
};
|
||||
//内容全部显示与部分隐藏
|
||||
var descToggle = function(){
|
||||
$(".post-all-content").each(function(){
|
||||
var postHeight = $(this).height();
|
||||
if (postHeight > 90){
|
||||
$(this).parent().next().css("display","block");
|
||||
$(this).parent().next().toggle(function(){
|
||||
$(this).text("点击隐藏");
|
||||
$(this).prev().css("height",postHeight);
|
||||
},function(){
|
||||
$(this).text("点击展开");
|
||||
$(this).prev().css("height",90);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadDataFromServer(8686, 0);
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd public/javascripts/wechat && gulp && gulp minify
|
Loading…
Reference in new issue