mark-board.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. //给分板模块
  2. var mark_board = function(option, success) {
  3. var object = new MarkBoard(option);
  4. success();
  5. return object;
  6. }
  7. function MarkBoard(option) {
  8. var self = this;
  9. this.markControl = option.markControl;
  10. this.needConfirm = option.needConfirm === true ? true : false;
  11. this.autoSubmit = option.autoSubmit === false ? false : true;
  12. this.showScoreBoard = option.showScoreBoard === false ? false : true;
  13. this.enableSkip = option.enableSkip === true ? true : false;
  14. this.init();
  15. this.markControl.on('task.get.before', this, function(event, context, eventObject) {
  16. this.task = undefined;
  17. this.stepList = undefined;
  18. this.currentStep = undefined;
  19. this.stepCount = undefined;
  20. this.render();
  21. });
  22. this.markControl.on('task.load.finish', this, function(event, context, eventObject) {
  23. this.initByTask(context.task);
  24. });
  25. this.markControl.on('history.submit.success', this, function(event, context, eventObject) {
  26. this.initByTask(context.task);
  27. });
  28. this.markControl.on('mark.focus.change', this, function(event, context, eventObject) {
  29. this.onFocusChange();
  30. });
  31. this.markControl.on('mark.step.change', this, this.onStepSelect);
  32. this.markControl.on('key.press', this, function(e, context, event) {
  33. var code = event.keyCode;
  34. //console.log('key press:' + code);
  35. if (this.currentStep != undefined && this.task != undefined) {
  36. if (code >= 48 && code <= 57) {
  37. this.onNumberInput(code - 48);
  38. event.preventDefault();
  39. return false;
  40. } else if (code >= 96 && code <= 105 && event.numLock) {
  41. this.onNumberInput(code - 96);
  42. event.preventDefault();
  43. return false;
  44. } else if (code == 46 || code == 110 || code == 190) {
  45. //小数点
  46. this.onDecimalInput();
  47. event.preventDefault();
  48. return false;
  49. } else if (code == 13 || code == 108) {
  50. //回车键
  51. if (this.currentStep.markFinish === true && this.task.markFinish === true) {
  52. this.onTaskSubmit();
  53. event.preventDefault();
  54. return false;
  55. } else {
  56. this.onNumberSubmit();
  57. event.preventDefault();
  58. return false;
  59. }
  60. }
  61. }
  62. });
  63. this.markControl.on('key.down', this, function(e, context, event) {
  64. var code = event.keyCode;
  65. //console.log('key down:' + code);
  66. if (this.currentStep != undefined && this.task != undefined) {
  67. if (code == 8 || code == 46) {
  68. //删除键&回退键
  69. this.onNumberDelete();
  70. event.preventDefault();
  71. return false;
  72. } else if (code == 32) {
  73. //屏蔽空格键按下效果
  74. return false;
  75. } else if (code == 80 && this.enableSkip) {
  76. //P键,跳过当前任务
  77. this.markControl.trigger('task.pass.success');
  78. }
  79. }
  80. });
  81. this.markControl.on('key.up', this, function(e, context, event) {
  82. var code = event.keyCode;
  83. console.log('key up:' + code);
  84. if (this.currentStep != undefined && this.task != undefined) {
  85. if (code == 32) {
  86. //空格键提交步骤分
  87. this.onNumberSubmit();
  88. event.preventDefault();
  89. return false;
  90. } else if (code == 37) {
  91. //←按键,切换到上一个步骤
  92. if (this.currentStep.number > 1) {
  93. this.resetCurrentStep();
  94. this.markControl.trigger('mark.step.change', this.currentStep.number - 1);
  95. event.preventDefault();
  96. return false;
  97. }
  98. } else if (code == 39) {
  99. //→按键,切换到下一个步骤
  100. if (this.currentStep.number < this.stepCount) {
  101. this.resetCurrentStep();
  102. this.markControl.trigger('mark.step.change', this.currentStep.number + 1);
  103. event.preventDefault();
  104. return false;
  105. }
  106. }
  107. }
  108. });
  109. this.markControl.on('mark.setting.init', this, function(event, context, setting) {
  110. var show = setting['score.board.show'];
  111. if (show != undefined && show == true) {
  112. self.showScoreBoard = true;
  113. }
  114. });
  115. }
  116. MarkBoard.prototype.init = function() {
  117. var self = this;
  118. this.stepBoard = getDom(this.step_board_dom, this.markControl).appendTo(this.markControl.container.centerContent);
  119. this.stepBoard.height(this.markControl.container.centerContent.height());
  120. this.stepBoard.selectiveHeader = this.stepBoard.find('#step-board-selective-header');
  121. this.stepBoard.stepHolder = this.stepBoard.find('.step-list');
  122. this.stepBoard.stepHolder.height(this.markControl.container.centerContent.height() - 120);
  123. this.stepBoard.stepHolder.css('overflow', 'scroll');
  124. //this.stepBoard.stepHolder.perfectScrollbar({
  125. // wheelSpeed: 20,
  126. // useKeyboard: false,
  127. // minScrollbarLength: 30,
  128. // suppressScrollX: true
  129. //});
  130. this.scoreBoard = getDom(this.scoreBoard_dom, this.markControl).appendTo(this.markControl.container);
  131. this.scoreBoard.header = getDom(this.scoreBoard_header_dom, this.markControl).appendTo(this.scoreBoard).find('#score-board-header');
  132. this.scoreBoard.stepHolder = getDom(this.scoreBoard_stepHolder_dom, this.markControl).appendTo(this.scoreBoard);
  133. this.scoreBoard.footer = getDom(this.scoreBoard_footer_dom, this.markControl).appendTo(this.scoreBoard).find('#score-board-total-score');
  134. this.scoreBoard.stepHolder.css('max-height', $(window).height() * 0.75);
  135. this.scoreBoard.stepHolder.css('overflow', 'scroll');
  136. this.scoreBoard.draggable({
  137. containment: "window"
  138. });
  139. this.scoreBoard.find('#task-submit-button').click(this, function(event) {
  140. var markBoard = event.data;
  141. if (markBoard.task != undefined && markBoard.currentStep.markFinish === true) {
  142. markBoard.onTaskSubmit();
  143. }
  144. });
  145. this.scoreBoard.find('#resetBtn').click(this, function(event) {
  146. var markBoard = event.data;
  147. var selectedBlockId = $(".block-id-list option:selected").val();
  148. if (markBoard.task != undefined) {
  149. if (markBoard.task.blockId == selectedBlockId) {
  150. alert("不能重新分发到同一题!");
  151. return false;
  152. } else if (selectedBlockId == 0) {
  153. alert("必须选择一题分发!");
  154. return false;
  155. } else {
  156. markBoard.task.reset = true;
  157. markBoard.task.blockId = selectedBlockId;
  158. markBoard.onTaskSubmit();
  159. }
  160. }
  161. });
  162. $('#resetBtn').click(this, function(event) {
  163. var markBoard = event.data;
  164. var selectedBlockId = $(".block-id-list option:selected").val();
  165. if (markBoard.task != undefined) {
  166. if (markBoard.task.blockId == selectedBlockId) {
  167. alert("不能重新分发到同一题!");
  168. return false;
  169. } else if (selectedBlockId == 0) {
  170. alert("必须选择一题分发!");
  171. return false;
  172. } else {
  173. markBoard.task.reset = true;
  174. markBoard.task.blockId = selectedBlockId;
  175. markBoard.onTaskSubmit();
  176. }
  177. }
  178. });
  179. if (this.enableSkip) {
  180. this.scoreBoard.find('#task-pass-button').show();
  181. this.scoreBoard.find('#task-pass-button').click(this, function(event) {
  182. var markBoard = event.data;
  183. markBoard.markControl.trigger('task.pass.success');
  184. });
  185. }
  186. this.scoreBoard.find('#score-board-close-button').click(this, function(event) {
  187. event.data.toggleScoreBoard(false);
  188. self.markControl.trigger('mark.setting.change', {
  189. 'score.board.show': false
  190. });
  191. });
  192. this.stepBoard.find('#show-score-board-button').click(this, function(event) {
  193. event.data.toggleScoreBoard(true);
  194. self.markControl.trigger('mark.setting.change', {
  195. 'score.board.show': true
  196. });
  197. });
  198. this.scoreBoard.find('.all-zero-button').click(this, function(event) {
  199. event.data.allZeroSubmit();
  200. });
  201. this.stepBoard.find('.all-zero-button').click(this, function(event) {
  202. event.data.allZeroSubmit();
  203. });
  204. this.popover = getDom(this.popover_dom, this.markControl).appendTo(this.markControl.container);
  205. this.popover.css('text-align', 'center');
  206. this.popover.title = this.popover.find('.popover-title');
  207. this.popover.title.css('font-size', '20px');
  208. this.popover.title.css('line-height', '25px');
  209. //this.popover.width('100');
  210. //this.popover.title.width('100');
  211. }
  212. MarkBoard.prototype.initByTask = function(task) {
  213. this.task = task;
  214. this.stepList = task.markStepList;
  215. this.currentStep = undefined;
  216. this.stepCount = this.stepList != undefined ? this.stepList.length : 0;
  217. task.totalScore = parseNumber(task.totalScore);
  218. var markFinish = true;
  219. var scoreList = task.scoreList != undefined && task.scoreList != '' ? task.scoreList.split(',') : [];
  220. for (var j in task.markStepList) {
  221. var step = task.markStepList[j];
  222. if (scoreList != undefined && scoreList.length > j) {
  223. step.markScore = parseNumber(scoreList[j]);
  224. step.score = new String(step.markScore);
  225. step.markFinish = true;
  226. } else {
  227. markFinish = false;
  228. }
  229. }
  230. task.markFinish = task.totalScore != undefined && markFinish == true;
  231. this.render(task);
  232. if (this.stepCount > 0) {
  233. this.markControl.trigger('mark.step.change', 1);
  234. } else if (task.markFinish == true) {
  235. this.currentStep = {
  236. markFinish: true
  237. };
  238. }
  239. }
  240. MarkBoard.prototype.onDecimalInput = function() {
  241. var score = this.currentStep.score;
  242. if ( !score.endWith('.')) {
  243. score = score + '.';
  244. }
  245. this.currentStep.score = score;
  246. this.currentStep.markFinish = false;
  247. this.onScoreChange();
  248. }
  249. MarkBoard.prototype.onNumberInput = function(number) {
  250. this.currentStep.score = this.currentStep.score + '' + number;
  251. this.currentStep.markFinish = false;
  252. this.onScoreChange();
  253. }
  254. MarkBoard.prototype.onNumberDelete = function(number) {
  255. var score = this.currentStep.score;
  256. if (score.length > 1) {
  257. score = score.substring(0, score.length - 1);
  258. } else {
  259. score = '';
  260. }
  261. this.currentStep.score = score;
  262. this.currentStep.markFinish = false;
  263. this.onScoreChange();
  264. }
  265. MarkBoard.prototype.onNumberSubmit = function() {
  266. var score = this.currentStep.score;
  267. var interval = this.currentStep.interval;
  268. if (score.length > 0) {
  269. if (interval < 1 && score.startWith('.')) {
  270. score = '0'.concat(score);
  271. } else if (interval < 1 && score.endWith('.')) {
  272. score = score.concat(interval.toString().substring(2));
  273. }
  274. }
  275. if (this.validateScore(this.currentStep, score)) {
  276. this.onScoreSubmit(true);
  277. } else if (this.showScoreBoard == true) {
  278. //分值表模式下,自动清除已输入的无效内容,免去删除操作
  279. this.resetCurrentStep();
  280. this.onScoreChange();
  281. }
  282. }
  283. //切换步骤时,重置当前步骤的状态
  284. //若当前分数未提交,则还原之前已给的分数;若之前还未给分,则清空分数显示
  285. MarkBoard.prototype.resetCurrentStep = function() {
  286. var step = this.currentStep;
  287. if (step != undefined) {
  288. if (step.markScore != undefined) {
  289. step.markFinish = true;
  290. step.score = new String(step.markScore);
  291. } else {
  292. step.markFinish = false;
  293. step.score = '';
  294. }
  295. this.markControl.trigger('mark.score.change');
  296. }
  297. }
  298. MarkBoard.prototype.onStepSelect = function(event, context, stepNumber) {
  299. if (stepNumber <= this.stepCount && stepNumber > 0) {
  300. //还是点击当前步骤,不触发任何动作
  301. if (this.currentStep != undefined && this.currentStep.number == stepNumber) {
  302. return;
  303. }
  304. //修改原step状态
  305. if (this.currentStep != undefined) {
  306. var dom = this.stepBoard.stepArray[this.currentStep.number - 1];
  307. dom.removeClass('current');
  308. if (this.currentStep.markScore != undefined) {
  309. dom.addClass('done');
  310. dom.find('.current-score').html(this.currentStep.markScore);
  311. } else {
  312. dom.addClass('todo');
  313. dom.find('.current-score').html('');
  314. }
  315. }
  316. this.togglePopover(false);
  317. this.currentStep = this.stepList[stepNumber - 1];
  318. if (this.currentStep.score == undefined || isNaN(this.currentStep.score)) {
  319. this.currentStep.score = '';
  320. }
  321. dom = this.stepBoard.stepArray[stepNumber - 1];
  322. dom.removeClass('done');
  323. dom.removeClass('todo');
  324. dom.addClass('current');
  325. //step列表自动滚动
  326. //alert(this.stepBoard.stepHolder.height() - dom.height());
  327. var scrollTop = this.stepBoard.stepHolder.scrollTop();
  328. var maxHeight = this.stepBoard.stepHolder.height();
  329. var domTop = dom.position().top;
  330. var domHeight = dom.height();
  331. if (domTop < 0 && scrollTop > 0) {
  332. scrollTop = Math.max(scrollTop - domHeight, 0);
  333. } else if ((domTop + domHeight) > maxHeight) {
  334. scrollTop += (domTop + domHeight - maxHeight + 5);
  335. }
  336. this.stepBoard.stepHolder.scrollTop(scrollTop);
  337. }
  338. }
  339. MarkBoard.prototype.onScoreChange = function() {
  340. if (this.currentStep != undefined) {
  341. var dom = this.stepBoard.stepArray[this.currentStep.number - 1];
  342. dom.find('.current-score').html(this.currentStep.score);
  343. this.togglePopover(false);
  344. }
  345. }
  346. MarkBoard.prototype.onScoreSubmit = function(autoNext) {
  347. if (this.currentStep != undefined) {
  348. this.currentStep.markScore = parseFloat(this.currentStep.score);
  349. this.currentStep.markFinish = true;
  350. this.onScoreChange();
  351. this.updateTotalScore();
  352. this.stepBoard.find('#total-score').html(this.task.totalScore);
  353. this.scoreBoard.footer.html(this.task.totalScore);
  354. var currentScore = this.currentStep.score;
  355. this.scoreBoard.stepArray[this.currentStep.number - 1].find('.score-select').each(function(index, obj) {
  356. if ($(obj).attr('data-score') == currentScore) {
  357. $(obj).addClass('active');
  358. } else {
  359. $(obj).removeClass('active');
  360. }
  361. });
  362. this.markControl.trigger('mark.score.change');
  363. if (autoNext === true && this.currentStep.number < this.stepCount) {
  364. this.markControl.trigger('mark.step.change', this.currentStep.number + 1);
  365. } else if (this.task.markFinish === true && this.showScoreBoard == false && this.autoSubmit === true) {
  366. this.onTaskSubmit();
  367. }
  368. }
  369. }
  370. MarkBoard.prototype.updateTotalScore = function() {
  371. if (this.task != undefined) {
  372. var totalScore = 0;
  373. var finish = true;
  374. for (var i in this.stepList) {
  375. if (this.stepList[i].markScore != undefined) {
  376. totalScore = numberAdd(totalScore, this.stepList[i].markScore);
  377. } else {
  378. finish = false;
  379. }
  380. }
  381. this.task.totalScore = totalScore;
  382. this.task.markFinish = finish;
  383. }
  384. }
  385. MarkBoard.prototype.allZeroSubmit = function() {
  386. if (this.task != undefined && this.stepList != undefined && this.stepList.length > 0) {
  387. for (var i in this.stepList) {
  388. this.stepList[i].markScore = 0;
  389. }
  390. for (var i in this.task.markStepList) {
  391. this.task.markStepList[i].markScore = 0;
  392. }
  393. this.onTaskSubmit();
  394. }
  395. }
  396. MarkBoard.prototype.onTaskSubmit = function() {
  397. var totalScore = 0;
  398. var scoreList = [];
  399. var finish = true;
  400. for (var i in this.stepList) {
  401. var score = this.stepList[i].markScore;
  402. if (score != undefined) {
  403. totalScore = numberAdd(totalScore, score);
  404. scoreList.push(score);
  405. } else {
  406. finish = false;
  407. }
  408. }
  409. if (this.task.reset) {
  410. finish = true;
  411. }
  412. if (!finish) {
  413. alert('当前任务还有未给分的步骤,请继续给分');
  414. } else if (!this.needConfirm || confirm('总分为' + totalScore + ', 确认要提交吗?')) {
  415. this.task.totalScore = totalScore;
  416. this.task.scoreList = scoreList.join(',');
  417. this.markControl.submitTask();
  418. }
  419. }
  420. MarkBoard.prototype.validateScore = function(step, scoreString) {
  421. var stepDom = this.stepBoard.stepArray[this.currentStep.number - 1].find('.current-score');
  422. if (!$.isNumeric(scoreString)) {
  423. this.togglePopover(true, '不是合法数字', stepDom);
  424. //alert('当前分数不是合法数字');
  425. return false;
  426. }
  427. var score = new Number(scoreString);
  428. if (score < step.min) {
  429. this.togglePopover(true, '不能小于' + step.min, stepDom);
  430. //alert('当前分数不应小于' + step.min);
  431. return false;
  432. }
  433. if (score > step.max) {
  434. this.togglePopover(true, '不能大于' + step.max, stepDom);
  435. //alert('当前分数不应大于' + step.max);
  436. return false;
  437. }
  438. var find = false;
  439. if (step.scoreList.length > 0) {
  440. for (var i in step.scoreList) {
  441. if (score == step.scoreList[i]) {
  442. find = true;
  443. }
  444. }
  445. }
  446. if (!find) {
  447. this.togglePopover(true, '不符合分值间隔要求', stepDom);
  448. //alert('当前分数不符合分值间隔要求');
  449. return false;
  450. }
  451. step.score = scoreString;
  452. return true;
  453. }
  454. MarkBoard.prototype.render = function(task) {
  455. if (task != undefined) {
  456. var self = this;
  457. var title = task.blockTitle;
  458. this.initMarkBoardHeader();
  459. this.stepBoard.stepHolder.empty();
  460. this.stepBoard.stepArray = [];
  461. if (task.markFinish === true) {
  462. this.stepBoard.find('#total-score').html(task.totalScore);
  463. this.scoreBoard.footer.html(task.totalScore);
  464. } else {
  465. this.stepBoard.find('#total-score').html('');
  466. this.scoreBoard.footer.html('');
  467. }
  468. this.scoreBoard.stepHolder.empty();
  469. this.scoreBoard.stepArray = [];
  470. for (var i in task.markStepList) {
  471. var step = task.markStepList[i];
  472. step.max = parseNumber(step.max);
  473. step.min = parseNumber(step.min);
  474. step.score = parseNumber(step.score);
  475. step.interval = parseNumber(step.interval);
  476. //初始化步骤列表
  477. var dom = getDom(this.step_dom, this.markControl);
  478. dom.attr('data-number', step.number);
  479. dom.find('.step-title').html(step.title);
  480. dom.find('.interval-score').html($.i18n.prop("mark.interval") + step.interval + $.i18n.prop("mark.score"));
  481. dom.find('.max-score').html(step.max);
  482. dom.find('.min-score').html(step.min);
  483. if (step.markFinish === true) {
  484. dom.addClass('done');
  485. dom.find('.current-score').html(step.score);
  486. } else {
  487. dom.addClass('todo');
  488. }
  489. dom.click(function() {
  490. self.onStepSelect(undefined, undefined, $(this).attr('data-number'));
  491. })
  492. this.stepBoard.stepArray.push(dom.appendTo(this.stepBoard.stepHolder));
  493. //初始化分值表
  494. var dom2 = getDom(this.scoreBoard_step_dom, this.markControl);
  495. dom2.attr('data-number', step.number);
  496. dom2.find('.number').html(step.title);
  497. var scoreHolder = dom2.find('.fraction');
  498. for (var j in step.scoreList) {
  499. step.scoreList[j] = parseNumber(step.scoreList[j]);
  500. var dom3 = getDom(this.scoreBoard_score_dom, this.markControl);
  501. var score = step.scoreList[j];
  502. dom3.attr('data-step-number', step.number);
  503. dom3.attr('data-score', score);
  504. dom3.html(score);
  505. dom3.appendTo(scoreHolder);
  506. if (step.markFinish === true && step.markScore == score) {
  507. dom3.addClass('active');
  508. }
  509. }
  510. this.scoreBoard.stepArray.push(dom2.appendTo(this.scoreBoard.stepHolder));
  511. }
  512. this.toggleScoreBoard(this.showScoreBoard);
  513. this.scoreBoard.find('.score-select').click(this, function(event) {
  514. var markBoard = event.data;
  515. if (markBoard.task != undefined) {
  516. var object = $(event.target);
  517. markBoard.markControl.trigger('mark.step.change', object.attr('data-step-number'));
  518. markBoard.currentStep.score = object.attr('data-score');
  519. markBoard.onScoreSubmit();
  520. }
  521. });
  522. this.stepBoard.stepHolder.scrollTop(0);
  523. } else {
  524. this.initMarkBoardHeader();
  525. this.stepBoard.stepHolder.empty();
  526. this.stepBoard.stepArray = [];
  527. this.stepBoard.find('#total-score').html('');
  528. this.stepBoard.hide();
  529. this.scoreBoard.stepHolder.empty();
  530. this.scoreBoard.stepArray = [];
  531. this.scoreBoard.hide();
  532. }
  533. }
  534. MarkBoard.prototype.initMarkBoardHeader = function() {
  535. var self = this;
  536. if (this.task == undefined) {
  537. this.stepBoard.selectiveHeader.hide();
  538. this.scoreBoard.header.html('');
  539. } else {
  540. var group = this.task.selectiveGroup;
  541. if (group != undefined) {
  542. this.scoreBoard.header.empty();
  543. var blockSelect = (this.scoreBoard.header).append(this.scoreBoard_selective_dom).find('select');
  544. blockSelect.append('<option value="0">无</option>');
  545. if (group.blockList != undefined) {
  546. for (var i = 0; i < group.blockList.length; i++) {
  547. var block = group.blockList[i];
  548. var selected = this.task.blockId == block.id ? 'selected' : '';
  549. blockSelect.append('<option value="' + block.id + '" ' + selected + '>' + block.title + '</option>');
  550. }
  551. }
  552. blockSelect.change(function() {
  553. self.onBlockChange($(this).val());
  554. });
  555. blockSelect = this.stepBoard.selectiveHeader.find('select');
  556. blockSelect.empty();
  557. blockSelect.append('<option value="0">无</option>');
  558. if (group.blockList != undefined) {
  559. for (var i = 0; i < group.blockList.length; i++) {
  560. var block = group.blockList[i];
  561. var selected = this.task.blockId == block.id ? 'selected' : '';
  562. blockSelect.append('<option value="' + block.id + '" ' + selected + '>' + block.title + '</option>');
  563. }
  564. }
  565. blockSelect.unbind();
  566. blockSelect.change(function() {
  567. self.onBlockChange($(this).val());
  568. });
  569. this.stepBoard.selectiveHeader.show();
  570. } else {
  571. this.stepBoard.selectiveHeader.hide();
  572. this.scoreBoard.header.html(this.task.blockTitle);
  573. }
  574. }
  575. }
  576. MarkBoard.prototype.toggleScoreBoard = function(show) {
  577. this.resetCurrentStep();
  578. if (show) {
  579. this.markControl.trigger('step.board.hide');
  580. this.showScoreBoard = true;
  581. this.scoreBoard.show();
  582. this.stepBoard.hide();
  583. } else {
  584. this.markControl.trigger('step.board.show');
  585. this.showScoreBoard = false;
  586. this.scoreBoard.hide();
  587. this.stepBoard.show();
  588. }
  589. }
  590. MarkBoard.prototype.onBlockChange = function(blockId) {
  591. if (this.task != undefined && this.task.selectiveGroup != undefined) {
  592. this.task.blockId = parseInt(blockId);
  593. this.task.totalScore = 0;
  594. this.task.scoreList = '';
  595. var block = undefined;
  596. for (var i = 0; i < this.task.selectiveGroup.blockList.length; i++) {
  597. if (this.task.blockId == this.task.selectiveGroup.blockList[i].id) {
  598. block = this.task.selectiveGroup.blockList[i];
  599. break;
  600. }
  601. }
  602. if (block != undefined) {
  603. this.task.markStepList = block.markStepList;
  604. } else {
  605. this.task.markStepList = [];
  606. }
  607. this.initByTask(this.task);
  608. }
  609. }
  610. MarkBoard.prototype.togglePopover = function(show, text, baseDom) {
  611. var popover = this.popover;
  612. if (show == true && baseDom != undefined) {
  613. //console.log(baseDom.offset().top + ',' + baseDom.offset().left);
  614. popover.offset({
  615. top: baseDom.offset().top + 20,
  616. left: baseDom.offset().left - popover.width()
  617. });
  618. popover.title.html(text);
  619. popover.show();
  620. //console.log(popover.offset().top + ',' + popover.offset().left);
  621. } else {
  622. popover.offset({
  623. top: 0,
  624. left: 0
  625. })
  626. popover.title.html('');
  627. popover.hide();
  628. }
  629. }
  630. MarkBoard.prototype.onFocusChange = function() {
  631. this.currentStep = null;
  632. }
  633. MarkBoard.prototype.step_board_dom = '<div class="span2 mark-steps" style="display:none"><div class="step-board">\
  634. <a href="#" class="header" id="show-score-board-button" data-i18n-text="mark.mouse"><< 鼠标给分</a>\
  635. <div class="sublist"><p class="fraction"><span data-i18n-text="mark.total.score">总分</span> <i id="total-score">5</i></p><div>\
  636. <a href="#" class="header all-zero-button" data-i18n-text="mark.score.zero">全零分</a>\
  637. <div class="step-list"></div>\
  638. </div></div>';
  639. MarkBoard.prototype.step_dom = '<div><div class="number">\
  640. <div class="title step-title"></div>\
  641. <div class="num current-score"></div></div>\
  642. <div class="score">\
  643. <div class="title interval-score"></div>\
  644. <div class="num min-score"></div>\
  645. <div class="icon">▲</div>\
  646. <div class="num max-score"></div>\
  647. </div></div>';
  648. MarkBoard.prototype.scoreBoard_dom = '<div class="score-board score-board-popover" style="display:none"></div>';
  649. MarkBoard.prototype.scoreBoard_header_dom = '<div class="header">\
  650. <p class="fl" id="score-board-header"></p>\
  651. <a class="header-close" id="score-board-close-button" href="#">\
  652. <i class="header-text" data-i18n-text="mark.keyboard">键盘给分 >></i></a>\
  653. </div>';
  654. MarkBoard.prototype.scoreBoard_stepHolder_dom = '<div class="content"></div>';
  655. MarkBoard.prototype.scoreBoard_step_dom = '<div class="sublist">\
  656. <p class="number"></p>\
  657. <p class="fraction"></p>\
  658. </div>';
  659. MarkBoard.prototype.scoreBoard_score_dom = '<a href="#" class="score-select"></a>';
  660. MarkBoard.prototype.scoreBoard_footer_dom = '<div class="footer">\
  661. <p class="font"><span data-i18n-text="mark.total.score.board">总分:</span><i class="yellow" id="score-board-total-score"></i></p>\
  662. <a id="task-submit-button" class="button" href="#" data-i18n-text="mark.submit">提 交</a>\
  663. <a class="button all-zero-button" href="##" data-i18n-text="mark.score.zero">全零分</a>\
  664. <a id="task-pass-button" class="button" href="#" style="display:none" data-i18n-text="mark.pass">跳 过</a>\
  665. </div>';
  666. MarkBoard.prototype.popover_dom = '<div class="popover left assistant">\
  667. <div class="arrow"></div>\
  668. <h3 class="popover-title"></h3></div>';
  669. MarkBoard.prototype.scoreBoard_selective_dom = '<i class="fl" data-i18n-text="mark.choose.result">选做结果</i>\
  670. <select class="block-id-list span1 mr-t"></select>';