mark-history.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.markControl.initMarkFunction();
  15. this.container.toggleButton = getDom(this.toggle_button_dom, this.markControl).appendTo(this.markControl.container.assistant.functionList);
  16. this.container.toggleButton.click(this, function(event) {
  17. event.data.toggle(true);
  18. });
  19. this.markControl.on('history.get.success', this, function(event, context, data) {
  20. var taskList = data.result;
  21. this.taskList = [];
  22. this.loading = false;
  23. this.container.list.empty();
  24. if(isArray(taskList) && taskList.length > 0) {
  25. this.taskList = taskList;
  26. for( var i in taskList) {
  27. var task = taskList[i];
  28. var row = getDom(this.history_row_dom, this.markControl).appendTo(this.container.list);
  29. row.find('.history-secret-number').html(task.studentId);
  30. var date = new Date();
  31. date.setTime(task.markTime);
  32. row.find('.history-time').html(date.format('hh:mm:ss'));
  33. row.find('.history-score').html(task.totalScore);
  34. row.attr('data-index', i);
  35. // 回评任务处理
  36. task.previous = true;
  37. // task.markFinish = true;
  38. // task.totalScore = parseFloat(task.totalScore);
  39. // var scoreList = task.scoreList != undefined ?
  40. // task.scoreList.split(',') : [];
  41. // for (var j in task.markStepList) {
  42. // var step = task.markStepList[j];
  43. // if (scoreList != undefined && scoreList.length > j) {
  44. // step.markScore = new Number(scoreList[j]);
  45. // step.score = new String(step.markScore);
  46. // step.markFinish = true;
  47. // }
  48. // }
  49. }
  50. }
  51. this.container.list.find('td').click(this, function(event) {
  52. var markHistory = event.data;
  53. var index = $(event.target).parent().attr('data-index');
  54. markHistory.onTaskSelect(index);
  55. });
  56. this.pageNumber = data.pageNumber;
  57. this.updateHeader();
  58. if(this.taskList.length > 0) {
  59. this.onTaskSelect(0);
  60. }
  61. });
  62. this.markControl.on('history.get.error', this, function(event, context, data) {
  63. alert('暂时无法读取评卷历史,请稍后重试');
  64. });
  65. this.markControl.on('task.submit.success', this, function(event, context, data) {
  66. if(this.enable) {
  67. this.toggle(false);
  68. }
  69. });
  70. this.markControl.on('task.get.success', this, function(event, context, data) {
  71. this.loading = false;
  72. });
  73. }
  74. MarkHistory.prototype.init = function() {
  75. this.container.empty();
  76. this.container.header = getDom(this.header_dom, this.markControl).appendTo(this.container);
  77. this.container.paginator = getDom(this.paginator_dom, this.markControl).appendTo(this.container);
  78. this.container.list = getDom(this.history_list_dom, this.markControl).appendTo(this.container).find('#history-list');
  79. var self = this;
  80. this.container.header.find('#close-history-button').click(this, function(event) {
  81. event.data.toggle(false);
  82. self.markControl.context.task = undefined;
  83. self.markControl.getTask();
  84. })
  85. this.container.paginator.find('#last-page-button').click(this, function(event) {
  86. var markHistory = event.data;
  87. markHistory.onSearch(markHistory.pageNumber + 1);
  88. });
  89. this.container.paginator.find('#next-page-button').click(this, function(event) {
  90. var markHistory = event.data;
  91. if(markHistory.pageNumber > 1) {
  92. markHistory.onSearch(markHistory.pageNumber - 1);
  93. }
  94. });
  95. }
  96. MarkHistory.prototype.toggle = function(enable) {
  97. this.enable = enable;
  98. if(enable) {
  99. this.init();
  100. this.pageNumber = 1;
  101. this.markControl.setTask(undefined);
  102. this.markControl.trigger('mark.sidebar.open');
  103. this.markControl.trigger('mark.history.open');
  104. this.updateHeader();
  105. this.container.list.empty();
  106. this.container.removeClass('hide');
  107. this.onSearch();
  108. } else {
  109. this.container.addClass('hide');
  110. this.markControl.trigger('mark.sidebar.close');
  111. this.markControl.trigger('mark.history.close');
  112. }
  113. }
  114. MarkHistory.prototype.updateHeader = function() {
  115. this.container.header.find('#history-start').html(this.pageSize * (this.pageNumber - 1));
  116. this.container.header.find('#history-end').html(this.pageSize * this.pageNumber);
  117. if(this.pageNumber == 1) {
  118. this.container.paginator.find('#next-page-label').show();
  119. this.container.paginator.find('#next-page-button').hide();
  120. } else {
  121. this.container.paginator.find('#next-page-label').hide();
  122. this.container.paginator.find('#next-page-button').show();
  123. }
  124. if(this.taskList.length < this.pageSize) {
  125. this.container.paginator.find('#last-page-label').show();
  126. this.container.paginator.find('#last-page-button').hide();
  127. } else {
  128. this.container.paginator.find('#last-page-label').hide();
  129. this.container.paginator.find('#last-page-button').show();
  130. }
  131. }
  132. MarkHistory.prototype.onSearch = function(pageNumber) {
  133. if(pageNumber == undefined || pageNumber < 1) {
  134. pageNumber = 1;
  135. }
  136. this.markControl.getHistory({
  137. pageNumber: pageNumber,
  138. pageSize: this.pageSize
  139. });
  140. }
  141. MarkHistory.prototype.onTaskSelect = function(index) {
  142. //初始化--特殊标识
  143. this.markControl.trigger('mark.specialTag.success');
  144. var number = new String(index);
  145. if(this.taskList != undefined && index < this.taskList.length && this.loading != true) {
  146. this.container.list.find('tr').each(function(index, obj) {
  147. if($(obj).attr('data-index') == number) {
  148. $(obj).addClass('active');
  149. } else {
  150. $(obj).removeClass('active');
  151. }
  152. });
  153. this.markControl.setTask(jQuery.extend(true, {}, this.taskList[index]));
  154. this.loading = true;
  155. }
  156. }
  157. MarkHistory.prototype.toggle_button_dom = '<a href="#">回评</a>';
  158. MarkHistory.prototype.header_dom = '<div class="header">\
  159. <p class="fl">前<i class="yellow" id="history-start"></i>-前<i class="yellow" id="history-end"></i></p>\
  160. <a href="#" id="close-history-button"><img src="{staticServer}/mark-new/images/hp-close.png"></a>\
  161. </div>';
  162. MarkHistory.prototype.paginator_dom = '<div class="m-pagination"><a id="last-page-button" href="#">上一页</a>\
  163. <i id="last-page-label">上一页</i>\
  164. <a id="next-page-button" href="#">下一页</a>\
  165. <i id="next-page-label">下一页</i></div>';
  166. MarkHistory.prototype.history_list_dom = '<div class="sublist"><table class="table table-hover">\
  167. <thead><tr><th>编号</th><th>时间</th><th>总分</th></tr></thead>\
  168. <tbody id="history-list"></tbody></table></div>';
  169. MarkHistory.prototype.history_row_dom = '<tr><td class="history-secret-number"></td>\
  170. <td class="history-time"></td><td class="history-score"></td></tr>';