From 24f5e245df08958c73651fc7b248c8a3b15527a7 Mon Sep 17 00:00:00 2001 From: cxt Date: Sun, 12 Jun 2016 14:20:55 +0800 Subject: [PATCH 001/156] =?UTF-8?q?=E9=BC=A0=E6=A0=87=E7=BB=8F=E8=BF=87?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E6=97=B6=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9C=80=E6=96=B0=E7=9A=845=E6=9D=A1?= =?UTF-8?q?=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 5 ++ app/views/layouts/_logined_header.html.erb | 14 ++-- .../layouts/_show_messages_list.html.erb | 79 ++++++++++++++++--- 3 files changed, 82 insertions(+), 16 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index b1e5456c5..e4f637b6d 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -49,6 +49,11 @@ class ExerciseController < ApplicationController return end @exercise = Exercise.find params[:id] + @exercise.course_messages.each do |message| + if User.current.id == message.user_id && message.viewed == 0 + message.update_attributes(:viewed => true) if message.viewed == 0 + end + end @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? exercise_end = @exercise.end_time > Time.now if @exercise.time == -1 diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index a87e83238..7ba0a23be 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -84,9 +84,9 @@
<%= link_to User.current.count_new_message , user_message_path(User.current), :class => "newsActive", :target =>"_Blank" %>
<% end %> <%#= link_to User.current.count_new_message, user_message_path(User.current), :class => "homepageNewsIcon" %> - +
+ <%=render :partial => 'layouts/message_loading' %> +
@@ -98,15 +98,15 @@ $("#navHomepageSearchType").hide(); }); - /*$("#user_messages").mouseenter(function(){ + $("#user_messages").mouseenter(function(){ $("#user_messages_list").show(); - $.get('<%#=user_messages_unviewed_users_path %>'); + $.get('<%=user_messages_unviewed_users_path %>'); $("#ajax-indicator").hide(); }).mouseleave(function(){ $("#user_messages_list").hide(); - $("#user_messages_list").html("<%#=escape_javascript(render :partial => 'layouts/message_loading') %>"); + $("#user_messages_list").html("<%=escape_javascript(render :partial => 'layouts/message_loading') %>"); - });*/ + }); $("#navHomepageProfile").mouseenter(function(){ $("#homepageProfileMenuIcon").addClass("homepageProfileMenuIconhover"); diff --git a/app/views/layouts/_show_messages_list.html.erb b/app/views/layouts/_show_messages_list.html.erb index 27e1d8896..addd04815 100644 --- a/app/views/layouts/_show_messages_list.html.erb +++ b/app/views/layouts/_show_messages_list.html.erb @@ -1,7 +1,6 @@

未读消息

<%= link_to '查看全部', user_message_path(User.current), :class => "shadowbox_news_all", :target =>"_Blank" %> \ No newline at end of file From 02e2831980ee7b2d9db591adb61af7bad346f83f Mon Sep 17 00:00:00 2001 From: cxt Date: Sun, 12 Jun 2016 17:17:37 +0800 Subject: [PATCH 002/156] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E7=95=99=E8=A8=80=E5=88=97=E8=A1=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admin/leave_messages.html.erb | 6 +++--- app/views/users/_user_jours_list.html.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/leave_messages.html.erb b/app/views/admin/leave_messages.html.erb index dee8b7443..986823faa 100644 --- a/app/views/admin/leave_messages.html.erb +++ b/app/views/admin/leave_messages.html.erb @@ -59,12 +59,12 @@ <%= format_date(journal.created_on) %> - + <%case journal.jour_type %> <% when 'Principal' %> - <%= link_to(journal.notes.html_safe, feedback_path(journal.jour_id)) %> + <%= link_to(strip_html(journal.notes), feedback_path(journal.jour_id)) %> <% when 'Course' %> - <%= link_to(journal.notes.html_safe, course_feedback_path(journal.jour_id)) %> + <%= link_to(strip_html(journal.notes), course_feedback_path(journal.jour_id)) %> <% end %> diff --git a/app/views/users/_user_jours_list.html.erb b/app/views/users/_user_jours_list.html.erb index afd498d06..6211aac7d 100644 --- a/app/views/users/_user_jours_list.html.erb +++ b/app/views/users/_user_jours_list.html.erb @@ -5,7 +5,7 @@ <%if jours %> <% jours.each do |jour|%> - <% unless jour.private == 1 && (!User.current || (User.current && jour.jour_id != User.current.id && jour.user_id != User.current.id)) %> + <% unless jour.private == 1 && (!User.current || (User.current && jour.jour_id != User.current.id && jour.user_id != User.current.id && !User.current.admin?)) %> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/javascripts/wechat/CommentBox.jsx b/public/javascripts/wechat/CommentBox.jsx deleted file mode 100644 index 7f30b38b1..000000000 --- a/public/javascripts/wechat/CommentBox.jsx +++ /dev/null @@ -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( -
- - -
- ); - } -}); - -var CommentList = React.createClass({ - render: function(){ - - var commentNodes = this.props.data.map(function(comment){ - return ( - - {comment.text} - - ) - }); - - return ( -
- {commentNodes} -
- ); - } -}); - -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 ( -
- - - -
- ); - } -}); - - -var Comment = React.createClass({ - - rawMarkup: function() { - var rawMarkup = marked(this.props.children.toString(), {sanitize: true}); - return { __html: rawMarkup }; - }, - - render: function(){ - return ( -
-

- {this.props.author} -

- -
- ) - } -}) - -React.render(, document.getElementById("example")); \ No newline at end of file diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index ca9682db2..adf445b51 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -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,'
'); - - 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: '
加载中...
', - }; -}]); - -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; - } - }; - }); -}]); diff --git a/public/javascripts/wechat/auth.js b/public/javascripts/wechat/auth.js deleted file mode 100644 index f9c2917fc..000000000 --- a/public/javascripts/wechat/auth.js +++ /dev/null @@ -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); - } - }); - } -}); \ No newline at end of file diff --git a/public/javascripts/wechat/blog_detail.js b/public/javascripts/wechat/blog_detail.js deleted file mode 100644 index 44121f83c..000000000 --- a/public/javascripts/wechat/blog_detail.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Created by root on 4/1/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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('
回复
'); - $(".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 + ")"); - } - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js new file mode 100644 index 000000000..732772e13 --- /dev/null +++ b/public/javascripts/wechat/controllers/activity.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/add_class.js b/public/javascripts/wechat/controllers/add_class.js new file mode 100644 index 000000000..099bb8e8e --- /dev/null +++ b/public/javascripts/wechat/controllers/add_class.js @@ -0,0 +1,4 @@ + +app.controller('AddClassController', ['$scope',function($scope){ + +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js new file mode 100644 index 000000000..56589122a --- /dev/null +++ b/public/javascripts/wechat/controllers/blog.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/course_notice.js b/public/javascripts/wechat/controllers/course_notice.js new file mode 100644 index 000000000..9a60d2222 --- /dev/null +++ b/public/javascripts/wechat/controllers/course_notice.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/discussion.js b/public/javascripts/wechat/controllers/discussion.js new file mode 100644 index 000000000..479f473bf --- /dev/null +++ b/public/javascripts/wechat/controllers/discussion.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/homework.js b/public/javascripts/wechat/controllers/homework.js new file mode 100644 index 000000000..5fb890741 --- /dev/null +++ b/public/javascripts/wechat/controllers/homework.js @@ -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); + }; +}); diff --git a/public/javascripts/wechat/controllers/issue.js b/public/javascripts/wechat/controllers/issue.js new file mode 100644 index 000000000..53bdbf265 --- /dev/null +++ b/public/javascripts/wechat/controllers/issue.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/journals.js b/public/javascripts/wechat/controllers/journals.js new file mode 100644 index 000000000..c292b1932 --- /dev/null +++ b/public/javascripts/wechat/controllers/journals.js @@ -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); + }; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/course_discussion.js b/public/javascripts/wechat/course_discussion.js deleted file mode 100644 index e01b6b451..000000000 --- a/public/javascripts/wechat/course_discussion.js +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Created by root on 4/1/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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('
回复
'); - $(".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 + ")"); - }*/ - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/course_notice.js b/public/javascripts/wechat/course_notice.js deleted file mode 100644 index 546aac385..000000000 --- a/public/javascripts/wechat/course_notice.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Created by root on 4/1/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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('
回复
'); - $(".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 + ")"); - } - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/directives/input_auto.js b/public/javascripts/wechat/directives/input_auto.js new file mode 100644 index 000000000..bcb44141e --- /dev/null +++ b/public/javascripts/wechat/directives/input_auto.js @@ -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'); + }); + } + } +}); \ No newline at end of file diff --git a/public/javascripts/wechat/directives/loading_spinner.js b/public/javascripts/wechat/directives/loading_spinner.js new file mode 100644 index 000000000..780056828 --- /dev/null +++ b/public/javascripts/wechat/directives/loading_spinner.js @@ -0,0 +1,7 @@ +app.directive('loadingSpinner', ['$http', function ($http) { + return { + restrict: 'A', + replace: true, + template: '
加载中...
', + }; +}]); diff --git a/public/javascripts/wechat/gulpfile.js b/public/javascripts/wechat/gulpfile.js index 439b6ae5d..ea0649376 100644 --- a/public/javascripts/wechat/gulpfile.js +++ b/public/javascripts/wechat/gulpfile.js @@ -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')) +}); diff --git a/public/javascripts/wechat/homework_detail.js b/public/javascripts/wechat/homework_detail.js deleted file mode 100644 index 166ed20bf..000000000 --- a/public/javascripts/wechat/homework_detail.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Created by root on 3/31/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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('
回复
'); - $(".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 + ")"); - };*/ - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/issue_detail.js b/public/javascripts/wechat/issue_detail.js deleted file mode 100644 index 2b2766d29..000000000 --- a/public/javascripts/wechat/issue_detail.js +++ /dev/null @@ -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=''; - - - 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('
回复
'); - $(".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 + ")"); - };*/ - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/message_detail.js b/public/javascripts/wechat/message_detail.js deleted file mode 100644 index 279da05d9..000000000 --- a/public/javascripts/wechat/message_detail.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Created by root on 4/1/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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('
回复
'); - $(".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 + ")"); - } - - -}); \ No newline at end of file diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js new file mode 100644 index 000000000..955ca2faf --- /dev/null +++ b/public/javascripts/wechat/others/factory.js @@ -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,'
'); + + 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}; +}); \ No newline at end of file diff --git a/public/javascripts/wechat/others/filter.js b/public/javascripts/wechat/others/filter.js new file mode 100644 index 000000000..2f57c2417 --- /dev/null +++ b/public/javascripts/wechat/others/filter.js @@ -0,0 +1,5 @@ +app.filter('safeHtml', function ($sce) { + return function (input) { + return $sce.trustAsHtml(input); + } +}); \ No newline at end of file diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js new file mode 100644 index 000000000..270c16edd --- /dev/null +++ b/public/javascripts/wechat/others/routes.js @@ -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; + } + }; + }); +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/project_discussion.js b/public/javascripts/wechat/project_discussion.js deleted file mode 100644 index 94cdcea10..000000000 --- a/public/javascripts/wechat/project_discussion.js +++ /dev/null @@ -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=''; - - - 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('
回复
'); - $(".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 + ")"); - }*/ - - -}); \ No newline at end of file From 01bd394a59a5467b614b0e95a1a3026c80aaf0dc Mon Sep 17 00:00:00 2001 From: Linda <2294690300@qq.com> Date: Tue, 14 Jun 2016 15:08:13 +0800 Subject: [PATCH 012/156] =?UTF-8?q?=E9=97=A8=E6=88=B7=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E7=A5=8E=E6=AC=A30613=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/_org_custom_header.html.erb | 13 ++-- .../organizations/_org_custom_left1.html.erb | 66 +++--------------- .../organizations/_org_custom_left3.html.erb | 8 +-- .../organizations/_org_custom_right3.html.erb | 26 ------- public/stylesheets/org2.css | 2 +- public/stylesheets/org_custom.css | 68 +++++++------------ public/stylesheets/public.css | 2 +- 7 files changed, 48 insertions(+), 137 deletions(-) diff --git a/app/views/organizations/_org_custom_header.html.erb b/app/views/organizations/_org_custom_header.html.erb index 91ca5aafb..e1dd1d65b 100644 --- a/app/views/organizations/_org_custom_header.html.erb +++ b/app/views/organizations/_org_custom_header.html.erb @@ -1,10 +1,10 @@
-
- <%= image_tag(url_to_avatar(@organization), width:"67", height: "61", :id => 'nh_user_tx', :class => "por_logo fl ", :target => "_blank") %> +
+ <%= image_tag(url_to_avatar(@organization), width:"51", height: "51", :id => 'nh_user_tx', :class => "por_logo fl mt1", :target => "_blank") %> <% if User.current.logged? %> diff --git a/app/views/organizations/_org_custom_left1.html.erb b/app/views/organizations/_org_custom_left1.html.erb index 4c1271ab8..7661b64d0 100644 --- a/app/views/organizations/_org_custom_left1.html.erb +++ b/app/views/organizations/_org_custom_left1.html.erb @@ -8,11 +8,11 @@
    <% if acts.count > 1 %> - <% acts[1..2].each do |activity| %> + <% acts[1..3].each do |activity| %> <% if activity.container_type == 'Organization' && activity.org_act_type == 'OrgDocumentComment' %> <% document = activity.org_act %>
  • - <%= link_to "热门推荐#{document.title}".html_safe, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), class: 'por_hot_title link-black', :target => "_blank", :title => document.title %> + <%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), class: 'por_hot_title link-black', :target => "_blank", :title => document.title %>

    <%= time_from_now(document.created_at) %> <%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %>

    @@ -25,7 +25,7 @@ <% title = message.parent_id.nil? ? message.subject : message.parent.subject %> <% if message.board.org_subfield_id %>
  • - <%= link_to "热门推荐#{title}".html_safe, board_message_url_in_org(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %> + <%= link_to document.title, board_message_url_in_org(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %>

    <%= time_from_now(message.created_on) %> <%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %>

    @@ -33,7 +33,7 @@
  • <% else %>
  • - <%= link_to "热门推荐#{title}".html_safe, board_message_path(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %> + <%= link_to document.title, board_message_path(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %>

    <%= time_from_now(message.created_on) %> <%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %>

    @@ -44,7 +44,7 @@ <% if activity.org_act_type == 'News' and News.where("id=?", activity.org_act_id).count > 0 %> <% news = activity.org_act %>
  • - <%= link_to "热门推荐#{news.title}".html_safe, news_path(news), class: 'por_hot_title link-black', :target => "_blank", :title => news.title %> + <%= link_to news.title, news_path(news), class: 'por_hot_title link-black', :target => "_blank", :title => news.title %>

    <%= time_from_now(news.created_on) %> <%= link_to news.author.show_name, user_path(news.author), :class => "por_hot_name link-blue", :target => "_blank" %>

    @@ -54,54 +54,6 @@ <% end %> <% end %> <% end %> - - <% if acts.count > 3 %> - <% activity = acts[3] %> - <% if activity.container_type == 'Organization' && activity.org_act_type == 'OrgDocumentComment' %> - <% document = activity.org_act %> -
  • - <%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), class: 'por_hot_title link-black', :target => "_blank", :title => document.title %> -

    <%= time_from_now(document.created_at) %> - <%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %> -

    - <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => document.id, :content=> document.content, :maxheight => 60, :maxwordsnum => 80, :maxwidth => 0, :cl => "por_hot_txt"} %> -
  • - <% else activity.container_type == 'OrgSubfield' %> - <% if activity.org_act_type == 'Message' and activity.org_act_id and Message.where("id=#{activity.org_act_id}").count > 0 %> - <% message = activity.org_act %> - <% content = message.parent_id.nil? ? message.content : message.parent.content %> - <% title = message.parent_id.nil? ? message.subject : message.parent.subject %> - <% if message.board.org_subfield_id %> -
  • - <%= link_to title, board_message_url_in_org(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %> -

    <%= time_from_now(message.created_on) %> - <%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %> -

    - <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => message.id, :content=> content, :maxheight => 60, :maxwordsnum => 80, :maxwidth => 0, :cl => "por_hot_txt"} %> -
  • - <% else %> -
  • - <%= link_to title, board_message_path(message.board.id,message.id), class: 'por_hot_title link-black', :target => "_blank", :title => title %> -

    <%= time_from_now(message.created_on) %> - <%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %> -

    - <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => message.id, :content=> content, :maxheight => 60, :maxwordsnum => 80, :maxwidth => 0, :cl => "por_hot_txt"} %> -
  • - <% end %> - <% end %> - <% if activity.org_act_type == 'News' and News.where("id=?", activity.org_act_id).count > 0 %> - <% news = activity.org_act %> -
  • - <%= link_to news.title, news_path(news), class: 'por_hot_title link-black', :target => "_blank", :title => news.title %> -

    <%= time_from_now(news.created_on) %> - <%= link_to news.author.show_name, user_path(news.author), :class => "por_hot_name link-blue", :target => "_blank" %> -

    - <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => news.id, :content=> news.description, :maxheight => 60, :maxwordsnum => 80, :maxwidth => 0, :cl => "por_hot_txt"} %> -
  • - <% end %> - <% end %> - <% end %> -
<%# if acts.count > 3 %> @@ -114,9 +66,11 @@ <% else %> <%= link_to image_tag("/files/uploads/image#{get_image_path_from_content(document.content)}", :width => "299", :height => "246"), org_document_comment_path(:id => document.id, :organization_id => document.organization.id), :target => "_blank" %> <% end %> - <%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), :class => 'por_hot_title_r link-black', :target => "_blank", :title => document.title %> -

<%= time_from_now(document.created_at) %><%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %>

- <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => document.id, :content=> document.content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +
+ <%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), :class => 'por_hot_title_r link-black', :target => "_blank", :title => document.title %> +

<%= time_from_now(document.created_at) %><%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %>

+ <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => document.id, :content=> document.content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +
<% else activity.container_type == 'OrgSubfield' %> diff --git a/app/views/organizations/_org_custom_left3.html.erb b/app/views/organizations/_org_custom_left3.html.erb index 3d5d01dee..fb2b83dd2 100644 --- a/app/views/organizations/_org_custom_left3.html.erb +++ b/app/views/organizations/_org_custom_left3.html.erb @@ -71,8 +71,8 @@ <% end %> <% end %>
- <% unless acts[1..5].nil? %> - <% acts[1..5].each do |activity| %> + <% unless acts[1..4].nil? %> + <% acts[1..4].each do |activity| %> <% if activity.container_type == 'Organization' && activity.org_act_type == 'OrgDocumentComment' %> <% document = activity.org_act %>
    @@ -110,10 +110,10 @@ <% end %> <% end %>
- <% unless acts[6..19].nil? %> + <% unless acts[5..16].nil? %>
    - <% acts[6..19].each do |activity| %> + <% acts[6..16].each do |activity| %> <% if activity.container_type == 'Organization' && activity.org_act_type == 'OrgDocumentComment' %> <% document = activity.org_act %>
  • <%= link_to "#{document.title}".html_safe, org_document_comment_path(:id => document.id, :organization_id => document.organization.id), class: 'por_hidden_w270 link-black', :target => "_blank" %>
  • diff --git a/app/views/organizations/_org_custom_right3.html.erb b/app/views/organizations/_org_custom_right3.html.erb index a461a38dc..a7f819ca2 100644 --- a/app/views/organizations/_org_custom_right3.html.erb +++ b/app/views/organizations/_org_custom_right3.html.erb @@ -33,9 +33,6 @@
  • 名师风采
  • -
  • - 学生英雄榜 -
@@ -65,29 +62,6 @@ <% end %>
-
-
    - <% excellent_students.each do |student| %> -
  • - <%= link_to image_tag(url_to_avatar(student), :width => "43", :height => "43", :class => "por_teachers_img fl mr15"), user_path(student), :alt => "用户头像", :target => '_blank', :class => "fl" %> -
    - <%=link_to student.try(:realname) ? student.try(:realname) :student.try(:login), user_path(student), :class => "por_teachers_name link-black fl", :target => '_blank' %> -

    <%= student.my_workplace %>

    -
    -

    - <% unless student.my_blogs_count == 0 %> - 博客 <%= student.my_blogs_count %> - <% end %> - <% unless student.courses.count == 0 %> - 课程 <%= student.courses.count %> - <% end %> -

    -
    -
    -
  • - <% end %> -
-
\ No newline at end of file diff --git a/public/javascripts/course.js b/public/javascripts/course.js index 9f6b6aabd..6fbf9f8c4 100644 --- a/public/javascripts/course.js +++ b/public/javascripts/course.js @@ -550,7 +550,7 @@ function check_late_penalty(id) } else { - obj.val("0"); + obj.val(""); } } diff --git a/public/javascripts/new_user.js b/public/javascripts/new_user.js index b6301afad..2771dd191 100644 --- a/public/javascripts/new_user.js +++ b/public/javascripts/new_user.js @@ -259,6 +259,24 @@ function regex_evaluation_end(){ } } +//处理迟交、缺评扣分 +function check_late_penalty(id) +{ + var obj = $("#" + id); + var regex = /^\d+$/; + if(regex.test(obj.val())) + { + if(obj.val() > 50) + { + obj.val("50"); + } + } + else + { + obj.val(""); + } +} + //验证匿评数量 function regex_evaluation_num(){ var evaluation_num = $.trim($("#evaluation_num").val()); From ada15b42123536486f0e62f76cb5f3072ccebd06 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 14 Jun 2016 16:03:10 +0800 Subject: [PATCH 014/156] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=8A=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4,=20=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=88=86=E5=BC=80=E5=86=99,=E4=BD=86=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=B6=E6=89=93=E6=88=90=E4=B8=80=E4=B8=AAjs=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/wechats/user_activities.html.erb | 4 +- public/assets/wechat/app.html | 13 ++++- public/javascripts/wechat/app.js | 7 --- public/javascripts/wechat/build/app.min.js | 14 +++++ .../wechat/controllers/activity.js | 6 +- public/javascripts/wechat/controllers/blog.js | 6 +- .../wechat/controllers/course_notice.js | 5 +- .../wechat/controllers/discussion.js | 4 +- .../wechat/controllers/homework.js | 4 +- .../javascripts/wechat/controllers/issue.js | 4 +- .../wechat/controllers/journals.js | 4 +- public/javascripts/wechat/others/factory.js | 12 ++-- public/javascripts/wechat/others/filter.js | 4 +- public/javascripts/wechat/others/routes.js | 4 +- public/javascripts/wechat/wechat_dev.js | 57 ------------------- script/assets | 3 + 16 files changed, 59 insertions(+), 92 deletions(-) create mode 100644 public/javascripts/wechat/build/app.min.js delete mode 100644 public/javascripts/wechat/wechat_dev.js create mode 100644 script/assets diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index 3d61d8fcf..073d45495 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -13,6 +13,8 @@ @@ -21,7 +23,7 @@ - + \ No newline at end of file diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html index d88efe50f..cabd224c4 100644 --- a/public/assets/wechat/app.html +++ b/public/assets/wechat/app.html @@ -2,7 +2,7 @@ - 我的动态 + 仅供本地调试使用 @@ -17,7 +17,15 @@
+ + + + @@ -33,6 +41,9 @@ + + + \ No newline at end of file diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index adf445b51..4d947e440 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -1,8 +1 @@ var app = angular.module('wechat', ['ngRoute']); -var apiUrl = '/api/v1/'; -var debug = true; //调试标志,如果在本地请置为true - -if(debug===true){ - apiUrl = 'http://localhost:3000/api/v1/'; - //apiUrl = 'http://www.trustie.net/api/v1/'; -} diff --git a/public/javascripts/wechat/build/app.min.js b/public/javascripts/wechat/build/app.min.js new file mode 100644 index 000000000..d8eacbf1b --- /dev/null +++ b/public/javascripts/wechat/build/app.min.js @@ -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,"
"),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
加载中...
'}}]); +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}}}])}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js index 732772e13..e17b7c5b3 100644 --- a/public/javascripts/wechat/controllers/activity.js +++ b/public/javascripts/wechat/controllers/activity.js @@ -1,5 +1,7 @@ -app.controller('ActivityController',function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){ +app.controller('ActivityController', + ['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common', + function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){ $scope.replaceUrl = function(url){ return url; }; @@ -63,4 +65,4 @@ app.controller('ActivityController',function($anchorScroll, $location,$scope, $h $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js index 56589122a..8eb45b604 100644 --- a/public/javascripts/wechat/controllers/blog.js +++ b/public/javascripts/wechat/controllers/blog.js @@ -1,5 +1,7 @@ -app.controller('BlogController', function($scope, $http, $routeParams, auth, common){ +app.controller('BlogController', + ['$scope', '$http', '$routeParams', 'auth', 'common', + function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -35,4 +37,4 @@ app.controller('BlogController', function($scope, $http, $routeParams, auth, com console.log(act); common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/course_notice.js b/public/javascripts/wechat/controllers/course_notice.js index 9a60d2222..24b0fdbe1 100644 --- a/public/javascripts/wechat/controllers/course_notice.js +++ b/public/javascripts/wechat/controllers/course_notice.js @@ -1,4 +1,5 @@ -app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){ +app.controller('CourseNoticeController', ['$scope', '$http', '$routeParams', 'auth', 'common', + function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -32,4 +33,4 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/discussion.js b/public/javascripts/wechat/controllers/discussion.js index 479f473bf..4828cb39a 100644 --- a/public/javascripts/wechat/controllers/discussion.js +++ b/public/javascripts/wechat/controllers/discussion.js @@ -1,5 +1,5 @@ -app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){ +app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('DiscussionController', function($scope, $http, $routeParams, aut $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/homework.js b/public/javascripts/wechat/controllers/homework.js index 5fb890741..795bf30e9 100644 --- a/public/javascripts/wechat/controllers/homework.js +++ b/public/javascripts/wechat/controllers/homework.js @@ -1,5 +1,5 @@ -app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){ +app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('HomeworkController', function($scope, $http, $routeParams, auth, $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); +}]); diff --git a/public/javascripts/wechat/controllers/issue.js b/public/javascripts/wechat/controllers/issue.js index 53bdbf265..09602f9e1 100644 --- a/public/javascripts/wechat/controllers/issue.js +++ b/public/javascripts/wechat/controllers/issue.js @@ -1,4 +1,4 @@ -app.controller('IssueController', function($scope, $http, $routeParams, auth, common){ +app.controller('IssueController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/journals.js b/public/javascripts/wechat/controllers/journals.js index c292b1932..f379525d7 100644 --- a/public/javascripts/wechat/controllers/journals.js +++ b/public/javascripts/wechat/controllers/journals.js @@ -1,4 +1,4 @@ -app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){ +app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -34,4 +34,4 @@ app.controller('JournalsController', function($scope, $http, $routeParams, auth, console.log(act); common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 955ca2faf..cefef3ab9 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -1,14 +1,10 @@ -app.factory('auth', function($http,$routeParams, $q){ +app.factory('auth', ['$http','$routeParams', '$q', 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){ @@ -32,7 +28,7 @@ app.factory('auth', function($http,$routeParams, $q){ return _openid; }; return {getOpenId: getOpenId, openid: openid}; -}); +}]); app.factory('rms', function(){ @@ -48,7 +44,7 @@ app.factory('rms', function(){ return {save: save, get: get}; }); -app.factory('common', function($http, auth, $routeParams){ +app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $routeParams){ var addCommonReply = function(id, type, data, cb){ if(!data.comment || data.comment.length<=0){ @@ -117,4 +113,4 @@ app.factory('common', function($http, auth, $routeParams){ }; return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise}; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/filter.js b/public/javascripts/wechat/others/filter.js index 2f57c2417..dcb8e9e6a 100644 --- a/public/javascripts/wechat/others/filter.js +++ b/public/javascripts/wechat/others/filter.js @@ -1,5 +1,5 @@ -app.filter('safeHtml', function ($sce) { +app.filter('safeHtml', ['$sce',function ($sce) { return function (input) { return $sce.trustAsHtml(input); } -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index 270c16edd..7ea270c6e 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -43,7 +43,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou }); //监听异步请求,实现加载中显隐标记 - $httpProvider.interceptors.push(function ($q, $rootScope) { + $httpProvider.interceptors.push(['$q', '$rootScope', function ($q, $rootScope) { if ($rootScope.activeCalls == undefined) { $rootScope.activeCalls = 0; } @@ -66,5 +66,5 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou return rejection; } }; - }); + }]); }]); \ No newline at end of file diff --git a/public/javascripts/wechat/wechat_dev.js b/public/javascripts/wechat/wechat_dev.js deleted file mode 100644 index 36529e0b8..000000000 --- a/public/javascripts/wechat/wechat_dev.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Created by root on 3/25/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_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); -}); diff --git a/script/assets b/script/assets new file mode 100644 index 000000000..bf4501127 --- /dev/null +++ b/script/assets @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cd public/javascripts/wechat && gulp && gulp minify From c50d307e897974d09401b34b1544fcbeca505088 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 14 Jun 2016 17:36:12 +0800 Subject: [PATCH 015/156] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=88=90=E5=91=98=E5=90=8E=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E6=89=93=E5=BC=80=EF=BC=8C=E6=95=B0=E6=8D=AE=E6=9C=AA=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 14 +++++++++++ .../_choose_group_member.html.erb | 25 +++++++++++++++++++ .../search_course_students.js.erb | 5 ++-- config/routes.rb | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 10431f01a..9e537d551 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1115,6 +1115,20 @@ class StudentWorkController < ApplicationController end end + def get_user_infor + req = Hash.new(false) + user = User.where("id = #{params[:user_id].to_i}").first + if user + req[:id] = user.id + req[:name] = user.show_name + req[:student_id] = user.user_extensions.student_id + req[:valid] = true + else + req[:valid] = false + end + render :json => req + end + private def searchstudent_by_name users, name mems = [] diff --git a/app/views/student_work/_choose_group_member.html.erb b/app/views/student_work/_choose_group_member.html.erb index c47c31d9d..b76f94511 100644 --- a/app/views/student_work/_choose_group_member.html.erb +++ b/app/views/student_work/_choose_group_member.html.erb @@ -105,6 +105,31 @@ $("#choose_students_list").append(link); <% end %> <% end %> + var ids = $("#group_member_ids").val().split(','); + if (ids.length > 1){ + for(var i=1; i"+data.name; + if (data.student_id != "" ) { + link += "("+data.student_id+")"; + } + link += ""; + $("#choose_students_list").append(link); + } + else + { + + } + } + ); + } + } }); <% end %> \ No newline at end of file diff --git a/app/views/student_work/search_course_students.js.erb b/app/views/student_work/search_course_students.js.erb index c7aa982b9..2ac4eeaab 100644 --- a/app/views/student_work/search_course_students.js.erb +++ b/app/views/student_work/search_course_students.js.erb @@ -7,7 +7,8 @@ $("#all_students_list").empty(); link += ""; $("#all_students_list").append(link); - var str = ""; + var str = $("#group_member_ids").val(); + /*var str = ""; var lists = $("#choose_students_list li"); if(lists.length > 0) { for(var i=0; i if (str.indexOf(<%=user.id.to_s %>) < 0) { $("#student_<%=user.id %>").one("click",function choose_student() { diff --git a/config/routes.rb b/config/routes.rb index 91ab5cffe..2c1362359 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -329,6 +329,7 @@ RedmineApp::Application.routes.draw do post 'last_codecomparetime' post 'set_score_rule' get 'work_canrepeat' + get 'get_user_infor' end end From 8fd4d518b26b159b6fe5040497c49b0944cc24af Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 15 Jun 2016 13:44:28 +0800 Subject: [PATCH 016/156] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=80=E8=AF=B7?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/api.rb | 3 +- app/api/mobile/apis/courses.rb | 25 ++++++-------- app/helpers/api_helper.rb | 22 ++++++++++++ app/models/course.rb | 19 +++++++++++ app/services/courses_service.rb | 34 ++++++++++++------- ...0160614072229_add_invite_code_to_course.rb | 5 +++ db/schema.rb | 3 +- 7 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20160614072229_add_invite_code_to_course.rb diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c86a36d05..058687776 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -67,8 +67,7 @@ module Mobile mount Apis::NewComment mount Apis::Praise - #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) - #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? + add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? end end diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 3a36a9e37..b585e7dae 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -97,25 +97,22 @@ module Mobile desc "加入课程" params do - requires :course_password, type: String + optional :openid, type: String, desc: '微信ID' + requires :invite_code, type: String, desc: '邀请码' end - post ":id" do + post "join" do authenticate! + cs = CoursesService.new - status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user) - out = {status: status[:state]} - message = case status[:state] - when 0; "加入成功" - when 1; "密码错误" - when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)" - when 3; "您已经加入了课程" - when 4; "您加入的课程不存在" - when 5; "您还未登录" - else; "未知错误,请稍后再试" - end - out.merge(message: message) + status = cs.join_course({openid: params[:openid], invite_code: params[:invite_code]}, current_user) + + { + status: status[:state], + messsge:CoursesService::JoinCourseError.message(status[:state]) + } end + desc "退出课程" params do requires :token, type: String diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index fb1231287..e993b120f 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -489,4 +489,26 @@ module ApiHelper self.update_attribute(:praise_num, self.praise_num.to_i - num) end + + class Errors + def self.define_error(arr) + @errors = {} + arr.each_with_index { |item, index| + if index %2 == 1 + @errors[arr[index-1]] = item + end + } + if arr.count % 2== 1 + @default_error = arr.last + else + @default_error = "未知错误" + end + + end + + def self.message(msg_id) + @errors[msg_id] || @default_error + end + end + end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 69dbec5d0..d379b24d3 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,3 +1,5 @@ +#coding=utf-8 + require 'elasticsearch/model' class Course < ActiveRecord::Base include Redmine::SafeAttributes @@ -404,6 +406,7 @@ class Course < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) end + #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 #def name # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) @@ -450,6 +453,22 @@ class Course < ActiveRecord::Base end end + # 生成邀请码 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_invite_code + code = invite_code + if !invite_code || invite_code.size <6 + self.invite_code = CODES.sample(6).join + save! && reload + code = invite_code + end + code + end + + def + + end + end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 2c8387349..93529f57c 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -300,23 +300,31 @@ class CoursesService @state end + class JoinCourseError < Errors + define_error [ + 0, '加入成功', + 1, '密码错误', + 2, '课程已过期 请联系课程管理员重启课程。', + 3, '您已经加入了课程', + 4, '您加入的课程不存在', + 5, '您还未登录', + 6, '申请成功,请等待审核完毕', + 7, '您已经发送过申请了,请耐心等待', + 8, '您已经是该课程的教师了', + 9, '您已经是该课程的教辅了', + 10, '您已经是该课程的管理员了', + '未知错误,请稍后再试' + ] + end #加入课程 #object_id:课程id #course_password :加入课程的密码 - #@state == 0 加入成功 - #@state == 1 密码错误 - #@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处) - #@state == 3 您已经加入了课程 - #@state == 4 您加入的课程不存在 - #@state == 5 您还未登录 - #@state == 6 申请成功,请等待审核完毕 - #@state == 7 您已经发送过申请了,请耐心等待 - #@state == 8 您已经是该课程的教师了 - #@state == 9 您已经是该课程的教辅了 - #@state == 10 您已经是该课程的管理员了 - #@state 其他 未知错误,请稍后再试 def join_course params,current_user - course = Course.find_by_id params[:object_id] + course = if params[:invite_code] + Course.find_by_invite_code(params[:invite_code]) + else + Course.find_by_id params[:object_id] + end @state = 10 if course diff --git a/db/migrate/20160614072229_add_invite_code_to_course.rb b/db/migrate/20160614072229_add_invite_code_to_course.rb new file mode 100644 index 000000000..8f7bb8da1 --- /dev/null +++ b/db/migrate/20160614072229_add_invite_code_to_course.rb @@ -0,0 +1,5 @@ +class AddInviteCodeToCourse < ActiveRecord::Migration + def change + add_column :courses, :invite_code, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 95ffceef1..820c6a035 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160612043259) do +ActiveRecord::Schema.define(:version => 20160614072229) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -550,6 +550,7 @@ ActiveRecord::Schema.define(:version => 20160612043259) do t.integer "excellent_option", :default => 0 t.integer "is_copy", :default => 0 t.integer "visits", :default => 0 + t.string "invite_code" end create_table "custom_fields", :force => true do |t| From caa966c85a52a40c70bfb950e37b05913b6ce165 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 15 Jun 2016 14:12:42 +0800 Subject: [PATCH 017/156] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=20=E5=88=86=E7=BB=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=8F=90=E4=BA=A4=E4=BD=9C=E5=93=81=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E4=BA=BA=E6=95=B0=E9=99=90=E5=88=B6=E4=B8=8D?= =?UTF-8?q?=E8=B5=B7=E4=BD=9C=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 3 +- .../_choose_group_member.html.erb | 48 ++++++++----------- .../student_work/_student_work_list.html.erb | 15 ++++-- app/views/student_work/edit.html.erb | 26 +++++----- app/views/student_work/new.html.erb | 26 +++++----- app/views/student_work/retry_work.js.erb | 3 +- 6 files changed, 56 insertions(+), 65 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9e537d551..22047efee 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1096,7 +1096,8 @@ class StudentWorkController < ApplicationController all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")" end all_students = User.where("id in #{all_student_ids}") - @commit_student_ids = @homework.student_work_projects.map{|student| student.user_id} + student_work_id = @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id + @commit_student_ids = @homework.student_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| format.js diff --git a/app/views/student_work/_choose_group_member.html.erb b/app/views/student_work/_choose_group_member.html.erb index b76f94511..e7d776cea 100644 --- a/app/views/student_work/_choose_group_member.html.erb +++ b/app/views/student_work/_choose_group_member.html.erb @@ -93,41 +93,31 @@ url: '<%= url_for(:controller => 'student_work', :action => 'search_course_students') %>'+'?homework='+<%=@homework.id %>, type:'get' }); - <% if defined?(edit_mode) && edit_mode %> - <% pro = @homework.student_work_projects.where("user_id = ?",User.current.id).first.project_id.to_i %> - <% members = @homework.student_work_projects.where("project_id = ? and is_leader =?",pro,0) %> - <% members.each do |member| %> - var link = "
  • <%=member.user.show_name %>"; - <% unless member.user.user_extensions.student_id == "" %> - link += "(<%=member.user.user_extensions.student_id %>)"; - <% end %> - link += "
  • "; - $("#choose_students_list").append(link); - <% end %> - <% end %> var ids = $("#group_member_ids").val().split(','); if (ids.length > 1){ for(var i=1; i"+data.name; - if (data.student_id != "" ) { - link += "("+data.student_id+")"; - } - link += ""; - $("#choose_students_list").append(link); - } - else + if($("#choose_student_"+ids[i]).length == 0) { + $.get( + '/student_work/get_user_infor', { + user_id: ids[i] + }, + function (data) { + if (data.valid) { + var link = "
  • "+data.name; + if (data.student_id != "" ) { + link += "("+data.student_id+")"; + } + link += "
  • "; + $("#choose_students_list").append(link); + } + else + { + } } - } - ); + ); + } } } }); diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb index eaf6b9304..cc078bf9c 100644 --- a/app/views/student_work/_student_work_list.html.erb +++ b/app/views/student_work/_student_work_list.html.erb @@ -4,14 +4,21 @@ (<%= @student_work_count%>人已交) - <% my_work = @homework.student_works.where("user_id = #{User.current.id}").first %> + <%# my_work = @homework.student_works.where("user_id = #{User.current.id}").first %> + <% my_work = cur_user_works_for_homework @homework %> <% if !@is_teacher && my_work.nil? && User.current.member_of_course?(@course) %> 您尚未提交作品 - <%=link_to "提交作品", new_student_work_url_without_domain(@homework.id),:class => 'blueCir ml5 f12' %> + <% unless @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> + <%=link_to "提交作品", new_student_work_url_without_domain(@homework.id),:class => 'blueCir ml5 f12' %> + <% end %> <% elsif !@is_teacher && my_work &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> - 您已提交且不可再修改,因为截止日期已过 + 已提交且不可再修改,因为截止日期已过 <% elsif !@is_teacher && my_work &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> - 您已提交,您还可以修改 + <% if @homework.homework_type == 3 %> + 组长已提交,组长还可修改 + <% else %> + 您已提交,您还可以修改 + <% end %> <% end %> <%if @is_teacher || @homework.homework_detail_manual.comment_status == 3 || @homework.is_open == 1%> diff --git a/app/views/student_work/edit.html.erb b/app/views/student_work/edit.html.erb index 8e1a2a546..ed0b369e8 100644 --- a/app/views/student_work/edit.html.erb +++ b/app/views/student_work/edit.html.erb @@ -103,21 +103,11 @@ } function popupRegex(){ - if($("#group_member_ids").length > 0) { - if(regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html())))) { - $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); - showModal('ajax-modal', '500px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("anonymos"); - } - } else { - $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); - showModal('ajax-modal', '500px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("anonymos"); - } + $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); + showModal('ajax-modal', '500px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); + $('#ajax-modal').parent().addClass("anonymos"); } function nh_check_field(params){ @@ -140,6 +130,12 @@ params.contentmsg.html(''); } } + if(!result) { + return result; + } + } + if($("#group_member_ids").length > 0) { + result=regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html()))); } return result; } diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index 453f717c9..dfddea306 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -62,21 +62,11 @@ } // 作品校验 function popupRegex(){ - if($("#group_member_ids").length > 0) { - if(regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html())))) { - $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); - showModal('ajax-modal', '500px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("anonymos"); - } - } else { - $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); - showModal('ajax-modal', '500px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("anonymos"); - } + $('#ajax-modal').html("

    作品信息完整性校验中,请稍等...

    "); + showModal('ajax-modal', '500px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); + $('#ajax-modal').parent().addClass("anonymos"); } function nh_check_field(params){ @@ -99,6 +89,12 @@ params.contentmsg.html(''); } } + if(!result) { + return result; + } + } + if($("#group_member_ids").length > 0) { + result=regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html()))); } return result; } diff --git a/app/views/student_work/retry_work.js.erb b/app/views/student_work/retry_work.js.erb index c6f354875..c15b81e09 100644 --- a/app/views/student_work/retry_work.js.erb +++ b/app/views/student_work/retry_work.js.erb @@ -1,2 +1,3 @@ hideModal('#popbox02'); -$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => {:container => @student_work, :has_program=>false,:has_group=>false})%>"); \ No newline at end of file +$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => {:container => @student_work, :has_program=>false,:has_group=>false})%>"); +$("#group_member_ids").val("<%=User.current.id %>"); \ No newline at end of file From 43192b8648ff593c31ddb8c114d57bd1c28540a8 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 15 Jun 2016 17:04:53 +0800 Subject: [PATCH 018/156] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E5=BC=B9=E6=A1=86=E5=A2=9E=E5=8A=A0=E4=BA=BA=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=AA=8C=E8=AF=81=E3=80=81=E7=82=B9=E5=87=BB=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=BC=B9=E6=A1=86=E6=97=B6=E8=BF=98=E5=8E=9F=E5=BC=B9?= =?UTF-8?q?=E6=A1=86=E4=B8=AD=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user_group_attr.html.erb | 3 ++ public/javascripts/homework.js | 48 +++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/views/users/_user_group_attr.html.erb b/app/views/users/_user_group_attr.html.erb index 681f158e7..952a3396e 100644 --- a/app/views/users/_user_group_attr.html.erb +++ b/app/views/users/_user_group_attr.html.erb @@ -3,11 +3,14 @@
    每组最小人数: 人 +
    每组最大人数: 人 +
    +