idle-process.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //评卷状态模块
  2. var idle_process = function(option, success) {
  3. var object = new IdleProcess(option);
  4. success();
  5. return object;
  6. }
  7. function IdleProcess(option) {
  8. this.markControl = option.markControl;
  9. this.logoutUrl = option.logoutUrl;
  10. this.timeoutMinute = parseInt(option.timeout) != undefined ? parseInt(option.timeout) : 3;
  11. this.intervalSecond = 15;
  12. this.markControl.on('task.get.success', this, function(event, context, eventObject) {
  13. this.libraryId = context.task.libraryId;
  14. this.start = new Date().getTime();
  15. });
  16. this.process();
  17. }
  18. IdleProcess.prototype.process = function() {
  19. var self = this;
  20. if (this.lastLibraryId == undefined) {
  21. this.lastLibraryId = this.libraryId;
  22. }
  23. var now = new Date().getTime();
  24. if (this.lastLibraryId != undefined && this.libraryId != undefined && this.start != undefined) {
  25. if (this.lastLibraryId == this.libraryId) {
  26. if ((now - this.start) > (this.timeoutMinute * 60 * 1000)) {
  27. window.location.href = this.logoutUrl;
  28. }
  29. }
  30. }
  31. setTimeout(function() {
  32. self.process();
  33. }, self.intervalSecond * 1000);
  34. }