mark-history.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //回评模块
  2. var mark_history = function(option, success) {
  3. var object = new MarkHistory(option);
  4. success();
  5. return object;
  6. }
  7. function MarkHistory(option) {
  8. this.markControl = option.markControl;
  9. //this.url = option.url;
  10. this.pageSize = option.pageSize;
  11. this.taskList = [];
  12. this.container = this.markControl.container.sidebar;
  13. this.loading = false;
  14. this.order = "time"
  15. this.sort = "desc";
  16. var isTag = false;
  17. this.markControl.initMarkFunction();
  18. this.container.toggleButton = getDom(this.toggle_button_dom, this.markControl).appendTo(this.markControl.container.assistant.functionList);
  19. this.container.toggleButton.click(this, function(event) {
  20. event.data.toggle(true);
  21. });
  22. this.markControl.on('history.get.success', this, function(event, context, data) {
  23. var taskList = data.result;
  24. this.taskList = [];
  25. this.loading = false;
  26. this.container.list.empty();
  27. if (isArray(taskList) && taskList.length > 0) {
  28. this.taskList = taskList;
  29. for (var i in taskList) {
  30. var task = taskList[i];
  31. var row = getDom(this.history_row_dom, this.markControl).appendTo(this.container.list);
  32. row.find('.history-secret-number').html(task.studentId);
  33. if(task.tags!=undefined && task.tags!=null ){
  34. row.find('.history-secret-number').addClass('tips');
  35. }
  36. var date = new Date();
  37. date.setTime(task.markTime);
  38. row.find('.history-time').html(date.format('hh:mm:ss'));
  39. row.find('.history-score').html(task.totalScore);
  40. row.attr('data-index', i);
  41. //回评任务处理
  42. task.previous = true;
  43. // task.markFinish = true;
  44. // task.totalScore = parseFloat(task.totalScore);
  45. // var scoreList = task.scoreList != undefined ? task.scoreList.split(',') : [];
  46. // for (var j in task.markStepList) {
  47. // var step = task.markStepList[j];
  48. // if (scoreList != undefined && scoreList.length > j) {
  49. // step.markScore = new Number(scoreList[j]);
  50. // step.score = new String(step.markScore);
  51. // step.markFinish = true;
  52. // }
  53. // }
  54. }
  55. }
  56. this.container.list.find('td').click(this, function(event) {
  57. var markHistory = event.data;
  58. var index = $(event.target).parent().attr('data-index');
  59. markHistory.onTaskSelect(index);
  60. });
  61. this.pageNumber = data.pageNumber;
  62. this.updatePage();
  63. this.updateSort(this.order,this.sort);
  64. if (this.taskList.length > 0) {
  65. this.onTaskSelect(0);
  66. }
  67. });
  68. this.markControl.on('history.get.error', this, function(event, context, data) {
  69. alert('暂时无法读取评卷历史,请稍后重试');
  70. });
  71. this.markControl.on('task.submit.success', this, function(event, context, data) {
  72. if (this.enable) {
  73. this.toggle(false);
  74. }
  75. });
  76. this.markControl.on('task.get.success', this, function(event, context, data) {
  77. this.loading = false;
  78. });
  79. this.markControl.on('history.submit.success', this, function(event, context, task) {
  80. if(task.previous==true){
  81. this.updateTaskScore(task.totalScore);
  82. }
  83. });
  84. }
  85. MarkHistory.prototype.init = function() {
  86. this.container.empty();
  87. this.container.paginator = getDom(this.paginator_dom, this.markControl).appendTo(this.container);
  88. this.container.header = getDom(this.header_dom, this.markControl).appendTo(this.container);
  89. this.container.search = getDom(this.history_search_dom, this.markControl).appendTo(this.container).find('#history-search');
  90. this.container.list = getDom(this.history_list_dom, this.markControl).appendTo(this.container).find('#history-list');
  91. var self = this;
  92. this.container.header.find('#close-history-button').click(this, function(event) {
  93. event.data.toggle(false);
  94. self.markControl.context.task = undefined;
  95. self.markControl.getTask();
  96. })
  97. this.container.paginator.find('#last-page-button').click(this, function(event) {
  98. var markHistory = event.data;
  99. if (markHistory.taskList.length < markHistory.pageSize) {
  100. return ;
  101. }
  102. if (self.container.search.find('#history-isTag').prop("checked")) {
  103. markHistory.isTag=true;
  104. } else{
  105. markHistory.isTag=false;
  106. }
  107. markHistory.onSearch(markHistory.pageNumber + 1,markHistory.order,markHistory.sort,markHistory.isTag);
  108. });
  109. this.container.paginator.find('#next-page-button').click(this, function(event) {
  110. var markHistory = event.data;
  111. if (markHistory.pageNumber == 1) {
  112. return ;
  113. }
  114. if (markHistory.pageNumber > 1) {
  115. if (self.container.search.find('#history-isTag').prop("checked")) {
  116. markHistory.isTag=true;
  117. } else{
  118. markHistory.isTag=false;
  119. }
  120. markHistory.onSearch(markHistory.pageNumber - 1,markHistory.order,markHistory.sort,markHistory.isTag);
  121. }
  122. });
  123. this.container.find('#studentId-search').click(this, function(event) {
  124. var markHistory = event.data;
  125. var studentId = self.container.find('#studentId-in').val();
  126. var re = /^[1-9]+[0-9]*]*$/ ;
  127. if(!re.test(studentId)){
  128. alert("请输入数字");
  129. return ;
  130. }
  131. if (self.container.search.find('#history-isTag').prop("checked")) {
  132. markHistory.isTag=true;
  133. } else{
  134. markHistory.isTag=false;
  135. }
  136. markHistory.onSearch(0,markHistory.order,markHistory.sort,markHistory.isTag,studentId);
  137. });
  138. this.container.find('#time-sort-th').click(this, function(event) {
  139. self.orderSearch("time");
  140. });
  141. this.container.find('#studentId-sort-th').click(this, function(event) {
  142. self.orderSearch("studentId");
  143. });
  144. this.container.find('#score-sort-th').click(this, function(event) {
  145. self.orderSearch("score");
  146. });
  147. self.updateSort(self.order,self.sort);
  148. self.updateLoading();
  149. this.container.find('#studentId-in').click(this, function(event) {
  150. self.markControl.trigger('mark.focus.change');
  151. });
  152. }
  153. MarkHistory.prototype.orderSearch = function(order) {
  154. this.order = order;
  155. if(this.sort == "asc"){
  156. this.sort = "desc";
  157. }else if(this.sort == "desc"){
  158. this.sort = "asc";
  159. }
  160. if (this.container.search.find('#history-isTag').prop("checked")) {
  161. this.isTag=true;
  162. } else{
  163. this.isTag=false;
  164. }
  165. this.onSearch(this.pageNumber,this.order,this.sort,this.isTag);
  166. }
  167. MarkHistory.prototype.toggle = function(enable) {
  168. this.enable = enable;
  169. if (enable) {
  170. this.init();
  171. this.pageNumber = 1;
  172. this.markControl.setTask(undefined);
  173. this.markControl.trigger('mark.sidebar.open');
  174. this.markControl.trigger('mark.history.open');
  175. this.updatePage();
  176. this.container.list.empty();
  177. this.container.show();
  178. this.onSearch();
  179. } else {
  180. this.container.hide();
  181. this.markControl.trigger('mark.sidebar.close');
  182. this.markControl.trigger('mark.history.close');
  183. }
  184. }
  185. MarkHistory.prototype.updatePage = function() {
  186. this.container.paginator.find('#history-start').html(this.pageSize * (this.pageNumber - 1));
  187. this.container.paginator.find('#history-end').html(this.pageSize * this.pageNumber);
  188. // if (this.pageNumber == 1) {
  189. // this.container.paginator.find('#next-page-button').hide();
  190. // }else{
  191. // this.container.paginator.find('#next-page-button').show();
  192. // }
  193. // if (this.taskList.length < this.pageSize) {
  194. // this.container.paginator.find('#last-page-button').hide();
  195. // } else{
  196. // this.container.paginator.find('#last-page-button').show();
  197. // }
  198. }
  199. MarkHistory.prototype.updateLoading = function() {
  200. if (this.loading) {
  201. this.container.find('#history-loading').show();
  202. }else{
  203. this.container.find('#history-loading').hide();
  204. }
  205. }
  206. MarkHistory.prototype.updateSort = function(order,sort) {
  207. this.container.find('#time-sort').removeClass();
  208. this.container.find('#studentId-sort').removeClass();
  209. this.container.find('#score-sort').removeClass();
  210. if(sort == 'desc'){
  211. this.container.find('#'+order+'-sort').addClass("down");
  212. }else{
  213. this.container.find('#'+order+'-sort').addClass("up");
  214. }
  215. }
  216. MarkHistory.prototype.onSearch = function(pageNumber,order,sort,isTag,studentId) {
  217. if (pageNumber == undefined || pageNumber < 1) {
  218. pageNumber = 1;
  219. }
  220. if (order == undefined ) {
  221. order = "time";
  222. }
  223. if (sort == undefined ) {
  224. sort = "desc";
  225. }
  226. if (isTag == undefined ) {
  227. isTag = false;
  228. }
  229. if (studentId == undefined || studentId=="") {
  230. studentId = null;
  231. }
  232. this.markControl.getHistory({
  233. pageNumber: pageNumber,
  234. pageSize: this.pageSize,
  235. order : order,
  236. sort : sort,
  237. isTag : isTag,
  238. studentId :studentId
  239. });
  240. }
  241. MarkHistory.prototype.onTaskSelect = function(index) {
  242. var number = new String(index);
  243. if (this.taskList != undefined && index < this.taskList.length && this.loading != true) {
  244. this.container.list.find('tr').each(function(index, obj) {
  245. if ($(obj).attr('data-index') == number) {
  246. $(obj).addClass('active');
  247. } else {
  248. $(obj).removeClass('active');
  249. }
  250. });
  251. var task = this.taskList[index];
  252. this.markControl.setTask(task);
  253. this.loading = true;
  254. }
  255. }
  256. MarkHistory.prototype.updateTaskScore = function(score) {
  257. this.container.list.find('tr').each(function(index, obj) {
  258. if ($(obj).hasClass("active")) {
  259. $(obj).find('td').last().html(score);
  260. }
  261. });
  262. }
  263. MarkHistory.prototype.toggle_button_dom = '<a href="#">回评</a>';
  264. MarkHistory.prototype.header_dom = '<div class="header">\
  265. <p class="fl">回评</p>\
  266. <a href="#" id="close-history-button"><img src="{staticServer}/mark-new/images/hp-close.png" /></a>\
  267. </div>';
  268. MarkHistory.prototype.paginator_dom = '<div class="c-page">\
  269. <a class="back" id="last-page-button" href="#"></a>\
  270. <a class="next" id="next-page-button" href="#"></a>\
  271. <span>前<i class="yellow" id="history-start"></i>-前<i class="yellow" id="history-end"></i></span>\
  272. </div>';
  273. MarkHistory.prototype.history_search_dom = '<div class="c-scbar cl">\
  274. <table id="history-search" cellpadding="0" cellspacing="0" width="100%">\
  275. <tr><td class="sc"><span><input type="text" placeholder="查找试卷" id="studentId-in" maxlength="10"/><em id="studentId-search"></em></span></td>\
  276. </tr></table></div>';
  277. MarkHistory.prototype.history_list_dom = '<div class="sublist"><div class="c-table">\
  278. <table class="table table-hover" cellpadding="0" cellspacing="0" width="100%">\
  279. <thead><tr><th id="studentId-sort-th">编号<em class="up" id="studentId-sort"></th>\
  280. <th id="time-sort-th">时间<em class="up" id="time-sort"></em></th><th id="score-sort-th">总分<em class="up" id="score-sort"></th></tr></thead>\
  281. <tbody class="loding" id="history-loading"><tr><td colspan="3"><div><img src="{staticServer}/mark-new/images/loding.gif"/></div><p>正在加载请稍候</p></td></tr></tbody>\
  282. <tbody id="history-list"></tbody></table></div></div>';
  283. MarkHistory.prototype.history_row_dom = '<tr><td class="history-secret-number"></td>\
  284. <td class="history-time"></td><td class="history-score"></td></tr>';